ROS Tutorial Summarize

本文提供ROS(机器人操作系统)的基础教程,涵盖工作空间创建、包管理、节点运行及主题消息发布等核心内容。通过实例演示如何使用常用命令进行ROS开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tutorial 1 (Configurations)

  • Create a ROS workspace:
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin_make
  • Overlay the workspace over environment:
source devel/setup.bash
  • Check out:
echo $ROS_PACKAGE_PATH

Tutorial 2 (Packages)

  • Find the path of a package:
rospack find roscpp
  • Go into the path of a package:
roscd roscpp

The command will only find ROS packages that are within the directories listed in your ROS_PACKAGE_PATH.

  • Go into the log directory:
roscd log
  • List directory content:
rosls roscpp_tutorials

Tutorial 3 (Packages)

  • Create a ROS package:
cd ~/catkin_ws/src
catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

beginner_tutorials is the created packages while those after it are dependencies.

  • Build the workspace:
cd ~/catkin_ws
catkin_make
  • Source the workspace:
. ~/catkin_ws/devel/setup.bash
  • List 1st order packages dependencies:
rospack depends1 beginner_tutorials

These dependencies are stored in the package.xml file:

roscd beginner_tutorials
cat package.xml
  • List dependencies recursively:
rospack depends beginner_tutorials
  • Customize the package.xml:

Without comments, the file content looks like this:

<?xml version="1.0"?>
<package>
  <name>beginner_tutorials</name>
  <version>0.0.0</version>
  <description>The beginner_tutorials package</description>

  <maintainer email="xiaoqiang@todo.todo">xiaoqiang</maintainer>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
</package>

It contains the description tag, maintainer tag, license tag and dependencies tags, which can be customized as you wish.

The dependencies are split into build_depend, buildtool_depend, exec_depend(run_depend sometimes) and test_depend.

We want our specified dependencies to be available at build and run time, so we’ll add a run_depend tag for each of them as well:

<?xml version="1.0"?>
<package>
  <name>beginner_tutorials</name>
  <version>0.0.0</version>
  <description>The beginner_tutorials package</description>

  <maintainer email="xiaoqiang@todo.todo">xiaoqiang</maintainer>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>

  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>
</package>

Tutorial 4 (Packages)

  • Build packages:
rosmake beginner_tutorials

It builds (compiles) the beginner_tutorials plus all its dependencies in a correct order.

rosmake multiple packages:

rosmake [package1] [package2] [package3]
  • catkin_make

Usage:

catkin_make [make_targets] [-DCMAKE_VARIABLES=...]

It combines the calls to cmake and make in the standard CMake workflow.

If no target specified, it will compile all packages in the workspaces together in a correct order:

catkin_make
catkin_make install # (optionally)

The above command will build any catkin project found in the src folder.

To build projects in a different place, you would call catkin_make like this:

catkin_make --source my_src
catkin_make install --source my_src # (optionally)

Now, build your packages:

cd ~/catkin_ws
catkin_make

Tutorial 5 (ROS node)

  • Running roscore:
roscore

roscore is the first thing you should run when using ROS.

  • Using rosnode:
rosnode list
rosnode info /rosout

ROS node isn’t much more than an executable file within a ROS package.

ROS nodes use a ROS client library to communicate with other nodes.

  • Using rosrun:
rosrun [package_name] [node_name]

rosrun runs a node within a package.

rosrun turtlesim turtlesim_node

List all running nodes:

rosnode list
  • Reassign the name for a node:
rosrun turtlesim turtlesim_node __name:=my_turtle

List all running nodes:

rosnode list
  • Review:

roscore: master + rosout + parameter server
rosnode: ROS tool to get information about a node
rosrun: runs a node from a given package

Tutorial 6 (ROS topic)

  • Start roscore and run turtlesim:
roscore
rosrun turtlesim turtlesim_node
  • Move the turtle:
rosrun turtlesim turtle_teleop_key

Now move the turtle with arrow keys.

  • Show the graph of ROS running nodes:
rosrun rqt_graph rqt_graph

The nodes turtlesim_node and turtle_teleop_key are comunicated by using ROS topic /turtle1/cmd_vel.

One message publisher turtle_teleop_key and one message subscriber turtlesim_node.

  • rostopic:
rostopic -h

This lists all the available options and their explanations.

rostopic echo /turtle1/cmd_vel

This prints the publishing messages.

  • List all the running topics:
rostopic list -h # help on the available options
rostopic list -v # verbose
  • Show message type:
rostopic type /turtle1/cmd_vel

Result is geometry_msgs/Twist.

  • Show details of this type of message with rosmsg:
rosmsg show geometry_msgs/Twist

Result is:

geometry_msgs/Vector3 linear
  float64 x
  float64 y
  float64 z
geometry_msgs/Vector3 angular
  float64 x
  float64 y
  float64 z
  • Directly publish message using rostopic:
rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'

-1 means publish the message once. If you want to publish a steady stream of messages, use -r.

-- tells the option parser that none of the following arguments is an option (important e.g. when the arguments contain negative numbers).

The arguments '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]' are in YAML syntax. See YAML command line documentation for details.

  • rostopic hz:

See how fast the turtlesim_node is publishing /turtle1/pose:

rostopic hz /turtle1/pose

We can see the detailed format of the publishing/subscribing message:

rostopic type /turtle1/cmd_vel | rosmsg show
  • Using rqt_plot:

To plot the curve between /turtle1/pose/x and /turtle1/pose/y:

rosrun rqt_plot rqt_plot

In the pop up window, type /turtle1/pose/x in the text box after the Topic and press Enter. Then type /turtle1/pose/y and repeat the process.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值