ARGoS 3
A parallel, multi-engine simulator for swarm robotics
differential_steering_default_sensor.cpp
Go to the documentation of this file.
1
7#include <argos3/core/simulator/simulator.h>
8#include <argos3/plugins/simulator/entities/wheeled_entity.h>
9#include <argos3/core/simulator/entity/composable_entity.h>
10
12
13namespace argos {
14
15 /****************************************/
16 /****************************************/
17
19 m_pcWheeledEntity(nullptr),
20 m_pcRNG(nullptr),
21 m_bAddNoise(false) {}
22
23 /****************************************/
24 /****************************************/
25
27 try {
28 m_pcWheeledEntity = &(c_entity.GetComponent<CWheeledEntity>("wheels"));
30 THROW_ARGOSEXCEPTION("The differential steering sensor can be associated only to a robot with 2 wheels");
31 }
36 }
37 catch(CARGoSException& ex) {
38 THROW_ARGOSEXCEPTION_NESTED("Error setting differential steering sensor to entity \"" << c_entity.GetId() << "\"", ex);
39 }
40 }
41
42 /****************************************/
43 /****************************************/
44
46 try {
48 /* Parse noise range */
51 if(m_cVelNoiseRange.GetSpan() != 0 ||
53 m_bAddNoise = true;
54 m_pcRNG = CRandom::CreateRNG("argos");
55 }
56 }
57 catch(CARGoSException& ex) {
58 THROW_ARGOSEXCEPTION_NESTED("Initialization error in default differential steering sensor", ex);
59 }
60 /* sensor is enabled by default */
61 Enable();
62 }
63
64 /****************************************/
65 /****************************************/
66
83
84 /****************************************/
85 /****************************************/
86
93
94 /****************************************/
95 /****************************************/
96
98 "differential_steering", "default",
99 "Carlo Pinciroli [ilpincy@gmail.com]",
100 "1.0",
101 "A generic differential steering sensor.",
102
103 "This sensor returns the current position and orientation of a robot. This sensor\n"
104 "can be used with any robot, since it accesses only the body component. In\n"
105 "controllers, you must include the ci_differential_steering_sensor.h header.\n\n"
106
107 "This sensor is enabled by default.\n\n"
108
109 "REQUIRED XML CONFIGURATION\n\n"
110
111 " <controllers>\n"
112 " ...\n"
113 " <my_controller ...>\n"
114 " ...\n"
115 " <sensors>\n"
116 " ...\n"
117 " <differential_steering implementation=\"default\" />\n"
118 " ...\n"
119 " </sensors>\n"
120 " ...\n"
121 " </my_controller>\n"
122 " ...\n"
123 " </controllers>\n\n"
124
125 "OPTIONAL XML CONFIGURATION\n\n"
126
127 "It is possible to add uniform noise to the sensor, thus matching the\n"
128 "characteristics of a real robot better. You can add noise through the\n"
129 "attributes 'vel_noise_range' and 'dist_noise_range'.\n"
130 "Attribute 'vel_noise_range' regulates the noise range on the velocity returned\n"
131 "by the sensor. Attribute 'dist_noise_range' sets the noise range on the\n"
132 "distance covered by the wheels.\n\n"
133
134 " <controllers>\n"
135 " ...\n"
136 " <my_controller ...>\n"
137 " ...\n"
138 " <sensors>\n"
139 " ...\n"
140 " <differential_steering implementation=\"default\"\n"
141 " vel_noise_range=\"-0.1:0.2\"\n"
142 " dist_noise_range=\"-10.5:13.7\" />\n"
143 " ...\n"
144 " </sensors>\n"
145 " ...\n"
146 " </my_controller>\n"
147 " ...\n"
148 " </controllers>\n\n",
149
150 "Usable"
151 );
152
153}
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
#define REGISTER_SENSOR(CLASSNAME, LABEL, IMPLEMENTATION, AUTHOR, VERSION, BRIEF_DESCRIPTION, LONG_DESCRIPTION, STATUS)
Registers a new sensor model inside ARGoS.
Definition sensor.h:63
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
void GetNodeAttributeOrDefault(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer, const T &t_default)
Returns the value of a node's attribute, or the passed default value.
Real Distance(const CVector2 &c_v1, const CVector2 &c_v2)
Computes the distance between the passed vectors.
Definition vector2.h:463
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
virtual void Enable()
Enables updating of sensor information in the event loop.
Definition ci_sensor.h:78
virtual void Init(TConfigurationNode &t_node)
Initializes the sensor from the XML configuration tree.
Definition ci_sensor.h:54
bool IsDisabled() const
Definition ci_sensor.h:86
Basic class for an entity that contains other entities.
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
const std::string & GetId() const
Returns the id of this entity.
Definition entity.h:157
void Enable()
Enables the entity.
Definition entity.h:265
static Real GetSimulationClockTick()
Returns the simulation clock tick.
The exception that wraps all errors in ARGoS.
T GetSpan() const
Definition range.h:64
static CRNG * CreateRNG(const std::string &str_category)
Creates a new RNG inside the given category.
Definition rng.cpp:347
CRadians Uniform(const CRange< CRadians > &c_range)
Returns a random value from a uniform distribution.
Definition rng.cpp:87
virtual void Update()
Updates the state of the entity associated to this sensor, if the sensor is currently enabled.
const Real * m_pfWheelVelocities
The wheel velocity taken from the wheeled entity.
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.
CWheeledEntity * m_pcWheeledEntity
Reference to wheeled entity associated to this sensor.
virtual void Reset()
Resets the sensor to the state it had just after Init().
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
const CVector3 & GetWheelPosition(size_t un_index) const
const Real * GetWheelVelocities() const
size_t GetNumWheels() const