wheeled_entity.cpp
Go to the documentation of this file.
1 
7 #include "wheeled_entity.h"
8 #include <argos3/core/simulator/space/space.h>
9 
10 namespace argos {
11 
12  /****************************************/
13  /****************************************/
14 
16  size_t un_num_wheels) :
17  CEntity(pc_parent),
18  m_unNumWheels(un_num_wheels) {
19  m_pcWheelPositions = new CVector3[m_unNumWheels];
20  m_pfWheelRadia = new Real[m_unNumWheels];
21  ::memset(m_pfWheelRadia, 0, m_unNumWheels * sizeof(Real));
22  m_pfWheelVelocities = new Real[m_unNumWheels];
23  ::memset(m_pfWheelVelocities, 0, m_unNumWheels * sizeof(Real));
24  Disable();
25  }
26 
27  /****************************************/
28  /****************************************/
29 
31  const std::string& str_id,
32  size_t un_num_wheels) :
33  CEntity(pc_parent, str_id),
34  m_unNumWheels(un_num_wheels) {
35  m_pcWheelPositions = new CVector3[m_unNumWheels];
36  m_pfWheelRadia = new Real[m_unNumWheels];
37  ::memset(m_pfWheelRadia, 0, m_unNumWheels * sizeof(Real));
38  m_pfWheelVelocities = new Real[m_unNumWheels];
39  ::memset(m_pfWheelVelocities, 0, m_unNumWheels * sizeof(Real));
40  Disable();
41  }
42 
43  /****************************************/
44  /****************************************/
45 
47  delete[] m_pcWheelPositions;
48  delete[] m_pfWheelRadia;
49  delete[] m_pfWheelVelocities;
50  }
51 
52  /****************************************/
53  /****************************************/
54 
56  ::memset(m_pfWheelVelocities, 0, m_unNumWheels * sizeof(Real));
57  }
58 
59  /****************************************/
60  /****************************************/
61 
63  const CVector3& c_position,
64  Real f_radius) {
65  if(un_index < m_unNumWheels) {
66  m_pcWheelPositions[un_index] = c_position;
67  m_pfWheelRadia[un_index] = f_radius;
68  }
69  else {
70  THROW_ARGOSEXCEPTION("CWheeledEntity::SetWheel() : index " << un_index << " out of bounds (allowed [0:" << m_unNumWheels << "])");
71  }
72  }
73 
74  /****************************************/
75  /****************************************/
76 
77  const CVector3& CWheeledEntity::GetWheelPosition(size_t un_index) const {
78  if(un_index < m_unNumWheels) {
79  return m_pcWheelPositions[un_index];
80  }
81  else {
82  THROW_ARGOSEXCEPTION("CWheeledEntity::GetWheelPosition() : index " << un_index << " out of bounds (allowed [0:" << m_unNumWheels << "])");
83  }
84  }
85 
86  /****************************************/
87  /****************************************/
88 
89  Real CWheeledEntity::GetWheelRadius(size_t un_index) const {
90  if(un_index < m_unNumWheels) {
91  return m_pfWheelRadia[un_index];
92  }
93  else {
94  THROW_ARGOSEXCEPTION("CWheeledEntity::GetWheelRadius() : index " << un_index << " out of bounds (allowed [0:" << m_unNumWheels << "])");
95  }
96  }
97 
98  /****************************************/
99  /****************************************/
100 
101  Real CWheeledEntity::GetWheelVelocity(size_t un_index) const {
102  if(un_index < m_unNumWheels) {
103  return m_pfWheelVelocities[un_index];
104  }
105  else {
106  THROW_ARGOSEXCEPTION("CWheeledEntity::GetWheelVelocity() : index " << un_index << " out of bounds (allowed [0:" << m_unNumWheels << "])");
107  }
108  }
109 
110  /****************************************/
111  /****************************************/
112 
113  void CWheeledEntity::SetVelocities(Real* pf_velocities) {
114  ::memcpy(m_pfWheelVelocities, pf_velocities, m_unNumWheels * sizeof(Real));
115  }
116 
117  /****************************************/
118  /****************************************/
119 
121 
122  /****************************************/
123  /****************************************/
124 
125 }
#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
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
Real GetWheelRadius(size_t un_index) const
CWheeledEntity(CComposableEntity *pc_parent, size_t un_num_wheels)
const CVector3 & GetWheelPosition(size_t un_index) const
void SetWheel(UInt32 un_index, const CVector3 &c_position, Real f_radius)
void SetVelocities(Real *pf_velocities)
Real GetWheelVelocity(size_t un_index) const