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) {
100 for(
auto it = mapLights.begin();
101 it != mapLights.end();
104 CLightEntity& cLight = *any_cast<CLightEntity*>(it->second);
117 cScanningRay.
ToVector(cSensorToLight);
166 return (f_intensity * f_intensity) / (f_distance * f_distance);
174 "Carlo Pinciroli [ilpincy@gmail.com]",
176 "A generic light sensor.",
178 "This sensor accesses a set of light sensors. The sensors all return a value\n"
179 "between 0 and 1, where 0 means nothing within range and 1 means the perceived\n"
180 "light saturates the sensor. Values between 0 and 1 depend on the distance of\n"
181 "the perceived light. Each reading R is calculated with R=(I/x)^2, where x is the\n"
182 "distance between a sensor and the light, and I is the reference intensity of the\n"
183 "perceived light. The reference intensity corresponds to the minimum distance at\n"
184 "which the light saturates a sensor. The reference intensity depends on the\n"
185 "individual light, and it is set with the \"intensity\" attribute of the light\n"
186 "entity. In case multiple lights are present in the environment, each sensor\n"
187 "reading is calculated as the sum of the individual readings due to each light.\n"
188 "In other words, light wave interference is not taken into account. In\n"
189 "controllers, you must include the ci_light_sensor.h header.\n\n"
191 "This sensor is enabled by default.\n\n"
193 "REQUIRED XML CONFIGURATION\n\n"
196 " <my_controller ...>\n"
200 " <light implementation=\"default\" />\n"
204 " </my_controller>\n"
206 " </controllers>\n\n"
208 "OPTIONAL XML CONFIGURATION\n\n"
210 "It is possible to draw the rays shot by the light sensor in the OpenGL\n"
211 "visualization. This can be useful for sensor debugging but also to understand\n"
212 "what's wrong in your controller. In OpenGL, the rays are drawn in cyan when\n"
213 "they are not obstructed and in purple when they are. In case a ray is\n"
214 "obstructed, a black dot is drawn where the intersection occurred.\n"
215 "To turn this functionality on, add the attribute \"show_rays\" as in this\n"
219 " <my_controller ...>\n"
223 " <light implementation=\"default\"\n"
224 " show_rays=\"true\" />\n"
228 " </my_controller>\n"
230 " </controllers>\n\n"
232 "It is possible to add uniform noise to the sensors, thus matching the\n"
233 "characteristics of a real robot better. This can be done with the attribute\n"
234 "\"noise_level\", whose allowed range is in [-1,1] and is added to the calculated\n"
235 "reading. The final sensor reading is always normalized in the [0-1] range.\n\n"
239 " <my_controller ...>\n"
243 " <light implementation=\"default\"\n"
244 " noise_level=\"0.1\" />\n"
248 " </my_controller>\n"
250 " </controllers>\n\n"
252 "OPTIMIZATION HINTS\n\n"
254 "1. For small swarms, enabling the light sensor (and therefore causing ARGoS to\n"
255 " update its readings each timestep) unconditionally does not impact performance too\n"
256 " much. For large swarms, it can impact performance, and selectively\n"
257 " enabling/disabling the light sensor according to when each individual robot needs it\n"
258 " (e.g., only when it is returning to the nest from foraging) can increase performance\n"
259 " by only requiring ARGoS to update the readings for a robot on the timesteps will be\n"
#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.
unsigned int UInt32
32-bit unsigned integer.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
bool GetClosestEmbodiedEntityIntersectedByRay(SEmbodiedEntityIntersectionItem &s_item, const CRay3 &c_ray)
Returns the closest intersection with an embodied entity to the ray start.
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.
REGISTER_SENSOR(CEPuckProximityDefaultSensor, "epuck_proximity", "default", "Danesh Tarapore [daneshtarapore@gmail.com]", "1.0", "The E-Puck proximity sensor.", "This sensor accesses the epuck proximity sensor. For a complete description\n" "of its usage, refer to the ci_epuck_proximity_sensor.h interface. For the XML\n" "configuration, refer to the default proximity sensor.\n", "Usable")
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
virtual void Enable()
Enables updating of sensor information in the event loop.
virtual void Init(TConfigurationNode &t_node)
Initializes the sensor from the XML configuration tree.
Basic class for an entity that contains other entities.
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
An entity that contains a pointer to the user-defined controller.
void AddIntersectionPoint(const CRay3 &c_ray, Real f_t_on_ray)
Adds an intersection point to the list.
void AddCheckedRay(bool b_obstructed, const CRay3 &c_ray)
Adds a ray to the list of checked rays.
const CVector3 & GetPosition() const
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
CVector3 Position
The position of the anchor wrt the global coordinate system.
TMapPerTypePerId & GetEntityMapPerTypePerId()
Returns a nested map of entities, ordered by type and by id.
std::map< std::string, CAny, std::less< std::string > > TMapPerType
A map of entities indexed by type description.
The exception that wraps all errors in ARGoS.
void TruncValue(T &t_value) const
void Set(const T &t_min, const T &t_max)
void Set(const CVector3 &c_start, const CVector3 &c_end)
CVector3 & ToVector(CVector3 &c_buffer) const
static CRNG * CreateRNG(const std::string &str_category)
Creates a new RNG inside the given category.
CRadians Uniform(const CRange< CRadians > &c_range)
Returns a random value from a uniform distribution.
Real Length() const
Returns the length of this vector.
CVector3 & Rotate(const CQuaternion &c_quaternion)
Rotates this vector by the given quaternion.
std::vector< Real > m_tReadings
const std::vector< Real > & GetReadings() const
CSpace & m_cSpace
Reference to the space.
virtual void Reset()
Resets the sensor to the state it had just after Init().
CRange< Real > m_cNoiseRange
Noise range.
virtual void Update()
Updates the state of the entity associated to this sensor, if the sensor is currently enabled.
CRandom::CRNG * m_pcRNG
Random number generator.
CLightSensorEquippedEntity * m_pcLightEntity
Reference to light sensor equipped entity associated to this sensor.
bool m_bAddNoise
Whether to add noise or not.
CControllableEntity * m_pcControllableEntity
Reference to controllable entity associated to this sensor.
bool m_bShowRays
Flag to show rays in the simulator.
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
virtual Real CalculateReading(Real f_distance, Real f_intensity)
Calculates the light reading resulting from a light source at the given distance.
Real GetIntensity() const
SSensor & GetSensor(size_t un_idx)
size_t GetNumSensors() const