3
3
* angle for each smart servo motor.
4
4
*/
5
5
6
+ /* *************************************************************************************
7
+ * INCLUDE
8
+ **************************************************************************************/
9
+
6
10
#include < Braccio++.h>
7
11
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
+
8
53
void setup ()
9
54
{
10
55
Serial.begin (115200 );
11
56
while (!Serial){}
12
57
13
- /* Call Braccio.begin() for default menu
14
- * or pass a function for custom menu.
15
- */
16
58
Braccio.begin ();
17
-
18
59
Serial.println (" Testing motor angular movement!" );
19
60
}
20
61
@@ -24,25 +65,13 @@ void loop()
24
65
Serial.println (" >> " );
25
66
26
67
while ((Serial.available () <= 0 )) { }
27
- int const selected_motor = Serial.parseInt ();
68
+ int const motor_id = Serial.parseInt ();
28
69
while (Serial.read () != ' \n ' ) { }
29
70
30
- if (selected_motor < 1 || selected_motor > 6 ) {
71
+ if (motor_id < 1 || motor_id > 6 ) {
31
72
Serial.println (" Error, wrong motor id, choose motor id between 1 and 6" );
32
73
return ;
33
74
}
34
75
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);
48
77
}
0 commit comments