During this lab, you should learn how to start the Turtlebot simulator, how to visualize data within ROS, and also how some additional features of ROS work.
Do you have any questions regarding the last week's lab or the homework?
You can simulate the Turtlebot robot using provided packages.
The same robot will be used for the semestral work and also in the upcoming homeworks.
The top-down view of the simulation looks as the image below.
Follow the steps in order to run the simulation:
catkin build
and source devel/setup.bash
inside your workspace folder).
roslaunch aro_sim robocop_sim.launch
.
After this you should see that two new program windows appear, one is RViz that can be used for visualizing data from the robot while the Gazebo is the robotic simulator.
There are several new key aspects/buzzwords to know from today's lab:
There are several quite well-working programs within ROS that you can use to visualize the data measured by the sensors or produced by your nodes. Most notably the RViz, rqt and PlotJuggler.
RViz is mainly useful for visualization of the current state of your robotic system, i.e., to show camera images, lidar scans, show mapped environment or show the robot's position.
You can start RViz by simply calling rviz
in your terminal once you are inside the singularity image.
By default, you should see 3D plot area in the middle, and the currently visualized data list in the left bar.
You can add new data to the visualization by pressing Add in the bottom left and then choose which data either by topic or by type of message. If you choose to add the data by message type, you will have to specify the topic later in the list of displayed messages in the left bar.
rqt has many plugins to visualize various information about your robotic system and its data.
By calling command rqt
in your terminal you can start rqt and then select the plugin you want to use in the menu.
Try visualizing in rqt plugins:
Alternatively, you can use some alias terminal commands for the most useful plugins. Try commands:
The PlotJuggler is a tool for plotting data (timeseries) online on a certain topic or plotting data loaded from rosbag.
The plot could be either 2D (time + value dimensions) or 3D (time + 2D value such as xy-axis dimensions).
You can start the PlotJuggler using rosrun plotjuggler plotjuggler
.
When started you can load data in the File tab (on the top left) from files such as rosbags.
Alternatively, you can select ROS Topic Subscriber in the Streaming tab, and select what topics should be visualized.
Afterward, you can select what timeseries (particular fields in the message, e.g., pose.position.x in Odometry message) you want to plot by dragging it over the plot area (drag two selected timeseries with right mouse button for 2D values).
Test the functionality by:
roslaunch aro_sim robocop_sim.launch
) and try plotting live published data.
Services are similar to topics, but they are used for synchronous communication with request + response model. They are useful for not so frequent messaging and in systems without communication dropouts.
In terminal you can use commands:
rossrv list/show/package
- list shows all available service types, show displays the definition of a given service type, package lists services of a certain package,
rosservice list/info <service_name>/call <service_name> <request data>
- list shows all running services, info gives you information about a specified service, call calls the specified service with specified request.
In python code you can create your own service definitions or you can use existing ones.
The services, similarly to topics, have Service server part (similar to topic subscriber) and Service client part (similar to topic publisher).
The service client sends service requests (e.g., for DeleteLight
service it is DeleteLightRequest
) and the service server accepts the requests, process them using some callback and generates a response (e.g., DeleteLightResponse
), which is sent back to service client.
The service server part of code would look like:
def handle_delete_light(request): # react to the service request of type DeleteLightRequest return response # response of type DeleteLightResponse s = rospy.Service('/gazebo/delete_light', DeleteLight, handle_delete_light)
The service client code can look like:
rospy.wait_for_service('/gazebo/delete_light') # waits for the service to be alive service_client = rospy.ServiceProxy('/gazebo/delete_light', DeleteLight) # creates the service client req = gazebo_msgs.srv.DeleteLightRequest() # creates the service request req.light_name = "sun" # fill the request response = service_client(req) # call the service and get the response
XML files that automatize the start-up of nodes. The launch files enable functionalities such as:
The xml file can include tag elements:
<launch>
- root element
<node>
- element that starts a new node with parameters such as: name - custom unique name of node, pkg - package of the node, type - name of the executable of the node, output - either output to screen or log file , respawn - restart the node if terminated, required - terminates other nodes in launchfile if this node is terminated.
<arg>
- argument of a launch file,
<include>
- element for including (starting) other launch files,
<param>
- to set parameters (described in following section),
<rosparam>
- to load yaml file with parameters (described in following section),
<group>
- to group individual nodes together into one namespace (e.g., /camera/…).
You can pass parameters to ROS nodes (and thus change the node behaviour) in different ways:
rosrun <package> <node> arg1:=value1 arg2:=value2
<param name=“arg1” value=“value1”/>
. You can specify either private parameters inside <node …> </node>
tags or global parameters outside the node.
<rosparam file=“$(find my_package)/config/my_params.yaml” />
, again either inside node or outside.
Once you have your python node you can load your private/global params using:
private_parameter = rospy.get_param("~private_parameter") global_parameter = rospy.get_param("/global_parameter")
TF is a ROS library for working with transformations between frames of reference. TF allows you to get, e.g., a position of a robot from any time by linear interpolation between measurements of the position. Moreover, it allows to create even complicated chains of transformations and expressing the position in any of the reference frames in the chain. For example, it allows you to get position in GPS coordinate frame of some object detected in camera measurement.
Once you run the turtlebot simulation try to:
rostopic echo /tf
in terminal to see the published transformations,
rqt
in top menu Plugins→Visualization→TF Tree or by command rosrun rqt_tf_tree rqt_tf_tree
.
Implement a simple keyboard joystick in python to drive the robot.
You can start the simulation together with the aro_robocop_keyboard node using roslaunch aro_robocop_keyboard robocop_keyboard.launch
.
Inside the aro_robocop_keyboard package follow the TODOs inside scripts/robocop_keyboard_control.py
.
The final functionality of the node should be as follows:
By pressing the specified keys the robot should increase/decrease linear and angular velocities.
w/x
' should increase/decrease the linear forward velocity of the robot.
a/d
should increase/decrease angular velocity around the z-axis (turning speed).
s
should stop the robot's movement.
Finally, you can also test the implemented stop service server by calling rosservice call /stop “{}”
in terminal.
Follow the assignment of the homework HW2.