20 #include <gazebo/physics/Base.hh> 21 #include <gazebo/physics/Link.hh> 22 #include <gazebo/physics/Model.hh> 23 #include <gazebo/physics/World.hh> 25 #include <uuv_gazebo_ros_plugins_msgs/FloatStamped.h> 39 #if GAZEBO_MAJOR_VERSION >= 8 42 gazebo::event::Events::DisconnectWorldUpdateBegin(
51 const uuv_gazebo_ros_plugins_msgs::FloatStamped::ConstPtr &_msg)
53 if (std::isnan(_msg->data))
55 ROS_WARN(
"ThrusterROSPlugin: Ignoring nan command");
80 ThrusterPlugin::Init();
94 ThrusterPlugin::Load(_parent, _sdf);
95 }
catch(gazebo::common::Exception &_e)
97 gzerr <<
"Error loading plugin." 98 <<
"Please ensure that your model is correct." 105 gzerr <<
"Not loading plugin since ROS has not been " 106 <<
"properly initialized. Try starting gazebo with ros plugin:\n" 107 <<
" gazebo -s libgazebo_ros_api_plugin.so\n";
113 this->
services[
"set_thrust_force_efficiency"] =
114 this->
rosNode->advertiseService(
118 this->
services[
"get_thrust_force_efficiency"] =
119 this->
rosNode->advertiseService(
123 this->
services[
"set_dynamic_state_efficiency"] =
124 this->
rosNode->advertiseService(
125 this->
topicPrefix +
"set_dynamic_state_efficiency",
128 this->
services[
"get_dynamic_state_efficiency"] =
129 this->
rosNode->advertiseService(
130 this->
topicPrefix +
"get_dynamic_state_efficiency",
133 this->
services[
"set_thruster_state"] =
134 this->
rosNode->advertiseService(
138 this->
services[
"get_thruster_state"] =
139 this->
rosNode->advertiseService(
143 this->
services[
"get_thruster_conversion_fcn"] =
144 this->
rosNode->advertiseService(
149 uuv_gazebo_ros_plugins_msgs::FloatStamped
154 uuv_gazebo_ros_plugins_msgs::FloatStamped
158 this->
rosNode->advertise<geometry_msgs::WrenchStamped>(
165 this->topicPrefix +
"thrust_efficiency", 1);
168 this->topicPrefix +
"dynamic_state_efficiency", 1);
170 gzmsg <<
"Thruster #" << this->
thrusterID <<
" initialized" << std::endl
171 <<
"\t- Link: " << this->
thrusterLink->GetName() << std::endl
172 <<
"\t- Robot model: " << _parent->GetName() << std::endl
173 <<
"\t- Input command topic: " <<
175 <<
"\t- Thrust output topic: " <<
192 uuv_gazebo_ros_plugins_msgs::FloatStamped thrustMsg;
194 thrustMsg.header.frame_id = this->
thrusterLink->GetName();
199 geometry_msgs::WrenchStamped thrustWrenchMsg;
201 thrustWrenchMsg.header.frame_id = this->
thrusterLink->GetName();
203 thrustWrenchMsg.wrench.force.x = thrustVector.X();
204 thrustWrenchMsg.wrench.force.y = thrustVector.Y();
205 thrustWrenchMsg.wrench.force.z = thrustVector.Z();
209 std_msgs::Bool isOnMsg;
210 isOnMsg.data = this->
isOn;
214 std_msgs::Float64 thrustEffMsg;
219 std_msgs::Float64 dynStateEffMsg;
227 uuv_gazebo_ros_plugins_msgs::SetThrusterEfficiency::Request& _req,
228 uuv_gazebo_ros_plugins_msgs::SetThrusterEfficiency::Response& _res)
230 if (_req.efficiency < 0.0 || _req.efficiency > 1.0)
232 _res.success =
false;
238 gzmsg <<
"Setting thrust efficiency at thruster " <<
239 this->
thrusterLink->GetName() <<
"=" << _req.efficiency * 100
247 uuv_gazebo_ros_plugins_msgs::GetThrusterEfficiency::Request& _req,
248 uuv_gazebo_ros_plugins_msgs::GetThrusterEfficiency::Response& _res)
256 uuv_gazebo_ros_plugins_msgs::SetThrusterEfficiency::Request& _req,
257 uuv_gazebo_ros_plugins_msgs::SetThrusterEfficiency::Response& _res)
259 if (_req.efficiency < 0.0 || _req.efficiency > 1.0)
261 _res.success =
false;
267 gzmsg <<
"Setting propeller efficiency at thruster " <<
268 this->
thrusterLink->GetName() <<
"=" << _req.efficiency * 100
276 uuv_gazebo_ros_plugins_msgs::GetThrusterEfficiency::Request& _req,
277 uuv_gazebo_ros_plugins_msgs::GetThrusterEfficiency::Response& _res)
285 uuv_gazebo_ros_plugins_msgs::SetThrusterState::Request& _req,
286 uuv_gazebo_ros_plugins_msgs::SetThrusterState::Response& _res)
288 this->
isOn = _req.on;
289 gzmsg <<
"Turning thruster " << this->
thrusterLink->GetName() <<
" " <<
290 (this->
isOn ?
"ON" :
"OFF") << std::endl;
297 uuv_gazebo_ros_plugins_msgs::GetThrusterState::Request& _req,
298 uuv_gazebo_ros_plugins_msgs::GetThrusterState::Response& _res)
300 _res.is_on = this->
isOn;
306 uuv_gazebo_ros_plugins_msgs::GetThrusterConversionFcn::Request& _req,
307 uuv_gazebo_ros_plugins_msgs::GetThrusterConversionFcn::Response& _res)
313 if (!_res.fcn.function_name.compare(
"Basic"))
315 gzmsg <<
"ThrusterROSPlugin::GetThrusterConversionFcn::Basic" << std::endl;
316 _res.fcn.tags.push_back(
"rotor_constant");
318 _res.fcn.data.push_back(param);
320 else if (!_res.fcn.function_name.compare(
"Bessa"))
322 gzmsg <<
"ThrusterROSPlugin::GetThrusterConversionFcn::Bessa" << std::endl;
323 _res.fcn.tags.push_back(
"rotor_constant_l");
325 _res.fcn.data.push_back(param);
327 _res.fcn.tags.push_back(
"rotor_constant_r");
329 _res.fcn.data.push_back(param);
331 _res.fcn.tags.push_back(
"delta_l");
333 _res.fcn.data.push_back(param);
335 _res.fcn.tags.push_back(
"delta_r");
337 _res.fcn.data.push_back(param);
339 else if (!_res.fcn.function_name.compare(
"LinearInterp"))
341 gzmsg <<
"ThrusterROSPlugin::GetThrusterConversionFcn::LinearInterp" << std::endl;
344 for (
auto& item : table)
346 gzmsg << item.first <<
" " << item.second << std::endl;
347 _res.fcn.lookup_table_input.push_back(item.first);
348 _res.fcn.lookup_table_output.push_back(item.second);
physics::LinkPtr thrusterLink
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
ros::Publisher pubThrustForceEff
Publisher for the thrust force efficiency.
void publish(const boost::shared_ptr< M > &message) const
bool GetThrustForceEfficiency(uuv_gazebo_ros_plugins_msgs::GetThrusterEfficiency::Request &_req, uuv_gazebo_ros_plugins_msgs::GetThrusterEfficiency::Response &_res)
Get the thrust efficiency factor.
double propellerEfficiency
gazebo::common::Time GetRosPublishPeriod()
Return the ROS publish period.
transport::PublisherPtr thrustTopicPublisher
gazebo::event::ConnectionPtr rosPublishConnection
Connection for callbacks on update world.
ROSCPP_DECL bool isInitialized()
boost::scoped_ptr< ros::NodeHandle > rosNode
Pointer to this ROS node's handle.
bool SetThrusterState(uuv_gazebo_ros_plugins_msgs::SetThrusterState::Request &_req, uuv_gazebo_ros_plugins_msgs::SetThrusterState::Response &_res)
Turn thruster on/off.
ros::Publisher pubThrust
Publisher for current actual thrust.
std::shared_ptr< ConversionFunction > conversionFunction
GZ_REGISTER_MODEL_PLUGIN(UmbilicalPlugin)
ros::Publisher pubThrustWrench
Publisher for current actual thrust as wrench.
common::Time thrustForceStamp
std::map< std::string, ros::ServiceServer > services
Map of thruster services.
void RosPublishStates()
Publish thruster state via ROS.
void SetThrustReference(const uuv_gazebo_ros_plugins_msgs::FloatStamped::ConstPtr &_msg)
Set new set point (desired thrust [N]) for thruster.
ros::Publisher pubDynamicStateEff
Publisher for the dynamic state efficiency.
~ThrusterROSPlugin()
Destructor.
virtual void Reset()
Reset Module.
transport::SubscriberPtr commandSubscriber
ThrusterROSPlugin()
Constrcutor.
bool SetThrustForceEfficiency(uuv_gazebo_ros_plugins_msgs::SetThrusterEfficiency::Request &_req, uuv_gazebo_ros_plugins_msgs::SetThrusterEfficiency::Response &_res)
Set the thrust efficiency factor.
ignition::math::Vector3d thrusterAxis
bool GetDynamicStateEfficiency(uuv_gazebo_ros_plugins_msgs::GetThrusterEfficiency::Request &_req, uuv_gazebo_ros_plugins_msgs::GetThrusterEfficiency::Response &_res)
Get the dynamic state efficiency factor.
bool GetThrusterConversionFcn(uuv_gazebo_ros_plugins_msgs::GetThrusterConversionFcn::Request &_req, uuv_gazebo_ros_plugins_msgs::GetThrusterConversionFcn::Response &_res)
Get thruster conversion function parameters.
bool GetThrusterState(uuv_gazebo_ros_plugins_msgs::GetThrusterState::Request &_req, uuv_gazebo_ros_plugins_msgs::GetThrusterState::Response &_res)
Get thruster state.
void SetRosPublishRate(double _hz)
Set the ROS publish frequency (Hz).
bool SetDynamicStateEfficiency(uuv_gazebo_ros_plugins_msgs::SetThrusterEfficiency::Request &_req, uuv_gazebo_ros_plugins_msgs::SetThrusterEfficiency::Response &_res)
Set the dynamic state efficiency factor.
ros::Publisher pubThrusterState
Publisher for the thruster state.
void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf)
Load module and read parameters from SDF.
ros::Subscriber subThrustReference
Subscriber reacting to new reference thrust set points.
gazebo::common::Time rosPublishPeriod
Period after which we should publish a message via ROS.
gazebo::common::Time lastRosPublishTime
Last time we published a message via ROS.
virtual void Init()
Initialize Module.