Skip to content

Commit 41e920c

Browse files
committed
Fix: Do not stop calibration flow if a certain servo can not reach the target.
1 parent 8ceec57 commit 41e920c

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

examples/Tools/Factory_Set_Initial_Servo_Position/Factory_Set_Initial_Servo_Position.ino

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,21 @@ bool set_initial_servo_position(int const id, float const target_angle)
8282
Serial.println(msg);
8383
}
8484

85-
if (!isTargetAngleReached(EPSILON)) {
86-
Serial.println("Servo did not reach target angle.");
85+
if (!isTargetAngleReached(EPSILON))
86+
{
87+
Serial.print("Error: Servo ");
88+
Serial.print(id);
89+
Serial.print(" did not reach target angle.");
90+
Serial.println();
8791
return false;
8892
}
8993

90-
if (isTimeout()) {
91-
Serial.println("Timeout error.");
94+
if (isTimeout())
95+
{
96+
Serial.print("Error: Servo ");
97+
Serial.print(id);
98+
Serial.println(" did not reach target angle within time limit.");
99+
Serial.println();
92100
return false;
93101
}
94102

@@ -111,22 +119,32 @@ void setup()
111119

112120
Braccio.disengage();
113121

122+
int success_cnt = 0;
114123
for (auto & servo : INITIAL_SERVO_POSITION)
115124
{
116125
Serial.print("Servo ");
117126
Serial.print(servo.id());
118127
Serial.print(": Target Angle = ");
119128
Serial.print(servo.angle());
120-
Serial.print(" °");
121129
Serial.println();
122130

123-
if (!set_initial_servo_position(servo.id(), servo.angle())) {
124-
Serial.println("ERROR.");
125-
return;
126-
}
131+
if (set_initial_servo_position(servo.id(), servo.angle()))
132+
success_cnt++;
127133
}
128134

129-
Serial.println("SUCCESS : all servos are set to their initial position.");
135+
if (success_cnt != (SmartServoClass::NUM_MOTORS - 1))
136+
{
137+
Serial.println("SUCCESS : all servos are set to their initial position.");
138+
}
139+
else
140+
{
141+
Serial.print("ERROR: only ");
142+
Serial.print(success_cnt);
143+
Serial.print(" of ");
144+
Serial.print(SmartServoClass::NUM_MOTORS);
145+
Serial.print(" could be set to the desired initial position.");
146+
Serial.println();
147+
}
130148
}
131149

132150
void loop()

0 commit comments

Comments
 (0)