9 #include <argos3/core/utility/math/matrix/rotationmatrix3.h>
10 #include <argos3/core/simulator/space/space.h>
11 #include <argos3/core/simulator/entity/controllable_entity.h>
12 #include <argos3/core/simulator/entity/embodied_entity.h>
13 #include <argos3/plugins/simulator/entities/rab_equipped_entity.h>
14 #include <argos3/plugins/simulator/entities/ground_sensor_equipped_entity.h>
15 #include <argos3/plugins/simulator/entities/led_equipped_entity.h>
16 #include <argos3/plugins/simulator/entities/light_sensor_equipped_entity.h>
17 #include <argos3/plugins/simulator/entities/proximity_sensor_equipped_entity.h>
18 #include <argos3/plugins/simulator/entities/battery_equipped_entity.h>
25 static const Real BODY_RADIUS = 0.035f;
26 static const Real BODY_HEIGHT = 0.086f;
28 static const Real INTERWHEEL_DISTANCE = 0.053f;
29 static const Real HALF_INTERWHEEL_DISTANCE = INTERWHEEL_DISTANCE * 0.5f;
30 static const Real WHEEL_RADIUS = 0.0205f;
32 static const Real PROXIMITY_SENSOR_RING_ELEVATION = 0.06f;
33 static const Real PROXIMITY_SENSOR_RING_RADIUS = BODY_RADIUS;
34 static const CRadians PROXIMITY_SENSOR_RING_START_ANGLE = CRadians((2 *
ARGOS_PI / 8.0f) * 0.5f);
35 static const Real PROXIMITY_SENSOR_RING_RANGE = 0.1f;
37 static const CRadians LED_RING_START_ANGLE = CRadians((
ARGOS_PI / 8.0f) * 0.5f);
38 static const Real LED_RING_RADIUS = BODY_RADIUS + 0.007;
39 static const Real LED_RING_ELEVATION = 0.086f;
40 static const Real RAB_ELEVATION = LED_RING_ELEVATION;
47 m_pcControllableEntity(nullptr),
48 m_pcEmbodiedEntity(nullptr),
49 m_pcGroundSensorEquippedEntity(nullptr),
50 m_pcLEDEquippedEntity(nullptr),
51 m_pcLightSensorEquippedEntity(nullptr),
52 m_pcProximitySensorEquippedEntity(nullptr),
53 m_pcRABEquippedEntity(nullptr),
54 m_pcWheeledEntity(nullptr),
55 m_pcBatteryEquippedEntity(nullptr) {
62 const std::string& str_controller_id,
66 size_t un_rab_data_size,
67 const std::string& str_bat_model) :
69 m_pcControllableEntity(nullptr),
70 m_pcEmbodiedEntity(nullptr),
71 m_pcGroundSensorEquippedEntity(nullptr),
72 m_pcLEDEquippedEntity(nullptr),
73 m_pcLightSensorEquippedEntity(nullptr),
74 m_pcProximitySensorEquippedEntity(nullptr),
75 m_pcRABEquippedEntity(nullptr),
76 m_pcWheeledEntity(nullptr),
77 m_pcBatteryEquippedEntity(nullptr) {
83 m_pcEmbodiedEntity =
new CEmbodiedEntity(
this,
"body_0", c_position, c_orientation);
88 m_pcWheeledEntity->
SetWheel(0,
CVector3(0.0f, HALF_INTERWHEEL_DISTANCE, 0.0f), WHEEL_RADIUS);
89 m_pcWheeledEntity->
SetWheel(1,
CVector3(0.0f, -HALF_INTERWHEEL_DISTANCE, 0.0f), WHEEL_RADIUS);
94 CVector3(0.0f, 0.0f, LED_RING_ELEVATION),
100 m_pcProximitySensorEquippedEntity =
124 CVector3 cOff, cDir, c_center =
CVector3(0.0f, 0.0f, PROXIMITY_SENSOR_RING_ELEVATION);
125 for(
UInt32 i = 0; i < 8; ++i)
127 cAngle = sensor_angle[i];
129 cOff.
Set(PROXIMITY_SENSOR_RING_RADIUS, 0.0f, 0.0f);
132 cDir.
Set(PROXIMITY_SENSOR_RING_RANGE, 0.0f, 0.0f);
134 m_pcProximitySensorEquippedEntity->
AddSensor(cOff, cDir, PROXIMITY_SENSOR_RING_RANGE, m_pcEmbodiedEntity->
GetOriginAnchor());
139 m_pcLightSensorEquippedEntity =
144 CVector3(0.0f, 0.0f, PROXIMITY_SENSOR_RING_ELEVATION),
145 PROXIMITY_SENSOR_RING_RADIUS,
146 PROXIMITY_SENSOR_RING_START_ANGLE,
147 PROXIMITY_SENSOR_RING_RANGE,
151 m_pcGroundSensorEquippedEntity =
171 CVector3(0.0f, 0.0f, RAB_ELEVATION));
208 m_pcWheeledEntity->
SetWheel(0,
CVector3(0.0f, HALF_INTERWHEEL_DISTANCE, 0.0f), WHEEL_RADIUS);
209 m_pcWheeledEntity->
SetWheel(1,
CVector3(0.0f, -HALF_INTERWHEEL_DISTANCE, 0.0f), WHEEL_RADIUS);
214 CVector3(0.0f, 0.0f, LED_RING_ELEVATION),
216 LED_RING_START_ANGLE,
221 m_pcProximitySensorEquippedEntity =
244 CVector3 cOff, cDir, c_center =
CVector3(0.0f, 0.0f, PROXIMITY_SENSOR_RING_ELEVATION);
245 for(
UInt32 i = 0; i < 8; ++i)
247 cAngle = sensor_angle[i];
249 cOff.
Set(PROXIMITY_SENSOR_RING_RADIUS, 0.0f, 0.0f);
252 cDir.
Set(PROXIMITY_SENSOR_RING_RANGE, 0.0f, 0.0f);
254 m_pcProximitySensorEquippedEntity->
AddSensor(cOff, cDir, PROXIMITY_SENSOR_RING_RANGE, m_pcEmbodiedEntity->
GetOriginAnchor());
260 m_pcLightSensorEquippedEntity =
265 CVector3(0.0f, 0.0f, PROXIMITY_SENSOR_RING_ELEVATION),
266 PROXIMITY_SENSOR_RING_RADIUS,
267 PROXIMITY_SENSOR_RING_START_ANGLE,
268 PROXIMITY_SENSOR_RING_RANGE,
272 m_pcGroundSensorEquippedEntity =
296 CVector3(0.0f, 0.0f, RAB_ELEVATION));
301 m_pcBatteryEquippedEntity->
Init(
GetNode(t_tree,
"battery"));
307 m_pcControllableEntity->
Init(
GetNode(t_tree,
"controller"));
336 #define UPDATE(COMPONENT) if(COMPONENT->IsEnabled()) COMPONENT->Update();
339 UPDATE(m_pcRABEquippedEntity);
340 UPDATE(m_pcLEDEquippedEntity);
341 UPDATE(m_pcBatteryEquippedEntity);
349 "Carlo Pinciroli [ilpincy@gmail.com]",
352 "The e-puck is a open-hardware, extensible robot intended for education. In its\n"
353 "simplest form, it is a two-wheeled robot equipped with proximity sensors,\n"
354 "ground sensors, light sensors, a microphone, a frontal camera, and a ring of\n"
355 "red LEDs. More information is available at http://www.epuck.org\n\n"
356 "REQUIRED XML CONFIGURATION\n\n"
359 " <e-puck id=\"eb0\">\n"
360 " <body position=\"0.4,2.3,0.25\" orientation=\"45,90,0\" />\n"
361 " <controller config=\"mycntrl\" />\n"
365 "The 'id' attribute is necessary and must be unique among the entities. If two\n"
366 "entities share the same id, initialization aborts.\n"
367 "The 'body/position' attribute specifies the position of the pucktom point of the\n"
368 "e-puck in the arena. When the robot is untranslated and unrotated, the\n"
369 "pucktom point is in the origin and it is defined as the middle point between\n"
370 "the two wheels on the XY plane and the lowest point of the robot on the Z\n"
371 "axis, that is the point where the wheels touch the floor. The attribute values\n"
372 "are in the X,Y,Z order.\n"
373 "The 'body/orientation' attribute specifies the orientation of the e-puck. All\n"
374 "rotations are performed with respect to the pucktom point. The order of the\n"
375 "angles is Z,Y,X, which means that the first number corresponds to the rotation\n"
376 "around the Z axis, the second around Y and the last around X. This reflects\n"
377 "the internal convention used in ARGoS, in which rotations are performed in\n"
378 "that order. Angles are expressed in degrees. When the robot is unrotated, it\n"
379 "is oriented along the X axis.\n"
380 "The 'controller/config' attribute is used to assign a controller to the\n"
381 "e-puck. The value of the attribute must be set to the id of a previously\n"
382 "defined controller. Controllers are defined in the <controllers> XML subtree.\n\n"
383 "OPTIONAL XML CONFIGURATION\n\n"
384 "You can set the emission range of the range-and-bearing system. By default, a\n"
385 "message sent by an e-puck can be received up to 80cm. By using the 'rab_range'\n"
386 "attribute, you can change it to, i.e., 4m as follows:\n\n"
389 " <e-puck id=\"eb0\" rab_range=\"4\">\n"
390 " <body position=\"0.4,2.3,0.25\" orientation=\"45,90,0\" />\n"
391 " <controller config=\"mycntrl\" />\n"
395 "You can also set the data sent at each time step through the range-and-bearing\n"
396 "system. By default, a message sent by an e-puck is 2 bytes long. By using the\n"
397 "'rab_data_size' attribute, you can change it to, i.e., 20 bytes as follows:\n\n"
400 " <e-puck id=\"eb0\" rab_data_size=\"20\">\n"
401 " <body position=\"0.4,2.3,0.25\" orientation=\"45,90,0\" />\n"
402 " <controller config=\"mycntrl\" />\n"
406 "You can also configure the battery of the robot. By default, the battery never\n"
407 "depletes. You can choose among several battery discharge models, such as\n"
408 "- time: the battery depletes by a fixed amount at each time step\n"
409 "- motion: the battery depletes according to how the robot moves\n"
410 "- time_motion: a combination of the above models.\n"
411 "You can define your own models too. Follow the examples in the file\n"
412 "argos3/src/plugins/simulator/entities/battery_equipped_entity.cpp.\n\n"
415 " <e-puck id=\"eb0\"\n"
416 " <body position=\"0.4,2.3,0.25\" orientation=\"45,0,0\" />\n"
417 " <controller config=\"mycntrl\" />\n"
418 " <battery model=\"time\" factor=\"1e-5\"/>\n"
424 " <e-puck id=\"eb0\"\n"
425 " <body position=\"0.4,2.3,0.25\" orientation=\"45,0,0\" />\n"
426 " <controller config=\"mycntrl\" />\n"
427 " <battery model=\"motion\" pos_factor=\"1e-3\"\n"
428 " orient_factor=\"1e-3\"/>\n"
434 " <e-puck id=\"eb0\"\n"
435 " <body position=\"0.4,2.3,0.25\" orientation=\"45,0,0\" />\n"
436 " <controller config=\"mycntrl\" />\n"
437 " <battery model=\"time_motion\" time_factor=\"1e-5\"\n"
438 " pos_factor=\"1e-3\"\n"
439 " orient_factor=\"1e-3\"/>\n"
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
unsigned int UInt32
32-bit unsigned integer.
float Real
Collects all ARGoS code.
#define ARGOS_PI
To be used when initializing static variables.
#define UPDATE(COMPONENT)
The namespace containing all the ARGoS related code.
TConfigurationNode & GetNode(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns the first of its child nodes with the wanted name.
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.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
bool NodeExists(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns true if one of its child nodes has the wanted name.
REGISTER_STANDARD_SPACE_OPERATIONS_ON_COMPOSABLE(CComposableEntity)
REGISTER_ENTITY(CFloorEntity, "floor", "Carlo Pinciroli [ilpincy@gmail.com]", "1.0", "It contains the properties of the arena floor.", "The floor entity contains the properties of the arena floor. In the current\n" "implementation, it contains only the color of the floor. The floor color is\n" "detected by the robots' ground sensors.\n\n" "REQUIRED XML CONFIGURATION\n\n" " <arena ...>\n" " ...\n" " <floor id=\"floor\"\n" " source=\"SOURCE\" />\n" " ...\n" " </arena>\n\n" "The 'id' attribute is necessary and must be unique among the entities. If two\n" "entities share the same id, initialization aborts.\n" "The 'source' attribute specifies where to get the color of the floor from. Its\n" "value, here denoted as SOURCE, can assume the following values:\n\n" " image The color is calculated from the passed image file\n" " loop_functions The color is calculated calling the loop functions\n\n" "When 'source' is set to 'image', as showed in the following example, you have\n" "to specify the image path in the additional attribute 'path':\n\n" " <arena ...>\n" " ...\n" " <floor id=\"floor\"\n" " source=\"image\"\n" " path=\"/path/to/imagefile.ext\" />\n" " ...\n" " </arena>\n\n" "Many image formats are available, such as PNG, JPG, BMP, GIF and many more.\n" "Refer to the FreeImage webpage for a complete list of supported image formats\n" "(http://freeimage.sourceforge.net/features.html).\n\n" "When 'source' is set to 'loop_functions', as showed in the following example,\n" "an image is implicitly created to be used as texture for graphical\n" "visualizations. The algorithm that creates the texture needs to convert from\n" "meters (in the arena) to pixels (of the texture). You control how many pixels\n" "per meter are used with the attribute 'pixels_per_meter'. Clearly, the higher\n" "value, the higher the quality, but also the slower the algorithm and the bigger\n" "the texture. The algorithm is called only once at init time, so the fact that\n" "it is slow is not so important. However, the image size is limited by OpenGL.\n" "Every implementation has its own limit, and you should check yours if any\n" "texture-related problem arises. Now for the example:\n\n" " <arena ...>\n" " ...\n" " <floor id=\"floor\"\n" " source=\"loop_functions\"\n" " pixels_per_meter=\"100\" />\n" " ...\n" " </arena>\n\n" "OPTIONAL XML CONFIGURATION\n\n" "None for the time being.\n", "Usable")
Basic class for an entity that contains other entities.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
void AddComponent(CEntity &c_component)
Adds a component to this composable entity.
An entity that contains a pointer to the user-defined controller.
void SetController(const std::string &str_controller_id)
Creates and assigns a controller with the given id.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
This entity is a link to a body in the physics engine.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
const std::string & GetId() const
Returns the id of this entity.
virtual void Destroy()
Destroys the entity, undoing whatever was done by Init() or by the standalone constructor.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
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].
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
CVector3 & RotateZ(const CRadians &c_angle)
Rotates this vector wrt the z axis.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
virtual void UpdateComponents()
Calls the Update() method on all the components.
virtual void Destroy()
Destroys the entity, undoing whatever was done by Init() or by the standalone constructor.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
void AddSensor(const CVector2 &c_offset, ESensorType e_type, SAnchor &s_anchor)
A container of CLEDEntity.
void AddLEDRing(const CVector3 &c_center, Real f_radius, const CRadians &c_start_angle, UInt32 un_num_leds, SAnchor &s_anchor, const CColor &c_color=CColor::BLACK)
Adds a ring of LEDs to this entity.
void AddSensorRing(const CVector3 &c_center, Real f_radius, const CRadians &c_start_angle, Real f_range, UInt32 un_num_sensors, SAnchor &s_anchor)
void AddSensor(const CVector3 &c_offset, const CVector3 &c_direction, Real f_range, SAnchor &s_anchor)
void SetWheel(UInt32 un_index, const CVector3 &c_position, Real f_radius)