Warning
This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

Lab 02

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?

Turtlebot simulator

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:

  1. Download the lab02.zip archive and unpack it in your workspace's src folder (to have e.g. catkin_ws/src/lab02_packages/).
  2. Build and source the workspace (using catkin build and source devel/setup.bash inside your workspace folder).
  3. Launch the simulation ideally inside tmux session by running launch file 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.

Robot Operating System (ROS) new buzzwords

There are several new key aspects/buzzwords to know from today's lab:

  • Service - Similar to topics, but used for synchronous communication with request + response model.
  • RViz - GUI program to visualize data such as cameras, maps, robot positions.
  • rqt - GUI program with many plugins to, e.g., plotting, calling services, publishing messages, showing graph of nodes.
  • PlotJuggler - GUI program to visualize data online on a certain topic or data loaded from rosbag.
  • Gazebo - Program for simulating robot physics.
  • ROS Parameters - a way of using global parameters among multiple nodes, i.e., using parameter server.
  • Config Files - yaml files with parameters for ROS nodes, they are loaded in launch files.
  • tf (transform system) - tf library is for working with transformations between frames of reference (e.g., transformation of camera measurements to GPS coordinates).

Visualization and debugging

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

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

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:

  • Plugins → Introspection → Node Graph,
  • Plugins → Visualization → TF Tree.

Alternatively, you can use some alias terminal commands for the most useful plugins. Try commands:

  • rqt_image_view - to see image data,
  • rqt_graph - to see connections between nodes,
  • rqt_plot - to plot 2D data from some topic.

PlotJuggler

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:

  • loading the bagfile from the homework 1,
  • run the simulator (roslaunch aro_sim robocop_sim.launch) and try plotting live published data.

Robot Operating System (ROS) continuation

Services

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

Launch files

XML files that automatize the start-up of nodes. The launch files enable functionalities such as:

  • Launching of multiple nodes,
  • Remapping of topics,
  • Grouping of nodes to namespaces,
  • Better handling of parameters/arguments as shown below.

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/…).

ROS Parameter

You can pass parameters to ROS nodes (and thus change the node behaviour) in different ways:

  • You can provide arguments to nodes using command line: rosrun <package> <node> arg1:=value1 arg2:=value2
  • A better way is to set the parameters in the launch file <param name=“arg1” value=“value1”/>. You can specify either private parameters inside <node …> </node> tags or global parameters outside the node.
  • The ultimate option is to use yaml file which is loaded in the launch file using <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")

Notice the list of parameters printed to terminal when you start a node.

TF (transform system)

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:

  • run rostopic echo /tf in terminal to see the published transformations,
  • visualize the tf tree in rqt in top menu Plugins→Visualization→TF Tree or by command rosrun rqt_tf_tree rqt_tf_tree.

Lab task

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.

  • Keys w/x' should increase/decrease the linear forward velocity of the robot.
  • Keys a/d should increase/decrease angular velocity around the z-axis (turning speed).
  • Key s should stop the robot's movement.

Finally, you can also test the implemented stop service server by calling rosservice call /stop “{}” in terminal.

Homework 2 assignment

Follow the assignment of the homework HW2.

courses/aro/tutorials/lab02.txt · Last modified: 2023/03/02 13:24 by penicrob