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> SENSOR_RANGE(0.0f, 1.0f);
21 static CRadians SENSOR_SPACING = CRadians(
ARGOS_PI / 12.0f);
22 static CRadians SENSOR_HALF_SPACING = SENSOR_SPACING * 0.5;
28 while(n_value < 0) n_value += un_modulo;
29 while(n_value >= un_modulo) n_value -= un_modulo;
33 static Real ComputeReading(
Real f_distance) {
34 if(f_distance > 2.5f) {
38 return ::exp(-f_distance * 2.0f);
42 static Real ScaleReading(
const CRadians& c_angular_distance) {
47 return (1.0f - 2.0f * c_angular_distance /
CRadians::PI);
55 m_pcEmbodiedEntity(nullptr),
59 m_cSpace(
CSimulator::GetInstance().GetSpace()) {}
84 Real fNoiseLevel = 0.0f;
86 if(fNoiseLevel < 0.0f) {
89 else if(fNoiseLevel > 0.0f) {
117 CRadians cTmp1, cTmp2, cOrientationZ;
120 CRay3 cOcclusionCheckRay;
138 for(
auto it = mapLights.begin();
139 it != mapLights.end();
142 CLightEntity& cLight = *(any_cast<CLightEntity*>(it->second));
156 cOcclusionCheckRay.
ToVector(cRobotToLight);
163 cAngleLightWrtFootbot = cRobotToLight.
GetZAngle();
164 cAngleLightWrtFootbot -= cOrientationZ;
171 Real fIdx = (cAngleLightWrtFootbot - SENSOR_HALF_SPACING) / SENSOR_SPACING;
172 SInt32 nReadingIdx =
static_cast<SInt32>((fIdx > 0) ? fIdx + 0.5f : fIdx - 0.5f);
180 for(
SInt32 nIndexOffset = -6; nIndexOffset < 7; ++nIndexOffset) {
181 UInt32 unIdx = Modulo(nReadingIdx + nIndexOffset, 24);
182 CRadians cAngularDistanceFromOptimalLightReceptionPoint =
Abs((cAngleLightWrtFootbot -
m_tReadings[unIdx].Angle).SignedNormalize());
188 m_tReadings[unIdx].Value += ComputeReading(fReading) * ScaleReading(cAngularDistanceFromOptimalLightReceptionPoint);
202 for(
size_t i = 0; i < 24; ++i) {
207 for(
size_t i = 0; i < 24; ++i) {
238 "footbot_light",
"rot_z_only",
239 "Carlo Pinciroli [ilpincy@gmail.com]",
241 "The foot-bot light sensor (optimized for 2D).",
242 "This sensor accesses a set of light sensors. The sensors all return a value\n"
243 "between 0 and 1, where 0 means nothing within range and 1 means the perceived\n"
244 "light saturates the sensor. Values between 0 and 1 depend on the distance of\n"
245 "the perceived light. Each reading R is calculated with R=(I/x)^2, where x is the\n"
246 "distance between a sensor and the light, and I is the reference intensity of the\n"
247 "perceived light. The reference intensity corresponds to the minimum distance at\n"
248 "which the light saturates a sensor. The reference intensity depends on the\n"
249 "individual light, and it is set with the \"intensity\" attribute of the light\n"
250 "entity. In case multiple lights are present in the environment, each sensor\n"
251 "reading is calculated as the sum of the individual readings due to each light.\n"
252 "In other words, light wave interference is not taken into account. In\n"
253 "controllers, you must include the ci_light_sensor.h header.\n\n"
254 "REQUIRED XML CONFIGURATION\n\n"
257 " <my_controller ...>\n"
261 " <footbot_light implementation=\"rot_z_only\" />\n"
265 " </my_controller>\n"
267 " </controllers>\n\n"
268 "OPTIONAL XML CONFIGURATION\n\n"
269 "It is possible to draw the rays shot by the light sensor in the OpenGL\n"
270 "visualization. This can be useful for sensor debugging but also to understand\n"
271 "what's wrong in your controller. In OpenGL, the rays are drawn in cyan when\n"
272 "they are not obstructed and in purple when they are. In case a ray is\n"
273 "obstructed, a black dot is drawn where the intersection occurred.\n"
274 "To turn this functionality on, add the attribute \"show_rays\" as in this\n"
278 " <my_controller ...>\n"
282 " <footbot_light implementation=\"rot_z_only\"\n"
283 " show_rays=\"true\" />\n"
287 " </my_controller>\n"
289 " </controllers>\n\n"
290 "It is possible to add uniform noise to the sensors, thus matching the\n"
291 "characteristics of a real robot better. This can be done with the attribute\n"
292 "\"noise_level\", whose allowed range is in [-1,1] and is added to the calculated\n"
293 "reading. The final sensor reading is always normalized in the [0-1] range.\n\n"
296 " <my_controller ...>\n"
300 " <footbot_light implementation=\"rot_z_only\"\n"
301 " noise_level=\"0.1\" />\n"
305 " </my_controller>\n"
307 " </controllers>\n\n"
308 "OPTIONAL XML CONFIGURATION\n\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.
signed int SInt32
32-bit signed integer.
unsigned int UInt32
32-bit unsigned integer.
float Real
Collects all ARGoS code.
#define ARGOS_PI
To be used when initializing static variables.
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.
T Abs(const T &t_v)
Returns the absolute value of the passed argument.
virtual void Enable()
Enables updating of sensor information in the event loop.
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.
This entity is a link to a body in the physics engine.
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
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.
It defines the basic type CRadians, used to store an angle value in radians.
static const CRadians PI
The PI constant.
static const CRadians PI_OVER_TWO
Set to PI / 2.
void ToEulerAngles(CRadians &c_z_angle, CRadians &c_y_angle, CRadians &c_x_angle) const
void TruncValue(T &t_value) const
void Set(const T &t_min, const T &t_max)
void SetEnd(const CVector3 &c_end)
void SetStart(const CVector3 &c_start)
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.
CRadians GetZAngle() const
Returns the angle between this vector and the z axis.
const TReadings & GetReadings() const
Returns the readings of 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.
CLightSensorEquippedEntity * m_pcLightEntity
Reference to light sensor equipped entity associated to this sensor.
CEmbodiedEntity * m_pcEmbodiedEntity
Reference to embodied entity associated to this sensor.
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.
virtual void Reset()
Resets the sensor to the state it had just after Init().
bool m_bAddNoise
Whether to add noise or not.
CSpace & m_cSpace
Reference to the space.
CControllableEntity * m_pcControllableEntity
Reference to controllable entity associated to this sensor.
CRandom::CRNG * m_pcRNG
Random number generator.
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
CFootBotLightRotZOnlySensor()
Real GetIntensity() const
size_t GetNumSensors() const