Add comments for anti-cogging

This commit is contained in:
Unknown
2017-10-31 22:21:21 -04:00
parent 63edce0150
commit f80eec37f1
2 changed files with 7 additions and 7 deletions
+4 -7
View File
@@ -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);
}
}
}
+3
View File
@@ -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){