[[McComb 01-04 The Best Way to Start and Stop the McComb-Robot|👉 Next page]] # McComb 02-03 Controlling the Robot via Arduino The Arduino Uno first does not want to function. When connected to the computer, it produces an error. ![[als-thn-IMG_9436-arduino-on-usb-cable.jpg]] After reinstalling the Arduino IDE in our office on the first floor – where the internet is much more stable for now – everything works. ![[als-thn-IMG_9437-arduino-IDE-program-our-office.jpg]] So now we are able to implement the project's test code with a few changes to finally test the functionality of our Arduino: ```Cpp void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(250); } ``` Everything works fine. We just changed the time for the delay a little bit, because when we started up the Arduino, the light on its board was already flashing as if the same test program was already installed. To be able to tell the difference and to be sure that our program was written on the Arduino successfully, we made this little tweak to the program. Unfortunately, the codes for the McComb-Roboter which should be available here: - https://www.robotoid.com/make-bot are no longer available. So we have to work with typing the code once again and copying the parts that work from the manual. This also means that the code of the subproject "BatBotWander (partial only)," which is indeed printed only partially in our instructions, is not fully available to us. Is the website to be found elsewhere online? - Automaticaddison, whose tutorials we used among others to the work with Lidar and Jetson Nano, uses the instructions of McComb too: - https://automaticaddison.com/how-to-make-a-remote-controlled-robot-arduino/ - This is also interesting: - https://doc.lagout.org/science/0_Computer%20Science/8_Electronics%20%26%20Robotics/Robot%20Builders%20Source%20Book%20-%20Gordon%20McComb.pdf We will use code from the following tutorial that should work just fine, as Automaticaddison does refer to McComb here: - https://automaticaddison.com/how-to-make-an-obstacle-avoiding-robot-arduino/ For now we have copied the relevant codes for the Arduino from McComb's manual and are ready for testing the robot. ## Test 1: Basic movements The following code from McComb's manual should make our freshly assembled robot do basic movements: ```Cpp #include <Servo.h> Servo servoRight; Servo servoLeft; void setup() { servoRight.attach(9); servoLeft.attach(10); } void loop() { servoRight.write(0); // Fwd servoLeft.write(180); delay(2000); servoRight.write(180); // Rev servoLeft.write(0); delay(2000); servoRight.write(180); // Right servoLeft.write(180); delay(2000); servoRight.write(0); // Left servoLeft.write(0); delay(2000); } ``` The robot moves as expected: ![[McComb-Roboter_1-comp.mp4]] The only unusual thing is a drift of our robot to the right side. It may be necessary to calibrate the servos later on. This tendency to the right side might also be the effect of a hardware-problem: Maybe the servos are not well enough aligned to each other. Especially the right servo seems to be sitting a little more backwards than the left one. The left one also seems to be a little bit out of its axis. But on the other hand the robot seems to move in a straight line when moving forward and backwards, so this should be okay and may be connected to missing calibration of the servos. The robot is quite fast, so we have to be careful not to drive it above the edge of our table. ==Hint: It is better to first connect the grey wire for the AA-batteries to power the servos and only then to plug the barrel jack from the 9V battery into the Arduino.== Otherwise the robot runs away before the grey cable is properly in place, sometimes. As the basic program works, we try another one. ## Robot does TaiChi With this code from McComb's manual the robot should move a little bit different. ```Cpp #include <Servo.h> Servo servoRight; Servo servoLeft; void setup() { servoRight.attach(9); servoLeft.attach(10); } void loop() { goForward(); delay(2000); goReverse(); delay(2000); goRight(); delay(2000); goLeft(); delay(2000); allStop(); delay(2000); } // Motion Routines: forward, reverse, turn, stop void goForward() { servoRight.write(0); servoLeft.write(180); } void goReverse() { servoRight.write(180); servoLeft.write(0); } void goRight() { servoRight.write(180); servoLeft.write(180); } void goLeft() { servoRight.write(0); servoLeft.write(0); } void allStop() { servoRight.write(90); servoLeft.write(90); } ``` Uploading the code we receive an error-message: ``` avrdude: ser_open(): can't open device "/dev/cu.usbmodem141301": No such file or directory Fehlgeschlagenes Hochladen: Hochladefehler: exit status 1 ``` Trying one of the programs that worked before, we receive the same error message, so it is not the new program that triggers that. Restarting the IDE does not solve the problem. We followed the instructions from - https://support.arduino.cc/hc/en-us/articles/4401874331410--Error-avrdude-when-uploading and already the first hint worked: - we just selected the board again (our Arduino Uno) within the IDE So now we try again with the new code from above. No error this time. Hint: ==Always select the board when opening a new file with Arduino==. The robot starts to run, but when moving backwards, the cable of a servo motor winds up around a wheel and we have to shut down the first attempt hastily. We put some wire around the two cables of the servos holding them above ground to prevent such problems in the future. ![[als-thn-IMG_9439-servo-cables-put-together-with-wire.jpg]] We start once again. The program works. It becomes very obvious now that the servos need to be calibrated. When the robot should stand still according to its programming, it is still moving, so we now have evidence that the calibration is indeed necessary: ![[McComb-Roboter_2-comp.mp4]] Now we want to halt for a moment and summarise the [[McComb 01-04 The Best Way to Start and Stop the McComb-Robot|best way we have found so far off how to start and stop our robot]] when experimenting with it. --- [[McComb 01-04 The Best Way to Start and Stop the McComb-Robot|👉 Next page]] # Back to: [[McComb 01-02 Installing and Wiring Batteries, Motors and Arduino]]