ROS下驱动SLAMETC的A2和A3雷达步骤如下:
1、连上激光雷达并进入至/dev文件夹中查看ttyUSB?的编号
2、使用sudo chmod 777 ttyUSB*来更改USB端口权限、
3、调整A2和A3激光雷达的硬件波特率使其匹配
4、编写launch文件使其同时启动,launch启动文件中需要修改节点名称使其不同,同时需要修改frame_id以便于tf变换。
<!--?xml version="1.0" encode="UTF-8"?-->
<launch>
<!-- A3 -->
<node name="rplidarNode" pkg="rplidar_ros" type="rplidarNode" output="screen">
<param name="serial_port" type="string" value="/dev/ttyUSB1"/>
<param name="serial_baudrate" type="int" value="256000"/>
<param name="frame_id" type="string" value="laser"/>
<param name="inverted" type="bool" value="false"/>
<param name="angle_compensate" type="bool" value="true"/>
<param name="scan_mode" type="string" value="Sensitivity"/>
</node>
<!-- A2 -->
<node name="rplidarNode1" pkg="rplidar_ros" type="rplidarNode" output="screen">
<param name="serial_port" type="string" value="/dev/ttyUSB0"/>
<param name="serial_baudrate" type="int" value="115200"/><!--A2 -->
<param name="frame_id" type="string" value="laser2"/>
<param name="inverted" type="bool" value="false"/>
<param name="angle_compensate" type="bool" value="true"/>
</node>
<node name="laser_tf" pkg="laser_tf" type="laser_tf" output="screen" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find rplidar_ros)/rviz/rplidar.rviz" />
</launch>
5.编写tf_node节点pack来建立起两激光雷达数据间关系
#include <ros/ros.h>
#include <tf/transform_broadcaster.h>
#include <tf/tf.h>
int main(int argc, char** argv){
ros::init(argc, argv, "laser_tf_Node");
ros::NodeHandle node;
ros::Rate r(100);
tf::TransformBroadcaster broadcaster;
while(ros::ok()){
broadcaster.sendTransform(
tf::StampedTransform(
tf::Transform(tf::Quaternion(0, 0, 0, 1), tf::Vector3(7, 0.0, 0.0)),ros::Time::now(),"laser", "laser2"));
r.sleep();
ros::spinOnce();
}
}
注意修改Cmake.txt文件中编译文件代码,否则无法生成生成包下可执行文件
add_executable(${PROJECT_NAME} src/laser_tf_node.cpp)
target_link_libraries(laser_tf
${catkin_LIBRARIES}
)