深入理解roslaunch中remap标签

demo 1:句柄为相对命名空间不为空,remap便签可只改变nodehandle句柄相对命名空间名称

 注:ros::NodeHandle nh("相对命名空间名称")

#include 
#include 
#include 

class Mimic
{
public:
  Mimic();

private:
  void poseCallback(const turtlesim::PoseConstPtr& pose);

  ros::Publisher twist_pub_;
  ros::Subscriber pose_sub_;
};

Mimic::Mimic()
{
  ros::NodeHandle input_nh("input");
  ros::NodeHandle output_nh("output");
  twist_pub_ = output_nh.advertise("cmd_vel", 1);
  pose_sub_ = input_nh.subscribe("pose", 1, &Mimic::poseCallback, this);
}

void Mimic::poseCallback(const turtlesim::PoseConstPtr& pose)
{
  geometry_msgs::Twist twist;
  twist.angular.z = pose->angular_velocity;
  twist.linear.x = pose->linear_velocity;
  twist_pub_.publish(twist);
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "turtle_mimic");
  Mimic mimic;

  ros::spin();
}

   
      
   

   
      
   
   
      
      
   

demo 2 :remap便签可只改变话题名称

注:nh.advertise<>("话题名称", )  or  nh.subscrebe<>("话题名称", , , )

//move_base.cpp

ros::NodeHandle nh;
    ...
//for comanding the base
vel_pub_ = nh.advertise("cmd_vel", 1);

  

  
  

  
    
    
    
  

 

你可能感兴趣的:(ROS)