Wednesday, June 22, 2011

ROS + Gmapping + P3DX + SICK

This post deals with the complete procedure of using ROS to record a bag file which contains the LaserScan data from the SICK (mounted on a P3DX) and using the gmapping ROS package to build a map.

Operating P3DX with a sidewinder joystick

Things needed:
1) P3DX
2) Laptop
3) Sidewinder joystick (you could you use any other joystick too with a corresponding launch file)
4) ROS installed on your system

ROS packages required:
1) p2os
2) joy (dependency for p2os)
3) teleop_joy_sidewinder.launch (you could also use teleop_joy.launch depending on your joystick). The contents of this file are as follows:


Step 1:
Run roscore in your first terminal.

roscore


Step 2:
Run the p2os_dashboard:

$ rosrun p2os_dashboard p2os_dashboard

It has three basic functions:
1) Provides the robot's battery information
2) A button to view rxconsole
3) A button to enable/disable motors

Step 3:
Run the p2os node to connect to p3dx.

$ rosrun p2os_driver _port:=/dev/ttyUSB0

_port should be given the device address of the p3dx serial cable.

Step 4:

Launch the joystick launch file:

$ roslaunch p2os_launch teleop_joy_sidewinder.launch

Remember to keep the teleop_joy_sidewinder.launch file in the p2os_launch folder.

Step 5:

Enable the motors using the button(gear-shaped) on the p2os-dashboard.

Drive the robot around using the following button presses:

L + R + Axis

Gathering Laser scans in a bag file:

Things needed:
1) SICK Laser (mounted on your p3dx)
2) All the other things from the previous step

ROS Packages required:
1) sicktoolbox
2) sicktoolbox_wrapper

Installation procedure:
1) First download and install the sicktoolbox using rosmake.
2) Fire up your favorite editor and open this file (your_ros_installation_directory)/ros/diamondback/stacks/sicktoolbox/build/sicktoolbox-1.0/c++/drivers/lms/sicklms-1.0/SickLMS.cc . Go to line 2319.
3) In this line, add the O_NDELAY flag as shown here:

if((_sick_fd = open(_sick_device_path.c_str(), O_RDWR | O_NOCTTY| O_NDELAY)) < 0) {
throw SickIOException("SickLMS::_setupConnection: - Unable to open serial port");
}


4) After this line, add a system sleep call for 30 seconds. This is required so as to allow the sick laser to start up and start scanning.

sleep(30);


5) After completing these changes, use the makefile to remake the package. Do not use rosmake.

$ make all


6) Now download and install the sicktoolbox_wrapper .

STEP 1:
Begin joystick operation as explained in the previous step.

STEP 2:
Run the sicklms node in the sicktoolbox_wrapper as shown:

$ rosrun sicktoolbox_wrapper sicklms _port:=/dev/ttyUSB1 _baud:=38400 _resolution:=1.0

The sicklms node publishes sensor_msgs/LaserScan on the topic called scan .
Check rxgraph to examine the scenario and check whether the sicklms node is publishing data to the scan topic.

NOTE:
1) _resolution:=1.0 is important for gmapping
2) Set _port to the device address of the SICK's serial cable.

STEP 3:
Run rosbag to start recording data from the topics scan and tf

$ rosbag record -o gmapping_data.bag /scan /tf

The bag file be stored in your current directory along with a time stamp appended to the file name.

STEP 4:
Use the joystick to drive the p3dx around while it collects data from the laser into the bag file.

STEP 5:
After finishing a drive around your room, check your bag file using rxbag to see if contains bot the tf and the scan data.

Running Gmapping on the saved bagfile:

Now that you have successfully recorded the laser data into a bag file, it can be used anytime. We will now use it run gmapping on this set.

ROS packages required:
1) gmapping -- http://www.ros.org/wiki/gmapping
2)pr2_navigation -- http://www.ros.org/wiki/pr2_navigation -- this package is required only for a file move_base.vcg

STEP 1:
Run roscore

STEP 2:
Set the use_sim_time paramter to true

$ rosparam set use_sim_time "true"


STEP 3:
Run a transform publisher node to publish tf information between the base link and the laser:
$ rosrun tf static_transform_publisher 0 0 0 0 0 0 base_link laser 100 

STEP 4:
Run the slam_gmapping node:

$ rosrun gmapping slam_gmapping

This node will subscribe to the tf and scan data from the bag file.

STEP 5:
Play the bag file:

$ rosbag play --clock gmapping_data.bag

The bag file start playing and you will be able to see the time elapsed on the terminal.

STEP 6:
To visualize the map now, there are two options:
1) Store the map to a png file:

$ rosrun map_server map_saver


2) Real time visualization:
Fire up rviz:

$ rosrun rviz rviz

Open the following file in rviz:
(YOUR_ROS_INSTALLATION_DIRECTORY)/ros/diamondback/stacks/pr2_navigation/pr2_navigation_global/rviz/move_base.vcg


After the file gets loaded, you will be able to see the progress of the mapping process in real time.

9 comments:

  1. Hello Mr.Nikhil Soni,

    I am trying to use P3DX to do GMapping as well.
    And I wonder in order to use p2os, do I have to use 2 computers? Can I use only one computer? Because I don't have my P3DX with built-in computer.

    Also, can I use keyboard instead of Joystick?

    Thank you in advance.

    ReplyDelete
  2. Hi,

    You do not need two computers to use p2os. Just place your laptop on the p3dx, connect via serial cable and start the p2os node as mentioned in the post above.

    I'd suggest using a joystick because the "joy" node publishes the button values which are used to publish velocity commands to p2os.

    ReplyDelete
  3. Thank you for your answer! I am able to connect P3DX using 1 computer as you suggested but I don't know why teleop_keyboard can run but won't work to receive my keyboard. I think I will try joy controller.
    Do you have suggestion which joy controller I should use? I'm afraid of joy driver's problem on Ubuntu.

    ReplyDelete
  4. I don't know why the teleop_keyboard won't work. I suggest that you use either the Xbox 360 controller or Microsoft sidewinder. Ubuntu 11.04 works just fine with them.

    ReplyDelete
  5. Thank you for suggestion! I am be able to use the teleop_keyboard and wish to try Xbox 360 controller as well. Before, I was very stupid that forgot to enable motors.

    ReplyDelete
  6. Hi Nikhil,

    Could you please tell me a bit details about how to install sicktoolbox and sicktoolbox_wrapper? i'm trying for few days. couldn't figure it out. I'm very new in ros. I installed hydro on ubuntu 12.04. now trying to connect sick laser?

    thanks in advance

    ReplyDelete
  7. Hi,

    For installation,
    $ git clone https://github.com/ros-drivers/sicktoolbox
    in your catkin workspace
    then use catkin_make to install it.

    For sicktoolbox_wrapper:
    $ git clone https://github.com/ros-drivers/sicktoolbox_wrapper
    and again, use catkin_make to install it.

    ReplyDelete
  8. Nikhil mate, u r awesome. Thanks a lots. I managed all steps.
    Going to test soon.

    thanks again

    ReplyDelete
  9. Hi Nikhil,
    I have some
    Hardware: Pioneer3, SICK-lms200, laptop, 2 usb-serial cables

    Software: ros-hydro-desktop-full on laptop running ubuntu-12.04. sicktoolbox(works fine)

    Objectives: 1. To control robot by laptop keyboard and log laser data. 2. To build map from that logged data using slam_gmapping.(I know how to achieve objective2)

    Could you please help me to connect my robot with laptop directly through usb-serial cable to achieve objective1? I tried to find from ask.ros. It seems if i follow those i need to connect my laptop with robot computer. but, my robot pc is obsolete. I tried to use p2os which is build on my catkin_ws.
    If i execute
    $rosrun p2os_teleop p2os_teleop _port:=/dev/ttyUSB0
    then i see
    [ INFO] [1382071862.920709537]: deadman_button: 0
    [ INFO] [1382071862.920890680]: run_button: 0
    and then it's doing nothing.
    if I execute
    $ rosrun p2os_driver _port:=/dev/ttyUSB0
    I get
    [rosrun] Couldn't find executable named /home/albot1/catkin_ws/src/p2os/p2os_driver/_port:=/dev/ttyUSB0
    Don't know what's going on. I think i didn't get all the steps properly.

    Thanks in advance

    ReplyDelete