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/proximity_sensor_equipped_entity.h>
19 static CRange<Real> UNIT(0.0f, 1.0f);
25 m_pcEmbodiedEntity(nullptr),
29 m_cSpace(
CSimulator::GetInstance().GetSpace()) {}
55 Real fNoiseLevel = 0.0f;
57 if(fNoiseLevel < 0.0f) {
58 THROW_ARGOSEXCEPTION(
"Can't specify a negative value for the noise level of the proximity sensor");
60 else if(fNoiseLevel > 0.0f) {
97 cScanningRay.
Set(cRayStart,cRayEnd);
140 return Exp(-f_distance);
147 "proximity",
"default",
148 "Carlo Pinciroli [ilpincy@gmail.com]",
150 "A generic proximity sensor.",
152 "This sensor accesses a set of proximity sensors. The sensors all return a value\n"
153 "between 0 and 1, where 0 means nothing within range and 1 means an external\n"
154 "object is touching the sensor. Values between 0 and 1 depend on the distance of\n"
155 "the occluding object, and are calculated as value=exp(-distance). In\n"
156 "controllers, you must include the ci_proximity_sensor.h header.\n\n"
158 "This sensor is enabled by default.\n\n"
160 "REQUIRED XML CONFIGURATION\n\n"
164 " <my_controller ...>\n"
168 " <proximity implementation=\"default\" />\n"
172 " </my_controller>\n"
174 " </controllers>\n\n"
176 "OPTIONAL XML CONFIGURATION\n\n"
178 "It is possible to draw the rays shot by the proximity sensor in the OpenGL\n"
179 "visualization. This can be useful for sensor debugging but also to understand\n"
180 "what's wrong in your controller. In OpenGL, the rays are drawn in cyan when\n"
181 "they are not obstructed and in purple when they are. In case a ray is\n"
182 "obstructed, a black dot is drawn where the intersection occurred.\n"
183 "To turn this functionality on, add the attribute \"show_rays\" as in this\n"
188 " <my_controller ...>\n"
192 " <proximity implementation=\"default\"\n"
193 " show_rays=\"true\" />\n"
197 " </my_controller>\n"
199 " </controllers>\n\n"
201 "It is possible to add uniform noise to the sensors, thus matching the\n"
202 "characteristics of a real robot better. This can be done with the attribute\n"
203 "\"noise_level\", whose allowed range is in [-1,1] and is added to the calculated\n"
204 "reading. The final sensor reading is always normalized in the [0-1] range.\n\n"
208 " <my_controller ...>\n"
212 " <proximity implementation=\"default\"\n"
213 " noise_level=\"0.1\" />\n"
217 " </my_controller>\n"
219 " </controllers>\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.
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.
This entity is a link to a body in the physics engine.
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
CVector3 Position
The position of the anchor wrt the global coordinate system.
The exception that wraps all errors in ARGoS.
void TruncValue(T &t_value) const
void Set(const T &t_min, const T &t_max)
Real GetDistance(Real f_t) const
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.
CRadians Uniform(const CRange< CRadians > &c_range)
Returns a random value from a uniform distribution.
CVector3 & Rotate(const CQuaternion &c_quaternion)
Rotates this vector by the given quaternion.
std::vector< Real > m_tReadings
const std::vector< Real > & GetReadings() const
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
CRange< Real > m_cNoiseRange
Noise range.
CControllableEntity * m_pcControllableEntity
Reference to controllable entity associated to this sensor.
bool m_bShowRays
Flag to show rays in the simulator.
bool m_bAddNoise
Whether to add noise or not.
CProximityDefaultSensor()
CRandom::CRNG * m_pcRNG
Random number generator.
virtual Real CalculateReading(Real f_distance)
Calculates the proximity reading when the closest occluding object is located as the given distance.
CEmbodiedEntity * m_pcEmbodiedEntity
Reference to embodied entity associated to this sensor.
virtual void Update()
Updates the state of the entity associated to this sensor, if the sensor is currently enabled.
CProximitySensorEquippedEntity * m_pcProximityEntity
Reference to proximity sensor equipped entity associated to this sensor.
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.
virtual void Reset()
Resets the sensor to the state it had just after Init().
SSensor & GetSensor(size_t un_idx)
size_t GetNumSensors() const