2.12/2.120 Intro to Robotics
Spring 20241
Table of Contents
We have already written most of the code for this lab. We hope that you will use the extra free time to fully understand the mobile robot codebase and prepare for the final competition. Have a great spring break!
Take some time to understand robot_main.cpp
, robot_drive.cpp
, robot_motion_control.cpp
, and robot_wireless.cpp
. At a high level:
robot_main.cpp
: Includes thesetup()
andloop()
functions, telling the microcontroller exactly what to do and when.robot_drive.cpp
: Sets up the motors and implements a PI controller to follow velocity setpoints.robot_motion_control.cpp
: Calculates odometry and setpoints based on either joystick or a given trajectory.robot_wireless.cpp
: Sets up two-way wireless communication with and sends messages to the microcontroller on your controller.
Open robot_motion_control.cpp
and read through updateOdometry()
. Make sure that you understand exactly how this function calculates odometry data. For reference:
Make sure your PlatformIO environment is set to be env:robot
and upload the code to the microcontroller on your mobile robot. Once the code has finished uploading, unplug the robot from your computer, set it on the ground, power it on, and press RST
. Your robot should now autonomously follow a U-Turn!
Your U-Turn will probably not be perfect! While odometry is straightforward to implement, it suffers from problems such as position drift due to wheel slippage. IMU data (or some combination of IMU and odometry) will likely be more reliable.
In robot_motion_control.cpp
, comment out #define UTURN
and uncomment #define CIRCLE
. This will change the followTrajectory()
function to follow a circle instead of a U-Turn. Your robot should now autonomously follow a circle!
In order to establish wireless communication, we first have to make sure that both microcontrollers know each other's MAC addresses.
Run lib/Wireless/examples/get_mac.cpp
(you will have to temporarily move the existing files inside the src/robot/
folder and replace them with get_mac.cpp
). Open lib/Wireless/wireless.h
and change robotAddr
to the MAC address being printed to the Serial monitor.
Connect to the microcontroller on your controller and change your PlatformIO environment to be env:controller
.
Forget how to change environments?
Please refer to the instructions from Lab 6.
Run lib/Wireless/examples/get_mac.cpp
(you will have to temporarily move the existing files inside the src/controller/
folder and replace them with get_mac.cpp
). Open lib/Wireless/wireless.h
and change controllerAddr
to this MAC address.
Run src/test_controller/controller_test.cpp
. You should see joystick readings being printed to your Serial monitor.
Upload controller_main.cpp
and controller_wireless.cpp
to the microcontroller on your controller. This will read the joystick and set up two-way wireless communication with the microcontroller on the mobile robot.
In robot_motion_control.cpp
, comment out #define CIRCLE
and uncomment #define JOYSTICK
. This will change the followTrajectory()
function to follow a joystick instead of a circle.
Set your PlatformIO environment back to env:robot
. Upload robot_main.cpp
, robot_drive.cpp
, robot_motion_control.cpp
, and robot_wireless.cpp
to the microcontroller on your mobile robot. At this point, you should be able to drive your mobile robot around with your joystick!
✅ CHECKOFF 1 ✅ |
---|
Show your mobile robot in action to a TA or LA. |
In robot_motion_control.cpp
, comment out #define JOYSTICK
and uncomment #define YOUR_TRAJECTORY
. In the followTrajectory()
function, make your own path using a state machine, taking UTURN
as inspiration.
✅ CHECKOFF 2 ✅ |
---|
Show your mobile robot in action to a TA or LA. |
Before you leave, please fill out https://tinyurl.com/212-feedback.
✅ CHECKOFF 3 ✅ |
---|
Show the feedback form completion screen to a TA or LA. |
Integrate the IMU with your mobile robot! This will probably be very useful for your final project.
Replace the existing wheels with mecanum wheels! Mecanum wheels allow the robot to move in any direction. However, the odometry and controller will be slightly different.
Footnotes
-
Version 1 - 2016: Peter Yu, Ryan Fish and Kamal Youcef-Toumi
Version 2 - 2017: Yingnan Cui and Kamal Youcef-Toumi
Version 3 - 2019: Jerry Ng
Version 4 - 2023: Joseph Ntaimo, Kentaro Barhydt, Ravi Tejwani, Kamal Youcef-Toumi and Harrison Chin
Version 5 - 2024: Jinger Chong, Josh Sohn ↩