ARGoS  3
A parallel, multi-engine simulator for swarm robotics
differential_steering_default_actuator.cpp
Go to the documentation of this file.
1 
8 #include <argos3/core/utility/logging/argos_log.h>
9 #include <argos3/core/utility/plugins/factory.h>
10 
11 namespace argos {
12 
13  /****************************************/
14  /****************************************/
15 
17  m_pcWheeledEntity(NULL),
18  m_pcRNG(NULL),
19  m_fNoiseStdDeviation(0.0f) {
22  }
23 
24  /****************************************/
25  /****************************************/
26 
28  try {
29  m_pcWheeledEntity = &(c_entity.GetComponent<CWheeledEntity>("wheels"));
30  if(m_pcWheeledEntity->GetNumWheels() != 2) {
31  THROW_ARGOSEXCEPTION("The differential steering actuator can be associated only to a robot with 2 wheels");
32  }
34  }
35  catch(CARGoSException& ex) {
36  THROW_ARGOSEXCEPTION_NESTED("Error setting differential steering actuator to entity \"" << c_entity.GetId() << "\"", ex);
37  }
38  }
39 
40  /****************************************/
41  /****************************************/
42 
44  try {
46  GetNodeAttributeOrDefault<Real>(t_tree, "noise_std_dev", m_fNoiseStdDeviation, 0.0f);
47  if(m_fNoiseStdDeviation > 0.0f) {
48  m_pcRNG = CRandom::CreateRNG("argos");
49  }
50  }
51  catch(CARGoSException& ex) {
52  THROW_ARGOSEXCEPTION_NESTED("Initialization error in foot-bot steering actuator.", ex);
53  }
54  }
55 
56  /****************************************/
57  /****************************************/
58 
60  Real f_right_velocity) {
61  /* Convert speeds in m/s */
62  m_fCurrentVelocity[LEFT_WHEEL] = f_left_velocity * 0.01f;
63  m_fCurrentVelocity[RIGHT_WHEEL] = f_right_velocity * 0.01f;
64  /* Apply noise */
65  if(m_fNoiseStdDeviation > 0.0f) {
67  }
68  }
69 
70  /****************************************/
71  /****************************************/
72 
75  }
76 
77  /****************************************/
78  /****************************************/
79 
83  }
84 
85  /****************************************/
86  /****************************************/
87 
91  }
92 
93  /****************************************/
94  /****************************************/
95 
96 }
97 
98 REGISTER_ACTUATOR(CDifferentialSteeringDefaultActuator,
99  "differential_steering", "default",
100  "Carlo Pinciroli [ilpincy@gmail.com]",
101  "1.0",
102  "The differential steering actuator.",
103  "This actuator controls the two wheels a differential steering robot. For a\n"
104  "complete description of its usage, refer to the\n"
105  "ci_differential_steering_actuator.h file.\n\n"
106  "REQUIRED XML CONFIGURATION\n\n"
107  " <controllers>\n"
108  " ...\n"
109  " <my_controller ...>\n"
110  " ...\n"
111  " <actuators>\n"
112  " ...\n"
113  " <differential_steering implementation=\"default\" />\n"
114  " ...\n"
115  " </actuators>\n"
116  " ...\n"
117  " </my_controller>\n"
118  " ...\n"
119  " </controllers>\n\n"
120  "OPTIONAL XML CONFIGURATION\n\n"
121  "It is possible to specify noisy speed in order to match the characteristics\n"
122  "of the real robot. This can be done with the attribute: 'noise_std_dev',\n"
123  "which indicates the standard deviation of a gaussian noise applied to the\n"
124  "desired velocity of the steering:\n\n"
125  " <controllers>\n"
126  " ...\n"
127  " <my_controller ...>\n"
128  " ...\n"
129  " <actuators>\n"
130  " ...\n"
131  " <differential_steering implementation=\"default\"\n"
132  " noise_std_dev=\"1\" />\n"
133  " ...\n"
134  " </actuators>\n"
135  " ...\n"
136  " </my_controller>\n"
137  " ...\n"
138  " </controllers>\n",
139  "Usable"
140  );
141 
argos::CRandom::CRNG::Gaussian
Real Gaussian(Real f_std_dev, Real f_mean=0.0f)
Returns a random value from a Gaussian distribution.
Definition: rng.cpp:131
argos::CDifferentialSteeringDefaultActuator::Reset
virtual void Reset()
Resets the actuator to the state it had just after Init().
Definition: differential_steering_default_actuator.cpp:80
argos::CEntity::GetId
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
differential_steering_default_actuator.h
argos::CDifferentialSteeringDefaultActuator::Init
virtual void Init(TConfigurationNode &t_tree)
Initializes the actuator from the XML configuration tree.
Definition: differential_steering_default_actuator.cpp:43
argos
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
argos::CComposableEntity
Basic class for an entity that contains other entities.
Definition: composable_entity.h:32
argos::CARGoSException
The exception that wraps all errors in ARGoS.
Definition: argos_exception.h:61
argos::CComposableEntity::GetComponent
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
Definition: composable_entity.cpp:109
argos::CDifferentialSteeringDefaultActuator::m_fNoiseStdDeviation
Real m_fNoiseStdDeviation
Noise parameters, at the moment noise is Gaussian.
Definition: differential_steering_default_actuator.h:78
argos::CWheeledEntity
Definition: wheeled_entity.h:15
argos::CEntity::Enable
void Enable()
Enables the entity.
Definition: entity.h:239
argos::CDifferentialSteeringDefaultActuator::LEFT_WHEEL
@ LEFT_WHEEL
Definition: differential_steering_default_actuator.h:31
argos::TConfigurationNode
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Definition: argos_configuration.h:27
argos::CDifferentialSteeringDefaultActuator::m_pcRNG
CRandom::CRNG * m_pcRNG
Random number generator.
Definition: differential_steering_default_actuator.h:75
THROW_ARGOSEXCEPTION_NESTED
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
Definition: argos_exception.h:115
THROW_ARGOSEXCEPTION
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
Definition: argos_exception.h:111
argos::CDifferentialSteeringDefaultActuator::Update
virtual void Update()
Updates the state of the entity associated to this actuator.
Definition: differential_steering_default_actuator.cpp:73
argos::CDifferentialSteeringDefaultActuator::AddGaussianNoise
virtual void AddGaussianNoise()
Adds noise to the steering velocity.
Definition: differential_steering_default_actuator.cpp:88
argos::CWheeledEntity::SetVelocities
void SetVelocities(Real *pf_velocities)
Definition: wheeled_entity.cpp:115
argos::CCI_DifferentialSteeringActuator::m_fCurrentVelocity
Real m_fCurrentVelocity[2]
Definition: ci_differential_steering_actuator.h:34
argos::CDifferentialSteeringDefaultActuator::CDifferentialSteeringDefaultActuator
CDifferentialSteeringDefaultActuator()
Constructor.
Definition: differential_steering_default_actuator.cpp:16
argos::CRandom::CreateRNG
static CRNG * CreateRNG(const std::string &str_category)
Creates a new RNG inside the given category.
Definition: rng.cpp:326
argos::CDifferentialSteeringDefaultActuator::RIGHT_WHEEL
@ RIGHT_WHEEL
Definition: differential_steering_default_actuator.h:32
REGISTER_ACTUATOR
REGISTER_ACTUATOR(CDifferentialSteeringDefaultActuator, "differential_steering", "default", "Carlo Pinciroli [ilpincy@gmail.com]", "1.0", "The differential steering actuator.", "This actuator controls the two wheels a differential steering robot. For a\n" "complete description of its usage, refer to the\n" "ci_differential_steering_actuator.h file.\n\n" "REQUIRED XML CONFIGURATION\n\n" " <controllers>\n" " ...\n" " <my_controller ...>\n" " ...\n" " <actuators>\n" " ...\n" " <differential_steering implementation=\"default\" />\n" " ...\n" " </actuators>\n" " ...\n" " </my_controller>\n" " ...\n" " </controllers>\n\n" "OPTIONAL XML CONFIGURATION\n\n" "It is possible to specify noisy speed in order to match the characteristics\n" "of the real robot. This can be done with the attribute: 'noise_std_dev',\n" "which indicates the standard deviation of a gaussian noise applied to the\n" "desired velocity of the steering:\n\n" " <controllers>\n" " ...\n" " <my_controller ...>\n" " ...\n" " <actuators>\n" " ...\n" " <differential_steering implementation=\"default\"\n" " noise_std_dev=\"1\" />\n" " ...\n" " </actuators>\n" " ...\n" " </my_controller>\n" " ...\n" " </controllers>\n", "Usable")
argos::CWheeledEntity::GetNumWheels
size_t GetNumWheels() const
Definition: wheeled_entity.h:34
argos::CDifferentialSteeringDefaultActuator::SetLinearVelocity
virtual void SetLinearVelocity(Real f_left_velocity, Real f_right_velocity)
Sets the linear velocity of the two steering.
Definition: differential_steering_default_actuator.cpp:59
Real
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
argos::CCI_Actuator::Init
virtual void Init(TConfigurationNode &t_node)
Initializes the actuator from the XML configuration tree.
Definition: ci_actuator.h:54
argos::CDifferentialSteeringDefaultActuator::m_pcWheeledEntity
CWheeledEntity * m_pcWheeledEntity
Definition: differential_steering_default_actuator.h:72
argos::CDifferentialSteeringDefaultActuator::SetRobot
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this actuator.
Definition: differential_steering_default_actuator.cpp:27