Homework 2
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. - Guidelines provides important information about what
you should turn-in, including information about your
README.mdfile.- As per the guidelines, your code must pass
colcon testcleanly
- As per the guidelines, your code must pass
- In general, you should refer to
ROSentities using relative names from within your nodes (i.e., no leading "/") - All python launchfiles written for this assignment should use a declarative style:
- When a launch file is listed as
filename.launch.{py,xml}you should implement both an XML and python version of that launchfile. - All data files that are installed should be installed to the appropriate sub-directory of the package's share directory
- e.g.,
config/myfile.yamlshould be installed to$(find-pkg-share mypackage)/config/myfile.yaml
- e.g.,
Overview
We will use turtlesim to simulate a robot in ROS. The turtle robot will be integrated into various standard ROS systems (e.g., tf, joint_states, etc)
and then we will control it to catch a brick that is dropped from the sky.
The repository is called homework2 and there will be two packages within the repository
turtle_brick(anament_pythonpackage)turtle_brick_interfaces(for any custom interfaces that must be defined)
Hints
Here are some general hints for this assignment:
- Familiarize yourself with the overall problem by reading the homework description.
- Work on the
urdf.xacrofile to build up the robot and the launchfile to visualize the robot simultaneously- It is especially useful to be able to view and manipulate the robot when debugging
.urdf.xacrofiles and the launchfile makes this process much simpler.
- It is especially useful to be able to view and manipulate the robot when debugging
- Slowly introduce node functionality over time.
- Write launchfiles early in the process. Use these launchfiles to make testing nodes easier.
Frames
The following coordinate frames will be used:
world. This is the fixed frame, representing the location of entities in the world- All other frames are descendants of
world
- All other frames are descendants of
odom. Items relative to this frame represent their location relative to the starting location of the turtle.- The turtle's location relative to
odomis it's position according to its wheel odometry - The
odomframe is at a fixed offset fromworldand represents the initial location of the turtle.
- The turtle's location relative to
brick. This frame is the location of the brickbase_link. This frame is the base location of the robot- The
base_linkhas other child frames, as defined by the robot'surdffile
- The
The Robot
- The turtle robot has the same kinematics as the
turtlesim - The robot is modeled as a unicycle robot that "self balances" on a caster. It consists of
- A
base_linkthat is the main location of the robot and is represented by a cube. - A
platformwhich is a cylindrical link at the top of the robot- The base of the
platformshould be parallel to the ground in the zero position, but should be able to rotate so that the brick can be dumped. - The
platformshould be a fixed vertical distance above thebase_link, so that it may rotate fully without colliding with the base link. - A fixed cylindrical link should connect the
base_linkto theplatform
- The base of the
- A
stemis a cylindrical link that turns about the vertical z-axis and is below thebase_link - A
wheelis connected to the stem and can roll as the robot moves - Each link should be a different color.
- A
- The robot has a maximum translational speed but infinite rotational speed, making it effectively omni-directional
- To move in a given direction, the
stempoints in that direction and then the robot translates (while the wheel rolls).
- To move in a given direction, the
- The
.urdf.xacrofile for the robot should be inurdf/turtle.urdf.xacro - The visual and collision components can be the same. The inertial components can be omitted because we are only using this model kinematically.
The Arena
- The arena should be depicted in
rviz2, with rectangular walls (drawn as markers) denoting its boundary - The arena should be the same size as the
turtlesimsimulator and have a matching coordinate system- The
worldframe should be the fixed frame. - The
odomframe should be at the initial location of the turtle
- The
Configuration
- A configuration file called
config/turtle.yamlshould include- The
platform_heightof the robot'splatformabove the ground - The
wheel_radiusof the robot's wheel - The
max_velocity, maximum translational velocity of the robot - The
gravity_accel, the acceleration due to gravity - The default values of these configuration items can be chosen by you.
- The
- Anything that relies on these parameters should read the appropriate parameters
- In other words, changing
config/turtle.yamlshould be the only change required to work with a differentplatform_heightorwheel_radiusand have the robot appear correctly - Changes to
config/turtle.yamlneed only take affect after the code is re-built and re-run.
- In other words, changing
Visualizing the Robot
- Write a launchfile called
show_turtle.launch.{py,xml}that displays the turtle robot (as defined byturtle.urdf.xacro) inrviz- The launchfile argument
use_jspcontrols the behavior of thejoint_state_publisher- If
use_jspisguithen thejoint_state_publisher_guiis used to publish joint states (the default) - If
use_jspisjspthen thejoint_state_publisheris used to publish joint states - If
use_jspisnonethen no nodes that publishjoint_statesare started by the launchfile - Document the arguments that the documentation shows up when using
ros2 launch -s
- If
- The launchfile argument
rviz_configcontains the name of thervizconfiguration file relative to the project's share directory. - The launchfile starts any other nodes that may be necessary to display the URDF in
rviz
- The launchfile argument
Turtle Node
- A node called
turtle_robotserves as a bridge between theturtlesimand actualrosinterfaces and is responsible for- Publishing the
joint_statesof the turtle robot- The wheel joint state should be published so that the wheel is rolling without slipping (compute based on the wheel radius and the forward velocity).
- Broadcasting the location of the
base_linkframe relative to theodomframe - Publishing
nav_msgs/Odometrymessage on theodomtopic (covariance can be ignored, twist can be a direct copy of the latestcmd_vel) - Publishing a
cmd_velmessage.- If the turtle is not moving, this node should publish a
cmd_velof 0 (a real robot would then detect the absence of such commands as a fault condition). - The robot is
holonomic(e.g., omni-directional), socmd_velcommands may include aycomponent. - The
turtlesimcan be madeholonomicby setting the appropriate parameter.
- If the turtle is not moving, this node should publish a
- Subscribing to a
goal_posetopic of thegeometry_msgs/msg/PoseStampedmessage type.- When the node receives this message it starts driving the robot toward the goal pose using
cmd_velmessages
- When the node receives this message it starts driving the robot toward the goal pose using
- Subscribing to a
tiltmessage (of custom typeturtle_brick_interfaces/msg/Tilt).- The tilt angle of the platform is set to the last message received on this topic
- Subscribes to the
turtle1/posemessage- This message provides the location of the robot, and can be used to set the odometry messages and transforms
- All publishing and broadcasting shall be done at 100 Hz.
- Publishing the
- Write a launchfile called
run_turtle.launch.{py,xml}that- Starts the
turtlesimnode (withholonomicset toTrue) - Starts the
turtle_robotnode - Includes
show_turtle.launch.{py,xml}as appropriate to draw theturtlerobot inrviz- Python launchfiles can be included in xml launchfiles and vice versa, you can use any combination you would like here.
- You can now test the
goal_posecommand and should see the robot move to the goal location - Use a declarative style for the launchfile.
- Starts the
Physics Module
- A module called
physics.pyshould contain ROS-independent code to keep track of the physics of the environment. It should provide a class with the following definition.
class World: """Keep track of the physics of the world.""" def __init__(self, brick, gravity, radius, dt): """ Initialize the world. Args: brick - The (x,y,z) location of the brick gravity - the acceleration due to gravity in m/s^2 radius - the radius of the platform dt - timestep in seconds of the physics simulation """ pass @property def brick(self): """ Get the brick's location. Return: (x,y,z) location of the brick """ pass @brick.setter def brick(self, location): """ Set the brick's location. Args: location - the (x,y,z) location of the brick """ pass def drop(self): """ Update the brick's location by having it fall in gravity for one timestep """ pass
Arena Node
- A node called
arenais responsible for simulating the environment by- Publishing markers that denote the boundaries of the environment
- Broadcasting the
brickframe at the location of the brick, and a marker to show it's location inrviz - Offer a service called
place(of custom typeturtle_brick_interfaces/srv/Place) that moves the brick to a specified location - Offering a service called
dropthat causes the brick to fall in gravity according to the specified rules:- After the service responds, the brick starts falling in gravity (using the specified
gravityacceleration). - If the brick hits the platform or the ground it stops falling.
- If the brick hits the platform it should move with the platform
- Your code can assume that the platform is at 0 degrees when the brick is dropped and does not need to handle other cases.
- If the brick is on the platform and the platform tilts, it should slide off the platform (friction-less, but in gravity)
- When the trailing-edge brick clears the platform, it magically floats in place.
- The angle of the brick relative to the ground should be the same as the angle of the platform relative to the ground at all times.
- After the service responds, the brick starts falling in gravity (using the specified
- The node should simulate the physics at
250 Hz
- The node should use the
physicsmodule to perform all calculations.
Control Node
- Write a node called
catcherthat causes the turtle to catch a falling brick- When the node detects that the brick is falling it first computes (based on
max_velocityandplatform_height) whether it can reach the brick on-time- If the brick cannot be caught on time, the node publishes a Text marker that lasts for 3 seconds that says "Unreachable"
- If the brick can be caught on time, the robot drives under the brick.
- When the brick is caught, the robot drives back to the arena center and
tiltsthe brick off.
- When the brick is caught, the robot drives back to the arena center and
- When the node detects that the brick is falling it first computes (based on
- Write a launchfile called
turtle_arena.launch.{py,xml}that runs all the nodes necessary for the turtle to catch a brick- The launchfile should include
run_turtle.launch.{py,xml}as needed - The
rvizconfiguration should show the turtle, the arena, and the brick
- The launchfile should include
Testing
- Your code should pass all the standard tests that are run with
colcon test - Write at least one
pytestunit test for each of the (required) members of thephysics.Worldclass - Write a test launchfile called
test_brick_launch.pythat verifies that theturtle_robotnode publishescmd_velcommands at 100 Hz - Your final result should not have any
rvizerrors or warnings once all nodes in a given launchfile have started running.
README
In the base directory of your repository (e.g. homework2) create a README.md using the following template (be sure to update the ${} with the answers.)
# ME495 Embedded Systems Homework 2
Author: ${Your Name}
${A brief overview of what the package does}
## Quickstart
1. Use `ros2 launch ${pkg} ${launchfile} ${options}` to start the arena and turtle simulation
2. Use ${ros2 service call here} to place a brick
3. Use ${ros2 service call here} to drop a brick
4. Here is a video of the turtle when the brick is within catching range
${embed video here, it must be playable on github. Upload the video as an issue and link to it}
5. Here is a video of the turtle when the brick cannot be caught
${embed video here, it must be playable on github. Upload the video as an issue and link to it}
- You should capture of each of the following scenarios
- The brick is dropped but cannot be caught
- The brick is dropped and is caught
- In all cases, the brick should be visible from the time it is placed in the air through the complete drop.
- The directory structure of your git repository should look like
homework2homework2/homework2/README.mdhomework2/turtle_brickhomework2/turtle_brick_interfaces