1. ros::init()
1.1 ros::init()
brief:ROS initialization function. This function will parse any ROS arguments (e.g., topic name remappings), and will consume them (i.e., argc and argv may be modified as a result of this call). Use this version if you are using the NodeHandle API
1.2 ros::start()
brief: Actually starts the internals of the node (spins up threads, starts the network polling and xmlrpc loops,connects to internal subscriptions like /clock, starts internal service servers, etc.).Usually unnecessary to call manually, as it is automatically called by the creation of the first NodeHandle if the node has not already been started. If you would like to prevent the automatic shutdown caused by the last NodeHandle going out of scope, call this before any NodeHandle has been created (e.g. immediately after init())
2 node_handle
2.1 subscribe
template<class M, class T>
Subscriber subscribe(const std::string& topic,
uint32_t queue_size,
void(T::*fp)(M),
T* obj,
const TransportHints& transport_hints = TransportHints())
/**
* brief: Subscribe to a topic, version for class member function with bare pointer
* param M [template] M here is the callback parameter type (e.g. const boost::shared_ptr<M const>& or const M&), \b not the message type, and should almost always be deduced
* param topic Topic to subscribe to
* param queue_size Number of incoming messages to queue up for
* processing (messages in excess of this queue capacity will be
* discarded).
* param fp Member function pointer to call when a message has arrived
* param obj Object to call fp on
* param transport_hints a TransportHints structure which defines various transport-related options
*/
cv_bridge
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr& source,
const std::string& encoding = std::string());
/**
* brief Convert an immutable sensor_msgs::Image message to an OpenCV-compatible CvImage, sharing
* the image data if possible.
*
* If the source encoding and desired encoding are the same, the returned CvImage will share
* the image data with \a source without copying it. The returned CvImage cannot be modified, as that
* could modify the \a source data.
*
* \param source A shared_ptr to a sensor_msgs::Image message
* \param encoding The desired encoding of the image data, one of the following strings:
* */
【1】 ros::NodeHandle::param()
template<typename T >
/*
*@brief:从参数服务器获取参数,获取失败使用默认值
*@param: param_name 索取参数的关键词
*@param: param_val 参数的赋值对象
*@param:default_val 默认值
*/
bool ros::NodeHandle::param (const std::string & param_name,
T & param_val,
const T & default_val
)const
【2】geometry_msgs::PoseStamped
/*
target_pose 的类型为geometry_msgs/PoseStamped
A Pose with reference coordinate frame and timestamp
Header header
Pose pose
Record PoseStamped := { _header : Header.Header; _pose : Pose.Pose}
*/
//-------------------- [demo]--------------------//
geometry_msgs/PoseStamped target_pose
//--step1: 构造header
target_pose.header.seq = 0;
target_pose.header.stamp =ros::Time::now();//如果有问题就使用Time(0)获取时间戳,确保类型一致
target_pose.header.frame_id = "map";
//--step2: 构造pose
target_pose.pose.position.x = x1;
target_pose.pose.position.y = y1;
target_pose.pose.position.z = 0.0;
target_pose.pose.orientation.x = 0.0;
target_pose.pose.orientation.y = 0.0;
target_pose.pose.orientation.w = 1.0;
参考blog:
[1] : Subscribe的第四个参数用法
[2] :ros wiki
[3] :glog的编译和使用