8 #include <argos3/core/utility/logging/argos_log.h>
9 #include <argos3/core/utility/math/cylinder.h>
10 #include <argos3/core/simulator/simulator.h>
11 #include <argos3/core/simulator/space/space.h>
12 #include <argos3/plugins/simulator/physics_engines/pointmass3d/pointmass3d_engine.h>
19 static Real SymmetricClamp(
Real f_max,
21 if(f_value > f_max)
return f_max;
22 if(f_value < -f_max)
return -f_max;
47 m_cQuadRotorEntity(c_quadrotor),
48 m_fBodyHeight(f_body_height),
49 m_fArmLength(f_arm_length),
50 m_fBodyMass(f_body_mass),
51 m_fBodyInertia(f_body_inertia),
60 m_cMaxForce(c_max_force),
61 m_fMaxTorque(f_max_torque) {
76 m_pfLinearError[0] = 0.0f;
77 m_pfLinearError[1] = 0.0f;
78 m_pfLinearError[2] = 0.0f;
103 cLimits.
GetMin().GetX() + m_fArmLength),
104 cLimits.
GetMax().GetX() - m_fArmLength));
107 cLimits.
GetMin().GetY() + m_fArmLength),
108 cLimits.
GetMax().GetY() - m_fArmLength));
112 cLimits.
GetMax().GetZ() - m_fBodyHeight));
133 m_cTorque.
SetValue(m_fRotationalControl);
154 const CRay3& c_ray)
const {
159 return m_cShape.
Intersects(f_t_on_ray, c_ray);
165 void CPointMass3DQuadRotorModel::PositionalControl() {
167 m_cLinearControl.
Set(
168 SymmetricClamp(m_cMaxForce.
GetX(), PDControl(
172 m_pfLinearError[0])),
173 SymmetricClamp(m_cMaxForce.
GetY(), PDControl(
177 m_pfLinearError[1])),
178 SymmetricClamp(m_cMaxForce.
GetZ(), PDControl(
184 m_fRotationalControl =
185 SymmetricClamp(m_fMaxTorque, PDControl(
186 (m_sDesiredPositionData.
Yaw - m_cYaw).SignedNormalize().GetValue(),
195 void CPointMass3DQuadRotorModel::SpeedControl() {
197 m_cLinearControl.
Set(
198 SymmetricClamp(m_cMaxForce.
GetX(), PDControl(
202 m_pfLinearError[0])),
203 SymmetricClamp(m_cMaxForce.
GetY(), PDControl(
207 m_pfLinearError[1])),
208 SymmetricClamp(m_cMaxForce.
GetZ(), PDControl(
214 m_fRotationalControl =
215 SymmetricClamp(m_fMaxTorque, PDControl(
216 (m_sDesiredSpeedData.
RotSpeed - m_cRotSpeed).GetValue(),
225 Real CPointMass3DQuadRotorModel::PDControl(
Real f_cur_error,
230 f_k_p * f_cur_error +
232 f_old_error = f_cur_error;
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
T Max(const T &t_v1, const T &t_v2)
Returns the bigger of the two passed arguments.
T Min(const T &t_v1, const T &t_v2)
Returns the smaller of the two passed arguments.
This entity is a link to a body in the physics engine.
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
Real GetPhysicsClockTick() const
Returns the length of the physics engine tick.
An anchor related to the body of an entity.
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
CVector3 Position
The position of the anchor wrt the global coordinate system.
void RegisterAnchorMethod(const SAnchor &s_anchor, void(MODEL::*pt_method)(SAnchor &))
Registers an anchor method.
CEmbodiedEntity & GetEmbodiedEntity()
Returns the embodied entity associated to this physics model.
const SBoundingBox & GetBoundingBox() const
Returns an axis-aligned box that contains the physics model.
CSpace & GetSpace() const
Returns a reference to the simulated space.
static CSimulator & GetInstance()
Returns the instance to the CSimulator class.
const CRange< CVector3 > & GetArenaLimits() const
Returns the arena limits.
It defines the basic type CRadians, used to store an angle value in radians.
CRadians & UnsignedNormalize()
Normalizes the value in the range [0:TWO_PI].
void SetValue(Real f_value)
Sets the value in radians.
bool Intersects(Real &f_t_on_ray, const CRay3 &c_ray)
void ToEulerAngles(CRadians &c_z_angle, CRadians &c_y_angle, CRadians &c_x_angle) const
void SetY(const Real f_y)
Sets the y coordinate of this vector.
Real GetX() const
Returns the x coordinate of this vector.
void SetX(const Real f_x)
Sets the x coordinate of this vector.
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
void SetZ(const Real f_z)
Sets the z coordinate of this vector.
Real GetY() const
Returns the y coordinate of this vector.
static const CVector3 Z
The z axis.
Real GetZ() const
Returns the z coordinate of this vector.
EControlMethod GetControlMethod() const
const SPositionControlData & GetPositionControlData() const
CVector3 m_cVelocity
The linear velocity of this model in the engine.
virtual void UpdateOriginAnchor(SAnchor &s_anchor)
Updates the origin anchor associated to the embodied entity.
CPointMass3DEngine & m_cPM3DEngine
Reference to the physics engine.
CVector3 m_cAcceleration
The acceleration of this model in the engine.
CVector3 m_cPosition
The position of the model in this engine.
virtual void CalculateBoundingBox()
Calculates the axis-aligned box that contains the entire physics model.
CPointMass3DQuadRotorModel(CPointMass3DEngine &c_engine, CEmbodiedEntity &c_body, CQuadRotorEntity &c_quadrotor, Real f_body_height, Real f_arm_length, Real f_body_mass, Real f_body_inertia, const CVector3 &c_pos_kp, const CVector3 &c_pos_kd, Real f_yaw_kp, Real f_yaw_kd, const CVector3 &c_vel_kp, const CVector3 &c_vel_kd, Real f_rot_kp, Real f_rot_kd, const CVector3 &c_max_force=CVector3(1000.0f, 1000.0f, 1000.0f), Real f_max_torque=1000.0f)
virtual bool CheckIntersectionWithRay(Real &f_t_on_ray, const CRay3 &c_ray) const
virtual void UpdateFromEntityStatus()
Updates the state of this model from the status of the associated entity.
virtual void UpdateOriginAnchor(SAnchor &s_anchor)
Updates the origin anchor associated to the embodied entity.