-
Notifications
You must be signed in to change notification settings - Fork 0
tuning and uploading the code
You will now install the Arduino application on your computer. Click on the the link for your operating system for instructions on how to do this.
https://www.arduino.cc/en/Guide/Windows#toc2 for Windows
https://www.arduino.cc/en/Guide/MacOSX#toc2 for MacOSX
Download the Arduino ‘sketch’ for the truck from the folder that these instructions are in (basic_go_baby_go_car_program_for_double_motors) and open it. Direct link to program: https://drive.google.com/open?id=0B2HJnUrZAwYrY1l5NWFHM1otYzA
When the sketch opens, save the sketch to your computer with File→ Save As.
Make sure that the truck is off. Plug one end of the USB cord into the port of the Arduino Nano microcontroller in the truck, and plug the other end of the USB cord into your computer.
Sniff for smoke; there shouldn’t be any!
Under the Tools menu of the Arduino application, click Board, and select Arduino Nano.
Look under the Tools menu again, and click Port. If there is only one available port, select it; Otherwise choose the bottom one.
In the Arduino application, upload the program by clicking Sketch→ Upload.
If the program doesn’t upload, and you saw more than one port, try a different one.
At the top of the code there are some values that need to be adjusted for your truck
Open the Serial monitor to see the information that the Arduino is sending, by going to the Tools menu and clicking Serial Monitor. If you don’t see scrolling text after a couple seconds, or if all you get is random symbols, the “baud rate” might not be set to 19200. Change the baud rate if necessary by selecting 19200 in the menu at the bottom right as shown in the picture below.
Figure 42
Push the joystick to the right (oriented as if you are sitting in the truck) as far as it goes, and enter the X joystick value (displayed in the serial monitor) for CONTROL_RIGHT.
Let the joystick center itself, and enter the X joystick value for CONTROL_CENTER_X.
Push the joystick to the left and enter the X joystick value for CONTROL_LEFT.
Push the joystick forward and enter the Y joystick value for CONTROL_UP.
Let the joystick center itself and enter the Y joystick value for CONTROL_CENTER_Y.
Push the joystick backward and enter the Y joystick value for CONTROL_DOWN.
Re-upload the program.
Unplug the Arduino, and turn on the truck! You should hear a couple of high-pitched beeps, a pause of a couple seconds, and then a lower pitched beep which tells you that the truck is ready to drive. Try driving the truck!
Four values change how long the truck takes to get to a new speed, either accelerating or decelerating (speeding up or slowing down). Each of the four values controls the rate of change of speed in a different situation. The values should be between around .05 (very slow acceleration) and around 3 (the motors can’t accelerate much faster). The values have to be positive.
variable | What happens if the number is larger | What happens if the number is smaller |
---|---|---|
ACCELERATION_FORWARD | The truck speeds up quickly when going forwards. | The truck speeds up slowly when going forwards. |
DECELERATION_FORWARD | The truck slows down quickly when going backwards. | The truck slows down slowly when going backwards. |
ACCELERATION_BACKWARD | The truck speeds up quickly when going backwards | The truck speeds up slowly when going backwards. |
DECELERATION_BACKWARD | The truck slows down quickly when going backwards. | The truck slows down slowly when going backwards. |
Change the acceleration/deceleration values by turning the truck off, plugging the Arduino in, and uploading the program. Then unplug the Arduino and turn the truck back on. See how the truck drives, and repeat the above steps as needed.
Change the next three values to change the speed of the truck. The range for FASTEST_FORWARD is 1500 (not moving at all) to 2000 (max speed), and this value changes how fast the truck can go in a forward direction.
The range for FASTEST_BACKWARD is 1500 (not moving at all) to 1000 (max speed), and this value changes how fast the truck can go in a backward direction.
The range for TURN_SPEED is 0 (not turning at all) to 1 (max speed), and this value changes how fast the truck spins in a circle.
The range for SLOW_TURNING_WHEN_MOVING is 0 (no turning allowed when moving forward) to 1 (as much turning when going forward as when stopped) and this value changes how much less to turn when moving forward or backward to help the truck make a smoother turn.
There are comments (grey text after “//” that don’t affect the code) in the program to explain what is happening. For more information on the commands used in this program or to go to the Arduino site see: https://www.arduino.cc/en/Reference/HomePage.