DQ's ROS Tutorials(Beginner Level) Study

1. Installing and Configuring Your ROS Environment

Installing please refer the artical: Ubuntu 14.04 install ROS Indigo
make sure that you have your environment properly setup.

printenv | grep ROS

Create a ROS Workspace , create a catkin workspace:

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace

Built the workspace:

$ cd ~/catkin_ws/
$ catkin_make

Before continuing source your new setup.*sh file:

$ source devel/setup.bash

make sure ROS_PACKAGE_PATH environment variable includes the directory you’re in:

$ echo $ROS_PACKAGE_PATH
/home/youruser/catkin_ws/src:/opt/ros/kinetic/share:/opt/ros/kinetic/stacks

2. Navigating the ROS Filesystem

sudo apt-get install ros-Indigo-ros-tutorials

rospack find [package_name]
eg: rospack find roscpp

roscd [locationname[/subdir]]
eg: roscd roscpp

echo $ROS_PACKAGE_PATH

roscd log

rosls [locationname[/subdir]]
eg: rosls roscpp_tutorials

3. Creating a ROS Package

# You should have created this in the Creating a Workspace Tutorial
$ cd ~/catkin_ws/src

$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

# build the packages in the catkin workspace
$ cd ~/catkin_ws
$ catkin_make

# To add the workspace to your ROS environment
$ . ~/catkin_ws/devel/setup.bash

4. Building a ROS Package

catkin_make is a command line tool which adds some convenience to the standard catkin workflow. You can imagine that catkin_make combines the calls to cmake and make in the standard CMake workflow.

source /opt/ros/indigo/setup.bash

# In a catkin workspace
# catkin_make --source my_src
# catkin_make install --source my_src  # (optionally)

cd ~/catkin_ws/
ls src
catkin_make
catkin_make install  # (optionally)

5. Understanding ROS Nodes

先安装一个轻量级模拟器(之前装过了):

$ sudo apt-get install ros-indigo-ros-tutorials

图的概念:

  • Nodes: A node is an executable that uses ROS to communicate with other nodes.

  • Messages: ROS data type used when subscribing or publishing to a topic.

  • Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.

  • Master: Name service for ROS (i.e. helps nodes find each other)

  • rosout: ROS equivalent of stdout/stderr

  • roscore: Master + rosout + parameter server (parameter server will be introduced later)

在一个终端中输入: roscore, 打开一个rosout服务, 在另一个终端中输入rosnode list, 将看到 /rosout, 查看详细信息: rosnode info /rosout.

# rosrun [package_name] [node_name], 需要先打开roscore, 在另一个终端输入
$ rosrun turtlesim turtlesim_node

# 再开一个终端
$ rosnode list

# 再开一个终端
$ rosrun turtlesim turtlesim_node __name:=my_turtle

$ rosnode cleanup

6. Understanding ROS Topics

setup

# First Terminal
roscore

# Second Terminal 
rosrun turtlesim turtlesim_node

# Third Terminal
rosrun turtlesim turtle_teleop_key
# Then you can use arrow keys of the keyboard to drive the turtle around.

ROS Topics

# Fourth Terminal
sudo apt-get install ros-indigo-rqt
sudo apt-get install ros-indigo-rqt-common-plugins

rosrun rqt_graph rqt_graph

# You can use the help option to get the available sub-commands for rostopic
rostopic -h

# rostopic echo shows the data published on a topic. 
rostopic echo /turtle/cmd_vel

# rostopic list returns a list of all topics currently subscribed to and published. 
rostopic list
rostopic list -h
rostopic list -v

ROS Messages

# rostopic type returns the message type of any topic being published. 
rostopic type /turtle1/cmd_vel
rostopic type /turtle1/command_velocity

rostopic with messages

# rostopic pub publishes data on to a topic currently advertised. 
# rostopic pub [topic] [msg_type] [args]
rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'

# rostopic hz reports the rate at which data is published. 
# rostopic hz [topic]
rostopic hz /turtle1/pose
rostopic type /turtle1/cmd_vel | rosmsg show

rqt_plot

# rqt_plot displays a scrolling time plot of the data published on topics.
rosrun rqt_plot rqt_plot

7. Understanding ROS Services and Parameters

ROS Services

Services are another way that nodes can communicate with each other. Services allow nodes to send a request and receive a response.

rosservicedescrible
rosservice listprint information about active services
rosservice callcall the service with the provided args
rosservice typeprint service type
rosservice findfind services by service type
rosservice uriprint service ROSRPC uri
rosservice list
rosservice type /clear

# clears the background of the turtlesim_node. 
rosservice call /clear

# This service lets us spawn a new turtle at a given location and orientation. 
rosservice type /spawn| rossrv show
rosservice call /spawn 2 2 0.2 ""
# Then Second Turtle will be seen.

rosparam

rosparam allows you to store and manipulate data on the ROS Parameter Server. The Parameter Server can store integers, floats, boolean, dictionaries, and lists. rosparam uses the YAML markup language for syntax. In simple cases, YAML looks very natural: 1 is an integer, 1.0 is a float, one is a string, true is a boolean, [1, 2, 3] is a list of integers, and {a: b, c: d} is a dictionary. rosparam has many commands that can be used on parameters, as shown below:

rosparamdescrible
rosparam setset parameter
rosparam getget parameter
rosparam loadload parameters from file
rosparam dumpdump parameters to file
rosparam deletedelete parameter
rosparam listlist parameter names
rosparam list

# we have to call the clear service for the parameter change to take effect
rosparam set /background_r 150
rosservice call /clear

rosparam get /background_g 

# write all the parameters to the file params.yaml 
rosparam dump params.yaml
rosparam load params.yaml copy
rosparam get /copy/background_b

8. Using rqt_console and roslaunch

rqt_console and rqt_logger_level

sudo apt-get install ros-indigo-rqt ros-indigo-rqt-common-plugins ros-indigo-turtlesim

# First Terminal
roscore

# Second Terminal
rosrun rqt_console rqt_console

# Third Terminal
rosrun rqt_logger_level rqt_logger_level

# Fourth Terminal
rosrun turtlesim turtlesim_node

# Fifth Terminal, let's run our turtle into the wall and see what is displayed in our rqt_console
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'

roslaunch

cd ~/catkin_ws
source devel/setup.bash
roscd beginner_tutorials
mkdir launch
cd launch
gedit turtlemimic.launch

# paste the following to turtlemimic.launch
# begin
<launch>

  <group ns="turtlesim1">
    <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
  </group>

  <group ns="turtlesim2">
    <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
  </group>

  <node pkg="turtlesim" name="mimic" type="mimic">
    <remap from="input" to="turtlesim1/turtle1"/>
    <remap from="output" to="turtlesim2/turtle1"/>
  </node>

</launch>
# end

roslaunch beginner_tutorials turtlemimic.launch
rostopic pub /turtlesim1/turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'
rqt_graph

9. Using rosed to edit files in ROS

sudo apt-get install vim
rosed roscpp Logger.msg

rosed roscpp <tab><tab>

# you can change you editor from vim to nano or emacs
export EDITOR='nano -w'
export EDITOR='emacs -nw'
# open a new Terminal and see if the EDITOR is defined
echo $EDITOR

10. Creating a ROS msg and srv

using msg and srv

cd ~/catkin_ws
source devel/setup.bash
roscd beginner_tutorials
mkdir msg
echo "int64 num" > msg/Num.msg

# package.xml, uncommented
<build_depend>message_generation</build_depend>
<run_depend>message_runtime</run_depend>

#  CMakeLists.txt
find_package(catkin REQUIRED COMPONENTS
   roscpp
   rospy
   std_msgs
   message_generation
)

catkin_package(
  ...
  CATKIN_DEPENDS message_runtime ...
  ...)

add_message_files(
  FILES
  Num.msg
)

generate_messages(
  DEPENDENCIES
  std_msgs
)

add_service_files(
  FILES
  AddTwoInts.srv
)

using rosmsg

rosmsg show beginner_tutorials/Num
rosmsg show Num

using srv

roscd beginner_tutorials
mkdir srv
roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv

rossrv show beginner_tutorials/AddTwoInts
rossrv show AddTwoInts

Common step for msg and srv

# In your catkin workspace
# cd ~/catkin_ws
# source devel/setup.bash
roscd beginner_tutorials
cd ../..
catkin_make install
cd -

Getting help

rosmsg -h
rosmsg show -h

11. Writing a Simple Publisher and Subscriber (C++)

Writing the Publisher Node

cd ~/catkin_ws
source devel/setup.bash
roscd beginner_tutorials
mkdir src
gedit src/talker.cpp

# paste the following code to talker.cpp
/*
 * Copyright (C) 2008, Morgan Quigley and Willow Garage, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *   * Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *   * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived from
 *     this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
// %Tag(FULLTEXT)%
// %Tag(ROS_HEADER)%
#include "ros/ros.h"
// %EndTag(ROS_HEADER)%
// %Tag(MSG_HEADER)%
#include "std_msgs/String.h"
// %EndTag(MSG_HEADER)%

#include <sstream>

/**
 * This tutorial demonstrates simple sending of messages over the ROS system.
 */
int main(int argc, char **argv)
{
  /**
   * The ros::init() function needs to see argc and argv so that it can perform
   * any ROS arguments and name remapping that were provided at the command line.
   * For programmatic remappings you can use a different version of init() which takes
   * remappings directly, but for most command-line programs, passing argc and argv is
   * the easiest way to do it.  The third argument to init() is the name of the node.
   *
   * You must call one of the versions of ros::init() before using any other
   * part of the ROS system.
   */
// %Tag(INIT)%
  ros::init(argc, argv, "talker");
// %EndTag(INIT)%

  /**
   * NodeHandle is the main access point to communications with the ROS system.
   * The first NodeHandle constructed will fully initialize this node, and the last
   * NodeHandle destructed will close down the node.
   */
// %Tag(NODEHANDLE)%
  ros::NodeHandle n;
// %EndTag(NODEHANDLE)%

  /**
   * The advertise() function is how you tell ROS that you want to
   * publish on a given topic name. This invokes a call to the ROS
   * master node, which keeps a registry of who is publishing and who
   * is subscribing. After this advertise() call is made, the master
   * node will notify anyone who is trying to subscribe to this topic name,
   * and they will in turn negotiate a peer-to-peer connection with this
   * node.  advertise() returns a Publisher object which allows you to
   * publish messages on that topic through a call to publish().  Once
   * all copies of the returned Publisher object are destroyed, the topic
   * will be automatically unadvertised.
   *
   * The second parameter to advertise() is the size of the message queue
   * used for publishing messages.  If messages are published more quickly
   * than we can send them, the number here specifies how many messages to
   * buffer up before throwing some away.
   */
// %Tag(PUBLISHER)%
  ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
// %EndTag(PUBLISHER)%

// %Tag(LOOP_RATE)%
  ros::Rate loop_rate(10);
// %EndTag(LOOP_RATE)%

  /**
   * A count of how many messages we have sent. This is used to create
   * a unique string for each message.
   */
// %Tag(ROS_OK)%
  int count = 0;
  while (ros::ok())
  {
// %EndTag(ROS_OK)%
    /**
     * This is a message object. You stuff it with data, and then publish it.
     */
// %Tag(FILL_MESSAGE)%
    std_msgs::String msg;

    std::stringstream ss;
    ss << "hello world " << count;
    msg.data = ss.str();
// %EndTag(FILL_MESSAGE)%

// %Tag(ROSCONSOLE)%
    ROS_INFO("%s", msg.data.c_str());
// %EndTag(ROSCONSOLE)%

    /**
     * The publish() function is how you send messages. The parameter
     * is the message object. The type of this object must agree with the type
     * given as a template parameter to the advertise<>() call, as was done
     * in the constructor above.
     */
// %Tag(PUBLISH)%
    chatter_pub.publish(msg);
// %EndTag(PUBLISH)%

// %Tag(SPINONCE)%
    ros::spinOnce();
// %EndTag(SPINONCE)%

// %Tag(RATE_SLEEP)%
    loop_rate.sleep();
// %EndTag(RATE_SLEEP)%
    ++count;
  }


  return 0;
}
// %EndTag(FULLTEXT)%

Writing the Subscriber Node

gedit src/listener.cpp

# paste the follwing code to listener.cpp
/*
 * Copyright (C) 2008, Morgan Quigley and Willow Garage, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *   * Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *   * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived from
 *     this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

// %Tag(FULLTEXT)%
#include "ros/ros.h"
#include "std_msgs/String.h"

/**
 * This tutorial demonstrates simple receipt of messages over the ROS system.
 */
// %Tag(CALLBACK)%
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}
// %EndTag(CALLBACK)%

int main(int argc, char **argv)
{
  /**
   * The ros::init() function needs to see argc and argv so that it can perform
   * any ROS arguments and name remapping that were provided at the command line.
   * For programmatic remappings you can use a different version of init() which takes
   * remappings directly, but for most command-line programs, passing argc and argv is
   * the easiest way to do it.  The third argument to init() is the name of the node.
   *
   * You must call one of the versions of ros::init() before using any other
   * part of the ROS system.
   */
  ros::init(argc, argv, "listener");

  /**
   * NodeHandle is the main access point to communications with the ROS system.
   * The first NodeHandle constructed will fully initialize this node, and the last
   * NodeHandle destructed will close down the node.
   */
  ros::NodeHandle n;

  /**
   * The subscribe() call is how you tell ROS that you want to receive messages
   * on a given topic.  This invokes a call to the ROS
   * master node, which keeps a registry of who is publishing and who
   * is subscribing.  Messages are passed to a callback function, here
   * called chatterCallback.  subscribe() returns a Subscriber object that you
   * must hold on to until you want to unsubscribe.  When all copies of the Subscriber
   * object go out of scope, this callback will automatically be unsubscribed from
   * this topic.
   *
   * The second parameter to the subscribe() function is the size of the message
   * queue.  If messages are arriving faster than they are being processed, this
   * is the number of messages that will be buffered up before beginning to throw
   * away the oldest ones.
   */
// %Tag(SUBSCRIBER)%
  ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
// %EndTag(SUBSCRIBER)%

  /**
   * ros::spin() will enter a loop, pumping callbacks.  With this version, all
   * callbacks will be called from within this thread (the main one).  ros::spin()
   * will exit when Ctrl-C is pressed, or the node is shutdown by the master.
   */
// %Tag(SPIN)%
  ros::spin();
// %EndTag(SPIN)%

  return 0;
}
// %EndTag(FULLTEXT)%

Buliding your nodes

Your resulting CMakeLists.txt should look like this:

<pre style="color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; white-space: pre-wrap;"># %Tag(FULLTEXT)%
cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

## Declare ROS messages and services
add_message_files(FILES Num.msg)
add_service_files(FILES AddTwoInts.srv)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package
catkin_package()

## Build talker and listener
include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker beginner_tutorials_generate_messages_cpp)

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_tutorials_generate_messages_cpp)

# %EndTag(FULLTEXT)%</pre>
cd ~/catkin_ws
catkin_make

13. Examining the Simple Publisher and Subscriber

# First Terminal
roscore

# second Terminal
cd ~/catkin_ws
source ./devel/setup.bash
rosrun beginner_tutorials talker

# Third Terminal
cd ~/catkin_ws
source ./devel/setup.bash
rosrun beginner_tutorials listener

14. Writing a Simple Service and Client (C++)

cd ~/catkin_ws
source ./devel/setup.bash
roscd beginner_tutorials

gedit src/add_two_ints_server.cpp
#include "ros/ros.h"
#include "beginner_tutorials/AddTwoInts.h"

bool add(beginner_tutorials::AddTwoInts::Request  &req,
         beginner_tutorials::AddTwoInts::Response &res)
{
    res.sum = req.a + req.b;
    ROS_INFO("request: x=%ld, y=%ld", (long int)req.a, (long int)req.b);
    ROS_INFO("sending back response: [%ld]", (long int)res.sum);
    return true;
}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "add_two_ints_server");
    ros::NodeHandle n;

    ros::ServiceServer service = n.advertiseService("add_two_ints", add);
    ROS_INFO("Ready to add two ints.");
    ros::spin();

    return 0;
}
gedit src/add_two_ints_client.cpp
#include "ros/ros.h"
#include "beginner_tutorials/AddTwoInts.h"
#include <cstdlib>

int main(int argc, char **argv)
{
   ros::init(argc, argv, "add_two_ints_client");
   if (argc != 3)
   {
       ROS_INFO("usage: add_two_ints_client X Y");
       return 1;
   }

   ros::NodeHandle n;
   ros::ServiceClient client = n.serviceClient<beginner_tutorials::AddTwoInts>("add_two_ints");
   beginner_tutorials::AddTwoInts srv;
   srv.request.a = atoll(argv[1]);
   srv.request.b = atoll(argv[2]);
   if (client.call(srv))
   {
     ROS_INFO("Sum: %ld", (long int)srv.response.sum);
   }
   else
   {
     ROS_ERROR("Failed to call service add_two_ints");
     return 1;
   }

   return 0;
}

CMakeLists.txt:

# %Tag(FULLTEXT)%
cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

## Declare ROS messages and services
add_message_files(FILES Num.msg)
add_service_files(FILES AddTwoInts.srv)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package
catkin_package()

## Build talker and listener
include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})

## Build service client and server
# %Tag(SRVCLIENT)%
add_executable(add_two_ints_server src/add_two_ints_server.cpp)
target_link_libraries(add_two_ints_server ${catkin_LIBRARIES})
add_dependencies(add_two_ints_server beginner_tutorials_gencpp)

add_executable(add_two_ints_client src/add_two_ints_client.cpp)
target_link_libraries(add_two_ints_client ${catkin_LIBRARIES})
add_dependencies(add_two_ints_client beginner_tutorials_gencpp)

# %EndTag(SRVCLIENT)%

# %EndTag(FULLTEXT)%
# In your catkin workspace
cd ~/catkin_ws
catkin_make

16. Examining the Simple Service and Client

# 接上一节
# NEW First Terminal
cd ~/catkin_ws
source ./devel/setup.bash
rosrun beginner_tutorials add_two_ints_server
# NEW Second Terminal
cd ~/catkin_ws
source ./devel/setup.bash
rosrun beginner_tutorials add_two_ints_client 1 3

17. Recording and playing back data

Recording data (creating a bag file)

# Three Terminal
roscore
rosrun turtlesim turtlesim_node 
rosrun turtlesim turtle_teleop_key

# see Published topics can be recorded
rostopic list -v

mkdir ~/bagfiles
cd ~/bagfiles
rosbag record -a
# Move back to the terminal window with turtle_teleop and move the turtle around for 10 or so seconds. Then In the window running rosbag record exit with a Ctrl-C.

Examining and playing the bag file

# Press Tab and it will give the only bagfile name
rosbag info <your bagfile>
rosbag play <your bagfile>

# this is the trajectory that would have resulted had you issued your keyboard commands twice as fast. 
rosbag play -r 2 <your bagfile>

Recording a subset of the data

# If any turtlesim nodes are running exit them and relaunch the keyboard teleop launch file: 
rosrun turtlesim turtlesim_node 
rosrun turtlesim turtle_teleop_key

rosbag record -O subset /turtle1/cmd_vel /turtle1/pose
# The -O argument tells rosbag record to log to a file named subset.bag, and the topic arguments cause rosbag record to only subscribe to these two topics. Move the turtle around for several seconds using the keyboard arrow commands, and then Ctrl-C the rosbag record. 

# check the contents of the bag file 
rosbag info subset.bag

18. Getting started with roswtf

roswtf examines your system to try and find problems.

# please make sure your roscore is NOT running. 
roscd
roswtf

# Start a roscore
roscd
roswtf

# Creat some errors. STOP roscore
roscd
ROS_PACKAGE_PATH=bad:$ROS_PACKAGE_PATH roswtf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值