The goals of lab 01 are to the build your robot and connect to it with your computer so you can enable computer control of the robot. The subgoals of lab 01 include:
Robot chasis construction
Wifi router setup
Fork the base code
Arduino software upload & testing
GUI Control
The key deliverable for lab 01 is to be submitted on Brightspace, one submission per team, (from any team member):
Lab 01 Video - illustrating command and control of the robot via the gui. It should be similar to Prof. Clark's video in step 8 of section 5 below.
The robot chassis is purchased from Osoyoo, which has its own instructions (link here), that we modify. There are several key differences between Osoyoo's construction set and ares, they are listed here:
Arduino - we replace the raspberry pi with an Arduino Giga R1
Arduino Wifi Shield -
Encoders - we replace one of the motors with a motor+encoder combination.
Lidar - we will add a top plate and lidar, but this step won't be done until a later lab.
We have taken the instruction videos from Osoyoo and editted them to account for these differences.
Step 1: Chasis construction up until motor install, (see video below). NOTE: At the 2:30 minute mark of the video, you will see that motors are being attached. For the RIGHT motor, use an encoder motor (that comes seperately from the main car kit) instead of the non-encoder motor that comes with the kit. The Step 2 image emphasises this motor configuration.
Step 2: Be sure you have two different types of motors (one with encoder, one without) as shown in the image below.
Step 3: Chasis construction up until circuit board attachment. NOTE: At the 15:30 minute mark of the video, you should use an Arduino Giga R1 instead of a Raspberry Pi board.
Step 4: Attach wires to the power board as shown in the image below. This includes:
a. Power to the left motor (red, black wires leading from motor to white adapter.) These appear in the left middle side of board in image below.
b. Power to the right motor (red, black wires leading from motor to white adapter.) These appear in the right middle side of board in image below.
c. Power out cable (pink, white wires connected to white adapter). These appear in bottom left of image below. They will connect to the Arduino wifi shield later.
d. Motor control cable (black, purple, green, yellow, white red in white adapter). These appear in bottom right of image below. They will connect to the Arduino wifi shield later.
Step 4: Finish attaching the Arduinio Giga R1 board to the top layer. Note that you will need to attach the Arduino's antenna that should be in the box. Be careful, it is small and easy to lose. Also, it is difficult to bend the antenna adapter when attaching it. A good Arduino Forum post suggests:
There is a trick to get this antennas on, don't push it flat down.
Angle it at 45 degrees and then push rotate it to 0 degrees, they go on easy as anything.
Step 5: Complete the second layer of the robot chassis, (see video below). The video below ends just before the attachment of a red raspberry pi wifi shield. Instead we will add an Arduino shield - to be done in step 6.
Step 6: Insert the Arduino Wifi Shield to the top of the Arduino board so alignment is as shown in the image below, (note the robot chassis is not shown).. Be sure to make sure ALL pins are aligned between the two boards before pushing down on the wifi shield. It is easy to bend the pins.
Step 7: Attach two rows of male-male header pins to the digital inputs of the Arduino shield as shown in the configuration below, (note the robot chassis is not shown). You may have to cut the headers to be of lengths 8 pins and 10 pins.
Step 8: Attach the second layer of the robot chassis, (see video below). Ignore all the wiring shown in this video. We will do our own version of wiring in Step 9.
Step 9: Complete wiring as in figures below. This includes adding the interfaces for:
The steering servo
The motor encoder
Later we will add the lidar wiring.
In the figure below, you can see a top down view of the Arduino Giga R1 and shield. We call the two rows of adapters the Left and Right rails
Wiring for the left rail is provided in the image below:
Wiring for the right rail is provided in the image below:
Note 1: The servo motor wires need to be hooked up to jumper wires that came in the chassis kit. You may need to use the male-to-male pin adapters to use them.
Your robot kit should come with a standard wifi router, i.e. a TP-Link AC1200 WiFi Router, (see image below). You can plug it in anywhere, but you will need to obtain its name and password (usually printed on a sticker on the bottom or back of the router.) You will need the router name and password for both your laptop computer AND the arduino setup.
When you plug in the router, attempt to connect to router with the router's name and password. You will need to be connected to the router when running the robot. Please make a note of your computer's IP address, (e.g. on a mac laptop go to "Wifi settings", select "Details" of the wifi you are connected to, scroll down to find the IP address).
The basecode for lab 01 is located in a github repository (link here). Then follow the steps below to download the code:
Step 1: If you don't have one, make yourself a github account.
Step 2: Make a copy of the course basecode repository in your github account. This is called "forking" the code. Simply press the fork button on the course repository page. Double check the "Owner" for the new forked repository is your user name. Then click the green "Create Fork" button.
Step 3: Now that you have your own version (which you can track, change, update, etc.), create a "clone" of your fork of the base code on your computer. To do this, open your forked repository, click the green "Code" button, and copy the http address shown to your clipboard. Next, in a terminal on your laptop computer, navigate to a directory where you want to put a copy of the repository. Then, type the following, replacing the http address with the one copied from your clipboard.
% git clone https://github.com/cmclarkk/NYU_ROB_GY_6213.git
Step 4: Investigate the code in the directory created. You should see two main folders, one for the arduino code that will run on the robot (named arduino_robot_code), and one folder for the python code that will run on your laptop computer (named python_robot_code).
Step 1: Before we start downloading and running code, we will protect the robot. First beach it as shown below, (the camera box works well). This way if powered on the robot can't run wild. This is good practice when testing ALL new software and hardware.
Step 2: Detach the steering rod from the servo motor as shown below. This is just in case your servo motor is not rotated to a good angle and will try to break the steering rod when Arduino code is launched.
Step 3: Download the Arduino software to your computer using the official Arduino site (link here).
Step 4: Navigate your base_code_lab_01 code in the ROB-GY 6213 repository and open the sketch named robot_arduino_code.ino. You must edit the sketch to allow the board to connect to the wifi router. The lines of code below should be modified accordingly, using information collected while setting up the wifi router.
char ssid[] = "TP-Link_7BD6"; // REPLACE with your team's router ssid
char pass[] = "15124654"; // REPLACE with your team's router password
char remoteIP[] = "192.168.0.192"; // REPLACE with your laptop's IP address on your team's router
Step 5: Connect your laptop to the Arduino with a USB cable and upload the sketch to the Arduino Giga R1 on the robot. You will need to set the board type and port for your sketch before you can upload. Hopefully the robot arduino is running code, (but the robot motors aren't spinning).
Note 1: You also may need some additional library installs, e.g. under Tools->Board Manager, set yourself up for the Mbed OS Giga boards:
Note 2: If you are using linux, you will need some specific commands as well to connect to the board, e.g. for OS Ubuntu 24.04:
1) Install additional Mbed OS Giga Boards Library (as discussed in Note 1)
2) Add my user to dialout group (i.e., sudo usermod -a -G dialout $USER)
3) Run post-install script provided from library (e.g., sudo ~/.arduino15/packages/arduino/hardware/mbed_giga/4.5.0/post_install.sh)
Step 6: Before you can drive your robot, you may need to update the center angle of the steering servo motor, defined as steering_angle_center on line 43 of the arduino sketch. Prof. Clark's robot had the value 75, but it might be different for each robot.
To determine what value to set here, test out a few different values by hardcoding the signal sent to the servo on line 287 of the sketch, to see which one makes the servo arm stand in a vertical position as shown in the image above. E.g. if you want to see if 76 is a better center angle, rewrite line 287 to be myServo.write(76);
Once you have a good center angle, edit line 43 with the center angle, put line 287 to what it was, upload the code and double check the servo arm moves to a vertical position. If it does, you can re-attach the steering rod to the servo arm.
Now that we have the robot hardware and software set up, we can try to drive the robot around using the Graphical User Interface (GUI). There are three things to check are working with the GUI, that you should take video evidence of and submit on Brightspace before the lab deadline:
Steering control
Forward speed control
Wheel encoder measurement updates
To run the GUI, and all associated code, follow these steps (the video below may help visualize):
Step 1: Make sure the robot is still beached for now.
Step 2: Be sure the wifi router is plugged in.
Step 3: Turn on the robot with a charged battery.
Step 4: Connect your laptop to the wifi router.
Step 5: In a terminal on your laptop computer, use cd to navigate to the "/base_code_lab_01/robot_python_code" folder of your local version of the repository.
Step 6: Edit lines 5 and 6 of the file "/base_code_lab_01/robot_python_code/ parameters.py" to have the correct ip addresses.
Step 7: Run the gui python script from a terminal with the following instructions:
% python3 robot_gui.py
You should see a GUI screen pop up in your web browser. From there you can:
a) Enable steering, and use the slider to steer the robot.
b) Enable speed, and use the slider to drive the robot forward.
c) Check the encoder counts change as the robot. drives foward. They may count down instead of up, but that is OK.
Note 1: The center screen grid will be empty until we add the lidar in lab 04.
Note 2: In thevideo below, the inset video of the robot wheels moving is NOT part of the gui. It is movie making magic only. Later you can add in camera feeds (lab 03).
Step 8: One last calibration step to consider: the scaling of each drive motors output values. The encoder motor has different gearing than the other motor. On line 165 of the Arduino Sketch, you can see a magic 0.75 scaling number used to match the two speeds of each motor. You can beach the robot and drive it with different scaling numbers to achieve equal speed from each motor if you want.