21 #include "osrf_gear/LogicalCameraImage.h" 23 #include <gazebo/physics/Link.hh> 24 #include <gazebo/physics/Model.hh> 25 #include <gazebo/physics/World.hh> 26 #include <gazebo/sensors/Sensor.hh> 27 #include <gazebo/sensors/SensorManager.hh> 51 if (_sdf->HasElement(
"robotNamespace"))
54 "robotNamespace")->Get<std::string>() +
"/";
61 <<
"unable to load plugin. Load the Gazebo system plugin " 62 <<
"'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
66 this->
model = _parent;
67 this->
node = transport::NodePtr(
new transport::Node());
68 this->
node->Init(this->
model->GetWorld()->GetName());
74 gzerr <<
"No logical camera found on any link\n";
78 std::string imageTopic_ros = _parent->GetName();
79 if (_sdf->HasElement(
"image_topic_ros")) {
80 imageTopic_ros = _sdf->Get<std::string>(
"image_topic_ros");
85 gzdbg <<
"Subscribing to gazebo topic: " << this->
sensor->Topic() <<
"\n";
93 sensors::SensorManager* sensorManager = sensors::SensorManager::Instance();
96 for (physics::LinkPtr link : this->
model->GetLinks())
98 for (
unsigned int i = 0; i < link->GetSensorCount(); ++i)
100 sensors::SensorPtr
sensor = sensorManager->GetSensor(link->GetSensorName(i));
101 if (sensor->Type() ==
"logical_camera")
118 osrf_gear::LogicalCameraImage imageMsg;
119 msgs::Vector3d cameraPosition = _msg->pose().position();
120 msgs::Quaternion cameraOrientation = _msg->pose().orientation();
121 imageMsg.pose.position.x = cameraPosition.x();
122 imageMsg.pose.position.y = cameraPosition.y();
123 imageMsg.pose.position.z = cameraPosition.z();
124 imageMsg.pose.orientation.x = cameraOrientation.x();
125 imageMsg.pose.orientation.y = cameraOrientation.y();
126 imageMsg.pose.orientation.z = cameraOrientation.z();
127 imageMsg.pose.orientation.w = cameraOrientation.w();
129 for (
int i = 0; i < _msg->model_size(); ++i)
131 msgs::Vector3d position = _msg->model(i).pose().position();
132 msgs::Quaternion orientation = _msg->model(i).pose().orientation();
133 osrf_gear::Model modelMsg;
134 modelMsg.pose.position.x = position.x();
135 modelMsg.pose.position.y = position.y();
136 modelMsg.pose.position.z = position.z();
137 modelMsg.pose.orientation.x = orientation.x();
138 modelMsg.pose.orientation.y = orientation.y();
139 modelMsg.pose.orientation.z = orientation.z();
140 modelMsg.pose.orientation.w = orientation.w();
142 imageMsg.models.push_back(modelMsg);
sensors::SensorPtr sensor
The logical camera sensor.
void publish(const boost::shared_ptr< M > &message) const
virtual ~ROSLogicalCameraPlugin()
Destructor.
ROS publisher for the logical camera.
void OnImage(ConstLogicalCameraImagePtr &_msg)
Callback for when logical camera images are received.
ROSCPP_DECL bool isInitialized()
physics::LinkPtr cameraLink
Link that holds the logical camera.
transport::SubscriberPtr imageSub
Subscription to logical camera image messages from gazebo.
ros::Publisher imagePub
ROS publisher for the logical camera image.
transport::NodePtr node
Node for communication with gazebo.
physics::ModelPtr model
Model that contains the logical camera.
ROSLogicalCameraPlugin()
Constructor.
void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
Load the plugin.
#define ROS_FATAL_STREAM(args)
void FindLogicalCamera()
Searches the model links for a logical camera sensor.
ros::NodeHandle * rosnode
ros node handle
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::string robotNamespace
for setting ROS name space
TrayID_t DetermineModelType(const std::string &modelName)
Determine the type of a gazebo model from its name.
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
std::string getTopic() const