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, they contain important information about what you should turn-in.
- In this document, the notation
${ws}means to substitute${ws}with whatever value is appropriate (like a bash variable substitution).- For example, if
${item} = Hello Therethan"This is the message: ${item}" becomes "This is the message: Hello There"
- 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 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. - Your homework repository (call it
${hw}) should also be under${ws}/src Your Workspace should look like the following (assuming that
${ws} = wsand${hw} = turtle_hw:ws/ # This directory is NOT a git repository ws/src # This directory is NOT a git repository ws/src/crazy_turtle # This directory is a git repository, but it is my git repository not yours. ws/src/turtle_hw # This directory is the git repository you are using for this assignment.
- Copy
${ws}/src/crazy_turtle/README.mdinto${ws}/src/${hw}/inspection.mdand add it to your git repository. inspection.mdcontains additional exercises that you should complete. Followinspection.mdand replace the${item}substitutions with the answer.- This exercise also serves as a quick introduction to some markdown basics.
- Copy
crazy_turtle/nodes/moverto$ws/$src/$hw/mover. 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 write a package called turtle_control that makes a turtle in turtlesim
follow waypoints.
First, you will have a turtle draw the waypoints in turtlesim.
Next, a different turtle will follow those waypoints.
- Each task below (with one exception) can be roughly followed in order.
- I suggest that before beginning you read through to understand the full scope of the problem.
- It also makes sense to work on the Launchfile in parallel, as having a launchfile early makes testing and debugging easier.
Package Setup
- The package you create should be called
turtle_controland contained in a single git repository - Create the
package.xmlandCMakeLists.txtin theturtle_controlrepository.- I recommend using
catkin_create_pkgso you can read the comments in the generated files and learn about the format. - Edit the
package.xmlto change the default but required fields to reflect your name, email, and a description of this package. - The package
exec_dependsonrospyandmessage_runtime(since we userospyandpythonmessages when the code runs. - The package
dependsonturtlesimbecause we use messages/services defined in that package. - The package
build_dependsonmessage_generationbecause we will be created custom messages and services. - There will be other dependencies that come up as you work on this assignment. Be sure to add them to
package.xmlandCMakeLists.txtas appropriate
- I recommend using
- Add
package.xmlandCMakeLists.txtto your git repository and commit them. - At this stage an
ls -ain the base directory of your repository should show.git,package.xml,CMakeLists.txtand (if appropriate for you).gitignore
Drawing the Waypoints
Node: setup
- The
setupnode is responsible for drawing all of the waypoints. Code this node innodes/setup - The waypoints should be stored in
config/waypoint.yamlas a list of coordinates (each coordinate is itself a list of length 2).- For example, a list of 3 waypoints is
[[1,2], [3,4], [5,6]] - The waypoints will be loaded into the parameter server as
/waypoints - To start out, you can hard-code the waypoints
- For example, a list of 3 waypoints is
- The
setupnode should implement a service calleddrawof typestd_srvs/Empty.- First, the service resets the
turtlesimand clears all drawings - Next the service draws all the waypoints, using an X shape
- You can draw line segments by teleporting the turtle while lifting and dropping its pen, as appropriate.
- First, the service resets the
- Use
rosrunto run your node,rosparamto load theyamlfile into the parameter server, androsserviceto call the service
Velocity Translator
Custom Message: TurtleVelocity
- Velocities in ROS are 3-D and use the
geometry_msgs/Twisttype. For 2D velocities,linear.xis the forward velocity andangular.zis the rotational velocity. - Create a custom message called
TurtleVelocity, with the following two fields:linear (float64): the linear velocity of the turtle in m/sangular (float64): the angular velocity of the turtle in rad/s.- Be sure to add comments (the
#character begins a comment) describing the fields. - Message definitions go under the
msgsubdirectory of your package (e.g.,turtle_control/msg).
- To properly use the custom message, follow the instructions as laid out by the long block comment in
CMakeLists.txt - Make sure your package compiles cleanly with
catkin_makeand has no linting errors fromcatkin_lintbefore proceeding- The errors from
catkin_linthelp explain whycatkin_makefails.
- The errors from
Node: translate
- Write a node called
translatethat converts betweengeometry_msgs/Twistandturtle_control/TurtleVelocitymessages - The node subscribes to a topic called
turtle_cmdof typeTurtleVelocity- The subscriber logs the input as a debug-level message
- The subscriber publishes a corresponding
geometry_msgs/Twistmessage on thecmd_veltopic
- Test the node by using ROS commands to send messages while watching the ROS log and the
cmd_veltopic.- To see the debugging message you will need to adjust the logger level of your node's
rosoutto debug. - You can use either
rqt_logger_levelor change settings inrqt_console.
- To see the debugging message you will need to adjust the logger level of your node's
Waypoint Follower
Write a node called follow that causes turtle1 to follow a series of waypoints.
When the turtle reaches the last waypoint it should head to the first waypoint and restart the cycle.
Parameters
- The waypoints are loaded into the Parameter server from
config/waypoint.yaml(this is the same file and parameter used by the setup node) - Private parameter
dist_threshis used to determine when the turtle is close enough to its destination to move to the next waypoint. - You may also add additional parameters if appropriate for your algorithm.
Subscribers
- The turtle may subscribe to the
posetopic from the turtlesim to read the pose, as reported by the turtle.
Services
- Create a custom service type called
Start- Inputs, are
x (float64)andy (float64)coordinates - Output is
distance (float64)
- Inputs, are
- The node implements a service called
restartof typeturtle_control/Start- If the
xandycoordinates of the starting location are out-of-bounds, returnNoneto indicate an error - The service calls the
drawservice offered by thesetupnode to clear the arena and draw the waypoints - The service resets the position of the turtle to it's starting location
- The service computes the theoretical distance traveled by the robot after traveling from its starting location to all the waypoints (not including any wrap-around/waypoints visited twice)
- The service starts the turtle moving and then returns the previously computed distance
- If the
Publishers
- The node should publish a
TurtleVelocitymessage on theturtle_cmdtopic to control the turtle and make it follow the waypoints.- The
translatenode subscribes toturtle_cmdand publish acmd_velfor the turtle to follow
- The
- The turtle should not start moving until the
restartservice has been called once.
Launchfile
- Write a launchfile called
launch/run_waypoints.launchthat loads all the parameters, launches theturtlesim,translate,follow, and setup nodes. - The launchfile should connect all the nodes together to make the turtle follow the waypoints
- Instructions for how to use your package (to be put in the README) consist of the launchfile command to use, followed by an example call to the reset service.
Rosbag
- Use
rosbagto capture enoughcmd_velcommands for the turtle to visit each waypoint twice, when starting from(x, y)(you may choose anyxandy.- Add the bagged data as a
turtle_control/waypoint.bag(e.g., the root directory of your repository)
- Add the bagged data as a
- Kill the
translatenode to stop the turtle from moving. - Manually call the
setup/drawservice to reset the arena and call a service to move the turtle to(x, y). - Use
rosbagto play back your bagged data and make the turtle move.- You should not expect the trajectory to be duplicated, due to the inexact timing with ROS bags (see here)
Demonstration
- Install
simplescreenrecorder(viaapt) or different screen recording software and use it to create a video of your code working. - Add your video to the
README.mdby placing it on a video-sharing website and writing out a link to it.