< >
Home » walking与Matlab入门教程 » walking与Matlab入门教程-订阅雷达、里程计、相机的订阅信息

walking与Matlab入门教程-订阅雷达、里程计、相机的订阅信息

walking与Matlab入门教程-订阅雷达、里程计、相机的订阅信息

说明:

  • 介绍如何在Matlab订阅雷达、里程计、相机的订阅信息

步骤:

  • 新开终端,启动底盘
ros2 launch walking_bringup robot.launch.py 
  • 新开终端,启动激光雷达测试
ros2 launch walking_tools test_laser.launch.py
  • 新开终端,启动相机测试
ros2 launch walking_tools test_d435i.launch.py
  • 打开Matlab软件

  • 设置域ID为2

setenv("ROS_DOMAIN_ID","2")
  • 创建ROS2节点
ros2Node = ros2node("/example_node")
  • 创建两个ROS2节点:/robotDataProcessingNod 和 /humanOperatorNode。
robotDataProcessingNode = ros2node("/robotDataProcessingNode",2);
humanOperatorNode = ros2node("/humanOperatorNode",2);
  • 接收传感器数据以/robotDataProcessingNode进行处理并发布消息以跟踪检测到的标志数量,发送速度命令以在/humanOperatorNode环境中驱动 TurtleBot,并在检测到标志时收到确认

  • 发布速度的信息

velPub = ros2publisher(humanOperatorNode,"/cmd_vel","geometry_msgs/Twist","Reliability","reliable","Durability","transientlocal","Depth",5);
  • 订阅雷达、里程计、相机的信息
laserSub = ros2subscriber(robotDataProcessingNode,"/scan","sensor_msgs/LaserScan","Reliability","besteffort","Durability","volatile","Depth",5);
odomSub = ros2subscriber(robotDataProcessingNode,"/odom","nav_msgs/Odometry","Reliability","reliable","Durability","volatile","Depth",5);
imageSub = ros2subscriber(robotDataProcessingNode,"/camera/color/image_raw","sensor_msgs/Image","Reliability","besteffort","Durability","volatile","Depth",5);
  • 控制器移动机器人。处理传感器数据以帮助机器人在环境中进行可视化和导航。当机器人靠近一个标志时,标志检测算法会输出一条确认消息,其中包含寻找下一个标志的指令。重复此任务,直到机器人到达停止标志
[laserPlotObj,imageAxesHandle,signText,axesHandle] = ExampleHelperQoSTurtleBotSetupVisualizer(velPub);
receive(laserSub,5);
receive(odomSub,5);
receive(imageSub,5);
laserSub.NewMessageFcn = @(msg)ExampleHelperQoSTurtleBotPlotScan(msg,laserPlotObj,odomSub);
imageSub.NewMessageFcn = @(msg)ExampleHelperQoSTurtleBotPlotImage(msg,imageAxesHandle);
  • 需要修改相机对应的分辨率:
C:\Users\XXX\Documents\MATLAB\Examples\R2022a\ros\ManageQualityOfServicePoliciesWithTurtleBotExample\ExampleHelperQoSTurtleBotPlotImage.m


permute(reshape(imageMsg.data,[3 1280 720]),[3 2 1]);
  • 这里使用D435i相机,修改对应的分辨率:1280 x 720

  • 结果如下:

请输入图片描述

演示视频

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: walking与matlab入门教程