8 #include <argos3/core/simulator/simulator.h>
9 #include <argos3/core/simulator/entity/composable_entity.h>
10 #include <argos3/core/simulator/entity/controllable_entity.h>
11 #include <argos3/plugins/simulator/entities/rab_equipped_entity.h>
12 #include <argos3/plugins/simulator/media/rab_medium.h>
25 m_pcRangeAndBearingEquippedEntity(nullptr),
26 m_fDistanceNoiseStdDev(0.0f),
27 m_fPacketDropProb(0.0f),
29 m_cSpace(
CSimulator::GetInstance().GetSpace()),
54 if((m_fPacketDropProb > 0.0f) ||
55 (m_fDistanceNoiseStdDev > 0.0f)) {
59 std::string strMedium;
63 m_pcRangeAndBearingEquippedEntity->
SetMedium(*m_pcRangeAndBearingMedium);
91 it != setRABs.
end(); ++it) {
93 if(m_pcRNG ==
nullptr ||
94 !(m_fPacketDropProb > 0.0f &&
103 m_pcRangeAndBearingEquippedEntity->
GetPosition()));
107 cVectorRobotToMessage -= m_pcRangeAndBearingEquippedEntity->
GetPosition();
109 if(m_pcRNG && m_fDistanceNoiseStdDev > 0.0f) {
111 m_pcRNG->
Gaussian(m_fDistanceNoiseStdDev),
127 sPacket.
Range *= 100.0f;
160 m_pcRangeAndBearingEquippedEntity->
Enable();
168 m_pcRangeAndBearingEquippedEntity->
Disable();
176 m_pcRangeAndBearingMedium->
RemoveEntity(*m_pcRangeAndBearingEquippedEntity);
183 "range_and_bearing",
"medium",
184 "Carlo Pinciroli [ilpincy@gmail.com]",
186 "The range-and-bearing sensor.",
188 "This sensor allows robots to perform situated communication, i.e., a form of\n"
189 "wireless communication whereby the receiver also knows the location of the\n"
190 "sender with respect to its own frame of reference.\n"
191 "This implementation of the range-and-bearing sensor is associated to the\n"
192 "range-and-bearing medium. To be able to use this sensor, you must add a\n"
193 "range-and-bearing medium to the <media> section.\n"
194 "This sensor allows a robot to receive messages. To send messages, you need the\n"
195 "range-and-bearing actuator.\n"
196 "To use this sensor, in controllers you must include the\n"
197 "ci_range_and_bearing_sensor.h header.\n\n"
199 "This sensor is enabled by default.\n\n"
201 "REQUIRED XML CONFIGURATION\n\n"
204 " <my_controller ...>\n"
208 " <range_and_bearing implementation=\"medium\"\n"
209 " medium=\"rab\" />\n"
213 " </my_controller>\n"
215 " </controllers>\n\n"
217 "The 'medium' attribute must be set to the id of the range-and-bearing medium\n"
218 "declared in the <media> section.\n\n"
220 "OPTIONAL XML CONFIGURATION\n\n"
222 "It is possible to draw the rays shot by the range-and-bearing sensor in the\n"
223 "OpenGL visualization. This can be useful for sensor debugging but also to\n"
224 "understand what's wrong in your controller. In OpenGL, the rays are drawn in\n"
225 "cyan when two robots are communicating.\n"
226 "To turn this functionality on, add the attribute \"show_rays\" as in this\n"
231 " <my_controller ...>\n"
235 " <range_and_bearing implementation=\"medium\"\n"
237 " show_rays=\"true\" />\n"
241 " </my_controller>\n"
243 " </controllers>\n\n"
245 "It is possible to add noise to the readings, thus matching the characteristics\n"
246 "of a real robot better. Noise is implemented as a random vector added to the\n"
247 "vector joining two communicating robots. For the random vector, the inclination\n"
248 "and azimuth are chosen uniformly in the range [0:PI] and [0:2PI], respectively,\n"
249 "and the length is drawn from a Gaussian distribution. The standard deviation of\n"
250 "the Gaussian distribution is expressed in meters and set by the user through\n"
251 "the attribute 'noise_std_dev' as shown in this example:\n\n"
255 " <my_controller ...>\n"
259 " <range_and_bearing implementation=\"medium\"\n"
261 " noise_std_dev=\"0.1\" />\n"
265 " </my_controller>\n"
267 " </controllers>\n\n"
269 "In addition, it is possible to specify the probability that a packet gets lost\n"
270 "even though the robot should have received it (i.e., packet dropping). To set\n"
271 "this probability, use the attribute 'packet_drop_prob' as shown in the example:\n"
275 " <my_controller ...>\n"
279 " <range_and_bearing implementation=\"medium\"\n"
281 " packet_drop_prob=\"0.1\" />\n"
285 " </my_controller>\n"
287 " </controllers>\n" ,
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define ARGOS_PI
To be used when initializing static variables.
The namespace containing all the ARGoS related code.
CRange< CRadians > INCLINATION_RANGE(CRadians(0), CRadians(ARGOS_PI))
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.
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
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.
virtual void Disable()
Disables 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 AddCheckedRay(bool b_obstructed, const CRay3 &c_ray)
Adds a ray to the list of checked rays.
void Disable()
Disables the entity.
void Enable()
Enables the entity.
const CQuaternion & GetOrientation() const
const CVector3 & GetPosition() const
T & GetMedium(const std::string &str_id)
Returns a reference to a medium.
static CSimulator & GetInstance()
Returns the instance to the CSimulator class.
The exception that wraps all errors in ARGoS.
Defines a very simple double-linked list that stores unique elements.
iterator begin() const
Returns an iterator to the first element.
iterator end() const
Returns an invalid iterator.
It defines the basic type CRadians, used to store an angle value in radians.
static const CRange< CRadians > UNSIGNED_RANGE
The unsigned normalization range [0:TWO_PI].
static const CRadians PI_OVER_TWO
Set to PI / 2.
CRadians & SignedNormalize()
Normalizes the value in the range [-PI:PI].
CQuaternion Inverse() const
static CRNG * CreateRNG(const std::string &str_category)
Creates a new RNG inside the given category.
bool Bernoulli(Real f_true=0.5)
Returns a random value from a Bernoulli distribution.
Real Gaussian(Real f_std_dev, Real f_mean=0.0f)
Returns a random value from a Gaussian distribution.
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.
void ToSphericalCoords(Real &f_radius, CRadians &c_inclination, CRadians &c_azimuth) const
Returns the vector contents as spherical coordinates.
CRadians HorizontalBearing
CRadians VerticalBearing
The vertical bearing is defined as the angle between the local robot XY plane and the message source ...
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.
virtual void Update()
Updates the state of the entity associated to this sensor, if the sensor is currently enabled.
virtual void Enable()
Enables updating of sensor information in the event loop.
CRangeAndBearingMediumSensor()
virtual void Reset()
Resets the sensor to the state it had just after Init().
virtual void Disable()
Disables updating of sensor information in the event loop.
virtual void Destroy()
Destroys the sensor.
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
void SetMedium(CRABMedium &c_medium)
const CSet< CRABEquippedEntity *, SEntityComparator > & GetRABsCommunicatingWith(CRABEquippedEntity &c_entity) const
Returns an immutable vector of RAB entities that can communicated with the given entity.
void RemoveEntity(CRABEquippedEntity &c_entity)
Removes the specified entity from the list of managed entities.