#include <ros/ros.h>
#include <pluginlib/class_list_macros.h>
#include <nodelet/nodelet.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Image.h>
#include <visualization_msgs/Marker.h>
#include <turtlebot_msgs/SetFollowState.h>
#include "dynamic_reconfigure/server.h"
#include "turtlebot_follower/FollowerConfig.h"
#include <depth_image_proc/depth_traits.h>
namespace turtlebot_follower
{
//* The turtlebot follower nodelet.
/**
* The turtlebot follower nodelet. Subscribes to point clouds
* from the 3dsensor, processes them, and publishes command vel
* messages.
*/
class TurtlebotFollower : public nodelet::Nodelet
{
public:
/*!
* @brief The constructor for the follower.
* Constructor for the follower.
*/
TurtlebotFollower() : min_y_(0.1), max_y_(0.5),
min_x_(-0.2), max_x_(0.2),
max_z_(0.8), goal_z_(0.6),
z_scale_(1.0), x_scale_(5.0)
{
}
~TurtlebotFollower()
{
delete config_srv_;
}
private:
double min_y_; /**< The minimum y position of the points in the box. */
double max_y_; /**< The maximum y position of the points in the box. */
double min_x_; /**< The minimum x position of the points in the box. */
double max_x_; /**< The maximum x position of the points in the box. */
double max_z_; /**< The maximum z position of the points in the box. 框中 点的最大z位置,以上四个字段用来设置框的大小*/
double goal_z_; /**< The distance away from the robot to hold the centroid 离机器人的距离,以保持质心*/
double z_scale_; /**< The scaling factor for translational robot speed 移动机器人速度的缩放系数*/
double x_scale_; /**< The scaling factor for rotational robot speed 旋转机器人速度的缩放系数*/
bool enabled_; /**< Enable/disable following; just prevents motor commands 启用/禁用追踪; 只是阻止电机命令,置为false后,机器人不会移动,/mobile_base/mobile_base_controller/cmd_vel topic 为空*/
// Service for start/stop following
ros::ServiceServer switch_srv_;
// Dynamic reconfigure server 动态配置服务
dynamic_reconfigure::Server<turtlebot_follower::FollowerConfig>* config_srv_;
/*!
* @brief OnInit method from node handle.
* OnInit method from node handle. Sets up the parameters
* and topics.
* 初始化handle,参数,和话题
*/
virtual void onInit()
{
ros::NodeHandle& nh = getNodeHandle();
ros::NodeHandle& private_nh = getPrivateNodeHandle();
//从参数服务器获取设置的参数(launch文件中设置数值)
private_nh.getParam("min_y", min_y_);
private_nh.getParam("max_y", max_y_);
private_nh.getParam("min_x", min_x_);
private_nh.getParam("max_x", max_x_);
private_nh.getParam("max_z", max_z_);
private_nh.getParam("goal_z", goal_z_);
private_nh.getParam("z_scale", z_scale_);
private_nh.getParam("x_scale", x_scale_);
private_nh.getParam("enabled", enabled_);
//设置机器人移动的话题(用于机器人移动):/mobile_base/mobile_base_controller/cmd_vel(换成机器人的移动topic)
cmdpub_ = private_nh.advertise<geometry_msgs::Twist> ("/mobile_base/mobile_base_