Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gazebo/physics/physics.hh"
00023 #include "rotors_gazebo_plugins/external/gazebo_lidar_plugin.h"
00024
00025 #include <gazebo/common/common.hh>
00026 #include <gazebo/common/Plugin.hh>
00027 #include <gazebo/gazebo.hh>
00028 #include <gazebo/physics/physics.hh>
00029 #include "gazebo/transport/transport.hh"
00030 #include "gazebo/msgs/msgs.hh"
00031
00032 #include <chrono>
00033 #include <cmath>
00034 #include <iostream>
00035 #include <memory>
00036 #include <stdio.h>
00037 #include <boost/algorithm/string.hpp>
00038
00039 #include "rotors_gazebo_plugins/common.h"
00040
00041 using namespace gazebo;
00042 using namespace std;
00043
00044
00045 GZ_REGISTER_SENSOR_PLUGIN(GazeboLidarPlugin)
00046
00047
00048 GazeboLidarPlugin::GazeboLidarPlugin()
00049 {
00050 }
00051
00052
00053 GazeboLidarPlugin::~GazeboLidarPlugin()
00054 {
00055 this->newLaserScansConnection.reset();
00056
00057 this->parentSensor.reset();
00058 this->world.reset();
00059 }
00060
00061
00062 void GazeboLidarPlugin::Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf)
00063 {
00064 if(kPrintOnPluginLoad) {
00065 gzdbg << __FUNCTION__ << "() called." << std::endl;
00066 }
00067
00068
00069 this->parentSensor =
00070 std::dynamic_pointer_cast<sensors::RaySensor>(_parent);
00071
00072 if (!this->parentSensor)
00073 gzthrow("RayPlugin requires a Ray Sensor as its parent");
00074
00075 this->world = physics::get_world(this->parentSensor->WorldName());
00076
00077 this->newLaserScansConnection =
00078 this->parentSensor->LaserShape()->ConnectNewLaserScans(
00079 boost::bind(&GazeboLidarPlugin::OnNewLaserScans, this));
00080
00081 if (_sdf->HasElement("robotNamespace"))
00082 namespace_ = _sdf->GetElement("robotNamespace")->Get<std::string>();
00083 else
00084 gzwarn << "[gazebo_lidar_plugin] Please specify a robotNamespace.\n";
00085
00086 node_handle_ = transport::NodePtr(new transport::Node());
00087 node_handle_->Init(namespace_);
00088
00089 const string scopedName = _parent->ParentName();
00090
00091 string topicName = "~/" + scopedName + "/lidar";
00092 boost::replace_all(topicName, "::", "/");
00093
00094 lidar_pub_ = node_handle_->Advertise<lidar_msgs::msgs::lidar>(topicName, 10);
00095 }
00096
00097
00098 void GazeboLidarPlugin::OnNewLaserScans()
00099 {
00100 lidar_message.set_time_msec(0);
00101 lidar_message.set_min_distance(parentSensor->RangeMin());
00102 lidar_message.set_max_distance(parentSensor->RangeMax());
00103 lidar_message.set_current_distance(parentSensor->Range(0));
00104
00105 lidar_pub_->Publish(lidar_message);
00106 }
rotors_gazebo_plugins
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Thu Apr 18 2019 02:43:43