Estimating Drive Velocity with Sphero RVR Using MATLAB
Summary
This teaching activity primarily allows students to write a program to collect position data from the rover robots and process them in MATLAB using the Sphero toolbox. They will evaluate the actual distance traveled and the velocity of the rover robots. The students will need to have already set up and connected to their robots previously to be able to successfully perform the activity within the allocated time.
Learning Goals
- Using RVR (rover) robots and MATLAB Sphero Toolbox, students will be able to collaborate with teams in order to:
- Understand how duty-cycle of the motors in the rover robots relates to the actual drive speed.
- Model the rover drive speed using position/distance data collected and plotted in MATLAB.
- Evaluate and present the mathematical relationship between distance and velocity in MATLAB.
Context for Use
EF 230 - Computer Solutions of Engineering Problems (2 credit hours) is a sophomore course for engineering majors offered at UTK. The primary focus is on developing computer programs in a modern programming language (MATLAB) to solve engineering problems. This is a lab-based course in a flipped classroom setting, therefore most of the class will be spent working through problems in small groups. Before each class, students will be responsible for working through Pre-lab Assignments to prepare for the lab. During class time, they will apply those skills to work through practice problems, with the assistance of their peers and TAs. The in-class labs usually run for 75 minutes. This teaching activity is designed to be completed within the class duration by teams of six students. Moreover, this activity is a primer for the final course requirement wherein student teams create prototype solutions to engineering problems by programming rover robots using MATLAB.
Description and Teaching Materials
See the instructions below for students:
Part 1: Determine getPosition() units and upload the resulting plot
1. Run a trial with the RVR driving in a straight line along a tape measure to determine the units of getPosition(). Select a speed between 60 and 110.
2. Here is an example plot created from running C3PO at a drive speed of 60:
3. Based on the distance traveled, determine getPosition() units. (most nearly feet, meters, inches, or centimeters?).
Download script: rvr_collect.m (Matlab File 1kB Oct27 24)
4. Edit the m-file header to fill in the blanks. Save your plot as a png and upload it to the Dropbox.
Part 2: Collect Data to determine the actual velocity for different setDriveSpeed() values
The Duty Cycle and pulsed-width-modulation
Duty cycle is the fractional or percentage on-time of a digital signal. A square wave with a 50% duty cycle is on 50% of the period, 30% duty cycle is on 30% of the time, etc.
The RVR's motors are driven with Pulse Width Modulation, or PWM, to vary the duty cycle. It effectively scales the voltage applied to the motor. Row motor values range between 0 and 255 (because a byte has 8 bits 2^8). A raw motor command of 255 provides 100% duty cycle PWM, 127 is ~ 50% duty cycle, 63 is ~ 25%, etc. Therefore, the units on drive speed input are proportional to but not the same as Velocity units.
Note: In practice, a drive speed of less than 60 is not adequate for a motion on the RVR. Although our original toolbox allowed for a drive speed of 255, to mitigate broken equipment, this semester a speed limiter of 110 has now been built into the toolbox.
We know that drive speed units are proportional to but not the same as Velocity units. We can use the diff to calculate the slope between successive position data points to generate velocity data.
The diff command calculates the slope of the line connecting successive data points. As a result, it is one element shorter than the number of time and distance data points.
In the lab, you learned that you can use forward, backward, or central difference for your plot so the slope vector and the original time vector will be the same length.
1. Paste the code below into the same file as Problem 1 to create a plot and estimate the velocity corresponding to your first drive speed.
You should get a plot like this:
2. Use the data points to determine the actual speed for that setDriveSpeed(). Ignore the outliers. Record the result. Repeat for other speeds.
3. Use Run Section to run only these commands to obtain your first velocity time plot without the robot driving again.
Download script: rvr_velocity.m (Matlab File 1kB Oct27 24)
4. Save your plot as a png and upload it to your Dropbox.
5. Repeat Parts 1 and 2 for other drive speeds. Run the robot on other drive speeds. Create velocity vs time plots for each drive speed to determine the corresponding actual speed.
6. Record the drive speed and actual speed for each trial. Use at least 4 speeds, they don't have to be the speeds listed below. You do not need to upload a plot for every trial, only v vs. t plot is needed in the Dropbox.
Drive Speed | Actual Speed
60 |
75 |
80 |
100 |
Part 3: Perform a curve fit to determine the mathematical relationship between driveSpeed() and actual velocity
1. Use curve fitting to determine the relationship between drive speed and actual speed for your robot. It may or may not be linear, and it may be different for each robot.
2. Paste the code below into the same file. Use Run Section to run only these commands.
Download script: rvr_correlate.m (Matlab File 1kB Oct27 24)
3. Save your plot as a png and upload the plot and entire m-file to the dropbox. Be sure to fill in the required info or commands for commented areas of the code.
Teaching Notes and Tips
The students should work with their regular robot team. They only need one set of files per team.
To maximize team efficiency, select a robot controller who has successfully, rapidly and confidently controlled an RVR with their computer in the past labs. One control computer should join the Zoom breakout room with the collaboration screen.
The students will collect RVR data and apply the concepts they have learned to help us answer these frequently asked questions so we can provide toolbox users more information about the commands.
Sphero RVR Robot Setup - Instructions for students:
if you do not follow all of these steps, it is highly likely your robot will not send the sensor data they need..
- Join the eduroam wi-fi
- Check that the robot battery is 4/4. If not, replace the battery.
- Whoever is controlling the robot should join the Zoom room and team breakout room
- Turn off your firewall (search for firewall using the magnifying glass and search box)
- Connect to your robot using the s=sphero('RV-UT22') command
- Wait for the circular light under the robot to turn on before you send commands, this indicates all systems are ready.
- Once the light is on, test the robot using the commad s.getPosition
- If the light does not turn on and/or s.getPosition returns 0 or locks up: use the clear command in MATLAB. When you see the ">>" turn the robot off. Turn the robot back on. Use the rosshutdown command in MATLAB. Wait ~1 minute and reconnect.
If needed, review the "Robot Info" (see attached file "SperoRVRinfo.pdf")
Assessment
To assess the learning goals, we look at techniques that align with students' ability to model, evaluate, and interpret data in MATLAB.
Practical Application Task (Lab Activity, as presented above):
- Have students set up a MATLAB-based experiment where they program the rover to move at varying speeds and then collect data. Assess how they model drive speed using position/distance data, including their ability to set up, collect, and interpret data in MATLAB. This type of task checks for practical and analytical skills directly in line with the learning objectives.
Code Review and Annotation/Comments (see suggested rubric below):
- Ask students to submit their MATLAB code and annotate it with explanations of each section. This allows you to assess their understanding of the MATLAB functions they use to model speed and evaluate relationships. The annotations should reveal their logic and reasoning, making it clear if they understand the data modeling and analysis steps.
Other potential assessment techniques to use:
- Data Analysis Report:
- Require a short written report where students explain how they modeled speed using position/distance data and discuss their findings. The report should include plots, the MATLAB code used, and a discussion on the relationship between distance and velocity. Emphasize evaluating their conclusions based on the data, which ties in with the evaluation learning goal.
- Conceptual Check-ins or Mini Quizzes:
- Periodic quizzes with MATLAB-based problem-solving questions on distance and velocity relationships can reinforce their knowledge and track progress. Use MATLAB Live Script for these quizzes to allow students to complete small coding exercises that are instantly assessed, focusing on specific aspects of data modeling and mathematical relationships.
- Peer Review Session:
- Set up a peer review session where students evaluate each other's approach to modeling and analyzing the rover's speed. This will enable them to articulate their understanding and spot issues in each other's work, reinforcing the evaluation of mathematical relationships.
- Reflection Exercise:
- Ask students to write a reflection on their challenges and learning in using MATLAB to model and evaluate speed relationships. This can provide insight into their understanding and self-assessment of the learning goals.
- AI-based Feedback:
- Ask students to use AI to ask for feedback for each step of their solution process. Ask students which feedback is useful/helpful and which feedback they use to improve their output. How did they construct the prompt? How did the response change based on how they changed the prompt?
Potential Deliverables for students:
1. Upload your plots as png files
- distance vs time plot
- one of your velocity vs time plots
- your curve fit plot
2. Upload your m-file. Be sure to fill in the required info or commands for commented lines in the m-file. You will only receive full credit for the m-file if it includes complete and understandable code, header, and comments. m-file should include:
- all 3 parts
- data used for curve fit
- all team member names
- text command for final equation titles and axis labels and units as indicated
3. Everyone should check the Dropbox after the files are uploaded to be sure the proper files were uploaded and all names are in the m-file header.
Suggested Rubric to use: suggested_rubric.docx (Microsoft Word 2007 (.docx) 16kB Nov6 24)
References and Resources
https://efcms.engr.utk.edu/ef230-2024-01/ - EF230 Website for Spring 2024