16 #include <gazebo/gazebo.hh> 24 const std::string &element)
26 if (!_sdf->HasElement(element))
28 std::cerr <<
" LiftDrag: Missing required element: " 40 if (!_sdf->HasElement(
"type"))
42 std::cerr <<
"liftdrag does not have a type element" << std::endl;
46 std::string identifier = _sdf->Get<std::string>(
"type");
48 if (creators_.find(identifier) == creators_.end())
50 std::cerr <<
"Cannot create LiftDrag with unknown identifier: " 51 << identifier << std::endl;
55 return creators_[identifier](_sdf);
69 if (creators_.find(_identifier) != creators_.end())
71 std::cerr <<
"Warning: Registering LiftDrag with identifier: " 72 << _identifier <<
" twice" << std::endl;
74 creators_[_identifier] = _creator;
76 std::cout <<
"Registered LiftDrag type " << _identifier << std::endl;
88 if (!_sdf->HasElement(
"lift_constant"))
90 std::cerr <<
"LiftDragQuadratic: expected element lift_constant" 95 if (!_sdf->HasElement(
"drag_constant"))
97 std::cerr <<
"LiftDragQuadratic: expected element drag_constant" 102 gzmsg <<
"Lift constant= " << _sdf->Get<
double>(
"lift_constant") << std::endl;
103 gzmsg <<
"Drag constant= " << _sdf->Get<
double>(
"drag_constant") << std::endl;
106 _sdf->Get<
double>(
"drag_constant"));
111 const ignition::math::Vector3d &_velL)
113 ignition::math::Vector3d velL = _velL;
114 double angle = atan2(_velL.Y(), _velL.X());
121 else if (angle < -M_PI_2)
127 double u = velL.Length();
129 double du2 = angle * u2;
131 double drag = angle * du2 * this->dragConstant;
132 double lift = du2 * this->liftConstant;
134 ignition::math::Vector3d liftDirectionL =
135 -ignition::math::Vector3d::UnitZ.Cross(_velL).Normalize();
136 ignition::math::Vector3d dragDirectionL = -_velL;
138 return lift*liftDirectionL + drag*dragDirectionL.Normalize();
145 if (!_tag.compare(
"drag_constant"))
146 _output = this->dragConstant;
147 else if (!_tag.compare(
"lift_constant"))
148 _output = this->liftConstant;
152 gzmsg <<
"LiftDragQuadratic::GetParam <" << _tag <<
">=" << _output <<
160 std::map<std::string, double> params;
161 params[
"drag_constant"] = this->dragConstant;
162 params[
"lift_constant"] = this->liftConstant;
184 _sdf->Get<
double>(
"fluid_density"),
185 _sdf->Get<
double>(
"a0"),
186 _sdf->Get<
double>(
"alpha_stall"),
187 _sdf->Get<
double>(
"cla"),
188 _sdf->Get<
double>(
"cla_stall"),
189 _sdf->Get<
double>(
"cda"),
190 _sdf->Get<
double>(
"cda_stall"));
205 ignition::math::Vector3d velL = _velL;
206 double angle = atan2(_velL.Y(), _velL.X());
214 else if (angle < -M_PI_2)
220 double alpha = angle + this->a0;
223 while (fabs(alpha) > 0.5 * M_PI)
225 alpha = alpha > 0 ? alpha - M_PI : alpha + M_PI;
228 double u = velL.Length();
231 double q = 0.5 * this->fluidDensity * u * u;
235 if (alpha > this->alphaStall)
238 double diffAlpha = alpha - this->alphaStall;
239 cl = this->cla*this->alphaStall +
240 this->claStall * diffAlpha;
241 cd = this->cda*this->alphaStall +
242 this->cdaStall * diffAlpha;
244 else if (alpha < -this->alphaStall)
247 double sumAlpha = alpha + this->alphaStall;
248 cl = -this->cla * this->alphaStall +
249 this->cdaStall * sumAlpha;
250 cd = -this->cda * this->alphaStall +
251 this->cdaStall * sumAlpha;
256 cd = this->cda * alpha;
257 cl = this->cla * alpha;
260 double lift = cl*q*this->area;
261 double drag = cd*q*this->area;
263 ignition::math::Vector3d liftDirectionL = -ignition::math::Vector3d::UnitZ.Cross(_velL).Normalize();
264 ignition::math::Vector3d dragDirectionL = -_velL;
266 return lift*liftDirectionL + drag*dragDirectionL.Normalize();
273 if (!_tag.compare(
"area"))
274 _output = this->area;
275 else if (!_tag.compare(
"fluid_density"))
276 _output = this->fluidDensity;
277 else if (!_tag.compare(
"a0"))
279 else if (!_tag.compare(
"alpha_stall"))
280 _output = this->alphaStall;
281 else if (!_tag.compare(
"cla"))
283 else if (!_tag.compare(
"cla_stall"))
284 _output = this->claStall;
285 else if (!_tag.compare(
"cda"))
287 else if (!_tag.compare(
"cda_stall"))
288 _output = this->cdaStall;
292 gzmsg <<
"LiftDragQuadratic::GetParam <" << _tag <<
">=" << _output <<
300 std::map<std::string, double> params;
301 params[
"area"] = this->area;
302 params[
"fluid_density"] = this->fluidDensity;
303 params[
"a0"] = this->a0;
304 params[
"alpha_stall"] = this->alphaStall;
305 params[
"cla"] = this->cla;
306 params[
"cla_stall"] = this->claStall;
307 params[
"cda"] = this->cda;
308 params[
"cda_stall"] = this->cdaStall;
virtual bool GetParam(std::string _tag, double &_output)
Return paramater in scalar form for the given tag.
LiftDrag * CreateLiftDrag(sdf::ElementPtr _sdf)
Create LiftDrag object according to its sdf Description.
static LiftDrag * create(sdf::ElementPtr _sdf)
Create thruster model of this type with parameter values from sdf.
virtual bool GetParam(std::string _tag, double &_output)
Return paramater in scalar form for the given tag.
static const std::string IDENTIFIER
Unique identifier for this dynamical model.
Lift&drag model that models lift/drag coeffs using two lines. This is based on Gazebo's LiftDragPlugin bu...
Abstract base class for Lift&Drag models.
virtual std::map< std::string, double > GetListParams()
Return list of all parameters.
Various Lift&Drag models for Fins.
REGISTER_LIFTDRAG_CREATOR(LiftDragQuadratic,&LiftDragQuadratic::create) LiftDrag *LiftDragQuadratic
bool RegisterCreator(const std::string &_identifier, LiftDragCreator _creator)
Register a LiftDrag class with its creator.
static LiftDrag * create(sdf::ElementPtr _sdf)
Create thruster model of this type with parameter values from sdf.
LiftDrag *(* LiftDragCreator)(sdf::ElementPtr)
Function pointer to create a certain LiftDrag object.
virtual ignition::math::Vector3d compute(const ignition::math::Vector3d &_velL)
Compute the lift and drag force.
static LiftDragFactory & GetInstance()
Returns the singleton instance of this factory.
virtual ignition::math::Vector3d compute(const ignition::math::Vector3d &velL)
Compute the lift and drag force.
static const std::string IDENTIFIER
Unique identifier for this dynamical model.
Basic quadratic (Hugin) lift&drag model, page 18 from [1]. [1] Engelhardtsen, Øystein. "3D AUV Collision Avoidance." (2007).
Factory singleton class that creates a LiftDrag from sdf.
static bool CheckForElement(sdf::ElementPtr _sdf, const std::string &element)
Check for element. Complain and return 0 if it is missing.
virtual std::map< std::string, double > GetListParams()
Return list of all parameters.