30 #if GAZEBO_MAJOR_VERSION >= 8 40 physics::WorldPtr _world, sdf::ElementPtr _sdf)
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";
50 GZ_ASSERT(_world != NULL,
"World pointer is invalid");
51 GZ_ASSERT(_sdf != NULL,
"SDF pointer is invalid");
58 this->
rosNode->advertiseService(
59 "/gazebo/get_origin_spherical_coordinates",
64 this->
rosNode->advertiseService(
65 "/gazebo/set_origin_spherical_coordinates",
69 this->
rosNode->advertiseService(
70 "/gazebo/transform_to_spherical_coordinates",
74 this->
rosNode->advertiseService(
75 "/gazebo/transform_from_spherical_coordinates",
78 #if GAZEBO_MAJOR_VERSION >= 8 79 gzmsg <<
"Spherical coordinates reference=" << std::endl
80 <<
"\t- Latitude [degrees]=" 81 << this->
world->SphericalCoords()->LatitudeReference().Degree()
83 <<
"\t- Longitude [degrees]=" 84 << this->
world->SphericalCoords()->LongitudeReference().Degree()
86 <<
"\t- Altitude [m]=" 87 << this->
world->SphericalCoords()->GetElevationReference()
90 gzmsg <<
"Spherical coordinates reference=" << std::endl
91 <<
"\t- Latitude [degrees]=" 92 << this->
world->GetSphericalCoordinates()->LatitudeReference().Degree()
94 <<
"\t- Longitude [degrees]=" 95 << this->
world->GetSphericalCoordinates()->LongitudeReference().Degree()
97 <<
"\t- Altitude [m]=" 98 << this->
world->GetSphericalCoordinates()->GetElevationReference()
105 uuv_world_ros_plugins_msgs::TransformToSphericalCoord::Request& _req,
106 uuv_world_ros_plugins_msgs::TransformToSphericalCoord::Response& _res)
108 ignition::math::Vector3d cartVec = ignition::math::Vector3d(
109 _req.input.x, _req.input.y, _req.input.z);
111 #if GAZEBO_MAJOR_VERSION >= 8 112 ignition::math::Vector3d scVec =
113 this->
world->SphericalCoords()->SphericalFromLocal(cartVec);
115 ignition::math::Vector3d scVec =
116 this->
world->GetSphericalCoordinates()->SphericalFromLocal(cartVec);
118 _res.latitude_deg = scVec.X();
119 _res.longitude_deg = scVec.Y();
120 _res.altitude = scVec.Z();
126 uuv_world_ros_plugins_msgs::TransformFromSphericalCoord::Request& _req,
127 uuv_world_ros_plugins_msgs::TransformFromSphericalCoord::Response& _res)
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);
135 ignition::math::Vector3d cartVec =
136 this->
world->GetSphericalCoordinates()->LocalFromSpherical(scVec);
138 _res.output.x = cartVec.X();
139 _res.output.y = cartVec.Y();
140 _res.output.z = cartVec.Z();
146 uuv_world_ros_plugins_msgs::GetOriginSphericalCoord::Request& _req,
147 uuv_world_ros_plugins_msgs::GetOriginSphericalCoord::Response& _res)
149 #if GAZEBO_MAJOR_VERSION >= 8 151 this->
world->SphericalCoords()->LatitudeReference().Degree();
153 this->
world->SphericalCoords()->LongitudeReference().Degree();
155 this->
world->SphericalCoords()->GetElevationReference();
158 this->
world->GetSphericalCoordinates()->LatitudeReference().Degree();
160 this->
world->GetSphericalCoordinates()->LongitudeReference().Degree();
162 this->
world->GetSphericalCoordinates()->GetElevationReference();
169 uuv_world_ros_plugins_msgs::SetOriginSphericalCoord::Request& _req,
170 uuv_world_ros_plugins_msgs::SetOriginSphericalCoord::Response& _res)
172 ignition::math::Angle angle;
173 angle.Degree(_req.latitude_deg);
174 #if GAZEBO_MAJOR_VERSION >= 8 175 this->
world->SphericalCoords()->SetLatitudeReference(angle);
177 this->
world->GetSphericalCoordinates()->SetLatitudeReference(angle);
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);
185 this->
world->GetSphericalCoordinates()->SetLongitudeReference(angle);
186 this->
world->GetSphericalCoordinates()->SetElevationReference(_req.altitude);
physics::WorldPtr world
Pointer to world.
void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
Load module and read parameters from SDF.
ROSCPP_DECL bool isInitialized()
virtual ~SphericalCoordinatesROSInterfacePlugin()
Destructor.
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's handle.
SphericalCoordinatesROSInterfacePlugin()
Constructor.
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.