Go to the documentation of this file.00001
00010
00011
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
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:
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
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
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:
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
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
00082
00083
00084
00085
00086 nh.param("pointcloud_radius", pointcloud_radius_, 0.25);
00087 pointcloud_side_x_ = pointcloud_radius_*sin(0.34906585);
00088 pointcloud_side_y_ = pointcloud_radius_*cos(0.34906585);
00089
00090 pointcloud_.resize(3);
00091 pointcloud_.header.frame_id = "/base_link";
00092
00093
00094 pointcloud_[0].x = pointcloud_[1].y = pointcloud_[2].x = 0.0;
00095 pointcloud_[0].z = pointcloud_[1].z = pointcloud_[2].z = 0.015;
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 }
00106
00107
00108 PLUGINLIB_EXPORT_CLASS(kobuki_bumper2pc::Bumper2PcNodelet, nodelet::Nodelet);