SphericalCoordinatesROSInterfacePlugin.cc
Go to the documentation of this file.
1 // Copyright (c) 2016 The UUV Simulator Authors.
2 // All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
17 
19 
20 namespace gazebo
21 {
22 
25 { }
26 
29 {
30 #if GAZEBO_MAJOR_VERSION >= 8
31  this->rosPublishConnection.reset();
32 #else
33  event::Events::DisconnectWorldUpdateBegin(this->rosPublishConnection);
34 #endif
35  this->rosNode->shutdown();
36 }
37 
40  physics::WorldPtr _world, sdf::ElementPtr _sdf)
41 {
42  if (!ros::isInitialized())
43  {
44  gzerr << "Not loading plugin since ROS has not been "
45  << "properly initialized. Try starting gazebo with ros plugin:\n"
46  << " gazebo -s libgazebo_ros_api_plugin.so\n";
47  return;
48  }
49 
50  GZ_ASSERT(_world != NULL, "World pointer is invalid");
51  GZ_ASSERT(_sdf != NULL, "SDF pointer is invalid");
52 
53  this->world = _world;
54  this->rosNode.reset(new ros::NodeHandle(""));
55 
56  // Advertise the service to get origin of the world in spherical coordinates
57  this->worldServices["get_origin_spherical_coordinates"] =
58  this->rosNode->advertiseService(
59  "/gazebo/get_origin_spherical_coordinates",
61 
62  // Advertise the service to get origin of the world in spherical coordinates
63  this->worldServices["set_origin_spherical_coordinates"] =
64  this->rosNode->advertiseService(
65  "/gazebo/set_origin_spherical_coordinates",
67 
68  this->worldServices["transform_to_spherical_coord"] =
69  this->rosNode->advertiseService(
70  "/gazebo/transform_to_spherical_coordinates",
72 
73  this->worldServices["transform_from_spherical_coord"] =
74  this->rosNode->advertiseService(
75  "/gazebo/transform_from_spherical_coordinates",
77 
78 #if GAZEBO_MAJOR_VERSION >= 8
79  gzmsg << "Spherical coordinates reference=" << std::endl
80  << "\t- Latitude [degrees]="
81  << this->world->SphericalCoords()->LatitudeReference().Degree()
82  << std::endl
83  << "\t- Longitude [degrees]="
84  << this->world->SphericalCoords()->LongitudeReference().Degree()
85  << std::endl
86  << "\t- Altitude [m]="
87  << this->world->SphericalCoords()->GetElevationReference()
88  << std::endl;
89 #else
90  gzmsg << "Spherical coordinates reference=" << std::endl
91  << "\t- Latitude [degrees]="
92  << this->world->GetSphericalCoordinates()->LatitudeReference().Degree()
93  << std::endl
94  << "\t- Longitude [degrees]="
95  << this->world->GetSphericalCoordinates()->LongitudeReference().Degree()
96  << std::endl
97  << "\t- Altitude [m]="
98  << this->world->GetSphericalCoordinates()->GetElevationReference()
99  << std::endl;
100 #endif
101 }
102 
105  uuv_world_ros_plugins_msgs::TransformToSphericalCoord::Request& _req,
106  uuv_world_ros_plugins_msgs::TransformToSphericalCoord::Response& _res)
107 {
108  ignition::math::Vector3d cartVec = ignition::math::Vector3d(
109  _req.input.x, _req.input.y, _req.input.z);
110 
111 #if GAZEBO_MAJOR_VERSION >= 8
112  ignition::math::Vector3d scVec =
113  this->world->SphericalCoords()->SphericalFromLocal(cartVec);
114 #else
115  ignition::math::Vector3d scVec =
116  this->world->GetSphericalCoordinates()->SphericalFromLocal(cartVec);
117 #endif
118  _res.latitude_deg = scVec.X();
119  _res.longitude_deg = scVec.Y();
120  _res.altitude = scVec.Z();
121  return true;
122 }
123 
126  uuv_world_ros_plugins_msgs::TransformFromSphericalCoord::Request& _req,
127  uuv_world_ros_plugins_msgs::TransformFromSphericalCoord::Response& _res)
128 {
129  ignition::math::Vector3d scVec = ignition::math::Vector3d(
130  _req.latitude_deg, _req.longitude_deg, _req.altitude);
131 #if GAZEBO_MAJOR_VERSION >= 8
132  ignition::math::Vector3d cartVec =
133  this->world->SphericalCoords()->LocalFromSpherical(scVec);
134 #else
135  ignition::math::Vector3d cartVec =
136  this->world->GetSphericalCoordinates()->LocalFromSpherical(scVec);
137 #endif
138  _res.output.x = cartVec.X();
139  _res.output.y = cartVec.Y();
140  _res.output.z = cartVec.Z();
141  return true;
142 }
143 
146  uuv_world_ros_plugins_msgs::GetOriginSphericalCoord::Request& _req,
147  uuv_world_ros_plugins_msgs::GetOriginSphericalCoord::Response& _res)
148 {
149 #if GAZEBO_MAJOR_VERSION >= 8
150  _res.latitude_deg =
151  this->world->SphericalCoords()->LatitudeReference().Degree();
152  _res.longitude_deg =
153  this->world->SphericalCoords()->LongitudeReference().Degree();
154  _res.altitude =
155  this->world->SphericalCoords()->GetElevationReference();
156 #else
157  _res.latitude_deg =
158  this->world->GetSphericalCoordinates()->LatitudeReference().Degree();
159  _res.longitude_deg =
160  this->world->GetSphericalCoordinates()->LongitudeReference().Degree();
161  _res.altitude =
162  this->world->GetSphericalCoordinates()->GetElevationReference();
163 #endif
164  return true;
165 }
166 
169  uuv_world_ros_plugins_msgs::SetOriginSphericalCoord::Request& _req,
170  uuv_world_ros_plugins_msgs::SetOriginSphericalCoord::Response& _res)
171 {
172  ignition::math::Angle angle;
173  angle.Degree(_req.latitude_deg);
174 #if GAZEBO_MAJOR_VERSION >= 8
175  this->world->SphericalCoords()->SetLatitudeReference(angle);
176 #else
177  this->world->GetSphericalCoordinates()->SetLatitudeReference(angle);
178 #endif
179 
180  angle.Degree(_req.longitude_deg);
181 #if GAZEBO_MAJOR_VERSION >= 8
182  this->world->SphericalCoords()->SetLongitudeReference(angle);
183  this->world->SphericalCoords()->SetElevationReference(_req.altitude);
184 #else
185  this->world->GetSphericalCoordinates()->SetLongitudeReference(angle);
186  this->world->GetSphericalCoordinates()->SetElevationReference(_req.altitude);
187 #endif
188  _res.success = true;
189  return true;
190 }
191 
193 GZ_REGISTER_WORLD_PLUGIN(SphericalCoordinatesROSInterfacePlugin)
194 }
void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
Load module and read parameters from SDF.
ROSCPP_DECL bool isInitialized()
event::ConnectionPtr rosPublishConnection
Connection for callbacks on update world.
bool GetOriginSphericalCoord(uuv_world_ros_plugins_msgs::GetOriginSphericalCoord::Request &_req, uuv_world_ros_plugins_msgs::GetOriginSphericalCoord::Response &_res)
Service call that returns the origin in WGS84 standard.
std::map< std::string, ros::ServiceServer > worldServices
All underwater world services.
bool SetOriginSphericalCoord(uuv_world_ros_plugins_msgs::SetOriginSphericalCoord::Request &_req, uuv_world_ros_plugins_msgs::SetOriginSphericalCoord::Response &_res)
Service call that returns the origin in WGS84 standard.
bool TransformToSphericalCoord(uuv_world_ros_plugins_msgs::TransformToSphericalCoord::Request &_req, uuv_world_ros_plugins_msgs::TransformToSphericalCoord::Response &_res)
Service call to transform from Cartesian to spherical coordinates.
boost::scoped_ptr< ros::NodeHandle > rosNode
Pointer to this ROS node&#39;s handle.
bool TransformFromSphericalCoord(uuv_world_ros_plugins_msgs::TransformFromSphericalCoord::Request &_req, uuv_world_ros_plugins_msgs::TransformFromSphericalCoord::Response &_res)
Service call to transform from spherical to Cartesian coordinates.


uuv_world_ros_plugins
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Mon Jul 1 2019 19:39:41