ros(23):接收rviz中的2D Nav Goal、2D Pose Estimate消息

1 rviz 教程

1.1 2D Nav Goal

This tool lets you set a goal sent on the “goal” ROS topic. Click on a location on the ground plane and drag to select the orientation:
二维导航目标(快捷键:g)
此工具允许您设置在”goal”ROS主题上发送的目标。单击地平面上的某个位置并拖动以选择方向:

即设置二维导航目标,并使用”goal”这个话题进行通讯(结合rviz的其他教程,话题名也可能是”/move_base_simple/goal”)

其消息类型为: geometry_msgs/PoseStamped

meng@meng:~/ideas/ros_ws$ rosmsg info geometry_msgs/PoseStamped
std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
geometry_msgs/Pose pose
  geometry_msgs/Point position
    float64 x
    float64 y
    float64 z
  geometry_msgs/Quaternion orientation
    float64 x
    float64 y
    float64 z
    float64 w

1.2 2D Pose Estimate

2D Pose Estimate (Keyboard shortcut: p)

This tool lets you set an initial pose to seed the localization system (sent on the “initialpose” ROS topic). Click on a location on the ground plane and drag to select the orientation:
二维姿势估计(键盘快捷键:p)
此工具允许您设置初始姿势以播种定位系统(发送至”initialpose”ROS主题)。单击地平面上的某个位置并拖动以选择方向:

即设置二维初始位姿并使用”initialpose”进行通讯

其消息类型为: geometry_msgs/PoseWithCovarianceStamped

meng@meng:~/ideas/ros_ws$ rosmsg info geometry_msgs/PoseWithCovarianceStamped
std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
geometry_msgs/PoseWithCovariance pose
  geometry_msgs/Pose pose
    geometry_msgs/Point position
      float64 x
      float64 y
      float64 z
    geometry_msgs/Quaternion orientation
      float64 x
      float64 y
      float64 z
      float64 w
  float64[36] covariance

1.3 打开rviz查看

Panels–Tool Properties(勾选)

ros(23):接收rviz中的2D Nav Goal、2D Pose Estimate消息

ros(23):接收rviz中的2D Nav Goal、2D Pose Estimate消息

2 订阅话题

订阅起点位姿和终点话题并打印输出的c++文件:receive_2d_nav_goal.cpp

#include "ros/ros.h"
#include "std_msgs/String.h"
#include
#include
#include

void chatterCallback(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg)
{
  double x=msg->pose.pose.position.x;
  double y=msg->pose.pose.position.y;
  std::cout<pose.position.x;
  double y=msg->pose.position.y;
  std::cout<

启动rviz和节点程序,用 2D Nav Goal、2D Pose Estimate 在rviz中做标记,即可打印输出:

ros(23):接收rviz中的2D Nav Goal、2D Pose Estimate消息

订阅起点位姿和终点,并保持发布:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include
#include
#include

ros::Publisher initialpose_pub,goal_pub;
geometry_msgs::PoseWithCovarianceStamped initialpose_tmp;//设置为全局变量,可以一直被发布出来
geometry_msgs::PoseStamped goal_tmp;

void initialpose_handler(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg)
{
  double x=msg->pose.pose.position.x;
  double y=msg->pose.pose.position.y;
  std::cout<header;
  // initialpose_tmp.header=msg->header;
  initialpose_pub.publish(initialpose_tmp);
}

void goal_handler(const geometry_msgs::PoseStamped::ConstPtr& msg)
{
  double x=msg->pose.position.x;
  double y=msg->pose.position.y;
  std::cout<("initialpose_my", 1);
  goal_pub = nh.advertise("goal_my", 1);

  while(ros::ok())
  {
    ros::spinOnce();
  }

  return 0;
}

ros(23):接收rviz中的2D Nav Goal、2D Pose Estimate消息

参考链接:

2D Nav Goal和2D Pose Estimate功能介绍:rviz/UserGuide – ROS Wiki

2D Nav Goal和2D Pose Estimate的消息类型:navigation/Tutorials/Using rviz with the Navigation Stack – ROS Wiki

Original: https://blog.csdn.net/BIT_HXZ/article/details/125267078
Author: biter0088
Title: ros(23):接收rviz中的2D Nav Goal、2D Pose Estimate消息

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/614185/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球