ME495: Embedded Systems in Robotics
Logistics
- Create a git repository using the link provided in Canvas.
- Your homework will be submitted via this git repository.
- I will grade whatever is on the
mainbranch when I clone the repository. - See Guidelines for important information about coding standards.
- Read over the guidelines prior to starting this assignment and prior to submitting the assignment.
- Your code need not pass
colcon testfor this assignment, but it is good practice for the future.
- In this document, the notation
${ws}means substitute the appropriate value for${ws}- For example, if
${item} = Hello Therethan"This is the message: ${item}"becomes"This is the message: Hello There" - Be sure to remove the
${}
- For example, if
Part I: Inspection
Here you will inspect a poorly-documented ROS package called crazy_turtle and improve its documentation.
- Create a new ROS workspace. Your workspace directory is
${ws}.- Do not have any spaces in the full path to your workspace: this may cause trouble later.
- Clone https://github.com/m-elwin/crazy_turtle into the source space (i.e.,
${ws}/src) of the workspace and checkout theros2branch. - Create a git repository for homework1 located at
${ws}/src/homework1Your directory structure should look like
${ws} # NOT a git repository ├─── src # NOT a git repository │ ├── crazy_turtle (ros2) # A git repository on the ros2 branch │ └── homework1 (main) # Your git repository for Homework 1
- Copy
${ws}/src/crazy_turtle/README.mdinto${ws}/src/homework1/inspection.mdand add it to your git repository. inspection.mdcontains additional exercises that you should complete.- Read
inspection.mdand replace the${item}substitutions with the answer. - This exercise also serves as a quick introduction to some Markdown basics.
- Read
- Copy
crazy_turtle/crazy_turtle/crazy_turtle/mover.pyto$ws/$src/homework1/mover.py. Edit the file and search for${item}substitutions, replacing them with the appropriate word or phrase.
Part II: Turtle Control
In this section 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 commit to git and merge into main.
You can (and should) add additional commits when appropriate.
Package Setup
- The
turtle_controlpackage is anament_pythonpackage and should be located at${ws}/src/homework1/turtle_control- This package has an
exec_dependonrclpyandturtlesim
- This package has an
- The
turtle_interfacespackage is anament_cmakepackage and should be located at${ws}/src/homework1/turtle_interfaces - Use
ros2 pkg createto create the packages. - Edit
package.xmlto change the default but required fields to reflect your name, email, and a description of each package. - As you develop the package make sure to maintain consistency with
package.xmland add any extra dependencies as they are needed.
Waypoint Node
- Create a node called
waypointthat (for now) logs aDEBUGmessage that says "Issuing Command!" at a fixed frequency using a timer.- This node will be expanded throughout this assignment and will form the base of the project.
- The frequency should be specified as a parameter called "frequency" and should default to 90 Hz.
- You will only see
DEBUGmessages when thenodeis run in a mode that enables theDEBUGlogger level.
- Make sure you can run the node with
ros2 run
Hints
- First make the node work using a hard-coded frequency, then add in the parameter.
- You need to set the logger level when running the node to see
DEBUGmessages. - To test if your code is working without setting the logger level, use an
ERRORmessage at first and later change it toDEBUG.
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 "MOVING" state, the node
DEBUGlogs "Issuing Command!" repeatedly - While moving the turtle should leave a visual trail behind to show where it has been
- When switching from
- The node will now have two states:
- Your code should not attempt to stop the timer or create multiple timers: instead it should change what the timer is doing based on whether the state is
MOVINGorSTOPPED.
Load Waypoints
- Create a custom service of type
turtle_interfaces/srv/Waypointsin theturtle_interfacespackage that allows you to send an arbitrary number of waypoints to a node and responds with the total straight-line distance that the turtle will travel to complete one cycle of the waypoints (i.e., starting and ending at the same place).- The fields in this service are defined as follows:
- The request has a
waypointsfield that is an array ofgeometry_msgs/msg/Pointobjects. Thezfield of the point is ignored. - The response has a
distancefield of typefloat64 - Do not forget to update the
package.xmlandCMakeLists.txtas needed for theturtle_interfacespackage.
- Add a service called
loadof theturtle_interfaces/srv/Waypointstype to thewaypointnode. This service shall:- Reset the
turtlesimnode to its initial state. - Draw an
Xat each waypoint. - Place the turtle at the first waypoint. The node should be
STOPPEDand turtle should not move. - Compute the straight-line distance from traversing one complete cycle of the waypoints and return that as a response.
- Reset the
Hint
- The turtle is able to "teleport". Teleportation should be used to draw the
Xbut not to follow the waypoints - See Blocking Calls for a useful pattern that enables calling "teleport" sequentially, while waiting for each step to complete.
Position Feedback
- Subscribe to the
turtlesimtopic that provides the position and orientation of the turtle. - This subscriber should store the received data for later use
- The subscriber should neither publish any messages nor call any services.
Command Publisher
- When the
toggleservice puts the node into theMOVINGstate, the turtle should start following the most recently loaded waypoints.- If no waypoints are loaded log an
ERRORmessage sayingNo waypoints loaded. Load them with the "load" service.
- If no waypoints are loaded log an
- When
MOVING, you should publishcmd_velcommands at the control loop frequency.- The
cmd_velvelocities must havelinear.y = 0to emulate a differential-drive robot.
- The
- 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
- This threshold should be set via a
- The turtle's path should be visible when following the waypoints
Hints
- Before working on the control algorithm itself, publish a constant command velocity
- Verify that the turtle moves
- use
ros2 topic hzto verify the frequency
Distance Estimate
- Create a custom message type called
ErrorMetricin theturtle_interfacespackage that contains 3 values:complete_loops: An integer counting the number of times the turtle has cycled through all the waypoints.actual_distance: The actual distance traveled (this can be estimated as a linear interpolation between position feedback subscriber callbacks).error: When a loop is completed, compute the difference between the straight-line distance of the path and the actual distance traveled.
- Publish this message 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).
- In this sense, the
- All metrics should be reset whenever the
/loadservice is called. - Your goal is to implement a control with the
errormetric after one loop as close to zero as possible.
Launch File XML
Write an xml launchfile called waypoints.launch.xml (put it in the launch/ directory of the turtle_control package).
The launchfile should:
- Start the
turtlesim_nodeand thewaypointnode. - Load parameters from
colors.yaml(stored in theconfig/directory of theturtle_controlpackage) to 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 be, at most,0.05m
Hint
- Don't forget to install the launchfile or config files using
setup.py
Example Run
You should capture an example run, according to the following instructions:
- The turtle traverses the following waypoints:
(3.9, 5.4), (1.4, 1.6), (2.2, 9.4), (7.2, 6.1), (4.0, 2.6), (8.2, 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
homework1/turtle.bagand be sure to 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.
README
In the base directory of your repository (e.g. homework1) create a README.md using the following template (be sure to update the ${} with the answers.)
# ME495 Embedded Systems Homework 1
Author: ${Your Name}
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.
4. Here is a video of the turtle in action.
${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}`
Video Upload Instructions
- To upload a video:
- Create a github issue on your repository, and attach the video file to the issue.
- The video will then have a github link. Placing that link in the README.md will embed the video.
- The video link must be on a its own line in the README.md, with a blank line preceding and succeeding it.
- The video must play properly when viewing your README.md on GitHub in order for it to count as having been submitted.
Final Repository Structure
- The directory structure of your git repository should look like
homework1homework1/inspection.mdhomework1/README.mdhomework1/turtle_controlhomework1/turtle_interfaceshomework1/mover.pyhomework1/turtle.baghomework1/citations.txthomework1/rosgraph.svg