jockey.cpp
Go to the documentation of this file.
00001 #include <nj_oa_costmap/jockey.h>
00002 
00003 namespace nj_oa_costmap
00004 {
00005 
00006 Jockey::Jockey(const std::string& name, const double robot_radius) :
00007   nj_oa_laser::Jockey(name, robot_radius),
00008   twist_handler_(robot_radius, "base_laser_link")
00009 {
00010   initTwistHandlerParam(twist_handler_);
00011 }
00012 
00013 void Jockey::initTwistHandlerParam(TwistHandler& twist_handler)
00014 {
00015   nj_oa_laser::Jockey::initTwistHandlerParam(twist_handler);
00016 
00017   private_nh_.getParam("laser_frame", twist_handler.laser_frame);
00018 
00019   int fake_laser_beam_count;
00020   if (private_nh_.getParam("fake_laser_beam_count", fake_laser_beam_count))
00021   {
00022     if (fake_laser_beam_count > 1)
00023     {
00024       twist_handler.fake_laser_beam_count = fake_laser_beam_count;
00025     }
00026     else
00027     {
00028       ROS_ERROR_STREAM("Parameter " << private_nh_.getNamespace() << "/fake_laser_beam_count must be at least 2, setting to default");
00029     }
00030   }
00031 
00032   private_nh_.getParam("range_max", twist_handler.range_max);
00033 }
00034 
00035 void Jockey::onTraverse()
00036 {
00037   ROS_DEBUG("Received action TRAVERSE or CONTINUE");
00038 
00039   ros::Subscriber map_handler = private_nh_.subscribe<nav_msgs::OccupancyGrid>("local_map", 1, &Jockey::handleMap, this);
00040   pub_twist_ = private_nh_.advertise<geometry_msgs::Twist>("cmd_vel", 1);
00041   
00042   ros::Rate r(100);
00043   while (ros::ok())
00044   {
00045     if (server_.isPreemptRequested() && !ros::ok())
00046     {
00047       ROS_INFO("%s: Preempted", jockey_name_.c_str());
00048       // set the action state to preempted
00049       server_.setPreempted();
00050       break;
00051     }
00052 
00053     ros::spinOnce();
00054     r.sleep();
00055   }
00056 }
00057 
00058 void Jockey::handleMap(const nav_msgs::OccupancyGridConstPtr& msg)
00059 {
00060   geometry_msgs::Twist twist = twist_handler_.getTwist(*msg);
00061 
00062   pub_twist_.publish(twist);
00063 }
00064 
00065 } // namespace nj_oa_costmap
00066 


nj_oa_costmap
Author(s): Gaël Ecorchard , Karel Košnar
autogenerated on Sat Jun 8 2019 20:58:44