In this lab you will construct a motion model for your robot. This will involve selecting a mathematical representation, i.e. a discrete time equation that relates past states and control inputs to current states. The model construction will also require modeling the control input functions and their associated uncertainty.
The main goal of lab 02 is to characterize robot motion using mathematical equations, accounting for the motion uncertainty that can be modeled probabilistically. The corresponding sub goals required to meet the main goal for lab 02 includes:
Pick your floor
Tune your steering
Explore the code
Map encoder counts to distance
Map steering commands to rotational velocity
Motion Model Implementation
Motion Model Sampling
Report Writing
Video Recording
There are two deliverables for lab 02 which must be submitted on Brightspace.
Lab 02 Video - that documents at least 3 motion modeling trajectories.
Lab 02 Report - that documents subgoals 4, 5, 6, 7.
Find a good room and location where you think you can run experiments all semester. It should be large enough to drive your robot around in, and have a floor type you think will be the “standard” floor texture for most future labs.
Run the robot many times, tuning the servo center angle in the Arduino code and also tuning the steering rod attached to the servo to make your robot drive as straight as possible when the GUI sends a zero steering angle.
To facilitate lab 02, we have added some new code. The base code can be found on the ROB_GY_6213 repo. Please pull from this repo to your forked code base from lab 01. Note that the lab 2 repo won't have your individual IP addresses. You will have to copy those over to your lab 2 folder. Listed below are major changes to the code:
GUI Updates - When you launch the GUI, you will notice a new button. This button will be used to run repetitive trials. When clicked, the robot should drive forward with the speed and steering set by the sliders, and it will drive forward for the hard coded variable trial_time in milliseconds. The value for trial_time is set in the parameters.py file. Be careful when using the lab 2 version of the GUI. To make this work well for repeated trials, we have disabled the code that sets speed and steering to zero when they become disabled. However, this makes data collection MUCH faster.
Data Logging files - data is now logged in pickle files during each experimental trial. Each trial will have its own file, named according to the speed, steering, date, and time. E.g. './data/robot_data_60_10_28_01_26_13_14_14.pkl’. This file is provided as an example run where speed was 60, steering was 10, the date was Jan 28, 2026, and the time was 1:14pm and 14 seconds.
Data Handling file - there is a new file called data_handling.py that opens and plots data from the experiment trial files. You can edit this data_handling.py file as you see fit. Try using the different load and plot functions, e.g. with terminal command python3 data_handling.py
Motion Modeling file - There is a new file called motion_models.py where you can put your motion model. There exists some infrastructure for you, but you will need to add your own models. E.g. you will replace the dummy code in the my_motion_model() function in a later section of this lab.
Sample Data - If you look within the directory named /base_code_lab_02/robot_python_code/data_straight, you will find data files corresponding to several trials run by Prof. Clark.
In this section, we will first construct a function that maps encoder counts to distance travelled. Assume the following notation, where s is the distance travelled by the robot in meters, when the encoder has change counts by the integer value e.
s = f_{se}(e)
Step 1: There are several ways to construct this function, but we provide one approach here. First, use tape to mark a robot start position on the ground. You can use this start position for EVERY trial you run in this lab. You may consider taping down the X_G and Y_G axis of a coordinate system G with your start pose being at the origin, facing in the positive X_G direction.
For several trial durations, (e.g. 5, 10, 15, 20 seconds), drive the robot forward with zero steering angle command at some nominal speed. Note that different speeds may yield different levels of uncertainty, but we don’t have time to vary every parameter.
For each trial duration, place the robot at a start position and drive the robot forward. Repeat this trial 3 to 10 times. At the end of each trial, record the encoder counts (which are on the GUI screen and logged in your pickle files). Also measure and record the actual X_G, Y_G distances travelled for each trial with a ruler, AND the resulting yaw angle theta_G. We will assume that your steering is tuned so well that the robot drives approximately straight and the actual distance travelled s is sqrt( x_g^2 + y_g^2).
When these trials are done, you should have a data set which contains a list of [encoder count, distance travelled] tuples. Fit a linear(?) function f_{se}(e) to the data set. This line should go through the data point [0, 0]. Think about why.
On a single figure, plot the [encoder count, distance travelled] data set as distance travelled vs encoder count. Also plot the predicted distances from your f_{se}(e) function vs encoder counts.
Step 2: For each tuple in your data set, you can calculate the difference between the predicted distance from f_{se}(e) and the actual measured distance. If we assume this difference is the standard error, or sigma_s, we can fit a second function that maps encoder distance to sigma_s^2. This function may not be linear.
sigma_s^2 = f_{ss}(e)
On a single figure, plot the squared differences (between actual distance s and distance s predicted with f_{se}(e)) as a function of encoder counts. Then overplot the predicted sigma_s^2 values from f_{ss}(e) as a function of encoder counts.
In this section, you will make a mapping function from steering angle command \alpha to w, (yaw rate). As in section 4, run many trials - but this time with different steering command values, and potentially various speed value commands v. At the end of each trial, you can measure a final change in yaw \theta. Given the duration of the trial, you can calculate the yaw rate w for each steering servo angle. Hence you will have a data set with tuples of [steering angle command, trial time, final yaw angle, speed commanded].
Fit a function f_w() to the data set.
w = f_w( \alpha) or w = f_w( v)
Similar to section 3, construct a function that maps steering command \alpha to variance in w as well.
sigma_w^2 = f_{sw}(\alpha) or igma_w^2 = f_{sw}(v)
One possibility is that sigma_w^2 is constant!
You can decide what motion models you want to implement. Assume the basic structure, where x_t is the 3 element vector with elements [ x_G, y_G, theta_G ]:
x_t = f(x_{t-1}, u_t)
A simple approach might be to modify the unicycle model to input forward distance travelled s, and rotational velocity w. In that case the vector u_t would contain only the two elements s and w.
You can implement your model in the motion_models.py file, within the function my_motion_model(). Once your model is implemented, use the plot_trajs() function in the data_handling.py file to plot the motion model predicted trajectories of all your trials from Sections 4 and 5 above. Over plot the actual trial end point X_G,Y_G positions that you measured with a ruler or tape measure.
You may also want to plot a fancy trajectory by logging data while steering the robot around a curvy path. Maybe try closing a loop and see if the predicted trajectory loops back to the start position.
Simulate 100s of experiment trials using the sim_trial() function in the data logging file. Use different trial durations and steering commands. The sim_trial() function should call your motion model. In a single plot, overplot the trajectory final positions from all simulated trials. Do the distributions of the final positions of simulated trials stretch or skew as expected?
Write a formal report, using IEEE format as mentioned on the website lab schedule page. For this lab, be sure to include all plots mentioned above, and more plots if you think they are significant. Assume the reader knows about robotics, but that they are not familiar with our class. Sections should include:
Abstract - The section should provide an overview of the work. There should be a minimum of one sentence that informs the reader about the motivation, method, experiment, and results. Be sure to provide at least two significant quantifiable results from your results that a reader may find interesting.
Introduction - Use at least one paragraph to describe the motivation for motion modeling. Use a paragraph to provide an overview of each section of the paper. E.g. “The method section will describe mathematical details of the motion model developed, after which the experimental design section will detail how the model was validated.”.
Method - Describe your motion model with mathematical equations. Start with what is given to you - i.e. introduce the robot (with an image) and discuss the inputs to your motion model. Be sure to define all new variables in text. Equations should not have words, just greek letter variables with numbers and letter subscripts. Number all equations.
Experiment design - Use images, photos, figures to explain the experimental setup and how physical measurements were taken.
Experimental results - Show all your plots here. Discuss assumptions problems, successes, etc. Label all plots. Each plot should be referred to at least once in your text discussions.
Conclusion - Present a high level understanding of the performance of your motion model when predicting trajectories. Highlight uncertainty representations and your confidence in your function approximations. Mention efforts that could be taken in the future to improve modeling.
References - Cite key references. You may want to do a little research to cite key textbooks, motion models you found.
Record and submit one video of your robot while being steered along your “fancy” trajectory.
With time permitting, explore new possibilities, e.g.:
Try a different motion model equation structure
Repeat parts of section 4 and 5 on different terrain like ice, slippery floor, etc.