Page tree
Skip to end of metadata
Go to start of metadata

Overview

The overarching goal of this week's assignment is to get our fleet of Turtlebots to the point where we can implement the waypoint guidance, developed in simulation last week, on the actual hardware.

References and Prerequisites

Linux

  • The Linux Command Line - free PDF book you should have downloaded for Assignment 2
    • Read Chapter 16 - Networking - Particularly commands: ping, ssh and scp
      Our multiple robots will be connected to a  common network; a working knowledge of basic networking will save you lots of headaches when debugging your implementations.
      In particular, we will make use of the ssh command to access the computers onboard the robots. 
      Note: If you follow the introductory examples in the reading, you may need to install the traceroute program: sudo apt-get install traceroute

ROS

  • Work through the tutorial: Running ROS across multiple machines (It is a good idea to work through this tutorial using your laptop and the Turtlebot as the two machines, so within the tutorial substitute
    • marvin=IP_OF_LAPTOP
    • hal=IP_OF_TURTLEBOT
  • We will start using rviz in this assignment.  Watch this 2 minute introduction: https://youtu.be/i--Sd4xH9ZE.

TurtleBot3

Git Repository / ROS Package

As in the last couple assignments, your submission for this assignment will be a Git repository that contains a ROS package.  The name of the repository on the github.com server should be mrc_hw4 and it should be a ROS package (catkin_create_pkg).

TurtleBot 3 Setup

We have a number of TurtleBot 3 platforms. Depending on class size, students may need to work in pairs to share platforms.  As we move toward working with multiple robots simultaneously, students will need to share resources.

Laptop: Add Turtlebot ROS Packages

You will need the following packages added to your catkin workspace.  

  1. turtlebot3
  2. turtlebot3_msgs
  3. turtlebot3_nps

Adding new ROS projects typically follows this workflow:

  1. Clone source code into your catkin workspace

    cd ~/catkin_ws/src
    git clone https://github.com/ROBOTIS-GIT/turtlebot3.git
    git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
    
    git clone https://github.com/bbingham-nps/turtlebot3_nps
  2. Make the source

    cd ~/catkin_ws
    catkin_make
  3. Update the environment to be aware of the new ROS packages by

    source ~/catkin_ws/devel/setup.bash

    OR 
    Start a new terminal.  

Laptop: Set Environment Variable to Declare Turtlebot Type

By adding the environmental variable declaration to your ~/.bashrc file, the variable will be set for every command line session on your laptop.

  1. Edit the  ~/.bashrc file on your [Laptop]

  2. Add the line

    export TURTLEBOT3_MODEL=burger
  3. Either issue source ~/.bashrc or open a new terminal so the changes take effect.

Turtlebot: Hardware and Setup Network

Follow these instructions to setup the Turtlebot, your laptop and the network to work together:

  • The general instructions are at Turtlebot3 Setup for ME4823
    • Each turtlebot should be setup (connecting to the network, proper hostname, new OpenCR firmware).
    • Please skip to the Laptop Network Setup section of the instructions to configure your computer to work with the turtlebot.

Remote ROS Communication 

Follow the instructions for the TurtleBot3 e-Manual:Bringup - specifically for the TurtleBot Burger.  Note that commands that are given to be run on the [Remote PC] are to be run on your local laptop.  Commands that are given to be run on the [TurtleBot] should be executed on the SBC by using SSH to login to the robot's computer.

This builds on Running ROS across multiple machines tutorial.  You should know the IP address of your laptop and of the TurtlbotBot SBC.  It is suggested that you work through the steps of the tutorial using these two machines to get familiar with the mental model of working across the network.

Exercise 1: Joystick Control and Post-Processing

In this exercise we will run ROS nodes on your laptop, connected to a Logitech Gamepad F310, and have these nodes communicate over wireless with the TurtleBot SBC.  You will then drive the Pioneer around while recording a bag file and then produce a plot of where the robot thought it went.

System Bringup

  1. [Laptop]
    1. Plug in a Logitech USB gamepad
      1. The left upper trigger button (labeled "LB") enables publication of Twist messages on the cmd_vel topic
      2. While holding the enable button, the left joystick controls the value of the foward velocity and angular velocity commands generated.
    2. Use the bringup.launch file from the turtlebot3_nps package to start roscore, set the robot description, start the state publisher, start rviz and start the gamepad teleoperation node

      roslaunch turtlebot3_nps bringup.launch
  2. [TurtleBot]
    1. Connect to your turtlebot via SSH
    2. Start the sensors and actuation nodes on the Turtlebot with

      roslaunch turtlebot3_bringup turtlebot3_robot.launch

When everything is running, your ROS graph should look like this..

And RVIZ should show you a view of the system like this...

Use the ROS topic examination tools (either the command line rostopic or the graphical rqt_topic) to examine the topics being published on the system.  

  • Find the current firmware version being used and verify that it is version '1.2.3'
  • Find the current battery voltage.
    When the battery voltage falls below 11.0 volts, the system will generate an audio alarm (beep), and the robot won't move.

Driving and Recording Data

Once you can drive the robot, start recording a log file on your laptop:

cd ~/
mkdir mrc_hw4_data
cd mrc_hw4_data
rosbag record --all --output-name=joy.bag

While the data is being recorded, drive the robot around.  The path isn't important, we just want to cover some ground.  Try to drive at least 5 linear meters in any pattern.

Post-Processing

Process the bag file to generate four plots based on the robot odomatry and save the plots in your mrc_hw4 repository

  1. A plot the X and Y location of your robot. Save this file as images/joy_odom_xy.png
  2. A plot of the heading angle (yaw) of your robot, in degrees, as a function of time. Save this file as images/joy_odom_yaw.png
  3. A plot of the forward velocity of your robot, as a function of time. Save this file as images/joy_odom_u.png
  4. A quiver plot showing the location, yaw and speed of the robot.  Save this file as images/joy_odom_quiver.png
    See Assignment 3 for an example of how to generate this plot.

You will need to process the Odometry messages

  1. Create a new MATLAB script called matlab/joy_post.m in your mrc_hw4 repository.

Here is a snippet of MATLAB code to illustrate getting the position and orientation out of the bag file.

% Create a bag file object with the file name
bag = rosbag('~/mrc_hw4_data/joy.bag')
  
% Display a list of the topics and message types in the bag file
bag.AvailableTopics
  
% Since the messages on topic /odom are of type Odometry,
% let's see some of the attributes of the Odometry
% This helps determine the syntax for extracting data
msg_odom = rosmessage('nav_msgs/Odometry')
showdetails(msg_odom)
  
% Get just the topic we are interested in
bagselect = select(bag,'Topic','/odom');
  
% Create a time series object based on the fields of the turtlesim/Pose
% message we are interested in
ts = timeseries(bagselect,'Pose.Pose.Position.X','Pose.Pose.Position.Y',...
    'Twist.Twist.Linear.X','Twist.Twist.Angular.Z',...
    'Pose.Pose.Orientation.W','Pose.Pose.Orientation.X',...
    'Pose.Pose.Orientation.Y','Pose.Pose.Orientation.Z');
% The time vector in the timeseries (ts.Time) is "Unix Time"
% which is a bit cumbersome.  Create a time vector that is relative 
% to the start of the log file
tt = ts.Time-ts.Time(1);
% Plot the X position vs time
figure(1);
clf();
plot(tt,ts.Data(:,1))
xlabel('Time [s]')
ylabel('X [m]')

The results might look something like this...

Exercise 2: Waypoint Guidance in Odometry Frame

In this exercise we will use the controller Simulink waypoint controller from the previous assignment to guide the TurtleBot to the five waypoints below

Waypoint
x (m)
y (m)
11.00.0
21.01.0
3-1.01.0
4-1.00.0
50.00.0
  • Note - the waypoints are slightly different than those used in the turtlesim example.
  • The turtlebot should get to within 0.1 m of each of the waypoints.
  • The maximum forward velocity command does not need to be explicitly set by the controller - the hardware will implement this
  • Similarly, the maximum magnitude of the angular velocity command does not need to be explicitly set by the controller - the hardware will implement this
  • The update rate of the Simulink program should be roughly 20 Hz

Once you have a working setup - record a bag file to collect the odometry record of a successful run through all the waypoints.

The deliverables for the exercise are the Simulink control programs and four graphs as image files

  • Save your final Simulink implementation in the directory mrc_hw4/simulink/turtlebot_waypoint.slx
  • Record a bag file while running the the waypoints and post-process that bag file to generate three image files:
    1. A plot the X and Y location of your robot. Save this file as images/waypoint_odom_xy.png
    2. A plot of the heading angle (yaw) of your robot, in degrees, as a function of time. Save this file as images/waypoint_odom_yaw.png
    3. A plot of the forward velocity of your robot, as a function of time. Save this file as images/waypoint_odom_u.png
    4. A quiver plot showing the location, yaw and speed of the robot.  Save this file as images/waypoint_odom_quiver.png

Odometry Quaternion to Position and Yaw

One thing you will certainly need to do is to extract the heading (yaw) angle from the pose information published by the Turtlebot. The Turtlebot publishes its navigation estimate as nav_msgs/Odometry messages.  Each Odometry message includes the position information as a geometry_msgs/Pose message.  Each Pose message contains orientation information as a geometry_msgs/Quaterion message.  Luckily MATLAB includes the quat2eul function to convert from a quaternion to Euler angles.   See the provided Simulink example: Simulink ROS Idioms

Development Notes

Porting your Simulink controller from the simulation to hardware will be challenging and will require you to use the tools we've been learning about.  Below are some recommendations, but there is not a unique way (or even a best way).

  • Your wpt_fcn within the Simulink program will likely require some tuning, e.g., changing the gains or adding some additional logic to make the robot behave the way you would like.
  • To develop/debug the system requires using a variety of tools.
    • Rviz provides a good way to see what the robot thinks it is doing.  The default configuration has the "Fixed Frame" for viewing the robot as the base_footprint which results in the center of the viewing window moving with the robot.  If you change the Fixed Frame to odom then the frame of reference will be the odometry navigation frame.  There is a dropdown in the GUI to select this.
    • To drill down into the system, using rostopic echo or rqt_topic allow you to see what the odometry and cmd_vel values are in real time.
  • When you stop the Simulink program the robot continues moving based on the last cmd_vel it received.  Since the gamepad is still active, you can enable the teleoperation to stop the robot.
  • You will likely want to start each iteration of the development with the robot in the X,Y,Theta position of 0,0,0 (at the origin).  A simple way to reset the odometry is to restart the nodes on the TurtleBot
    • Return to the terminal window where you are logged on to the TurtleBot via SSH - where you previously issued the roslaunch turtlebot3_bringup turtlebot3_robot.launch command
    • Stop the ROS nodes with Ctrl-C
    • Restart the nodes by reissuing roslaunch turtlebot3_bringup turtlebot3_robot.launch

Stopping the Turtlebot

When you stop the Simulink program the robot continues moving based on the last cmd_vel it received.  There are a few ways you might manually send a Twist message to the turtlebot to stop it.

  • If the the gamepad is still active, you can enable the teleoperation to stop the robot.
  • From a terminal (either on the Laptop or the Turtlebot) publish a twist command with all zeros

    rostopic pub -1 /cmd_vel geometry_msgs/Twist -- '[0.0, 0.0, 0.0]' '[0.0, 0.0, 0.0]'
     

Summary

Upon completing the assignment your mrc_hw4 repository should look something like this...

 

 

  • No labels