(9)激光雷达跟随

激光雷达跟随

原理

1、激光雷达会检测最近的一个物体作为跟随物

2、会有一个中距值,大于这个会靠近上去,等于这个值会停下来,小于这个值会后退到等于这个值。

基本操作

1、小车开机,连接wifi,远程登录

##登录密码:dongguan
ssh wheeltec@192.168.0.100

2、挂载(wheeltec):

##挂载密码:raspberry
sudo mount -t nfs 192.168.0.100:/home/wheeltec/wheeltec_robot /mnt

3、激光雷达跟随(passoni):

roslaunch simple_follower laser_follower.launch 

① 在功能包 simple_follower下的launch文件下的 laser_follower.launch文件,有可以修改速度和中距值的
② 在功能包 simple_follower下的parameters文件下有一个可以修改PID参数的(左边一列是z轴旋转角速度的参数,右边一列是x轴方向的线速度参数)

4、查看预览话题(passoni):

roslaunch list

5、返回角度和距离值的话题(wheeltec):

roslaunch echo /object_tracker/current/current_pasition

距离单位是米

6、查看速度的话题(wheeltec):

roslaunch echo /smoother_cmd_vel

一个线速度和一个角速度

要实现ROS激光雷达跟随,可以使用ROS中的导航堆栈(navigation stack),它可以帮助机器人规划路径并执行移动操作。下面是一个基本的C++程序示例,用于订阅激光雷达数据并执行基于障碍物规避的路径跟随。 ```cpp #include <ros/ros.h> #include <sensor_msgs/LaserScan.h> #include <geometry_msgs/Twist.h> // Callback function for laser scan data void laserCallback(const sensor_msgs::LaserScan::ConstPtr& scan) { // Initialize ROS node handle and publisher for velocity commands ros::NodeHandle nh; ros::Publisher vel_pub = nh.advertise<geometry_msgs::Twist>("cmd_vel", 1); // Initialize velocity command message geometry_msgs::Twist vel_cmd; vel_cmd.linear.x = 0.0; vel_cmd.angular.z = 0.0; // Calculate the distance to the closest obstacle float min_dist = scan->ranges[0]; for (int i = 1; i < scan->ranges.size(); i++) { if (scan->ranges[i] < min_dist) { min_dist = scan->ranges[i]; } } // Determine the direction of the closest obstacle if (min_dist > 0.5) { vel_cmd.linear.x = 0.5; vel_cmd.angular.z = 0.0; } else if (scan->ranges[0] < scan->ranges[scan->ranges.size()/2]) { vel_cmd.linear.x = 0.0; vel_cmd.angular.z = -0.5; } else { vel_cmd.linear.x = 0.0; vel_cmd.angular.z = 0.5; } // Publish the velocity command message vel_pub.publish(vel_cmd); } int main(int argc, char** argv) { // Initialize ROS node ros::init(argc, argv, "laser_follow"); // Initialize ROS node handle and subscriber for laser scan data ros::NodeHandle nh; ros::Subscriber laser_sub = nh.subscribe<sensor_msgs::LaserScan>("scan", 1, laserCallback); // Spin ROS node ros::spin(); return 0; } ``` 这个例子演示了如何订阅激光雷达数据并根据最近的障碍物规划机器人的运动。在这个例子中,我们使用ROS的geometry_msgs/Twist消息类型来发布机器人的速度命令。通过调整if-else语句中的速度和角速度,可以改变机器人的运动方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值