ARGoS  3
A parallel, multi-engine simulator for swarm robotics
positioning_default_sensor.cpp
Go to the documentation of this file.
1 
7 #include <argos3/core/simulator/simulator.h>
8 #include <argos3/core/simulator/entity/embodied_entity.h>
9 #include <argos3/core/simulator/entity/composable_entity.h>
10 
12 
13 namespace argos {
14 
15  /****************************************/
16  /****************************************/
17 
19  m_pcEmbodiedEntity(NULL),
20  m_pcRNG(NULL),
21  m_bAddNoise(false) {}
22 
23  /****************************************/
24  /****************************************/
25 
27  m_pcEmbodiedEntity = &(c_entity.GetComponent<CEmbodiedEntity>("body"));
30  }
31 
32  /****************************************/
33  /****************************************/
34 
36  try {
38  /* Parse noise range */
39  GetNodeAttributeOrDefault(t_tree, "pos_noise_range", m_cPosNoiseRange, m_cPosNoiseRange);
42  if(m_cPosNoiseRange.GetSpan() != 0 ||
43  m_cAngleNoiseRange.GetSpan() != CRadians::ZERO ||
44  m_cAxisNoiseRange.GetSpan() != 0) {
45  m_bAddNoise = true;
46  m_pcRNG = CRandom::CreateRNG("argos");
47  }
48  }
49  catch(CARGoSException& ex) {
50  THROW_ARGOSEXCEPTION_NESTED("Initialization error in default positioning sensor", ex);
51  }
52  }
53 
54  /****************************************/
55  /****************************************/
56 
59  if(m_bAddNoise) {
69  }
70  else {
72  }
73  }
74 
75  /****************************************/
76  /****************************************/
77 
81  }
82 
83  /****************************************/
84  /****************************************/
85 
87  "positioning", "default",
88  "Carlo Pinciroli [ilpincy@gmail.com]",
89  "1.0",
90  "A generic positioning sensor.",
91  "This sensor returns the current position and orientation of a robot. This sensor\n"
92  "can be used with any robot, since it accesses only the body component. In\n"
93  "controllers, you must include the ci_positioning_sensor.h header.\n\n"
94  "REQUIRED XML CONFIGURATION\n\n"
95  " <controllers>\n"
96  " ...\n"
97  " <my_controller ...>\n"
98  " ...\n"
99  " <sensors>\n"
100  " ...\n"
101  " <positioning implementation=\"default\" />\n"
102  " ...\n"
103  " </sensors>\n"
104  " ...\n"
105  " </my_controller>\n"
106  " ...\n"
107  " </controllers>\n\n"
108  "OPTIONAL XML CONFIGURATION\n\n"
109  "It is possible to add uniform noise to the sensor, thus matching the\n"
110  "characteristics of a real robot better. You can add noise through the\n"
111  "attributes 'pos_noise_range', 'angle_noise_range', and 'axis_noise_range'.\n"
112  "Attribute 'pos_noise_range' regulates the noise range on the position returned\n"
113  "by the sensor. Attribute 'angle_noise_range' sets the noise range on the angle\n"
114  "(values expressed in degrees). Attribute 'axis_noise_range' sets the noise for\n"
115  "the rotation axis. Angle and axis are used to calculate a quaternion, which is\n"
116  "the actual returned value for rotation.\n\n"
117  " <controllers>\n"
118  " ...\n"
119  " <my_controller ...>\n"
120  " ...\n"
121  " <sensors>\n"
122  " ...\n"
123  " <positioning implementation=\"default\"\n"
124  " pos_noise_range=\"-0.1:0.2\"\n"
125  " angle_noise_range=\"-10.5:13.7\"\n"
126  " axis_noise_range=\"-0.3:0.4\" />\n"
127  " ...\n"
128  " </sensors>\n"
129  " ...\n"
130  " </my_controller>\n"
131  " ...\n"
132  " </controllers>\n\n"
133  "OPTIONAL XML CONFIGURATION\n\n"
134  "None.\n",
135  "Usable"
136  );
137 
138 }
argos::CCI_PositioningSensor::m_sReading
SReading m_sReading
Definition: ci_positioning_sensor.h:42
argos::CEmbodiedEntity::GetOriginAnchor
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
Definition: embodied_entity.h:119
argos::SAnchor::Orientation
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
Definition: physics_model.h:53
argos::CCI_PositioningSensor::SReading::Position
CVector3 Position
Definition: ci_positioning_sensor.h:24
argos::CRandom::CRNG::Uniform
CRadians Uniform(const CRange< CRadians > &c_range)
Returns a random value from a uniform distribution.
Definition: rng.cpp:87
argos::CPositioningDefaultSensor::SetRobot
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
Definition: positioning_default_sensor.cpp:26
argos::CPositioningDefaultSensor::m_cPosNoiseRange
CRange< Real > m_cPosNoiseRange
Noise range on position.
Definition: positioning_default_sensor.h:55
argos::CPositioningDefaultSensor::m_cAxisNoiseRange
CRange< Real > m_cAxisNoiseRange
Noise range on axis.
Definition: positioning_default_sensor.h:61
argos::CPositioningDefaultSensor::Update
virtual void Update()
Updates the state of the entity associated to this sensor.
Definition: positioning_default_sensor.cpp:57
argos
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
argos::CVector3
A 3D vector class.
Definition: vector3.h:29
argos::CRadians
It defines the basic type CRadians, used to store an angle value in radians.
Definition: angles.h:42
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
positioning_default_sensor.h
argos::CCI_PositioningSensor::SReading::Orientation
CQuaternion Orientation
Definition: ci_positioning_sensor.h:25
argos::CPositioningDefaultSensor::Reset
virtual void Reset()
Resets the sensor to the state it had just after Init().
Definition: positioning_default_sensor.cpp:78
argos::CEmbodiedEntity
This entity is a link to a body in the physics engine.
Definition: embodied_entity.h:48
argos::TConfigurationNode
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Definition: argos_configuration.h:27
argos::CQuaternion::FromAngleAxis
CQuaternion & FromAngleAxis(const CRadians &c_angle, const CVector3 &c_vector)
Definition: quaternion.h:125
argos::CPositioningDefaultSensor::m_cAngleNoiseRange
CRange< CRadians > m_cAngleNoiseRange
Noise range on angle.
Definition: positioning_default_sensor.h:58
argos::CCI_PositioningSensor::m_cAngle
CRadians m_cAngle
Definition: ci_positioning_sensor.h:43
argos::CRange::GetSpan
T GetSpan() const
Definition: range.h:64
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
argos::CPositioningDefaultSensor::Init
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.
Definition: positioning_default_sensor.cpp:35
argos::CPositioningDefaultSensor::CPositioningDefaultSensor
CPositioningDefaultSensor()
Definition: positioning_default_sensor.cpp:18
argos::CPositioningDefaultSensor
Definition: positioning_default_sensor.h:26
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::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::CRandom::CreateRNG
static CRNG * CreateRNG(const std::string &str_category)
Creates a new RNG inside the given category.
Definition: rng.cpp:326
argos::CPositioningDefaultSensor::m_pcRNG
CRandom::CRNG * m_pcRNG
Random number generator.
Definition: positioning_default_sensor.h:49
argos::CQuaternion::ToAngleAxis
void ToAngleAxis(CRadians &c_angle, CVector3 &c_vector) const
Definition: quaternion.h:142
argos::CCI_PositioningSensor::m_cAxis
CVector3 m_cAxis
Definition: ci_positioning_sensor.h:44
argos::CCI_Sensor::Init
virtual void Init(TConfigurationNode &t_node)
Initializes the sensor from the XML configuration tree.
Definition: ci_sensor.h:54
argos::SAnchor::Position
CVector3 Position
The position of the anchor wrt the global coordinate system.
Definition: physics_model.h:51
argos::CPositioningDefaultSensor::m_bAddNoise
bool m_bAddNoise
Whether to add noise or not.
Definition: positioning_default_sensor.h:52
argos::CPositioningDefaultSensor::m_pcEmbodiedEntity
CEmbodiedEntity * m_pcEmbodiedEntity
Reference to embodied entity associated to this sensor.
Definition: positioning_default_sensor.h:46
argos::CRadians::ZERO
static const CRadians ZERO
Set to zero radians.
Definition: angles.h:79