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 
13 namespace argos {
14 
15  /****************************************/
16  /****************************************/
17 
19  m_pcWheeledEntity(NULL),
20  m_pcRNG(NULL),
21  m_bAddNoise(false) {}
22 
23  /****************************************/
24  /****************************************/
25 
27  try {
28  m_pcWheeledEntity = &(c_entity.GetComponent<CWheeledEntity>("wheels"));
29  if(m_pcWheeledEntity->GetNumWheels() != 2) {
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 */
49  GetNodeAttributeOrDefault(t_tree, "vel_noise_range", m_cVelNoiseRange, m_cVelNoiseRange);
51  if(m_cVelNoiseRange.GetSpan() != 0 ||
52  m_cDistNoiseRange.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  }
61 
62  /****************************************/
63  /****************************************/
64 
70  if(m_bAddNoise) {
75  }
76  }
77 
78  /****************************************/
79  /****************************************/
80 
86  }
87 
88  /****************************************/
89  /****************************************/
90 
92  "differential_steering", "default",
93  "Carlo Pinciroli [ilpincy@gmail.com]",
94  "1.0",
95  "A generic differential steering sensor.",
96  "This sensor returns the current position and orientation of a robot. This sensor\n"
97  "can be used with any robot, since it accesses only the body component. In\n"
98  "controllers, you must include the ci_differential_steering_sensor.h header.\n\n"
99  "REQUIRED XML CONFIGURATION\n\n"
100  " <controllers>\n"
101  " ...\n"
102  " <my_controller ...>\n"
103  " ...\n"
104  " <sensors>\n"
105  " ...\n"
106  " <differential_steering implementation=\"default\" />\n"
107  " ...\n"
108  " </sensors>\n"
109  " ...\n"
110  " </my_controller>\n"
111  " ...\n"
112  " </controllers>\n\n"
113  "OPTIONAL XML CONFIGURATION\n\n"
114  "It is possible to add uniform noise to the sensor, thus matching the\n"
115  "characteristics of a real robot better. You can add noise through the\n"
116  "attributes 'vel_noise_range' and 'dist_noise_range'.\n"
117  "Attribute 'vel_noise_range' regulates the noise range on the velocity returned\n"
118  "by the sensor. Attribute 'dist_noise_range' sets the noise range on the\n"
119  "distance covered by the wheels.\n"
120  "value for rotation.\n\n"
121  " <controllers>\n"
122  " ...\n"
123  " <my_controller ...>\n"
124  " ...\n"
125  " <sensors>\n"
126  " ...\n"
127  " <differential_steering implementation=\"default\"\n"
128  " vel_noise_range=\"-0.1:0.2\"\n"
129  " dist_noise_range=\"-10.5:13.7\" />\n"
130  " ...\n"
131  " </sensors>\n"
132  " ...\n"
133  " </my_controller>\n"
134  " ...\n"
135  " </controllers>\n\n"
136  "OPTIONAL XML CONFIGURATION\n\n"
137  "None.\n",
138  "Usable"
139  );
140 
141 }
argos::CRandom::CRNG::Uniform
CRadians Uniform(const CRange< CRadians > &c_range)
Returns a random value from a uniform distribution.
Definition: rng.cpp:87
argos::CEntity::GetId
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
argos::CDifferentialSteeringDefaultSensor::m_pfWheelVelocities
const Real * m_pfWheelVelocities
The wheel velocity taken from the wheeled entity.
Definition: differential_steering_default_sensor.h:49
argos::CWheeledEntity::GetWheelVelocities
const Real * GetWheelVelocities() const
Definition: wheeled_entity.h:56
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
differential_steering_default_sensor.h
argos::CWheeledEntity
Definition: wheeled_entity.h:15
argos::CEntity::Enable
void Enable()
Enables the entity.
Definition: entity.h:239
argos::CDifferentialSteeringDefaultSensor::m_bAddNoise
bool m_bAddNoise
Whether to add noise or not.
Definition: differential_steering_default_sensor.h:55
argos::CCI_DifferentialSteeringSensor::SReading::CoveredDistanceRightWheel
Real CoveredDistanceRightWheel
Definition: ci_differential_steering_sensor.h:26
argos::CCI_DifferentialSteeringSensor::m_sReading
SReading m_sReading
Definition: ci_differential_steering_sensor.h:74
argos::CCI_DifferentialSteeringSensor::SReading::CoveredDistanceLeftWheel
Real CoveredDistanceLeftWheel
Definition: ci_differential_steering_sensor.h:25
argos::CDifferentialSteeringDefaultSensor::m_cDistNoiseRange
CRange< Real > m_cDistNoiseRange
Noise range on distance.
Definition: differential_steering_default_sensor.h:61
argos::TConfigurationNode
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Definition: argos_configuration.h:27
argos::CDifferentialSteeringDefaultSensor::Init
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.
Definition: differential_steering_default_sensor.cpp:45
argos::CDifferentialSteeringDefaultSensor::m_pcRNG
CRandom::CRNG * m_pcRNG
Random number generator.
Definition: differential_steering_default_sensor.h:52
argos::Distance
Real Distance(const CVector2 &c_v1, const CVector2 &c_v2)
Computes the distance between the passed vectors.
Definition: vector2.h:418
argos::CRange::GetSpan
T GetSpan() const
Definition: range.h:64
argos::CCI_DifferentialSteeringSensor::SReading::VelocityRightWheel
Real VelocityRightWheel
Definition: ci_differential_steering_sensor.h:24
argos::CDifferentialSteeringDefaultSensor::CDifferentialSteeringDefaultSensor
CDifferentialSteeringDefaultSensor()
Definition: differential_steering_default_sensor.cpp:18
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::CDifferentialSteeringDefaultSensor::Reset
virtual void Reset()
Resets the sensor to the state it had just after Init().
Definition: differential_steering_default_sensor.cpp:81
argos::REGISTER_SENSOR
REGISTER_SENSOR(CEyeBotLightRotZOnlySensor, "eyebot_light", "rot_z_only", "Carlo Pinciroli [ilpincy@gmail.com]", "1.0", "The eye-bot light sensor (optimized for 2D).", "This sensor accesses a set of light sensors. The sensors all return a value\n" "between 0 and 1, where 0 means nothing within range and 1 means the perceived\n" "light saturates the sensor. Values between 0 and 1 depend on the distance of\n" "the perceived light. Each reading R is calculated with R=(I/x)^2, where x is the\n" "distance between a sensor and the light, and I is the reference intensity of the\n" "perceived light. The reference intensity corresponds to the minimum distance at\n" "which the light saturates a sensor. The reference intensity depends on the\n" "individual light, and it is set with the \"intensity\" attribute of the light\n" "entity. In case multiple lights are present in the environment, each sensor\n" "reading is calculated as the sum of the individual readings due to each light.\n" "In other words, light wave interference is not taken into account. In\n" "controllers, you must include the ci_light_sensor.h header.\n\n" "REQUIRED XML CONFIGURATION\n\n" " <controllers>\n" " ...\n" " <my_controller ...>\n" " ...\n" " <sensors>\n" " ...\n" " <eyebot_light implementation=\"rot_z_only\" />\n" " ...\n" " </sensors>\n" " ...\n" " </my_controller>\n" " ...\n" " </controllers>\n\n" "OPTIONAL XML CONFIGURATION\n\n" "It is possible to draw the rays shot by the light sensor in the OpenGL\n" "visualization. This can be useful for sensor debugging but also to understand\n" "what's wrong in your controller. In OpenGL, the rays are drawn in cyan when\n" "they are not obstructed and in purple when they are. In case a ray is\n" "obstructed, a black dot is drawn where the intersection occurred.\n" "To turn this functionality on, add the attribute \"show_rays\" as in this\n" "example:\n\n" " <controllers>\n" " ...\n" " <my_controller ...>\n" " ...\n" " <sensors>\n" " ...\n" " <eyebot_light implementation=\"rot_z_only\"\n" " show_rays=\"true\" />\n" " ...\n" " </sensors>\n" " ...\n" " </my_controller>\n" " ...\n" " </controllers>\n\n" "It is possible to add uniform noise to the sensors, thus matching the\n" "characteristics of a real robot better. This can be done with the attribute\n" "\"noise_level\", whose allowed range is in [-1,1] and is added to the calculated\n" "reading. The final sensor reading is always normalized in the [0-1] range.\n\n" " <controllers>\n" " ...\n" " <my_controller ...>\n" " ...\n" " <sensors>\n" " ...\n" " <eyebot_light implementation=\"rot_z_only\"\n" " noise_level=\"0.1\" />\n" " ...\n" " </sensors>\n" " ...\n" " </my_controller>\n" " ...\n" " </controllers>\n\n" "OPTIONAL XML CONFIGURATION\n\n" "None.\n", "Usable")
argos::CDifferentialSteeringDefaultSensor::SetRobot
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
Definition: differential_steering_default_sensor.cpp:26
argos::CWheeledEntity::GetWheelPosition
const CVector3 & GetWheelPosition(size_t un_index) const
Definition: wheeled_entity.cpp:79
argos::CDifferentialSteeringDefaultSensor
Definition: differential_steering_default_sensor.h:26
argos::CCI_DifferentialSteeringSensor::SReading::VelocityLeftWheel
Real VelocityLeftWheel
Definition: ci_differential_steering_sensor.h:23
argos::GetNodeAttributeOrDefault
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.
Definition: argos_configuration.h:318
argos::CPhysicsEngine::GetSimulationClockTick
static Real GetSimulationClockTick()
Returns the simulation clock tick.
Definition: physics_engine.cpp:264
argos::CRandom::CreateRNG
static CRNG * CreateRNG(const std::string &str_category)
Creates a new RNG inside the given category.
Definition: rng.cpp:326
argos::CDifferentialSteeringDefaultSensor::m_pcWheeledEntity
CWheeledEntity * m_pcWheeledEntity
Reference to wheeled entity associated to this sensor.
Definition: differential_steering_default_sensor.h:46
argos::CWheeledEntity::GetNumWheels
size_t GetNumWheels() const
Definition: wheeled_entity.h:34
argos::CDifferentialSteeringDefaultSensor::m_cVelNoiseRange
CRange< Real > m_cVelNoiseRange
Noise range on velocity.
Definition: differential_steering_default_sensor.h:58
argos::CCI_Sensor::Init
virtual void Init(TConfigurationNode &t_node)
Initializes the sensor from the XML configuration tree.
Definition: ci_sensor.h:54
argos::CCI_DifferentialSteeringSensor::SReading::WheelAxisLength
Real WheelAxisLength
Definition: ci_differential_steering_sensor.h:27
argos::CDifferentialSteeringDefaultSensor::Update
virtual void Update()
Updates the state of the entity associated to this sensor.
Definition: differential_steering_default_sensor.cpp:65