Autoware学习笔记——WaypointSaver节点

Autoware学习笔记——WaypointSaver节点

一、要解决问题

  • 学会message_filters中subscriber,Synchronizer的使用

  • 学会boost::bind 占位符的使用,弄清楚占位符后无参数的原因

  • private_nh_以及WaypointSaver::WaypointSaver() : private_nh_("~")的意思

  • 看懂launch文件unless if

二、代码分析

  • 头文件部分
#include <ros/ros.h>
#include <geometry_msgs/PoseStamped.h>
#include <visualization_msgs/Marker.h>
#include <visualization_msgs/MarkerArray.h>
//为了使用message_filters库中的subscriber
#include <message_filters/subscriber.h>
//为了使用message_filters库中的synchronizer
#include <message_filters/synchronizer.h>
//为了使用synchronizers的approximate_time规则
#include <message_filters/sync_policies/approximate_time.h>
#include <std_msgs/Float32.h>
#include <tf/transform_datatypes.h>
#include <fstream>
#include "libwaypoint_follower/libwaypoint_follower.h"
  • main函数
int main(int argc, char **argv)
{
   
  ros::init(argc, argv, "waypoint_saver");
  //实例化了WaypointSaver类
  WaypointSaver ws;
  ros::spin();
  return 0;
}

  • 初始化部分
//近似时间规则将subscriber队列长度作为其构造函数的参数,这里的50和下面的pose_sub_以及twist_sub_队列长度相对应
static const int SYNC_FRAMES = 50;
//定义近似时间规则TwistPoseSync,将接收TwistStamped和PoseStamped消息类型的两个subscriber进行同步
typedef message_filters::sync_policies::ApproximateTime<geometry_msgs::TwistStamped, geometry_msgs::PoseStamped>
    TwistPoseSync;
  • WaypointSaver类
class WaypointSaver
{
   
public:
  WaypointSaver();
  ~WaypointSaver();

private:
  // functions

  void TwistPoseCallback(const geometry_msgs::TwistStampedConstPtr &twist_msg,
                         const geometry_msgs::PoseStampedConstPtr &pose_msg) const;
  void poseCallback(const geometry_msgs::PoseStampedConstPtr &pose_msg) const;
  void displayMarker(geometry_msgs::Pose pose, double velocity) const;
  void outputProcessing(geometry_msgs::Pose current_pose, double velocity) const;

  // handle
  ros::NodeHandle nh_;
  ros::NodeHandle private_nh_;

  // publisher
  ros::Publisher waypoint_saver_pub_;

  // subscriber
  //定义了一个message_filters::Subscriber<geometry_msgs::TwistStamped>类型的指针
  message_filters::Subscriber<geometry_msgs::TwistStamped> *twist_sub_;
  //定义了一个message_filters::Subscriber<geometry_msgs::PoseStamped> 类型的指针
  message_filters::Subscriber<geometry_msgs::PoseStamped> *pose_sub_;
  //定义了一个message_filters::Synchronizer<TwistPoseSync> 类型的指针
  message_filters::Synchronizer<TwistPoseSync> *sync_tp_;

  
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值