mirror of
https://github.com/scottbez1/smartknob.git
synced 2025-11-04 17:19:40 +08:00
Add some basic bounds checking during calibration
This commit is contained in:
parent
3fdd9fa601
commit
08146e292d
@ -338,6 +338,7 @@ void MotorTask::calibrate() {
|
|||||||
// TODO: dig into SimpleFOC calibration and find/fix the issue
|
// TODO: dig into SimpleFOC calibration and find/fix the issue
|
||||||
|
|
||||||
log("\n\n\nStarting calibration, please DO NOT TOUCH MOTOR until complete!");
|
log("\n\n\nStarting calibration, please DO NOT TOUCH MOTOR until complete!");
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
motor.controller = MotionControlType::angle_openloop;
|
motor.controller = MotionControlType::angle_openloop;
|
||||||
motor.pole_pairs = 1;
|
motor.pole_pairs = 1;
|
||||||
@ -345,6 +346,9 @@ void MotorTask::calibrate() {
|
|||||||
|
|
||||||
float a = 0;
|
float a = 0;
|
||||||
|
|
||||||
|
motor.voltage_limit = FOC_VOLTAGE_LIMIT;
|
||||||
|
motor.move(a);
|
||||||
|
|
||||||
// #### Determine direction motor rotates relative to angle sensor
|
// #### Determine direction motor rotates relative to angle sensor
|
||||||
for (uint8_t i = 0; i < 200; i++) {
|
for (uint8_t i = 0; i < 200; i++) {
|
||||||
encoder.update();
|
encoder.update();
|
||||||
@ -371,7 +375,12 @@ void MotorTask::calibrate() {
|
|||||||
|
|
||||||
log("");
|
log("");
|
||||||
|
|
||||||
// TODO: check for no motor movement!
|
float movement_angle = fabsf(end_sensor - start_sensor);
|
||||||
|
if (movement_angle < radians(30) || movement_angle > radians(180)) {
|
||||||
|
snprintf(buf_, sizeof(buf_), "ERROR! Unexpected sensor change: start=%.2f end=%.2f", start_sensor, end_sensor);
|
||||||
|
log(buf_);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
log("Sensor measures positive for positive motor rotation:");
|
log("Sensor measures positive for positive motor rotation:");
|
||||||
if (end_sensor > start_sensor) {
|
if (end_sensor > start_sensor) {
|
||||||
@ -431,6 +440,12 @@ void MotorTask::calibrate() {
|
|||||||
snprintf(buf_, sizeof(buf_), "Electrical angle / mechanical angle (i.e. pole pairs) = %.2f", electrical_per_mechanical);
|
snprintf(buf_, sizeof(buf_), "Electrical angle / mechanical angle (i.e. pole pairs) = %.2f", electrical_per_mechanical);
|
||||||
log(buf_);
|
log(buf_);
|
||||||
|
|
||||||
|
if (electrical_per_mechanical < 3 || electrical_per_mechanical > 12) {
|
||||||
|
snprintf(buf_, sizeof(buf_), "ERROR! Unexpected calculated pole pairs: %.2f", electrical_per_mechanical);
|
||||||
|
log(buf_);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int measured_pole_pairs = (int)round(electrical_per_mechanical);
|
int measured_pole_pairs = (int)round(electrical_per_mechanical);
|
||||||
snprintf(buf_, sizeof(buf_), "Pole pairs set to %d", measured_pole_pairs);
|
snprintf(buf_, sizeof(buf_), "Pole pairs set to %d", measured_pole_pairs);
|
||||||
log(buf_);
|
log(buf_);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user