Skip to main content
Version: 2.2

Position Mode (High-Frequency Control)

Mode Principle and Applicable Scenarios

Position Mode does not have built-in trajectory planning. When a target position is input, the actuator will immediately rotate to the target position at a speed limited by the value specified in the message. This mode supports high-frequency control and is typically used for running trajectories, where the user is responsible for trajectory planning at the upper level and transmitting trajectory data at high frequency.

Parameter Configuration

  • Parameters affecting the trajectory: PID parameters for the current loop, velocity loop, and position loop. These values can be modified in real time, even with high-frequency messages. For modifying PID parameters, please refer to the PID parameter setting section.
  • Parameters affecting actuator execution results: current limit, speed limit, and target position. These values can be sent at high frequency.
  • For messages used to set the above parameters, please refer to the CAN2.0B communication protocol.

Example Code

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

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

# current_pid_set(motor, {0.006}, {0.001})
# velocity_pid_set(motor, {50}, {1.2})
# position_pid_set(motor, {0.008}, {0})

pi = 3.1415926536
d = 0.002
cycle = 20
num = 1
i = 0
while 1:
t = i * d
ang = pi * math.sin(2 * pi / cycle * t)
pos = ang / pi / 2 * 65536;
motor.write_position({10000}, {3000}, {pos});
i= i + 1

time.sleep(d)

if t >= cycle * num:
break

write_position(motor, limit_cur, limit_vel, {0})
time.sleep(3)

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;

// POSITION_MODE
cout << endl << "position mode" << endl;
motor.reset();
motor.mode_selection(Mode::POSITION_MODE, Feedback_cycle1, Feedback_cycle2, Feedback_cycle3);

// 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

#define pi 3.1415926536
double d = 0.002; // unit time
double cycle = 10; // Track cycle
size_t num = 1;
while (1)
{
static size_t i = 0;

double t = i * d;

double ang = pi * sinl(2 * pi / cycle * t);
int pos = ang / pi / 2 * 65536;

motor.write_position(10000, 3000, pos);

i++;
delay(d);

if (t >= cycle * num)
{
break;
}
}
motor.write_position(10000, 1515, 0);
delay(3);

#ifdef _WIN32
timeEndPeriod(1);
#endif
}