19 #include <gazebo/gazebo.hh> 20 #include <gazebo/physics/Link.hh> 21 #include <gazebo/physics/Model.hh> 22 #include <gazebo/physics/World.hh> 30 FinPlugin::FinPlugin() : inputCommand(0), angle(0), finID(-1)
39 #if GAZEBO_MAJOR_VERSION >= 8 51 this->
node = transport::NodePtr(
new transport::Node());
52 #if GAZEBO_MAJOR_VERSION >= 8 53 this->
node->Init(_model->GetWorld()->Name());
55 this->
node->Init(_model->GetWorld()->GetName());
59 GZ_ASSERT(_sdf->HasElement(
"fin_id"),
"Could not find fin_id parameter.");
60 this->
finID = _sdf->Get<
int>(
"fin_id");
61 GZ_ASSERT(this->finID >= 0,
"Fin ID must be greater or equal than zero");
64 std::stringstream strs;
65 strs <<
"/" << _model->GetName() <<
"/fins/" << this->finID <<
"/";
69 std::string inputTopic, outputTopic;
70 if (_sdf->HasElement(
"input_topic"))
71 std::string inputTopic = _sdf->Get<std::string>(
"input_topic");
75 if (_sdf->HasElement(
"output_topic"))
76 outputTopic = _sdf->Get<std::string>(
"output_topic");
80 GZ_ASSERT(_sdf->HasElement(
"link_name"),
"Could not find link_name.");
81 std::string link_name = _sdf->Get<std::string>(
"link_name");
82 this->
link = _model->GetLink(link_name);
83 GZ_ASSERT(this->link,
"link is invalid");
85 GZ_ASSERT(_sdf->HasElement(
"joint_name"),
"Could not find joint_name.");
86 std::string joint_name = _sdf->Get<std::string>(
"joint_name");
87 this->
joint = _model->GetJoint(joint_name);
88 GZ_ASSERT(this->joint,
"joint is invalid");
91 GZ_ASSERT(_sdf->HasElement(
"dynamics"),
"Could not find dynamics.");
93 _sdf->GetElement(
"dynamics")));
96 GZ_ASSERT(_sdf->HasElement(
"liftdrag"),
"Could not find liftdrag");
99 _sdf->GetElement(
"liftdrag")));
102 GZ_ASSERT(_sdf->HasElement(
"current_velocity_topic"),
103 "Could not find current_velocity_topic.");
104 std::string currentVelocityTopic =
105 _sdf->Get<std::string>(
"current_velocity_topic");
107 GZ_ASSERT(!currentVelocityTopic.empty(),
108 "Fluid velocity topic tag cannot be empty");
110 gzmsg <<
"Subscribing to current velocity topic: " << currentVelocityTopic
117 uuv_gazebo_plugins_msgs::msgs::Double>(outputTopic);
140 "nan in this->inputCommand");
142 double upperLimit, lowerLimit;
143 #if GAZEBO_MAJOR_VERSION >= 8 144 upperLimit = this->
joint->UpperLimit(0);
145 lowerLimit = this->
joint->LowerLimit(0);
147 upperLimit = this->
joint->GetUpperLimit(0).Radian();
148 lowerLimit = this->
joint->GetLowerLimit(0).Radian();
156 _info.simTime.Double());
159 ignition::math::Pose3d finPose;
160 ignition::math::Vector3d linVel;
161 #if GAZEBO_MAJOR_VERSION >= 8 162 finPose = this->
link->WorldPose();
163 linVel = this->
link->WorldLinearVel();
165 finPose = this->
link->GetWorldPose().Ign();
166 linVel = this->
link->GetWorldLinearVel().Ign();
169 ignition::math::Vector3d ldNormalI = finPose.Rot().RotateVector(
170 ignition::math::Vector3d::UnitZ);
173 ignition::math::Vector3d velInLDPlaneI = ldNormalI.Cross(velI.Cross(ldNormalI));
174 ignition::math::Vector3d velInLDPlaneL = finPose.Rot().RotateVectorReverse(velInLDPlaneI);
transport::SubscriberPtr currentSubscriber
Subcriber to current message.
ignition::math::Vector3d finForce
Force component calculated from the lift and drag module.
double angle
Latest fin angle in [rad].
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
double inputCommand
Latest input command.
const boost::shared_ptr< const uuv_gazebo_plugins_msgs::msgs::Double > ConstDoublePtr
Definition of a pointer to the floating point message.
physics::JointPtr joint
The fin joint.
GZ_REGISTER_MODEL_PLUGIN(UmbilicalPlugin)
ignition::math::Vector3d currentVelocity
Current velocity vector read from topic.
void OnUpdate(const common::UpdateInfo &_info)
Update the simulation state.
virtual ~FinPlugin()
Destructor.
static DynamicsFactory & GetInstance()
Returns the singleton instance of this factory.
common::Time angleStamp
Time stamp of latest thrust force.
void UpdateCurrentVelocity(ConstVector3dPtr &_msg)
Reads current velocity topic.
std::shared_ptr< Dynamics > dynamics
Fin dynamic model.
static LiftDragFactory & GetInstance()
Returns the singleton instance of this factory.
void UpdateInput(ConstDoublePtr &_msg)
Callback for the input topic subscriber.
Model plugin for description of a submarine's fin.
transport::NodePtr node
Gazebo node.
std::string topicPrefix
Topic prefix.
physics::LinkPtr link
The fin link.
transport::SubscriberPtr commandSubscriber
Subscriber to the reference signal topic.
event::ConnectionPtr updateConnection
Update event.
transport::PublisherPtr anglePublisher
Publisher to the output thrust topic.
std::shared_ptr< LiftDrag > liftdrag
Lift&Drag model.