ME450: Embedded Systems in Robotics
Guidelines
- The Guidelines provide important important information about coding standards, expectations, and logistical considerations for this assignment.
- I recommend reading the guidelines both before starting the assignment and prior to your final submission:
Overview
You will be creating a ROS 2 system that enables a simulated turtle to follow waypoints.
Layout
Workspace
${ws}is your ROS 2 workspace (e.g.,~/ws/hw1). This is NOT a git repository.${ws}/build,${ws}/log, and${ws}/installare all directories generated bycolcon. They are NOT submitted and NOT part of your git repository.${hw1.git}is your Homework 1 Git Repository (e.g.,~/ws/hw1/src/${hw1.git}). You submit only${hw1.git}
Repository
${hw1.git}/citations.txtis your citations file${hw1.git}/ai_citationsis a directory containing any AI related citation material (if needed)${hw1.git}/README.meis yourREADME.md, based off of the following template (with the appropriate${}sections filled in)- All packages created are direct child directories of
${hw1.git}
Turtle Control
You will control a turtle in turtlesim to follow waypoints, while tracing it's path.
Each step in this section can be viewed as a milestone where it would be appropriate to
- Test each piece and make sure it works before proceeding
- Commit to git and merge into
mainupon completion (though you should also add additional commits when appropriate). - Do not create any ROS API elements (e.g., services/topics/etc) other than those specified in these instructions.
- For full credit, the
turtlesim/holonomicparameter must be false
Packages
To prepare for the project, create the packages that you need.
- The
turtleconpackage is anament_pythonpackage and should be located at${hw1.git}/turtlecon- All nodes,
yamlandlaunchfiles belong in this package
- All nodes,
- The
turtle_interfacespackage is anament_cmakepackage that should be located at${hw1.git}/turtle_interfaces- This package holds any custom interfaces that are created.
Waypoint Node
Create a node called waypoint (in ${hw1.git}/turtlecon/turtlecon/waypoint.py) that
- Creates a timer that runs at a fixed frequency based on a parameter called
frequencythat defaults to 100 Hz - Logs a
DEBUGmessage from that timer that says "Issuing Command!" for each iteration of the timer - Once the timer is setup it should run until the node is terminated.
- Do not attempt to stop the timer or create multiple timers
Corrupt Node
Create a node called corrupt (in ${hw1.git}/turtlecon/turtlecon/corrupt.py) that
- Subscribes to a topic called
pure_cmd_velof typegeometry_msgs/msg/Twist - For every
pure_cmd_velmessage receives publishes a corrupted version oncmd_velof typegeometry_msgs/msg/Twist:- Gaussian Noise is added independently to the linear and rotational velocities
- The noise is zero mean, with standard deviation proportional to
noise_coefficient * |velocity| - The
noise_coefficientis a parameter that defaults to0.05
Toggle Service
- Using the
std_srvs/EmptyService type, create a service calledtoggleand have thewaypointnode offer it.- The node will now have two states:
MOVINGandSTOPPED. It starts in theSTOPPEDstate. - When
toggleis called, the node switches states.- When switching from
MOVINGtoSTOPPEDthe nodeINFOlogs "Stopping." one time. - While in the
MOVINGstate, the nodeDEBUGlogs "Issuing Command!" repeatedly at the control frequency
- When switching from
- The node will now have two states:
Load Waypoint Service
Service Type
- Create a custom service of type
turtle_interfaces/srv/LoadWaypointsthat allows sending a sequence of waypoints to a node- The
Requestcontains a field calledwaypointsthat is an array ofgeometry_msgs/msg/Pointmessages.- The
zfield of each point is ignored.
- The
- The
Responseis a field calleddistanceof typefloat64with the total straight-line distance the turtle travels if it starts at the first waypoint, visits each waypoint in sequence, and returns to the start.
- The
Service Server
Add a service called load of the turtle_interfaces/srv/LoadWaypoints type to the waypoint node. This service shall:
- Reset the
turtlesimnode to its initial state. - Put the node into the
STOPPEDstate - Draw an isosceles triangle at each waypoint such that
- The triangle points toward the next waypoint in the sequence.
- The centroid of the triangle indicates the exact waypoint location and is marked with a dot
- Drawing should be accomplished by exclusively using services
- Place the turtle at the first waypoint, pointing toward the next waypoint
- Compute the straight-line distance from traversing one complete cycle of the waypoints and return that as a response.
Turtle Position Subscriber
- to the appropriate
turtlesimfeedback to receive the position and orientation of the turtle - Use the data received to track the actual distance traveled
- The data from this subscriber will be used when computing error metrics and (optionally) for control.
Control Publisher
- When the
toggleservice puts the node into theMOVINGstate, the turtle should start traveling between the waypoints.- If no waypoints are loaded log an
ERRORmessage sayingNo waypoints loaded. Load them with the "load" serviceand keep the state asSTOPPED.
- If no waypoints are loaded log an
- If the turtle is
STOPPED(by another call totoggle) it should stop moving.- Resuming (by another call to
toggle) should have the turtle continue along the waypoints.
- Resuming (by another call to
- A turtle reaches a waypoint if it is within some threshold distance of that the waypoint
- This threshold should be set via a
toleranceparameter to the node (defaults to0.05)
- This threshold should be set via a
- The turtle's path should be visible when following the waypoints
- You may use data received
Distance Estimate
ErrorMetric Message Type
- Create a custom message type called
ErrorMetricin theturtle_interfacespackage that contains:complete_loops: An integer counting the number of times the turtle has cycled through all the waypoints.actual_distance: The actual distance travelederror: The difference between the straight-line distance of the path and the actual distance traveled.time: The total time that the turtle has been moving
Publishing ErrorMetrics
- Publish an
ErrorMetricmessage on the/loop_metricstopic every time the turtle completes a new cycle of the waypoints.- In this sense, the
ErrorMetricis only updated once per full cycle. - The
actual_distanceanderrorare cumulative (i.e., if theturtlehas completed 3 loops this is the actual distance traveled for the 3 loops and the error over that time). - The
timeis also cumulative. It should use the time according torclcpyand when the turtle isSTOPPEDtime does not accumulate.
- In this sense, the
- All metrics should be reset whenever the
/loadservice is called. - Your goal is to implement a control with the
errormetric as small as possible.
Launch File XML
Write an xml launchfile called ${hw1.git}/turtlecon/launch/waypoints.launch.xml that
- Starts the
turtlesim_node,waypointandcorruptnodes. - Loads parameters from
${hw1.git}/turtlecon/config/colors.yamlto set the colors of theturtlesim_node.- The color you set should be visually distinct from the default value (e.g., it should not primarily be a shade of blue).
- Specify the following parameters for
waypointsfrequencyshould be 100 Hztoleranceshould be0.04m
- Specify the following parameters for
corruptnoise_coeffientshould be0.04
- The
waypointsnode cannot publish directly to theturtlesim_node. Instead, it's output must be routed through thecorruptnode.
Example Run
You should capture an example run, according to the following instructions:
- The turtle traverses the following waypoints:
(3.8, 5.5), (1.4, 1.5), (2.3, 9.4), (7.1, 6.1), (4.0, 2.7), (8.1, 1.5) - You stop and resume the turtle one time.
- The turtle completes more than 1 but less than 2 cycles.
- Capture a screen-cast and a
ros2 bagcapture of/turtle1/cmd_velwhile performing this experiment.- Save the bag to
${hw1.git}/turtle.bagand include it in thegitrepository
- Save the bag to
- Manually reset the turtlesim and kill the
waypointnode. - Use
ros2 bagto play-back the bagged data to make the turtle move.- Capture a screen-cast of the turtle moving based on bag data.
- Do not expect the bagged run to duplicate the actual run!
README
Here is a specific template for this homework's README.md
# ME450 Embedded Systems Homework 1
Author: ${Your Name}
## Overview
A waypoint following project for ROS 2
## Instructions
1. Use `ros2 launch ${pkg} ${launchfile}` to run the code
2. The `${ros2 service call /load <put arguments here that you used to make the video>}` service loads waypoints for the turtle to follow
3. The `${ros2 service call /stop <put arguments here that you used to make the video>}` starts and stops the turtle.
## Videos
4. The turtle in action. The error was ${error_metric} meters after one cycle and the cycle was completed in ${time} seconds
${embed video here, must show up inline in the README.md when rendered on github. Video file itself should be uploaded as a github issue and linked here, not in the repository}`
5. Here is a video when the bag is played.
${embed video here, must show up inline in the README.md when rendered on github. Video file itself should be uploaded as a github issue and linked here, not in the repository}`