ros相关笔记
ros命令
查看package的依赖
查看直接依赖
rospack depends1 beginner_tutorials
输出
roscpp
rospy
std_msgs
查看所有依赖包(包括依赖的包 依赖的 包)
rospack depends beginner_tutorials
更改ros默认依赖的opencv
https://blog.csdn.net/qq_33161084/article/details/90914366
ros melodic使用full安装后会自动安装opencv3.2,但cmake配置文件中的依赖添加并不完整,很多时候需要手动添加需要的依赖。如果系统中存在多个版本opencv,切换版本时也可以使用接下来的方法修改配置。
配置文件地址为:/opt/ros/melodic/share/cv_bridge/cmake/cv_bridgeConfig.cmake
catkin_make不编译某些package
https://answers.ros.org/question/54181/how-to-exclude-one-package-from-the-catkin_make-build/
catkin_make -DCATKIN_BLACKLIST_PACKAGES="foo;bar"
catkin_make指定编译某个package
catkin_make -DCATKIN_WHITELIST_PACKAGES=" 你的包名"
查看cmake相关变量
比如查看CATKIN变量
在build目录
cmake -L|grep CATKIN
CATKIN_BLACKLIST_PACKAGES:STRING=vps_detect
CATKIN_DEVEL_PREFIX:PATH=/home/nano/***/devel
CATKIN_ENABLE_TESTING:BOOL=ON
CATKIN_SKIP_TESTING:BOOL=OFF
CATKIN_SYMLINK_INSTALL:BOOL=OFF
CATKIN_WHITELIST_PACKAGES:STRING=
日志相关
rosconsole will load a config file from $ROS_ROOT/config/rosconsole.config when it initializes.
rosconsole also lets you define your own configuration file that will be used by log4cxx, defined by the ROSCONSOLE_CONFIG_FILE environment variable. Anything defined in this config file will override the default config file.
A simple example:
# Set the default ros output to warning and higher
log4j.logger.ros=WARN
# Override my package to output everything
log4j.logger.ros.my_package_name=DEBUG
cd $ROS_ROOT/config
vi rosconsole.config
#
# rosconsole will find this file by default at $ROS_ROOT/config/rosconsole.config
#
# You can define your own by e.g. copying this file and setting
# ROSCONSOLE_CONFIG_FILE (in your environment) to point to the new file
#
log4j.logger.ros=INFO
log4j.logger.ros.roscpp.superdebug=WARN
拷贝文件到xx目录,配置ROSCONSOLE_CONFIG_FILE环境变量=xx/rosconsole.config
日志级别分为
- DEBUG
- INFO
- WARN
- ERROR
- FATAL
launch file相关
todo
catkin_make编译相关
要让ros将某个目录认为是一个package.则在该目录下需要有package.xml文件
rostopic
查看当前有哪些topic

查看某一topic具体内容

roslaunch file注意事项
<param name="image_detected_topic" default="$(arg image_detected_topic)"/>
不要写成
<param name="image_detected_topic" default="$(arg_image_detected_topic)"/>

python3中使用rospy
rospy在安装ros时被默认安装到了/opt/ros/kinetic/lib/python2.7/dist-packages
python3中使用需要指定PYTHONPATH.并安装 rospkg catkin_pkg
https://stackoverflow.com/questions/49758578/installation-guide-for-ros-kinetic-with-python-3-5-on-ubuntu-16-04

pip install pyyaml
pip install rospkg catkin_pkg
代码里:
import sys
print(sys.path)
sys.path.append('/opt/ros/kinetic/lib/python2.7/dist-packages')
print(sys.path)
指定了PYTHONPATH的话,会把$PYTHONPATH加到sys.path的最前面.导致某些python3的库无法使用,比如cv2.
坐标转换相关
tf2::Matrix 完成矩阵和rpy等的转换.
http://docs.ros.org/en/jade/api/tf2/html/classtf2_1_1Matrix3x3.html
- 查看两个坐标系之间的关系
rosrun tf tf_echo base_link odom
-
rviz中xyz轴的颜色分别为红绿蓝.
-
查看系统中的tf tree
rosrun rqt_tf_tree rqt_tf_tree
-
rpy/matrix/四元数在线转换
https://www.andre-gaschler.com/rotationconverter/ -
ros中tf的frame_id和child_frame_id
表达的是frame_id这个坐标系到child_frame_id这个坐标系的变换.注意是frame坐标系到child_frame_id坐标系的变换!不是frame坐标系下的一个点变换到child_frame_id.
比如:A和B两个坐标系.变化矩阵为T
[1.,0., 0., -1,
0., 1., 0., 0,
0., 0., 1., 0,
0.0, 0.0, 0.0, 1.0,]
其对应的rpy xyz为
x:-1 y:0 z:0 roll:0 pitch:0 yaw:0
frame_id:A child_frame_id:B
表达的是A坐标系在x方向移动-1得到坐标系B. 坐标系A下的一个点pA与坐标系B下的点pB的对应关系为pA=T.dot(pB) 而不是pB=T.dot(pA)
- 由于要生成tf tree,所以不允许一个child frame有多个parent frame
比如
send_tf(fame_id=A,child_frame_id=B)
send_tf(fame_id=A,child_frame_id=C)
这样是合法的.
send_tf(fame_id=B,child_frame_id=A)
send_tf(fame_id=C,child_frame_id=A)
这样是不合法的.
不合法不是说程序不能编译运行. 你可以这么发,但是lookupTransform的时候是会报错的.
Failure at 1629192966.109406812
Exception thrown:"front_camera" passed to lookupTransform argument target_frame does not exist.
The current list of frames is:
Frame rslidar exists with parent right_camera.
ros中认定了一个frame只有能一个parent frame.详见http://wiki.ros.org/tf/FAQ
The frames are published incorrectly. tf expects the frames to form a tree. This means that each frame can only have one parent. If you publish for example both the transforms:
from "A (parent) to B (child)" and
from "C (parent) to B (child)".
This means that B has two parents: A and C. tf cannot de
- rostf2_ros包中有节点发送tf.
<node pkg="tf2_ros" type="static_transform_publisher" name="vehicle_rslidar_tf_fake" args="0.8 0.0 2.0 0.0 0.0 0.0 ndt_base_link rslidar_fake" />
- lookupTransform
xx = tf_buffer_.lookupTransform("A", "B",cluster_header_stamp, ros::Duration(2.5));
lookupTransform查询的是"A"坐标系到"B"坐标系的变换. 也即:B坐标系下的一个点p0左乘xx得到其在A坐标系下的位置.
- doTransform
tf2::doTransform(p0,p1,msg_transform_stamped_xx);
p0左乘msg_transform_stamped_xx得到p1. 如果p0是点p在坐标系A下的坐标,p1是点p在坐标系B下的坐标, 那么msg_transform_stamped_xx应该是坐标系B到坐标系A的变换.即lokkupTransform("B","A",timestamp)
topic相关
- 回调函数不变.改变topic.
https://stackoverflow.com/questions/17066839/unsubscribe-from-a-topic-and-subscribe-from-a-new-one-runtime-c-ros
os::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("A", 1, callbackFunc);
// Do something
...
// shutdown the subscriber (this should be unnecessary)
sub.shutdown();
// Now change the subscriber
sub = nh.subscribe("B", 1, callbackFunc);
// You are no longer subscribed to topic A
- ros中不支持一个puber在多个topic上发送信息
浙公网安备 33010602011771号