Go to the documentation of this file.00001 #include <nj_oa_laser/jockey.h>
00002
00003 namespace nj_oa_laser
00004 {
00005
00006 Jockey::Jockey(const std::string& name, const double robot_radius) :
00007 lama_jockeys::NavigatingJockey(name),
00008 twist_handler_(robot_radius)
00009 {
00010 initTwistHandlerParam(twist_handler_);
00011 }
00012
00013 void Jockey::initTwistHandlerParam(TwistHandler& twist_handler)
00014 {
00015 private_nh_.getParam("robot_radius", twist_handler.robot_radius);
00016 private_nh_.getParam("min_distance", twist_handler.min_distance);
00017 private_nh_.getParam("long_distance", twist_handler.long_distance);
00018 private_nh_.getParam("turnrate_collide", twist_handler.turnrate_collide);
00019 private_nh_.getParam("vel_close_obstacle", twist_handler.vel_close_obstacle);
00020 private_nh_.getParam("turnrate_factor", twist_handler.turnrate_factor);
00021 private_nh_.getParam("max_linear_velocity", twist_handler.max_linear_velocity);
00022 private_nh_.getParam("max_angular_velocity", twist_handler.max_angular_velocity);
00023 private_nh_.getParam("short_lateral_distance", twist_handler.short_lateral_distance);
00024 private_nh_.getParam("long_lateral_distance", twist_handler.long_lateral_distance);
00025 private_nh_.getParam("force_turn_left_factor", twist_handler.force_turn_left_factor);
00026 }
00027
00028 void Jockey::onTraverse()
00029 {
00030 ROS_DEBUG("Received action TRAVERSE or CONTINUE");
00031
00032 ros::Subscriber laser_handler = private_nh_.subscribe<sensor_msgs::LaserScan>("base_scan", 1, &Jockey::handleLaser, this);
00033 pub_twist_ = private_nh_.advertise<geometry_msgs::Twist>("cmd_vel", 1);
00034
00035
00036 ros::Rate r(100);
00037 while (ros::ok())
00038 {
00039 ros::spinOnce();
00040 if (server_.isPreemptRequested() && !ros::ok())
00041 {
00042 ROS_INFO("%s: Preempted", jockey_name_.c_str());
00043
00044 server_.setPreempted();
00045 break;
00046 }
00047
00048 r.sleep();
00049 }
00050
00051 pub_twist_.shutdown();
00052 }
00053
00054 void Jockey::onStop()
00055 {
00056 ROS_DEBUG("Received action STOP or INTERRUPT");
00057 result_.final_state = lama_jockeys::NavigateResult::DONE;
00058 result_.completion_time = ros::Duration(0.0);
00059 server_.setSucceeded(result_);
00060 }
00061
00062 void Jockey::onInterrupt()
00063 {
00064 ROS_DEBUG("Received action INTERRUPT");
00065 onStop();
00066 }
00067
00068 void Jockey::onContinue()
00069 {
00070 ROS_DEBUG("Received action CONTINUE");
00071 onTraverse();
00072 }
00073
00074
00075
00076 void Jockey::handleLaser(const sensor_msgs::LaserScanConstPtr& msg)
00077 {
00078 geometry_msgs::Twist twist = twist_handler_.getTwist(*msg);
00079 pub_twist_.publish(twist);
00080 }
00081
00082 }