rotor_equipped_entity.cpp
Go to the documentation of this file.
1 
8 #include <argos3/core/simulator/space/space.h>
9 
10 namespace argos {
11 
12  /****************************************/
13  /****************************************/
14 
16  size_t un_num_rotors) :
17  CEntity(pc_parent),
18  m_unNumRotors(un_num_rotors) {
19  m_pcRotorPositions = new CVector3[m_unNumRotors];
20  m_pfRotorVelocities = new Real[m_unNumRotors];
21  ::memset(m_pfRotorVelocities, 0, m_unNumRotors * sizeof(Real));
22  Disable();
23  }
24 
25  /****************************************/
26  /****************************************/
27 
29  const std::string& str_id,
30  size_t un_num_rotors) :
31  CEntity(pc_parent, str_id),
32  m_unNumRotors(un_num_rotors) {
33  m_pcRotorPositions = new CVector3[m_unNumRotors];
34  m_pfRotorVelocities = new Real[m_unNumRotors];
35  ::memset(m_pfRotorVelocities, 0, m_unNumRotors * sizeof(Real));
36  Disable();
37  }
38 
39  /****************************************/
40  /****************************************/
41 
43  delete[] m_pcRotorPositions;
44  delete[] m_pfRotorVelocities;
45  }
46 
47  /****************************************/
48  /****************************************/
49 
51  ::memset(m_pfRotorVelocities, 0, m_unNumRotors * sizeof(Real));
52  }
53 
54  /****************************************/
55  /****************************************/
56 
58  const CVector3& c_position) {
59  if(un_index < m_unNumRotors) {
60  m_pcRotorPositions[un_index] = c_position;
61  }
62  else {
63  THROW_ARGOSEXCEPTION("CRotorEquippedEntity::SetRotor() : index " << un_index << " out of bounds (allowed [0:" << m_unNumRotors << "])");
64  }
65  }
66 
67  /****************************************/
68  /****************************************/
69 
70  const CVector3& CRotorEquippedEntity::GetRotorPosition(size_t un_index) const {
71  if(un_index < m_unNumRotors) {
72  return m_pcRotorPositions[un_index];
73  }
74  else {
75  THROW_ARGOSEXCEPTION("CRotorEquippedEntity::GetRotorPosition() : index " << un_index << " out of bounds (allowed [0:" << m_unNumRotors << "])");
76  }
77  }
78 
79  /****************************************/
80  /****************************************/
81 
83  if(un_index < m_unNumRotors) {
84  return m_pfRotorVelocities[un_index];
85  }
86  else {
87  THROW_ARGOSEXCEPTION("CRotorEquippedEntity::GetRotorVelocity() : index " << un_index << " out of bounds (allowed [0:" << m_unNumRotors << "])");
88  }
89  }
90 
91  /****************************************/
92  /****************************************/
93 
95  ::memcpy(m_pfRotorVelocities, pf_velocities, m_unNumRotors * sizeof(Real));
96  }
97 
98  /****************************************/
99  /****************************************/
100 
102 
103  /****************************************/
104  /****************************************/
105 
106 }
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(CEntity)
Basic class for an entity that contains other entities.
The basic entity type.
Definition: entity.h:90
void Disable()
Disables the entity.
Definition: entity.h:275
A 3D vector class.
Definition: vector3.h:31
void SetRotor(UInt32 un_index, const CVector3 &c_position)
Real GetRotorVelocity(size_t un_index) const
CRotorEquippedEntity(CComposableEntity *pc_parent, size_t un_num_rotors)
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
const CVector3 & GetRotorPosition(size_t un_index) const
void SetVelocities(Real *pf_velocities)