kobuki_bumper2pc.cpp
Go to the documentation of this file.
00001 
00010 /*****************************************************************************
00011 ** Includes
00012 *****************************************************************************/
00013 
00014 #include <pluginlib/class_list_macros.h>
00015 
00016 #include "../include/kobuki_bumper2pc/kobuki_bumper2pc.hpp"
00017 
00018 namespace kobuki_bumper2pc
00019 {
00020 
00021 void Bumper2PcNodelet::cliffEventCB(const kobuki_msgs::CliffEvent::ConstPtr& msg)
00022 {
00023   if (pointcloud_pub_.getNumSubscribers() == 0)
00024     return;
00025 
00026   // We replicate the sensors order of bumper/cliff event messages: LEFT = 0, CENTER = 1 and RIGHT = 2
00027   switch (msg->sensor)
00028   {
00029     case kobuki_msgs::CliffEvent::LEFT:
00030       pointcloud_[msg->sensor].x = (msg->state == kobuki_msgs::CliffEvent::CLIFF)? +pointcloud_side_x_: 99;
00031       pointcloud_[msg->sensor].y = (msg->state == kobuki_msgs::CliffEvent::CLIFF)? +pointcloud_side_y_: 99;
00032       break;
00033     case kobuki_msgs::CliffEvent::CENTER:       // y-coordinate is always 0
00034       pointcloud_[msg->sensor].x = (msg->state == kobuki_msgs::CliffEvent::CLIFF)? +pointcloud_radius_: 99;
00035       break;
00036     case kobuki_msgs::CliffEvent::RIGHT:
00037       pointcloud_[msg->sensor].x = (msg->state == kobuki_msgs::CliffEvent::CLIFF)? +pointcloud_side_x_: 99;
00038       pointcloud_[msg->sensor].y = (msg->state == kobuki_msgs::CliffEvent::CLIFF)? -pointcloud_side_y_: 99;
00039       break;
00040     default:
00041       // This cannot happen unless CliffEvent message changes
00042       ROS_WARN("Unknown sensor id (%d); ignoring", msg->sensor);
00043       break;
00044   }
00045 
00046   pointcloud_pub_.publish(pointcloud_);
00047 }
00048 
00049 void Bumper2PcNodelet::bumperEventCB(const kobuki_msgs::BumperEvent::ConstPtr& msg)
00050 {
00051   if (pointcloud_pub_.getNumSubscribers() == 0)
00052     return;
00053 
00054   // We replicate the sensors order of bumper/cliff event messages: LEFT = 0, CENTER = 1 and RIGHT = 2
00055   switch (msg->bumper)
00056   {
00057     case kobuki_msgs::BumperEvent::LEFT:
00058       pointcloud_[msg->bumper].x = (msg->state == kobuki_msgs::BumperEvent::PRESSED)? +pointcloud_side_x_: 99;
00059       pointcloud_[msg->bumper].y = (msg->state == kobuki_msgs::BumperEvent::PRESSED)? +pointcloud_side_y_: 99;
00060       break;
00061     case kobuki_msgs::BumperEvent::CENTER:       // y-coordinate is always 0
00062       pointcloud_[msg->bumper].x = (msg->state == kobuki_msgs::BumperEvent::PRESSED)? +pointcloud_radius_: 99;
00063       break;
00064     case kobuki_msgs::BumperEvent::RIGHT:
00065       pointcloud_[msg->bumper].x = (msg->state == kobuki_msgs::BumperEvent::PRESSED)? +pointcloud_side_x_: 99;
00066       pointcloud_[msg->bumper].y = (msg->state == kobuki_msgs::BumperEvent::PRESSED)? -pointcloud_side_y_: 99;
00067       break;
00068     default:
00069       // This cannot happen unless BumperEvent message changes
00070       ROS_WARN("Unknown sensor id (%d); ignoring", msg->bumper);
00071       break;
00072   }
00073 
00074   pointcloud_pub_.publish(pointcloud_);
00075 }
00076 
00077 void Bumper2PcNodelet::onInit()
00078 {
00079   ros::NodeHandle nh = this->getPrivateNodeHandle();
00080 
00081   // Bumper/cliff pointcloud distance to base frame; should be something like the robot radius plus
00082   // costmap resolution plus an extra to cope with robot inertia. This is a bit tricky parameter: if
00083   // it's too low, costmap will ignore this pointcloud (the robot footprint runs over the hit obstacle),
00084   // but if it's too big, hit obstacles will be mapped too far from the robot and the navigation around
00085   // them will probably fail.
00086   nh.param("pointcloud_radius", pointcloud_radius_, 0.25);
00087   pointcloud_side_x_ = pointcloud_radius_*sin(0.34906585); // 20 degrees
00088   pointcloud_side_y_ = pointcloud_radius_*cos(0.34906585);
00089 
00090   pointcloud_.resize(3);
00091   pointcloud_.header.frame_id = "/base_link";
00092 
00093   // bumper/cliff "points" fix coordinates (the others depend on sensor activation/deactivation)
00094   pointcloud_[0].x = pointcloud_[1].y = pointcloud_[2].x = 0.0;   // +π/2, 0 and -π/2 from x-axis
00095   pointcloud_[0].z = pointcloud_[1].z = pointcloud_[2].z = 0.015; // z: elevation from base frame
00096 
00097   pointcloud_pub_  = nh.advertise < pcl::PointCloud <pcl::PointXYZ> > ("pointcloud", 10);
00098 
00099   cliff_event_sub_  = nh.subscribe("cliff_events",  10, &Bumper2PcNodelet::cliffEventCB,  this);
00100   bumper_event_sub_ = nh.subscribe("bumper_events", 10, &Bumper2PcNodelet::bumperEventCB, this);
00101 
00102   ROS_INFO("Bumper/cliff pointcloud configured at distance %f from base frame", pointcloud_radius_);
00103 }
00104 
00105 } // namespace kobuki_bumper2pc
00106 
00107 
00108 PLUGINLIB_EXPORT_CLASS(kobuki_bumper2pc::Bumper2PcNodelet, nodelet::Nodelet);


kobuki_bumper2pc
Author(s): Jorge Santos Simon
autogenerated on Mon Oct 6 2014 01:30:54