Skip to main content
Version: Next

Profile Velocity Mode

Mode Principle

Profile Velocity Mode controls the rotation speed of the actuator. This mode has built-in velocity planning. When a target speed is set, the actuator will accelerate or decelerate to that target speed according to the specified acceleration/deceleration values. The resulting speed curve is trapezoidal.

Parameter Configuration

  • Parameters affecting the velocity trajectory: acceleration and deceleration values in velocity mode, and the kp and ki values of the current and velocity loops. For setting methods, please refer to PID parameter setting.
  • Parameters affecting actuator execution results: current limit and target speed.
  • All of the above parameters can be modified in real time. For messages used to set these parameters, please refer to the CAN2.0B communication protocol.

Example Code

(1)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_VELOCITY_MODE
# limit_cur(mA): limit current
# vel(rpm): target velocity of motor
limit_cur = [10000]
vel = [1000]

reset(motor)
time.sleep(0.6)
mode_selection(motor, PROFILE_VELOCITY_MODE, Feedback_cycle1, Feedback_cycle2, Feedback_cycle3)
time.sleep(1)

# velocity_acc_dec_set(motor, {2000}, {2000})
# current_pid_set(motor, {0.006}, {0.001})
# velocity_pid_set(motor, {50}, {1.2})

write_profile_velocity(motor, limit_cur, vel)
time.sleep(2)
velocity = get_v_p_c_v(motor)[0][-1] # return the content of the first status packet
write_profile_velocity(motor, limit_cur, {0})
time.sleep(2)

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_VELOCITY_MODE
// cur(mA): limit current
// vel(rpm): target velocity of motor
cur = 10000;
int16_t vel = 500;

motor.reset();
motor.mode_selection(Mode::PROFILE_VELOCITY_MODE, Feedback_cycle1, Feedback_cycle2, Feedback_cycle3);

// 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_profile_velocity(cur, vel);

cout << endl << "profile velocity mode" << endl;
printf("target_velocity: %d\n", vel);
delay(2);
MotorStatus status = motor.get_motor_status({status_packet1,status_packet2,status_packet3});
printf("velocity: %d\n", status.velocity_value);

motor.write_profile_velocity(cur, 0);
delay(1);

#ifdef _WIN32
timeEndPeriod(1);
#endif
}