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
main
branch 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 test
for 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 There
than"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 theros2
branch. - Create a git repository for homework1 located at
${ws}/src/homework1
Your 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.md
into${ws}/src/homework1/inspection.md
and add it to your git repository. inspection.md
contains additional exercises that you should complete.- Read
inspection.md
and 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.py
to$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_control
package is anament_python
package and should be located at${ws}/src/homework1/turtle_control
- This package has
exec_depends
onrclpy
andturtlesim
- This package has
- The
turtle_interfaces
package is anament_cmake
package and should be located at${ws}/src/homework1/turtle_interfaces
- Use
ros2 pkg create
to create the packages. - Edit
package.xml
to 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.xml
and add any extra dependencies as they are needed.
Waypoint Node
- Create a node called
waypoint
that (for now) logs aDEBUG
message 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
DEBUG
messages when thenode
is run in a mode that enables theDEBUG
logger 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
DEBUG
messages. - To test if your code is working without setting the logger level, use an
ERROR
message at first and later change it toDEBUG
.
Toggle Service
- Using the
std_srvs/Empty
Service type, create service calledtoggle
and have thewaypoint
node offer it.- The node will now have two states:
MOVING
andSTOPPED
. It starts in theSTOPPED
state. - When
toggle
is called, the node switches states.- When switching from
MOVING
toSTOPPED
the nodeINFO
logs "Stopping." one time. - While in the "MOVING" state, the node
DEBUG
logs "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
MOVING
orSTOPPED
.
Load Waypoints
- Create a custom service of type
turtle_interfaces/srv/Waypoints
in theturtle_interfaces
package 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
waypoints
field that is an array ofgeometry_msgs/msg/Point
objects. Thez
field of the point is ignored. - The response is a
distance
of typefloat64
- Do not forget to update the
package.xml
andCMakeLists.txt
as needed for theturtle_interfaces
package.
- Add a service called
load
of theturtle_interfaces/srv/Waypoints
type to thewaypoint
node. This service shall:- Reset the
turtlesim
node to its initial state. - Draw an
X
at each waypoint. - Place the turtle at the first waypoint. The node should be
STOPPED
and turtle should not move. - Compute the straight-line distance from traversing the waypoints and return that as a response.
- Reset the
Hint
- The turtle is able to "teleport". Teleportation can be used to draw the
X
but 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 a
turtlesim
topic that provides the position and orientation of the turtle. - This subscriber should store the received data for later use
- The subscriber should not publish any messages or call any services.
Command Publisher
- When the
toggle
service puts the node into theMOVING
state, the turtle should start following the most recently loaded waypoints.- If no waypoints are loaded log an
ERROR
message sayingNo waypoints loaded. Load them with the "load" service
.
- If no waypoints are loaded log an
- When
MOVING
, you should publishcmd_vel
commands at the control loop frequency.- The
cmd_vel
velocities must havelinear.y = 0
to 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
tolerance
parameter
- This threshold should be set via a
Hints
- Before working on the control algorithm itself, publish a constant command velocity
- Verify that the turtle moves
- use
ros2 topic hz
to verify the frequency
Distance Estimate
- Create a custom message type called
ErrorMetric
in theturtle_interfaces
package 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_metrics
topic every time the turtle completes a new cycle of the waypoints.- In this sense, the
ErrorMetric
is only updated once per full cycle. - The
actual_distance
anderror
are cumulative (i.e., if theturtle
has 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
/load
service is called.
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_node
and thewaypoint
node. - Load parameters from
colors.yaml
(stored in theconfig/
directory of theturtle_control
package) 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
waypoints
frequency
should be 100 Hztolerance
should be, at most,0.05m
Hint
- Don't forget to install the launchfile or config files using
setup.py
Example Run
In the example run:
- The turtle traverses the following waypoints:
(1.4, 1.6), (2.2, 9.4), (7.2, 6.1), (4.0, 2.6), (8.2, 1.5), (4.1, 5.3)
- 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 bag
capture of/turtle1/cmd_vel
while performing this experiment.- Save the bag to
homework1/turtle.bag
and be sure to include it in thegit
repository
- Save the bag to
- Manually reset the turtlesim and kill the
waypoint
node. - Use
ros2 bag
to play-back the bagged data to make the turtle move. Describe what happens in theREADME.md
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}`
Video Upload Instructions
- To upload a video:
- Create a github issue on your repository, and attach the 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 it.
- The video must play properly when viewing your README.md on GitHub in order for it to count as having been submitted.
- The directory structure of your git repository should look like
homework1
homework1/inspection.md
homework1/README.md
homework1/turtle_control
homework1/turtle_interfaces
homework1/mover.py
homework1/turtle.bag
homework1/citations.txt
homework1/rosgraph.svg