From 4e7f6cd6de74c617219f14e01498282c9bf6b24a Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 09:28:00 +0100 Subject: [PATCH 1/6] 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. --- .../Testing_communications.ino | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/Testing_communications/Testing_communications.ino b/examples/Testing_communications/Testing_communications.ino index 72b4b7b..fd6c01d 100644 --- a/examples/Testing_communications/Testing_communications.ino +++ b/examples/Testing_communications/Testing_communications.ino @@ -1,23 +1,32 @@ #include "Braccio++.h" -int selected_motor = 0; - -void setup() { +void setup() +{ Serial.begin(115200); - while(!Serial){} - Serial.println("Testing the motor communication!"); + while(!Serial) { } + Braccio.begin(); + Serial.println("Testing motor communication!"); + Serial.println("Choose motor 1 to 6 to test the connection"); + Serial.print(">> "); } -void loop() { - Serial.println("Choose the motor 1 to 6 to test the connection:"); - while((Serial.available() <= 0)){}; - int motorID = Serial.parseInt(); +void loop() +{ + while(Serial.available() <= 0) { } + int const motorID = Serial.parseInt(); + while(Serial.read() != '\n') { } + + if (motorID < 1 || motorID > 6) { + Serial.println("Error, wrong motor id, choose value between 1 and 6"); + Serial.print(">> "); + return; + } - bool connected = (Braccio.connected(motorID)); - if (connected) + if (Braccio.connected(motorID)) Serial.println("Communcation with motor " + String(motorID) + " successful"); else Serial.println("Communcation failure - Please check the motor " + String(motorID) + " connection"); - Serial.println(); + + Serial.print(">> "); } From 75f2b2dc0075833c524d55a1a2e25cc640a43254 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 09:28:31 +0100 Subject: [PATCH 2/6] Fixing type in 'communication'. --- examples/Testing_communications/Testing_communications.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Testing_communications/Testing_communications.ino b/examples/Testing_communications/Testing_communications.ino index fd6c01d..1964642 100644 --- a/examples/Testing_communications/Testing_communications.ino +++ b/examples/Testing_communications/Testing_communications.ino @@ -24,9 +24,9 @@ void loop() } if (Braccio.connected(motorID)) - Serial.println("Communcation with motor " + String(motorID) + " successful"); + Serial.println("Communication with motor " + String(motorID) + " successful"); else - Serial.println("Communcation failure - Please check the motor " + String(motorID) + " connection"); + Serial.println("Communication failure - Please check the motor " + String(motorID) + " connection"); Serial.print(">> "); } From 752722c53bc202a4c596fa1d98bcd8742c34b334 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 09:30:25 +0100 Subject: [PATCH 3/6] Move example Testing_communication into 'Tools' subfolder. Reasoning: It's not really a relevant example to demonstrate library usage but rather a utililty/testing tool in case something breaks. --- .../{ => Tools}/Testing_communications/Testing_communications.ino | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{ => Tools}/Testing_communications/Testing_communications.ino (100%) diff --git a/examples/Testing_communications/Testing_communications.ino b/examples/Tools/Testing_communications/Testing_communications.ino similarity index 100% rename from examples/Testing_communications/Testing_communications.ino rename to examples/Tools/Testing_communications/Testing_communications.ino From 656831d1c494489b4bca3c0cf974467e3919148d Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 09:36:40 +0100 Subject: [PATCH 4/6] Rename 'Testing_communications' to 'Test_Motor_Communications' to make it fully clear what this sketch is actually about. --- .../Test_Motor_Communication.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/Tools/{Testing_communications/Testing_communications.ino => Test_Motor_Communication/Test_Motor_Communication.ino} (100%) diff --git a/examples/Tools/Testing_communications/Testing_communications.ino b/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino similarity index 100% rename from examples/Tools/Testing_communications/Testing_communications.ino rename to examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino From 663d543e1105d87b78d2b3e2f6d86540c802186e Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 09:45:19 +0100 Subject: [PATCH 5/6] Describing the purpose of the 'Test_Motor_Communication' sketch in a comment at the beginning of the file. --- .../Test_Motor_Communication/Test_Motor_Communication.ino | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino b/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino index 1964642..dbb6c37 100644 --- a/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino +++ b/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino @@ -1,3 +1,8 @@ +/* This example allows a user to test if communication + * can be established with a motor which can be selected + * via inputting the desired number in the serial monitor. + */ + #include "Braccio++.h" void setup() From 376721061877ec995274666c7b3ec5bd431c2829 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 09:47:30 +0100 Subject: [PATCH 6/6] Replacing " with <> for including Braccio++ library file. --- .../Tools/Test_Motor_Communication/Test_Motor_Communication.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino b/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino index dbb6c37..5e7972b 100644 --- a/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino +++ b/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino @@ -3,7 +3,7 @@ * via inputting the desired number in the serial monitor. */ -#include "Braccio++.h" +#include void setup() {