ROS-an example

1. 通过VNC 在VNC窗口上出入

odroid@odroid-desktop:~$ roscore  得到下面错误信息

process[rosout-1]: started with pid [3751]
started core service [/rosout]
terminate called after throwing an instance of 'std::runtime_error'
what(): locale::facet::_S_create_c_locale name not valid
[rosout-1] process has died [pid 3751, exit code -6, cmd /opt/ros/jade/lib/rosout/rosout __name:=rosout __log:=/home/odroid/.ros/log/9cdba11a-3419-11e1-a50e-36e66a0e97b1/rosout-1.log].
log file: /home/odroid/.ros/log/9cdba11a-3419-11e1-a50e-36e66a0e97b1/rosout-1*.log

解决方法:

 

export LC_ALL="C" 

 

这到底是什么意思?
LC_ALL=C 是为了去除所有本地化的设置,让命令能正确执行。
---------------------------------

在Linux中通过locale来设置程序运行的不同语言环境,locale由ANSI C提供支持。locale的命名规则为<语言>_<地区>.<字符集编码>,如zh_CN.UTF-8,zh代表中文,CN代表大陆地区,UTF-8表示字符集。在locale环境中,有一组变量,代表国际化环境中的不同设置:1. LC_COLLATE
定义该环境的排序和比较规则

2. LC_CTYPE
用于字符分类和字符串处理,控制所有字符的处理方式,包括字符编码,字符是单字节还是多字节,如何打印等。是最重要的一个环境变量。

3. LC_MONETARY
货币格式

4. LC_NUMERIC
非货币的数字显示格式

5. LC_TIME
时间和日期格式

6. LC_MESSAGES
提示信息的语言。另外还有一个LANGUAGE参数,它与LC_MESSAGES相似,但如果该参数一旦设置,则LC_MESSAGES参数就会失效。LANGUAGE参数可同时设置多种语言信息,如LANGUANE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"。

7. LANG
LC_*的默认值,是最低级别的设置,如果LC_*没有设置,则使用该值。类似于 LC_ALL。

8. LC_ALL
它是一个宏,如果该值设置了,则该值会覆盖所有LC_*的设置值。注意,LANG的值不受该宏影响。

C"是系统默认的locale,"POSIX"是"C"的别名。所以当我们新安装完一个系统时,默认的locale就是C或POSIX。

2. 创建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

创建的包beginner_tutorials 里面没有实际的代码

build 

$ cd ~/catkin_ws
$ catkin_make

加入环境变量

$ . ~/catkin_ws/devel/setup.bash

3. run example

前提条件已经安装了jade版本的例程

$ sudo apt-get install ros-<distro>-ros-tutorials

在终端中启动服务端

roscore

在另外一个终端中

rosrun turtlesim turtlesim_node
$ rosrun [package_name] [node_name]

改变 node的名字

$ rosrun turtlesim turtlesim_node __name:=my_turtle
$ rosnode list
You will see something similar to:
/rosout
/my_turtle
rosnode ping my_turtle
rosnode: node is [/my_turtle]
pinging /my_turtle with a timeout of 3.0s
xmlrpc reply from http://aqy:42235/     time=1.152992ms
xmlrpc reply from http://aqy:42235/     time=1.120090ms
xmlrpc reply from http://aqy:42235/     time=1.700878ms
xmlrpc reply from http://aqy:42235/     time=1.127958ms

在第三个终端中输入

$ rosrun turtlesim turtle_teleop_key

可以使用键盘控制乌龟运动

4. 查看topic之间的图形关系,  安装 rqt_graph

$ sudo apt-get install ros-<distro>-rqt
$ sudo apt-get install ros-<distro>-rqt-common-plugins

 

In a new terminal:

$ rosrun rqt_graph rqt_graph

You will see something similar to:

rqt_graph_turtle_key.png

 

连各个node之间采用名为/turtle1/command_velocity topic来通信

5 .rostopic 工具 ,可以查看node之间的信息

$ rostopic -h
rostopic bw     display bandwidth used by topic
rostopic echo   print messages to screen
rostopic hz     display publishing rate of topic    
rostopic list   print information about active topics
rostopic pub    publish data to topic
rostopic type   print topic type

例如上例

$
$ rostopic type /turtle1/cmd_vel
  • You should get:
    geometry_msgs/Twist
rostopic list -h
Usage: rostopic list [/topic]

Options:
  -h, --help            show this help message and exit
  -b BAGFILE, --bag=BAGFILE
                        list topics in .bag file
  -v, --verbose         list full details about each topic
  -p                    list only publishers
  -s                    list only subscribers

 

$ rostopic echo /turtle1/cmd_vel

 

rostopic pub publishes data on to a topic currently advertised.

Usage:

rostopic pub [topic] [msg_type] [args]
  • $ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
turtlesim/Velocity 为msg_type  -r 1 为1s发布一次

 6. rqt_console and roslaunch

$ rosrun rqt_console rqt_console

$ rosrun rqt_logger_level rqt_logger_level

开启两个窗口后,在新的终端执行

Now let's start turtlesim in a new terminal:


$ rosrun turtlesim turtlesim_node

这样在 rqt_console 中就可以看到log消息了

 

 

 

 

posted @ 2015-07-03 16:33  fastwave2004  阅读(1149)  评论(0编辑  收藏  举报