8 #include <argos3/core/simulator/entity/composable_entity.h>
9 #include <argos3/core/simulator/entity/controllable_entity.h>
10 #include <argos3/core/simulator/simulator.h>
11 #include <argos3/core/simulator/space/space.h>
18 static const Real FOOTBOT_RADIUS = 0.085036758f;
20 static const Real SHORT_RANGE_MIN_DISTANCE = 0.0f;
21 static const Real SHORT_RANGE_RAY_START = FOOTBOT_RADIUS;
22 static const Real SHORT_RANGE_RAY_END = FOOTBOT_RADIUS + 0.26f;
24 static const Real LONG_RANGE_MIN_DISTANCE = 0.12f;
25 static const Real LONG_RANGE_RAY_START = FOOTBOT_RADIUS;
26 static const Real LONG_RANGE_RAY_END = FOOTBOT_RADIUS + 1.42f;
28 static const Real SENSOR_ELEVATION = 0.123199866f;
36 m_cSpace(
CSimulator::GetInstance().GetSpace()),
49 if(m_cNoiseRange.
GetSpan() > 0.0f) {
69 m_pcDistScanEntity->
Enable();
90 CalculateRaysNotRotating();
92 m_cLastDistScanRotation = m_pcDistScanEntity->
GetRotation();
99 CalculateRaysRotating();
103 m_cLastDistScanRotation = m_pcDistScanEntity->
GetRotation();
123 void CFootBotDistanceScannerRotZOnlySensor::UpdateNotRotating() {
125 CRadians cAngle = m_cLastDistScanRotation;
127 Real fReading = CalculateReadingForRay(m_cShortRangeRays0[0], SHORT_RANGE_MIN_DISTANCE);
133 fReading = CalculateReadingForRay(m_cLongRangeRays1[0], LONG_RANGE_MIN_DISTANCE);
139 fReading = CalculateReadingForRay(m_cShortRangeRays2[0], SHORT_RANGE_MIN_DISTANCE);
145 fReading = CalculateReadingForRay(m_cLongRangeRays3[0], LONG_RANGE_MIN_DISTANCE);
153 #define ADD_READING(RAYS,MAP,INDEX,MINDIST) \
154 cAngle += cInterSensorSpan; \
155 cAngle.SignedNormalize(); \
156 fReading = CalculateReadingForRay(RAYS[INDEX],MINDIST); \
157 MAP[cAngle] = fReading; \
158 m_tReadingsMap[cAngle] = fReading;
160 #define ADD_READINGS(RAYS,MAP,MINDIST) \
161 ADD_READING(RAYS,MAP,1,MINDIST) \
162 ADD_READING(RAYS,MAP,2,MINDIST) \
163 ADD_READING(RAYS,MAP,3,MINDIST) \
164 ADD_READING(RAYS,MAP,4,MINDIST) \
165 ADD_READING(RAYS,MAP,5,MINDIST)
167 void CFootBotDistanceScannerRotZOnlySensor::UpdateRotating() {
168 CRadians cInterSensorSpan = (m_pcDistScanEntity->
GetRotation() - m_cLastDistScanRotation).UnsignedNormalize() / 6.0f;
169 CRadians cStartAngle = m_cLastDistScanRotation;
171 CRadians cAngle = cStartAngle;
173 Real fReading = CalculateReadingForRay(m_cShortRangeRays0[0], SHORT_RANGE_MIN_DISTANCE);
180 fReading = CalculateReadingForRay(m_cShortRangeRays2[0], SHORT_RANGE_MIN_DISTANCE);
187 fReading = CalculateReadingForRay(m_cLongRangeRays1[0], LONG_RANGE_MIN_DISTANCE);
194 fReading = CalculateReadingForRay(m_cLongRangeRays3[0], LONG_RANGE_MIN_DISTANCE);
203 Real CFootBotDistanceScannerRotZOnlySensor::CalculateReadingForRay(
const CRay3& c_ray,
204 Real f_min_distance) {
206 SEmbodiedEntityIntersectionItem sIntersection;
209 *m_pcEmbodiedEntity)) {
212 Real fDistance = c_ray.GetDistance(sIntersection.TOnRay);
213 if(fDistance > f_min_distance) {
215 if(m_bShowRays) m_pcControllableEntity->
AddCheckedRay(
true, c_ray);
216 return fDistance * 100.0f;
220 if(m_bShowRays) m_pcControllableEntity->
AddCheckedRay(
true, c_ray);
226 if(m_bShowRays) m_pcControllableEntity->
AddCheckedRay(
false, c_ray);
235 #define CALCULATE_SHORT_RANGE_RAY(ANGLE,INDEX) \
236 m_cDirection.RotateZ(ANGLE); \
237 m_cOriginRayStart = m_cDirection; \
238 m_cOriginRayEnd = m_cDirection; \
239 m_cOriginRayStart *= SHORT_RANGE_RAY_START; \
240 m_cOriginRayEnd *= SHORT_RANGE_RAY_END; \
241 m_cRayStart = m_pcEmbodiedEntity->GetOriginAnchor().Position; \
242 m_cRayStart += m_cOriginRayStart; \
243 m_cRayStart.SetZ(m_cRayStart.GetZ() + SENSOR_ELEVATION); \
244 m_cRayEnd = m_pcEmbodiedEntity->GetOriginAnchor().Position; \
245 m_cRayEnd += m_cOriginRayEnd; \
246 m_cRayEnd.SetZ(m_cRayEnd.GetZ() + SENSOR_ELEVATION); \
247 m_cShortRangeRays0[INDEX].Set(m_cRayStart, m_cRayEnd); \
248 m_cRayStart = m_pcEmbodiedEntity->GetOriginAnchor().Position; \
249 m_cRayStart -= m_cOriginRayStart; \
250 m_cRayStart.SetZ(m_cRayStart.GetZ() + SENSOR_ELEVATION); \
251 m_cRayEnd = m_pcEmbodiedEntity->GetOriginAnchor().Position; \
252 m_cRayEnd -= m_cOriginRayEnd; \
253 m_cRayEnd.SetZ(m_cRayEnd.GetZ() + SENSOR_ELEVATION); \
254 m_cShortRangeRays2[INDEX].Set(m_cRayStart, m_cRayEnd); \
257 #define CALCULATE_LONG_RANGE_RAY(ANGLE,INDEX) \
258 m_cDirection.RotateZ(ANGLE); \
259 m_cOriginRayStart = m_cDirection; \
260 m_cOriginRayEnd = m_cDirection; \
261 m_cOriginRayStart *= LONG_RANGE_RAY_START; \
262 m_cOriginRayEnd *= LONG_RANGE_RAY_END; \
263 m_cRayStart = m_pcEmbodiedEntity->GetOriginAnchor().Position; \
264 m_cRayStart += m_cOriginRayStart; \
265 m_cRayStart.SetZ(m_cRayStart.GetZ() + SENSOR_ELEVATION); \
266 m_cRayEnd = m_pcEmbodiedEntity->GetOriginAnchor().Position; \
267 m_cRayEnd += m_cOriginRayEnd; \
268 m_cRayEnd.SetZ(m_cRayEnd.GetZ() + SENSOR_ELEVATION); \
269 m_cLongRangeRays1[INDEX].Set(m_cRayStart, m_cRayEnd); \
270 m_cRayStart = m_pcEmbodiedEntity->GetOriginAnchor().Position; \
271 m_cRayStart -= m_cOriginRayStart; \
272 m_cRayStart.SetZ(m_cRayStart.GetZ() + SENSOR_ELEVATION); \
273 m_cRayEnd = m_pcEmbodiedEntity->GetOriginAnchor().Position; \
274 m_cRayEnd -= m_cOriginRayEnd; \
275 m_cRayEnd.SetZ(m_cRayEnd.GetZ() + SENSOR_ELEVATION); \
276 m_cLongRangeRays3[INDEX].Set(m_cRayStart, m_cRayEnd);
281 void CFootBotDistanceScannerRotZOnlySensor::CalculateRaysNotRotating() {
284 CRadians cTmp1, cTmp2, cOrientationZ;
287 cOrientationZ += m_pcDistScanEntity->
GetRotation();
289 CVector2 cAbsoluteOrientation(1.0, cOrientationZ);
301 void CFootBotDistanceScannerRotZOnlySensor::CalculateRaysRotating() {
304 CRadians cTmp1, cTmp2, cOrientationZ;
307 cOrientationZ += m_cLastDistScanRotation;
309 CVector2 cAbsoluteOrientation(1.0, cOrientationZ);
311 CVector2 cInterSensorSpan(1.0f, (m_pcDistScanEntity->
GetRotation() - m_cLastDistScanRotation).UnsignedNormalize() / 6.0f);
334 "footbot_distance_scanner",
"rot_z_only",
335 "Carlo Pinciroli [ilpincy@gmail.com]",
337 "The foot-bot distance scanner sensor (optimized for 2D).",
338 "This sensor accesses the foot-bot distance scanner sensor. For a complete\n"
339 "description of its usage, refer to the common interface.\n"
340 "In this implementation, the readings are calculated under the assumption that\n"
341 "the foot-bot is always parallel to the XY plane, i.e., it rotates only around\n"
342 "the Z axis. This implementation is faster than a 3D one and should be used\n"
343 "only when the assumption about the foot-bot rotation holds.\n\n"
345 "This sensor is enabled by default.\n\n"
347 "REQUIRED XML CONFIGURATION\n\n"
350 " <my_controller ...>\n"
354 " <footbot_distance_scanner implementation=\"rot_z_only\" />\n"
358 " </my_controller>\n"
360 " </controllers>\n\n"
361 "OPTIONAL XML CONFIGURATION\n\n"
362 "It is possible to draw the rays shot by the distance scanner in the OpenGL\n"
363 "visualization. This can be useful for sensor debugging but also to understand\n"
364 "what's wrong in your controller. In OpenGL, the rays are drawn in cyan when\n"
365 "they are not obstructed and in purple when they are. In case a ray is\n"
366 "obstructed, a black dot is drawn where the intersection occurred.\n"
367 "To turn this functionality on, add the attribute 'show_rays=\"true\"' in the\n"
368 "XML as in this example:\n\n"
371 " <my_controller ...>\n"
375 " <footbot_distance_scanner implementation=\"rot_z_only\"\n"
376 " show_rays=\"true\" />\n"
380 " </my_controller>\n"
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
float Real
Collects all ARGoS code.
#define CALCULATE_LONG_RANGE_RAY(ANGLE, INDEX)
#define ADD_READINGS(RAYS, MAP, MINDIST)
#define CALCULATE_SHORT_RANGE_RAY(ANGLE, INDEX)
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.
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
void Enable()
Enables the entity.
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
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.
CRadians & SignedNormalize()
Normalizes the value in the range [-PI:PI].
static const CRadians ZERO
Set to zero radians.
void ToEulerAngles(CRadians &c_z_angle, CRadians &c_y_angle, CRadians &c_x_angle) const
static CRNG * CreateRNG(const std::string &str_category)
Creates a new RNG inside the given category.
static const CVector3 Y
The y axis.
static const CVector3 X
The x axis.
TReadingsMap m_tLongReadingsMap
Map storing the last received packets from the long distance sensors.
TReadingsMap m_tReadingsMap
Map storing all the last received packets.
TReadingsMap m_tShortReadingsMap
Map storing the last received packets from the short distance sensors.
const CRadians & GetRotation() const
CFootBotDistanceScannerRotZOnlySensor()
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
virtual void Reset()
Resets the sensor to the state it had just after Init().
virtual void Update()
Updates the state of the entity associated to this sensor, if the sensor is currently enabled.
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.