ROS--4 常用的命令(小乌龟实例)

1: 配置环境

source /opt/ros/kinetic/setup.bash 

配置env内容如下

ROS_ROOT=/opt/ros/kinetic/share/ros The path where core ros packages are stored

PATH=/opt/ros/kinetic/bin:... The path to the ROS binaries, which we will be using throughout this lesson.

ROS_DISTRO=kinetic Which distribution of ROS is being used. In this case, we are using kinetic

PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages The path to the ROS python packages, which we will be using next lesson.

More information about the environment variables mentioned above, the ones not mentioned here, and others can be found here.

ROS/EnvironmentVariables - ROS Wiki

命令添加到启动脚本,自动配置

echo “source /opt/ros/kinetic/setup.bash ”  >>  ~/.bashrc

2. Starting the Master process

Before any ROS nodes can be run, the Master process must be started.

The Master process is responsible for the following (and more)

  • Providing naming and registration services to other running nodes
  • Tracking all publishers and subscribers
  • Aggregating log messages generated by the nodes
  • Facilitating connections between nodes
$ roscore

3.running Turtlesim Nodes

Now that the ROS master is running, we can run our first two ROS nodes.

First we will start the turtlesim_node, in the turtlesim package using the following command.

$ rosrun turtlesim turtlesim_node

Next, we will start the turtle_teleop_key node, also from the turtlesim package.

$ rosrun turtlesim turtle_teleop_key

Ps: turtlesim_nodeturtle_teleop_keyturtlesim里创建的两个node, turtlesimROS自带的一个软件包。在ROS里,每个node可以理解为一个独立的进程,有独立运行空间,又与其他node之间可以同步或通信。

4.Listing all Active Nodes

To get a list of all nodes that are active and have been registered with the ROS Master, we can use the command 

rosnode list

ps:列出当前运行系统中所有node

We can see that there are three active nodes that have been registered with the ROS Master, /rosout/teleop_turtle, and /turtlesim.

  • /rosout 
  • This node is launched by roscore. It subscribes to the standard /rosout topic, the topic to which all nodes send log messages.
  • /teleop_turtle 
  • This is our keyboard teleop node. Notice that it’s not named turtle_teleop_key. There’s no requirement that a node’s broadcasted name is the same as the name of it’s associated executable.
  • /turtlesim 
  • The node name associated with the turtlebot_sim node

5. Listing All Topics

In a similar fashion, we are able to query the ROS Master for a list of all topics. To do so, we use the command 

rostopic list.

Ps:列出当前运行系统中所有的topic。

  • /rosout_agg :Aggregated feed of messages published to /rosout.
  • /turtle1/cmd_vel :Topic upon which velocity commands are sent/received. Publishing a velocity message to this topic will command turtle1 to move.

  • /turtle1/color_sensor :Each turtle in turtlesim is equipped with a color sensor, and readings from the sensor are published to this topic.
  • /turtle1/pose :The position and orientation of turtle1 are published to this topic.

6. Get Information About a Specific Topic

If we wish to get information about a specific topic, who is publishing to it, subscribed to it, or the type of message associated with it, we can use the command

 $rostopic info.

Let’s check into the /turtle1/cmd_vel topic:

$rostopic info /turtle1/cmd_vel

Ps:查看/turtle1/cmd_vel主题的详细信息,包括主题发布者/订阅者,消息类型等。

As would be expected, there are two nodes registered on this topic. Our publisher, the teleop_turtle node, and our subscriber, the turtlesim node. Additionally, we can see that the type of message used on this topic is geometry_msgs/Twist.

7.Show Message Information

Let’s get some more information about the geometry_msgs/Twist message on the /turtle1/cmd_vel topic, to do so, we will use the rosmsg info command.

$rosmsg info geometry_msgs/Twist 

We can see that a Twist message consists nothing more than two Vector3 messages. One for linear velocity, and another for angular velocities, with each velocity component being represented by a float64.

Note: Sometimes, the message definition won’t provide an ample amount of detail about a message type. For example, in the example above, how can we be sure that linear and angular vectors above refer to velocities, and not positions? One way to get more detail would be to look at the comments in the message’s definition file. To do so, we can issue the following command: 

rosed geometry_msgs Twist.msg.

Note 2: More information about rosed, including how to select which editor is used by default can be found here.

ROS/Tutorials/UsingRosEd - ROS Wiki

8.Echo Messages on a Topic

Sometimes it may be useful to look at a topic’s published messages in real time.

To do so, we can use the command rostopic echo. Let’s take a look at the /turtle1/cmd_vel topic.

$ rostopic echo /turtle1/cmd_vel

If we then command the turtle to move from the turtle_teleop_key window, we will be able to see the output message in real-time.

Ps:实时查看主题信息

8. Computer Graph

rosrun rqt_graph rqt_graph

可以看到ROS的图形化界面,展示计算图所有结点的关系

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值