mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-22 16:14:37 +08:00
Add comments for anti-cogging
This commit is contained in:
@@ -235,17 +235,14 @@ void motor_parse_cmd(uint8_t* buffer, int len, SerialPrintf_t response_interface
|
||||
if (numscan == 1) {
|
||||
print_monitoring(limit);
|
||||
}
|
||||
} else if (buffer[0] == 't') {
|
||||
//printf("Running anti-cogging.\n");
|
||||
} else if (buffer[0] == 't') { // Run Anti-Cogging Calibration
|
||||
for (int i = 0; i < num_motors; i++) {
|
||||
// Ensure the cogging map was correctly allocated earlier and that the motor is capable of calibrating
|
||||
if (motors[i].cogging_map != NULL && motors[i].error == ERROR_NO_ERROR) {
|
||||
//printf("Motor %d running\n",i);
|
||||
if (anti_cogging_calibration(&motors[i])) {
|
||||
printf("Motor %d Anti-Cogging Enabled\n", i);
|
||||
set_pos_setpoint(&motors[i], 0.0f, 0.0f, 0.0f);
|
||||
motors[i].use_anti_cogging = true;
|
||||
set_pos_setpoint(&motors[i], 0.0f, 0.0f, 0.0f); // Send the motor home
|
||||
motors[i].use_anti_cogging = true; // We're good to go, enable anti-cogging
|
||||
}
|
||||
//printf("Motor %d ERROR\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1256,6 +1256,9 @@ static void control_motor_loop(Motor_t* motor) {
|
||||
// Velocity control
|
||||
float Iq = motor->current_setpoint;
|
||||
|
||||
// Anti-cogging is enabled after calibration
|
||||
// We get the current position and apply a current feed-forward
|
||||
// ensuring that we handle negative encoder positions properly (-1 == ENCODER_CPR - 1)
|
||||
if(motor->use_anti_cogging){
|
||||
int32_t cogPos = (int32_t)motor->encoder.pll_pos % (int32_t)ENCODER_CPR;
|
||||
if(cogPos < 0){
|
||||
|
||||
Reference in New Issue
Block a user