Skip to content

Commit 4e7f6cd

Browse files
committed
Fixing issue that CR is interpreted as a integer.
As a result immediately following a connection attempts with the desired motor number a connection with an invalid motor id (0) is attempted which results in a communication failure and a lot of non relevant serial output.
1 parent cfda43e commit 4e7f6cd

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
#include "Braccio++.h"
22

3-
int selected_motor = 0;
4-
5-
void setup() {
3+
void setup()
4+
{
65
Serial.begin(115200);
7-
while(!Serial){}
8-
Serial.println("Testing the motor communication!");
6+
while(!Serial) { }
7+
98
Braccio.begin();
9+
Serial.println("Testing motor communication!");
10+
Serial.println("Choose motor 1 to 6 to test the connection");
11+
Serial.print(">> ");
1012
}
1113

12-
void loop() {
13-
Serial.println("Choose the motor 1 to 6 to test the connection:");
14-
while((Serial.available() <= 0)){};
15-
int motorID = Serial.parseInt();
14+
void loop()
15+
{
16+
while(Serial.available() <= 0) { }
17+
int const motorID = Serial.parseInt();
18+
while(Serial.read() != '\n') { }
19+
20+
if (motorID < 1 || motorID > 6) {
21+
Serial.println("Error, wrong motor id, choose value between 1 and 6");
22+
Serial.print(">> ");
23+
return;
24+
}
1625

17-
bool connected = (Braccio.connected(motorID));
18-
if (connected)
26+
if (Braccio.connected(motorID))
1927
Serial.println("Communcation with motor " + String(motorID) + " successful");
2028
else
2129
Serial.println("Communcation failure - Please check the motor " + String(motorID) + " connection");
22-
Serial.println();
30+
31+
Serial.print(">> ");
2332
}

0 commit comments

Comments
 (0)