跳到主要内容
版本:2.2

轮廓位置模式(大角度控制)

模式原理

轮廓位置模式内置了轨迹规划的功能,输入目标位置之后执行器将自己规划出一条平滑的轨迹,并按照该轨迹旋转,直到达到目标位置。在到达上一个目标位置之前,执行器将忽略接收到的其它控制报文。这个模式适合大角度的控制,但是并不支持高频的控制指令。

参数配置

  • 影响到轨迹的参数有:速度模式加减速度值,电流环、速度环和位置环的pid参数值,这些值都支持实时更改,即使用报文高频更改,pid参数修改请参考PID参数设置
  • 影响到执行器执行结果的参数有:限制电流值,限制速度值,目标位置值,这些值只能在上一个目标位置已经到达之后才能更改
  • 有关设置以上参数的报文,请参考CAN2.0B 通信协议

示例代码

Python:

from motor_control import *

# port_name: Windows: "COM*" Linux: "/dev/ttyUSB*"
# id: Executor ID
# Baudrate: The baud rate can only be 921600
port_name = "COM6"
id = [0x00]
Baudrate = 921600
motor = MotorControl(port_name, id, Baudrate)

# Feedback_cycle1(ms): Feedback period of the first status packet,
# Including voltage, pwm, current, speed
# Feedback_cycle2(ms):Feedback period of the second status packet,
# Including the position of the motor and the position of the actuator
# Feedback_cycle3(ms):Feedback period of the third status packet,
# Including MOS tube, motor temperature, chip temperature and warning information,
# error information, operation mode
# cur: current(mA)
Feedback_cycle1 = 10
Feedback_cycle2 = 10
Feedback_cycle3 = 10

# PROFILE_POSITION_MODE
# limit_cur(mA): limit current
# limit_vel(rpm): the limit velocity of motor
# pos(count): target position, With a 16-bit encoder, the actuator counts 65536 per revolution.
limit_cur = [10000]
limit_vel = [1000]
pos = [20000]
reset(motor)
time.sleep(0.6)
mode_selection(motor, PROFILE_POSITION_MODE, Feedback_cycle1, Feedback_cycle2, Feedback_cycle3)
time.sleep(1)

# velocity_acc_dec_set(motor, {2000}, {2000})
# current_pid_set(motor, {0.0006}, {0.0001})
# velocity_pid_set(motor, {50}, {1.2})
# position_pid_set(motor, {0.008}, {0})

write_profile_position(motor, limit_cur, limit_vel, pos)
time.sleep(5)
position = get_pos(motor)[0][-1] # return the content of the second status packet
write_profile_position(motor, limit_cur, limit_vel, {0})
time.sleep(5)

c++:

#include <motor_control.h>
#include <multi_motor_control.h>
#include <iostream>
#include <thread>
#include <chrono>

#ifdef _WIN32
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
#endif

#define delay(s) std::this_thread::sleep_for(std::chrono::milliseconds((int32_t)(s*1000)))

int main()
{
#ifdef _WIN32
timeBeginPeriod(1);
#endif

#define status_packet1 0xb1
#define status_packet2 0xb2
#define status_packet3 0xb3

// port_name: Windows: "COM*" Linux: "/dev/ttyUSB*"
// id: Executor ID
// Baudrate: The baud rate can only be 921600
string port_name = "COM6";
uint32_t Baudrate = 921600;
uint8_t id = 0x00;
MotorControl motor(port_name, Baudrate, id);

// Feedback_cycle1(ms): Feedback period of the first status packet,
// Including voltage, pwm, current, speed
// Feedback_cycle2(ms):Feedback period of the second status packet,
// Including the position of the motor and the position of the actuator
// Feedback_cycle3(ms):Feedback period of the third status packet,
// Including MOS tube, motor, chip temperature and warning information,
// error information, current operation mode
// cur: current(mA)
uint8_t Feedback_cycle1 = 10;
uint8_t Feedback_cycle2 = 10;
uint8_t Feedback_cycle3 = 10;

// PROFILE_POSITION_MODE
// cur(mA): limit current
// vel(rpm): the limit velocity of motor
// pos(count): target position, With a 16-bit encoder, the actuator counts 65536 per revolution.
cur = 10000;
vel = 1000;
int32_t pos = 20000;

motor.reset();
delay(0.6);
motor.mode_selection(Mode::PROFILE_POSITION_MODE, Feedback_cycle1, Feedback_cycle2, Feedback_cycle3);
delay(0.6);

// motor.write_velocity_acc_dec(2000, 2000); // Params: acceleration, deceleration
// motor.write_current_pid(0.006, 0.001); // Params: KP, KI
// motor.write_velocity_pid(50, 1.2); // Params: KP, KI
// motor.write_position_pid(0.008, 0); // Params: KP, KD

motor.write_profile_position(cur, vel, 0);
delay(2);
motor.write_profile_position(cur, vel, pos);

cout << endl << "profile position mode" << endl;
printf("target_position: %d\n", pos);
delay(5);
MotorStatus status = motor.get_motor_status({status_packet1,status_packet2,status_packet3});
printf("position: %d\n", status.actuator_position_value);

motor.write_profile_position(cur, vel, 0);
delay(3);

#ifdef _WIN32
timeEndPeriod(1);
#endif
}