Skip to content

Commit de2560f

Browse files
authored
Merge pull request #13 from bcmi-labs/refactor-Moving_Motors
Clean-up and refactor `examples`/`Moving_Motors`
2 parents 333a373 + 6857340 commit de2560f

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

examples/Moving_Motors/Moving_Motors.ino

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* This example demonstrates how to use the motor
2+
* API of the Braccio++ to directly control the
3+
* angle for each smart servo motor.
4+
*/
5+
6+
#include <Braccio++.h>
7+
8+
void setup()
9+
{
10+
Serial.begin(115200);
11+
while(!Serial){}
12+
13+
/* Call Braccio.begin() for default menu
14+
* or pass a function for custom menu.
15+
*/
16+
Braccio.begin();
17+
18+
Serial.println("Testing motor angular movement!");
19+
}
20+
21+
void loop()
22+
{
23+
Serial.println("Choose motor to test (1 - 6):");
24+
Serial.println(">> ");
25+
26+
while((Serial.available() <= 0)) { }
27+
int const selected_motor = Serial.parseInt();
28+
while(Serial.read() != '\n') { }
29+
30+
if (selected_motor < 1 || selected_motor > 6) {
31+
Serial.println("Error, wrong motor id, choose motor id between 1 and 6");
32+
return;
33+
}
34+
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+
}
48+
}

0 commit comments

Comments
 (0)