ARGoS
3
A parallel, multi-engine simulator for swarm robotics
|
Go to the documentation of this file.
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 #include <argos3/plugins/simulator/entities/light_entity.h>
11 #include <argos3/plugins/simulator/entities/light_sensor_equipped_entity.h>
20 static CRange<Real> UNIT(0.0f, 1.0f);
29 m_cSpace(
CSimulator::GetInstance().GetSpace()) {}
54 Real fNoiseLevel = 0.0f;
56 if(fNoiseLevel < 0.0f) {
59 else if(fNoiseLevel > 0.0f) {
94 for(CSpace::TMapPerType::iterator it = mapLights.begin();
95 it != mapLights.end();
98 CLightEntity& cLight = *any_cast<CLightEntity*>(it->second);
111 cScanningRay.
ToVector(cSensorToLight);
160 return (f_intensity * f_intensity) / (f_distance * f_distance);
168 "Carlo Pinciroli [ilpincy@gmail.com]",
170 "A generic light sensor.",
171 "This sensor accesses a set of light sensors. The sensors all return a value\n"
172 "between 0 and 1, where 0 means nothing within range and 1 means the perceived\n"
173 "light saturates the sensor. Values between 0 and 1 depend on the distance of\n"
174 "the perceived light. Each reading R is calculated with R=(I/x)^2, where x is the\n"
175 "distance between a sensor and the light, and I is the reference intensity of the\n"
176 "perceived light. The reference intensity corresponds to the minimum distance at\n"
177 "which the light saturates a sensor. The reference intensity depends on the\n"
178 "individual light, and it is set with the \"intensity\" attribute of the light\n"
179 "entity. In case multiple lights are present in the environment, each sensor\n"
180 "reading is calculated as the sum of the individual readings due to each light.\n"
181 "In other words, light wave interference is not taken into account. In\n"
182 "controllers, you must include the ci_light_sensor.h header.\n\n"
183 "REQUIRED XML CONFIGURATION\n\n"
186 " <my_controller ...>\n"
190 " <light implementation=\"default\" />\n"
194 " </my_controller>\n"
196 " </controllers>\n\n"
197 "OPTIONAL XML CONFIGURATION\n\n"
198 "It is possible to draw the rays shot by the light sensor in the OpenGL\n"
199 "visualization. This can be useful for sensor debugging but also to understand\n"
200 "what's wrong in your controller. In OpenGL, the rays are drawn in cyan when\n"
201 "they are not obstructed and in purple when they are. In case a ray is\n"
202 "obstructed, a black dot is drawn where the intersection occurred.\n"
203 "To turn this functionality on, add the attribute \"show_rays\" as in this\n"
207 " <my_controller ...>\n"
211 " <light implementation=\"default\"\n"
212 " show_rays=\"true\" />\n"
216 " </my_controller>\n"
218 " </controllers>\n\n"
219 "It is possible to add uniform noise to the sensors, thus matching the\n"
220 "characteristics of a real robot better. This can be done with the attribute\n"
221 "\"noise_level\", whose allowed range is in [-1,1] and is added to the calculated\n"
222 "reading. The final sensor reading is always normalized in the [0-1] range.\n\n"
225 " <my_controller ...>\n"
229 " <light implementation=\"default\"\n"
230 " noise_level=\"0.1\" />\n"
234 " </my_controller>\n"
236 " </controllers>\n\n"
237 "OPTIONAL XML CONFIGURATION\n\n"
std::vector< Real > m_tReadings
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
CRadians Uniform(const CRange< CRadians > &c_range)
Returns a random value from a uniform distribution.
CSpace & m_cSpace
Reference to the space.
void AddIntersectionPoint(const CRay3 &c_ray, Real f_t_on_ray)
Adds an intersection point to the list.
The namespace containing all the ARGoS related code.
CLightSensorEquippedEntity * m_pcLightEntity
Reference to light sensor equipped entity associated to this sensor.
Basic class for an entity that contains other entities.
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.
The exception that wraps all errors in ARGoS.
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
size_t GetNumSensors() const
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
void AddCheckedRay(bool b_obstructed, const CRay3 &c_ray)
Adds a ray to the list of checked rays.
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
const CVector3 & GetPosition() const
Real Length() const
Returns the length of this vector.
bool GetClosestEmbodiedEntityIntersectedByRay(SEmbodiedEntityIntersectionItem &s_item, const CRay3 &c_ray)
Returns the closest intersection with an embodied entity to the ray start.
virtual void Update()
Updates the state of the entity associated to this sensor.
#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.
CVector3 & ToVector(CVector3 &c_buffer) const
CRandom::CRNG * m_pcRNG
Random number generator.
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")
std::map< std::string, CAny, std::less< std::string > > TMapPerType
A map of entities indexed by type description.
void TruncValue(T &t_value) const
virtual Real CalculateReading(Real f_distance, Real f_intensity)
Calculates the light reading resulting from a light source at the given distance.
CRange< Real > m_cNoiseRange
Noise range.
unsigned int UInt32
32-bit unsigned integer.
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.
void Set(const T &t_min, const T &t_max)
Real GetIntensity() const
SSensor & GetSensor(size_t un_idx)
void Set(const CVector3 &c_start, const CVector3 &c_end)
static CRNG * CreateRNG(const std::string &str_category)
Creates a new RNG inside the given category.
CVector3 & Rotate(const CQuaternion &c_quaternion)
Rotates this vector by the given quaternion.
TMapPerTypePerId & GetEntityMapPerTypePerId()
Returns a nested map of entities, ordered by type and by id.
An entity that contains a pointer to the user-defined controller.
virtual void Reset()
Resets the sensor to the state it had just after Init().
virtual void Init(TConfigurationNode &t_node)
Initializes the sensor from the XML configuration tree.
CVector3 Position
The position of the anchor wrt the global coordinate system.
const std::vector< Real > & GetReadings() const
float Real
Collects all ARGoS code.
bool m_bShowRays
Flag to show rays in the simulator.
CControllableEntity * m_pcControllableEntity
Reference to controllable entity associated to this sensor.
bool m_bAddNoise
Whether to add noise or not.