跳到主要内容
版本:1.1.0

C++

配置环境

  • Linux:
  1. 在终端依次执行以下命令(下载serial库):
git clone     https://github.com/wjwwood/serial.git
cd serial
mkdir build
cd build
cmake ..
make
sudo make install
  1. 在TA_CAN\C++\Linux\build路径下的终端中输入cmake..生成构建文件,再输入make生成可执行文件
  • Windows:
  1. 下载Visual Studio 并安装"使用C++的桌面开发"(案例:Visual Studio 2022)

  2. 安装CMake https://cmake.org/download/

  3. 开发工具(二选一):

  • Visual Studio Code:
  1. 在Developer Command Prompt for VS 2022中编译serial
cd <Project Path>\TA_CAN\C++\Windows\serial\build
cmake -G "Visual Studio 17 2022" ..
cmake --build . --config Release
  1. 将TA_CAN\C++\Windows\vs_code路径下CMakeLists.txt文件中的serial路径改为本地路径

  2. 在Developer Command Prompt for VS 2022t中编译可执行文件

cd <Project Path>\TA_CAN\C++\Windows\vs_code\build
cmake -G "Visual Studio 17 2022" ..
cmake --build . --config Release
  • Visual Studio 2022:
  1. 在Developer Command Prompt for VS 2022中编译serial
cd <Project Path>\TA_CAN\C++\Windows\serial\build
cmake -G "Visual Studio 17 2022" ..
cmake --build . --config Release
  1. 将TA_CAN\C++\Windows\vs\project路径下的CMakeLists.txt文件中的serial路径改为本地路径 配置必须为Release,如果选择Debug则需要重新编译serial

创建类对象

  • 单执行器

demo:

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)
  • 多执行器

demo:

#include <multi_motor_control.h>
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

修改类对象ID

  • 单执行器

motor.set_obhect_id(new_id);

demo: 修改ID为0x00

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.set_obhect_id(0x00);
}
  • 多执行器

motors.set_obhect_id(vector<uint8_t> new_id);

demo: 修改ID为0x00和0x01

#include <multi_motor_control.h>
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.set_obhect_id({0x00, 0x01});
}

复位

  • 单执行器

vector<int> result = motor.reset();

现象:执行器LED灯先变红后变蓝

返回序列号和更新日期

demo:

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.reset();
}
  • 多执行器

vector<vector<int>> result = motors.reset();

现象:执行器LED灯先变红后变蓝

返回序列号和更新日期

demo:

#include <multi_motor_control.h>
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.reset();
}

模式选择

  • 单执行器
motor.mode_selection(Mode::<b>Control mode</b>, Feedback cycle 1, Feedback cycle 2, Feedback cycle 3);

控制模式选择请参考控制模式

demo: 进入轮廓速度模式

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::PROFILE_VELOCITY_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
}
  • 多执行器
motors.mode_selection(Mode::<b>Control mode</b>, Feedback cycle 1, Feedback cycle 2, Feedback cycle 3);

控制模式选择请参考控制模式

demo: 进入轮廓速度模式

#include <multi_motor_control.h>
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::PROFILE_VELOCITY_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
}
  • 控制模式

异步模式

  • 单执行器
motor.mode_selection(Mode::ASYNC_MODE, xx, xx, xx)
motor.write_async(Duty value)

(执行器无异常时尽量不使用)

demo: 设置占空值为500

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::ASYNC_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
motor.write_async(500); // Params: duty values
}
  • 多执行器
motors.mode_selection(Mode::ASYNC_MODE, xx, xx, xx)
motors.write_async(vector<int16_t>Duty value)

(执行器无异常时尽量不使用) demo: 设置占空值为500

#include <multi_motor_control.h>
vector<int16_t>duty_values = { 500, 500};
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::ASYNC_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
motors.write_async(duty_values); // Params: vector of duty values
}

开环模式

  • 单执行器
motor.mode_selection(Mode::OPEN_LOOP_MODE, xx, xx, xx)
motor.write_open_loop(Duty value)

(执行器无异常时尽量不使用)

demo: 设置占空值为500

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::OPEN_LOOP_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
motor.write_open_loop(500); // Params: duty values
}
  • 多执行器
motors.mode_selection(Mode::OPEN_LOOP_MODE, xx, xx, xx)
motors.write_open_loop(vector<int16_t>Duty value)

(执行器无异常时尽量不使用)

demo: 设置占空值为500

#include <multi_motor_control.h>
vector<int16_t>duty_values = { 300, 300 };
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::OPEN_LOOP_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
motors.write_open_loop(duty_values); // Params: vector of duty values
}

电流模式

  • 单执行器
motor.mode_selection(Mode::CURRENT_MODE, xx, xx, xx);
motor.write_current(Target current);

demo: 将目标电流设置成500mA

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::CURRENT_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
motor.write_current(500); // Params: target current
}
  • 多执行器
motors.mode_selection(Mode::CURRENT_MODE, xx, xx, xx);
motors.write_current(vector<int16_t> Target current);

demo: 将目标电流设置成500mA

#include <multi_motor_control.h>
vector<int16_t>cur = { 500, 500 };
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::CURRENT_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
motors.write_current(cur); // Params: vector of target current
}

轮廓速度模式

  • 单执行器
motor.mode_selection(Mode::PROFILE_VELOCITY_MODE, xx, xx, xx)
motor.write_profile_velocity(Current limit, Target velocity)

demo: 将目标速度设置成500rpm

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::PROFILE_VELOCITY_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
motor.write_profile_velocity(2000, 500); // Params: current limit, target velocity
}
  • 多执行器
motors.mode_selection(Mode::PROFILE_VELOCITY_MODE, xx, xx, xx)
motors.write_profile_velocity(vector<int16_t>Current limit, vector<int16_t>Target velocity)

demo: 将目标速度设置成500rpm

#include <multi_motor_control.h>
vector<int16_t>cur = { 3000, 3000 };
vector<int16_t>vel = { 500, 500 };
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::PROFILE_VELOCITY_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
motors.write_profile_velocity(cur, vel); // Params: vector of current limit, vector of target velocity
}

轮廓位置模式

  • 单执行器
motor.mode_selection(Mode::PROFILE_POSITION_MODE, xx, xx, xx);
motor.write_profile_position(Current limit, Velocity limit, Target position);

demo: 将目标位置设置成360°

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::PROFILE_POSITION_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10); // Windows: Sleep(ms) Linux: sleep(s)
motor.write_profile_position(3000, 1000, 65535); // Params: current limit, velocity limit, target position
}

减速器端旋转一圈的值为16bits=65536

  • 多执行器
motors.mode_selection(Mode::PROFILE_POSITION_MODE, xx, xx, xx)
motors.write_profile_position(vector<int16_t>Current limit, vector<int16_t>Velocity limit, vector<int32_t>Target position)

demo: 将目标位置设置成360°

#include <multi_motor_control.h>
vector<int16_t>cur = { 3000, 3000 };
vector<int16_t>vel = { 1000, 1000 };
vector<int32_t>pos = { 65535, 65535 };
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::PROFILE_POSITION_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10); // Windows: Sleep(ms) Linux: sleep(s)
motors.write_profile_position(cur, vel, pos); // Params: vector of current limit, vector of velocity limit, vector of target position
}

减速器端旋转一圈的值为16bits=65536

位置模式

  • 单执行器
motor.mode_selection(Mode::POSITION_MODE, xx, xx, xx)
motor.write_position(Current limit, Velocity limit, Target position)

demo: 将目标位置设置成360°

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::POSITION_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10) ; // Windows: Sleep(ms) Linux: sleep(s)
motor.write_position(3000, 1000, 65535); // Params: current limit, velocity limit, target position
}

减速器端旋转一圈的值为16bits=65536

  • 多执行器
motors.mode_selection(Mode::POSITION_MODE, xx, xx, xx)
motors.write_position(vector<int16_t>Current limit, vector<int16_t>Velocity limit, vector<int32_t>Target position)

demo: 将目标位置设置成360°

#include <multi_motor_control.h>
vector<int16_t>cur = { 3000, 3000 };
vector<int16_t>vel = { 1000, 1000 };
vector<int32_t>pos = { 65535, 65535 };
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::POSITION_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10); // Windows: Sleep(ms) Linux: sleep(s)
motors.write_position(cur, vel, pos); // Params: vector of current limit, vector of velocity limit, vector of target position
}

减速器端旋转一圈的值为16bits=65536

MIT模式

  • 单执行器
motor.mode_selection(Mode::MIT_MODE, xx, xx, xx)
motor.write_mit(Target current, Target velocity, Target position, KP, KD)

demo 点到点(电流的大小应视情况而定)

目标速度为0,其他不为0 (电流为前馈转矩补偿)

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::MIT_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10); // Windows: Sleep(ms) Linux: sleep(s)
motor.write_mit(300, 0, 65535, 13.1, 10.0); // Params: target current, target velocity, target position, kp, kd
}

固定速度(电流的大小应视情况而定)

目标位置和KP为0,其他不为0 (电流为前馈转矩补偿)

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::MIT_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10); // Windows: Sleep(ms) Linux: sleep(s)
motor.write_mit(300, 500, 0, 0.0, 10.0); // Params: target current, target velocity, target position, kp, kd
}

固定扭矩

目标电流不为0,其他都为0

#include <motor_control.h>
string port_name = "COM27" // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::MIT_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10); // Windows: Sleep(ms) Linux: sleep(s)
motor.write_mit(500, 0, 0, 0.0, 0.0); // Params: target current, target velocity, target position, kp, kd
}
  • 多执行器
motors.mode_selection(Mode::MIT_MODE, xx, xx, xx)
motors.write_mit(vector<int16_t>target current, vector<int16_t>target velocity, vector<int16_t>target position, vector<float>KP, vector<float>KD)

demo: 点到点(电流的大小应视情况而定)

目标速度为0,其他不为0 (电流为前馈转矩补偿)

#include <multi_motor_control.h>
vector<int16_t>cur = { 300, 300 };
vector<int16_t>vel = { 0, 0 };
vector<int32_t>pos = { 65535, 65535 };
vector<float>kp = { 13.1, 13.1 };
vector<float>kd = { 10.0, 10.0 };
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::MIT_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10); // Windows: Sleep(ms) Linux: sleep(s)
motors.write_mit(cur, vel, pos, kp, kd); // Params: vector of target current, vector of target velocity, vector of target position,
// vector of kp, vector of kd
}

固定速度(电流的大小应视情况而定)

目标位置和KP为0,其他不为0 (电流为前馈转矩补偿)

#include <multi_motor_control.h>
vector<int16_t>cur = { 300, 300 };
vector<int16_t>vel = { 500, 500 };
vector<int32_t>pos = { 0, 0 };
vector<float>kp = { 0.0, 0.0 };
vector<float>kd = { 10.0, 10.0 };
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::MIT_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10); // Windows: Sleep(ms) Linux: sleep(s)
motors.write_mit(cur, vel, pos, kp, kd); // Params: vector of target current, vector of target velocity, vector of target position,
// vector of kp, vector of kd
}

固定扭矩

目标电流不为0,其他都为0

#include <multi_motor_control.h>
vector<int16_t>cur = { 500, 500 };
vector<int16_t>vel = { 0, 0 };
vector<int32_t>pos = { 0, 0 };
vector<float>kp = { 0.0, 0.0 };
//vector<float>kd = { 0.0, 0.0 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::MIT_MODE, 10, 10, 10); // Params: Mode::operation mode, feedback cycle 1, 2, 3
Sleep(10); // Windows: Sleep(ms) Linux: sleep(s)
motors.write_mit(cur, vel, pos, kp, kd); // Params: vector of target current, vector of target velocity, vector of target position,
// vector of kp, vector of kd
}

读取参数

  • 单执行器
MotorStatus status = motor.get_motor_status(header_types);

header_types: 0xB1, 0xB2, 0xB3

MotorStatus是用来存放执行器参数的结构体

读全部参数

读电压、PWM、电流和速度

读电机位置和执行器位置

读mos管温度、电机温度、G431芯片温度、警告类型和错误类型

  • 多执行器
vector<MultiMotorStatus> all_motor_status = motors.get_motor_status(vector<uint8_t>header_types);

header_types: 0xB1, 0xB2, 0xB3

MultiMotorStatus是用来存放执行器参数的结构体

读全部参数

读电压、PWM、电流和速度

读电机位置和执行器位置

读mos管温度、电机温度、G431芯片温度、警告类型和错误类型

其他功能

  • 单执行器

刹车、修改开环模式加减速度、修改profile速度加减速度、修改电流pid、修改速度pid、修改位置pid

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.brake_control(-2000, 500); // Params: pwm, durations
motor.write_openloop_acc_dec(2000, 2000); // Params: acceleration, deceleration
motor.write_velocity_acc_dec(2000, 2000); // Params: acceleration, deceleration
motor.write_current_pid(0.001, 0.001); // Params: KP, KI
motor.write_velocity_pid(0.001, 0.001); // Params: KP, KI
motor.write_position_pid(0.001, 0.001); // Params: KP, KD
}

实时修改轮廓速度的加速度和减速度

#include <motor_control.h>
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MotorControl motor(port_name, 921600, 0x01); // Params: serial port path (string), baud rate (uint32_t), actuator id (0x05060100)

int main()
{
motor.mode_selection(Mode::PROFILE_VELOCITY_MODE, 10, 10, 10);
while (1)
{
static int16_t i = 0;
i += 100;
motor.write_velocity_acc_dec(i, i);
cout << i << endl;
if (i >= 1000)
{
break;
}
motor.write_profile_velocity(3000, 1000);
Sleep(4000);
motor.write_profile_velocity(3000, 0);
Sleep(3000);
}
}
  • 多执行器

刹车、修改开环模式加减速度、修改profile速度加减速度、修改电流pid、修改速度pid、修改位置pid

#include <multi_motor_control.h>
vector<int16_t>pwm = { 2000, 2000 };
vector<uint16_t>dur = { 500, 500 };
vector<int16_t>acc_ = { 2000, 2000 };
vector<int16_t>dec_ = { 2000, 2000 };
vector<float>kps = { 0.001, 0.001 };
vector<float>kis = { 0.001, 0.001 };
vector<float>kds = { 0.001, 0.001 };
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.brake_control(pwm, dur); // Params: vector of pwm, vector of durations
motors.write_openloop_acc_dec(acc_, dec_); // Params: vector of acceleration, vector of deceleration
motors.write_velocity_acc_dec(acc_, dec_); // Params: vector of acceleration, vector of deceleration
motors.write_current_pid(kps, kis); // Params: vector of KP, vector of KI
motors.write_velocity_pid(kps, kis); // Params: vector of KP, vector of KI
motors.write_position_pid(kps, kds); // Params: vector of KP, vector of KD

实时修改轮廓速度的加速度和减速度

#include <multi_motor_control.h>
vector<int16_t>cur = { 3000, 3000 };
vector<int16_t>vel = { 1000, 1000 };
vector<int16_t>vel_0 = { 0, 0 };
vector<uint8_t>ids = { 0x01, 0x17 };
string port_name = "COM27"; // Windows: "COM*" Linux: "/dev/ttyUSB*"
MultiMotorControl motors(port_name, 921600, ids); // Params: serial port path (string), baud rate (uint32_t), actuator ids (0x05060100, 0x05061700)

int main()
{
motors.mode_selection(Mode::PROFILE_VELOCITY_MODE, 10, 10, 10);
Sleep(100);
while (1)
{
static int16_t i = 0;
i += 100;
vector<int16_t> acc_dec = { i, i };
motors.write_velocity_acc_dec(acc_dec, acc_dec);
cout << i << endl;
if (i >= 1000)
{
break;
}
motors.write_profile_velocity(cur, vel);
Sleep(4000);
motors.write_profile_velocity(cur, vel_0);
Sleep(3000);
}
}