Skip to content

Commit 500419c

Browse files
committed
Revamping example to steer every servo through the full range of motion.
1 parent fd8b8ea commit 500419c

File tree

1 file changed

+48
-19
lines changed

1 file changed

+48
-19
lines changed

examples/Tools/Test_Motor_Angular_Control/Test_Motor_Angular_Control.ino

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,59 @@
33
* angle for each smart servo motor.
44
*/
55

6+
/**************************************************************************************
7+
* INCLUDE
8+
**************************************************************************************/
9+
610
#include <Braccio++.h>
711

12+
/**************************************************************************************
13+
* FUNCTIONS
14+
**************************************************************************************/
15+
16+
void test_motor(int const id)
17+
{
18+
Serial.print("Connecting ..... ");
19+
for (; !Braccio.get(id).connected(); delay(10)) { }
20+
Serial.println("OK.");
21+
delay(500);
22+
23+
Serial.print("Disengaging .... ");
24+
Braccio.get(id).disengage();
25+
Serial.println("OK.");
26+
delay(500);
27+
28+
Serial.print("Engaging ....... ");
29+
Braccio.get(id).engage();
30+
Serial.println("OK.");
31+
delay(500);
32+
33+
Serial.print("Drive to start . ");
34+
Braccio.get(id).move().to(0.0f).in(1s);
35+
Serial.println("OK.");
36+
delay(1500);
37+
38+
for (float target_angle = 0.0f; target_angle < 315.0f; target_angle += 1.0f)
39+
{
40+
Braccio.get(id).move().to(target_angle).in(200ms);
41+
delay(250);
42+
43+
char msg[64] = {0};
44+
snprintf(msg, sizeof(msg), "Angle (Target | Current) = %.2f | %.2f", target_angle, Braccio.get(id).position());
45+
Serial.println(msg);
46+
}
47+
}
48+
49+
/**************************************************************************************
50+
* SETUP/LOOP
51+
**************************************************************************************/
52+
853
void setup()
954
{
1055
Serial.begin(115200);
1156
while(!Serial){}
1257

13-
/* Call Braccio.begin() for default menu
14-
* or pass a function for custom menu.
15-
*/
1658
Braccio.begin();
17-
1859
Serial.println("Testing motor angular movement!");
1960
}
2061

@@ -24,25 +65,13 @@ void loop()
2465
Serial.println(">> ");
2566

2667
while((Serial.available() <= 0)) { }
27-
int const selected_motor = Serial.parseInt();
68+
int const motor_id = Serial.parseInt();
2869
while(Serial.read() != '\n') { }
2970

30-
if (selected_motor < 1 || selected_motor > 6) {
71+
if (motor_id < 1 || motor_id > 6) {
3172
Serial.println("Error, wrong motor id, choose motor id between 1 and 6");
3273
return;
3374
}
3475

35-
float const ANGLE_START = 0.0;
36-
float const ANGLE_STOP = 180.0;
37-
float const ANGLE_INCREMENT = 10.0;
38-
39-
for (float angle = ANGLE_START; angle <= ANGLE_STOP; angle += ANGLE_INCREMENT)
40-
{
41-
Braccio.move(selected_motor).to(angle);
42-
Serial.print("Target angle: " + String(angle));
43-
Serial.print(" | ");
44-
Serial.print("Current angle: " + String(Braccio.get(selected_motor).position()));
45-
Serial.println();
46-
delay(100);
47-
}
76+
test_motor(motor_id);
4877
}

0 commit comments

Comments
 (0)