ROS实践(5)-调试相关

来源:互联网 发布:知乎长沙java培训 编辑:程序博客网 时间:2024/05/23 20:28

一 编译程序

root@yangkai04-Inspiron-3650:~/dev/rosbook# cp -r /home/yangkai04/Documents/Learning\ ROS\ for\ Robotics\ Programming\ 1448OS_Code/1448OS_03_code/chapter3_tutorials .
root@yangkai04-Inspiron-3650:~/dev/rosbook# mv chapter3_tutorials chapter3_tutorials.bak
root@yangkai04-Inspiron-3650:~/dev/rosbook# roscreate-pkg chapter3_tutorials std_msgs rospy roscpp
Created package directory /root/dev/rosbook/chapter3_tutorials
Created include directory /root/dev/rosbook/chapter3_tutorials/include/chapter3_tutorials
Created cpp source directory /root/dev/rosbook/chapter3_tutorials/src
Created package file /root/dev/rosbook/chapter3_tutorials/Makefile
Created package file /root/dev/rosbook/chapter3_tutorials/manifest.xml
Created package file /root/dev/rosbook/chapter3_tutorials/CMakeLists.txt
Created package file /root/dev/rosbook/chapter3_tutorials/mainpage.dox

Please edit chapter3_tutorials/manifest.xml and mainpage.dox to finish creating your package
root@yangkai04-Inspiron-3650:~/dev/rosbook# ls
chapter2_tutorials  chapter3_tutorials  chapter3_tutorials.bak
root@yangkai04-Inspiron-3650:~/dev/rosbook# ls chapter3_tutorials2
CMakeLists.txt  include  mainpage.dox  Makefile  manifest.xml  src
root@yangkai04-Inspiron-3650:~/dev/rosbook# cp -r chapter3_tutorials.bak/* chapter3_tutorials/
root@yangkai04-Inspiron-3650:~/dev/rosbook# cd chapter3_tutorials
root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter3_tutorials# ls
bag             config   launch        Makefile      output  srv
CMakeLists.txt  include  mainpage.dox  manifest.xml  src
root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter3_tutorials# rospack depends chapter3_tutorials
[rospack] Error: package 'chapter3_tutorials' depends on non-existent package 'opencv2' and rosdep claims that it is not a system dependency. Check the ROS_PACKAGE_PATH or try calling 'rosdep update'

解决:

简单的说,就是indigo版本以后,opencv的包,就不叫opencv2了,改成cv_bridge即可。


再次运行rosmake

root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter3_tutorials# rosmake
[rospack] Error: package 'chapter3_tutorials' depends on non-existent package 'pcl' and rosdep claims that it is not a system dependency. Check the ROS_PACKAGE_PATH or try calling 'rosdep update'

解决:
当前不叫pcl了,可以用命令查看:
root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter3_tutorials# rospack list | grep pcl
pcl_conversions /opt/ros/indigo/share/pcl_conversions
pcl_msgs /opt/ros/indigo/share/pcl_msgs
pcl_ros /opt/ros/indigo/share/pcl_ros

因此,把manifest.xml中:
  <depend package="pcl"/>
改为:
  <depend package="pcl_conversions"/>
  <depend package="pcl_msgs"/>
即可。

最后,再修改下example1.cpp,将以下几行注释掉:

  //ROSCONSOLE_AUTOINIT;
  //log4cxx::LoggerPtr my_logger =
  //  log4cxx::Logger::getLogger( ROSCONSOLE_DEFAULT_NAME );
  //my_logger->setLevel(
  //  ros::console::g_level_lookup[ros::console::levels::Debug]
  //);重新编译,即可成功

root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter3_tutorials# ls
bag  bin  build  CMakeLists.txt  config  include  launch  mainpage.dox  Makefile  manifest.xml  output  src  srv  srv_gen
root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter3_tutorials# rosmake
[ rosmake ] Results:                                                                                                                     
[ rosmake ] Built 65 packages with 0 failures.                                                                                           
[ rosmake ] Summary output to directory                                                                                                  
[ rosmake ] /root/.ros/rosmake/rosmake_output-20161110-145543  


二 调试-启动方法一

terminal1 启动主节点

root@yangkai04-Inspiron-3650:/home/yangkai04# roscore
... logging to /root/.ros/log/3e7bc9d8-a714-11e6-bcd2-f48e38af57c0/roslaunch-yangkai04-Inspiron-3650-7572.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://yangkai04-Inspiron-3650:46094/
ros_comm version 1.11.20

terminal2 启动其他节点

root@yangkai04-Inspiron-3650:/home/yangkai04# roscd chapter3_tutorials

root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter3_tutorials# gdb bin/example1
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from bin/example1...done.
(gdb) r
Starting program: /root/dev/rosbook/chapter3_tutorials/bin/example1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff170d700 (LWP 3299)]
[New Thread 0x7ffff0f0c700 (LWP 3300)]
[New Thread 0x7fffebfff700 (LWP 3301)]
[New Thread 0x7fffeb7fe700 (LWP 3306)]
[Thread 0x7fffeb7fe700 (LWP 3306) exited]
[Thread 0x7ffff170d700 (LWP 3299) exited]
[Thread 0x7ffff0f0c700 (LWP 3300) exited]
[Thread 0x7ffff7fbe7c0 (LWP 3294) exited]
[Inferior 1 (process 3294) exited normally]

三 调试-启动方法二

创建launch文件到chapter3_tutorials/launch/example1_gdb.launch,文件内容如下:

<?xml version="1.0" encoding="UTF-8"?><launch>  <!-- Logger config -->  <env name="ROSCONSOLE_CONFIG_FILE"       value="$(find chapter3_tutorials)/config/chapter3_tutorials.config"/>  <!-- Example 1 -->  <node pkg="chapter3_tutorials" type="example1" name="example1"        output="screen" launch-prefix="xterm -e gdb --args"/></launch>

启动主节点(rescore),以后都忽略该命令的输出

启动调试节点

roslaunch chapter3_tutorials example1_gdb.launch

运行结果



四 调试-valgrind

安装valgrind:

apt-get install valgrind

root@yangkai04-Inspiron-3650:/home/yangkai04# val
valgrind            valgrind-di-server  validlocale
valgrind.bin        valgrind-listener   
root@yangkai04-Inspiron-3650:/home/yangkai04# valgrind

编辑launch文件:

root@yangkai04-Inspiron-3650:/home/yangkai04# roscd chapter3_tutorials
root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter3_tutorials# vim launch/example1_valgrind.launch

<?xml version="1.0" encoding="UTF-8"?><launch>  <!-- Logger config -->  <env name="ROSCONSOLE_CONFIG_FILE"       value="$(find chapter3_tutorials)/config/chapter3_tutorials.config"/>  <!-- Example 1 -->  <node pkg="chapter3_tutorials" type="example1" name="example1"        output="screen" launch-prefix="valgrind"/></launch>


启动,下表中,紫色字体部分是valgrind输出信息。

root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter3_tutorials# roslaunch chapter3_tutorials example1_valgrind.launch
... logging to /root/.ros/log/61204ce8-a71e-11e6-bcd2-f48e38af57c0/roslaunch-yangkai04-Inspiron-3650-5695.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://yangkai04-Inspiron-3650:43913/

SUMMARY
========

PARAMETERS
 * /rosdistro: indigo
 * /rosversion: 1.11.20

NODES
  /
    example1 (chapter3_tutorials/example1)

auto-starting new master
process[master]: started with pid [5707]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 61204ce8-a71e-11e6-bcd2-f48e38af57c0
process[rosout-1]: started with pid [5720]
started core service [/rosout]
process[example1-2]: started with pid [5724]
==5724== Memcheck, a memory error detector
==5724== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==5724== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==5724== Command: /root/dev/rosbook/chapter3_tutorials/bin/example1 __name:=example1 __log:=/root/.ros/log/61204ce8-a71e-11e6-bcd2-f48e38af57c0/example1-2.log
==5724==
[DEBUG] [1478765961.873507730]: This is a simple DEBUG message!
[DEBUG] [1478765961.907039003]: This is a DEBUG message with an argument: 3.140000
[DEBUG] [1478765961.916783000]: This is DEBUG stream message with an argument: 3.14

==5724==
==5724== HEAP SUMMARY:
==5724==     in use at exit: 3,724 bytes in 48 blocks
==5724==   total heap usage: 2,537 allocs, 2,489 frees, 188,408 bytes allocated
==5724==
==5724== LEAK SUMMARY:
==5724==    definitely lost: 0 bytes in 0 blocks
==5724==    indirectly lost: 0 bytes in 0 blocks
==5724==      possibly lost: 716 bytes in 13 blocks
==5724==    still reachable: 3,008 bytes in 35 blocks
==5724==         suppressed: 0 bytes in 0 blocks
==5724== Rerun with --leak-check=full to see details of leaked memory
==5724==
==5724== For counts of detected and suppressed errors, rerun with: -v
==5724== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

[example1-2] process has finished cleanly
log file: /root/.ros/log/61204ce8-a71e-11e6-bcd2-f48e38af57c0/example1-2*.log

^C[rosout-1] killing on exit
[master] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
done


0 0
原创粉丝点击