Go to the documentation of this file.
7 #include "box_entity.h"
8 #include <argos3/core/utility/math/matrix/rotationmatrix3.h>
9 #include <argos3/core/simulator/space/space.h>
10 #include <argos3/core/simulator/simulator.h>
11 #include <argos3/plugins/simulator/media/led_medium.h>
13 namespace argos {
15  /****************************************/
16  /****************************************/
19  CComposableEntity(NULL),
20  m_pcEmbodiedEntity(NULL),
21  m_pcLEDEquippedEntity(NULL),
22  m_fMass(1.0f),
23  m_pcLEDMedium(NULL) {}
25  /****************************************/
26  /****************************************/
28  CBoxEntity::CBoxEntity(const std::string& str_id,
29  const CVector3& c_position,
30  const CQuaternion& c_orientation,
31  bool b_movable,
32  const CVector3& c_size,
33  Real f_mass) :
34  CComposableEntity(NULL, str_id),
35  m_pcEmbodiedEntity(
36  new CEmbodiedEntity(this,
37  "body_0",
38  c_position,
39  c_orientation,
40  b_movable)),
41  m_pcLEDEquippedEntity(
42  new CLEDEquippedEntity(this,
43  "leds_0")),
44  m_cSize(c_size),
45  m_fMass(f_mass) {
46  AddComponent(*m_pcEmbodiedEntity);
47  AddComponent(*m_pcLEDEquippedEntity);
48  }
50  /****************************************/
51  /****************************************/
54  try {
55  /* Init parent */
57  /* Parse XML to get the size */
58  GetNodeAttribute(t_tree, "size", m_cSize);
59  /* Parse XML to get the movable attribute */
60  bool bMovable;
61  GetNodeAttribute(t_tree, "movable", bMovable);
62  if(bMovable) {
63  /* Parse XML to get the mass */
64  GetNodeAttribute(t_tree, "mass", m_fMass);
65  }
66  else {
67  m_fMass = 0.0f;
68  }
69  /* Create embodied entity using parsed data */
70  m_pcEmbodiedEntity = new CEmbodiedEntity(this);
71  AddComponent(*m_pcEmbodiedEntity);
72  m_pcEmbodiedEntity->Init(GetNode(t_tree, "body"));
73  m_pcEmbodiedEntity->SetMovable(bMovable);
74  /* Init LED equipped entity component */
75  m_pcLEDEquippedEntity = new CLEDEquippedEntity(this);
76  AddComponent(*m_pcLEDEquippedEntity);
77  if(NodeExists(t_tree, "leds")) {
78  /* Create LED equipped entity
79  * NOTE: the LEDs are not added to the medium yet
80  */
81  m_pcLEDEquippedEntity->Init(GetNode(t_tree, "leds"));
82  /* Add the LEDs to the medium */
83  std::string strMedium;
84  GetNodeAttribute(GetNode(t_tree, "leds"), "medium", strMedium);
85  m_pcLEDMedium = &CSimulator::GetInstance().GetMedium<CLEDMedium>(strMedium);
86  m_pcLEDEquippedEntity->SetMedium(*m_pcLEDMedium);
87  m_pcLEDEquippedEntity->Enable();
88  }
90  }
91  catch(CARGoSException& ex) {
92  THROW_ARGOSEXCEPTION_NESTED("Failed to initialize box entity \"" << GetId() << "\".", ex);
93  }
94  }
96  /****************************************/
97  /****************************************/
100  /* Reset all components */
102  /* Update components */
104  }
106  /****************************************/
107  /****************************************/
110  m_pcLEDMedium = &c_medium;
111  m_pcLEDEquippedEntity->SetMedium(*m_pcLEDMedium);
112  m_pcLEDEquippedEntity->Enable();
113  }
115  /****************************************/
116  /****************************************/
119  m_pcLEDEquippedEntity->Disable();
120  }
122  /****************************************/
123  /****************************************/
125  void CBoxEntity::AddLED(const CVector3& c_offset,
126  const CColor& c_color) {
127  m_pcLEDEquippedEntity->AddLED(c_offset,
128  GetEmbodiedEntity().GetOriginAnchor(),
129  c_color);
131  }
133  /****************************************/
134  /****************************************/
137  "box",
138  "Carlo Pinciroli []",
139  "1.0",
140  "A stretchable 3D box.",
141  "The box entity can be used to model walls, obstacles or box-shaped grippable\n"
142  "objects. It can be movable or not. A movable object can be pushed and gripped.\n"
143  "An unmovable object is pretty much like a wall.\n\n"
145  "To declare an unmovable object (i.e., a wall) you need the following:\n\n"
146  " <arena ...>\n"
147  " ...\n"
148  " <box id=\"box1\" size=\"0.75,0.1,0.5\" movable=\"false\">\n"
149  " <body position=\"0.4,2.3,0\" orientation=\"45,0,0\" />\n"
150  " </box>\n"
151  " ...\n"
152  " </arena>\n\n"
153  "To declare a movable object you need the following:\n\n"
154  " <arena ...>\n"
155  " ...\n"
156  " <box id=\"box1\" size=\"0.75,0.1,0.5\" movable=\"true\" mass=\"2.5\">\n"
157  " <body position=\"0.4,2.3,0\" orientation=\"45,0,0\" />\n"
158  " </box>\n"
159  " ...\n"
160  " </arena>\n\n"
161  "The 'id' attribute is necessary and must be unique among the entities. If two\n"
162  "entities share the same id, initialization aborts.\n"
163  "The 'size' attribute specifies the size of the box along the three axes, in\n"
164  "the X,Y,Z order. When you add a box, imagine it initially unrotated and\n"
165  "centered in the origin. The size, then, corresponds to the extent along the X,\n"
166  "Y and Z axes.\n"
167  "The 'movable' attribute specifies whether or not the object is movable. When\n"
168  "set to 'false', the object is unmovable: if another object pushes against it,\n"
169  "the box won't move. When the attribute is set to 'true', the box is movable\n"
170  "upon pushing or gripping. When an object is movable, the 'mass' attribute is\n"
171  "required.\n"
172  "The 'mass' attribute quantifies the mass of the box in kg.\n"
173  "The 'body/position' attribute specifies the position of the base of the box in\n"
174  "the arena. The three values are in the X,Y,Z order.\n"
175  "The 'body/orientation' attribute specifies the orientation of the 3D box. All\n"
176  "rotations are performed with respect to the center of mass. The order of the\n"
177  "angles is Z,Y,X, which means that the first number corresponds to the rotation\n"
178  "around the Z axis, the second around Y and the last around X. This reflects\n"
179  "the internal convention used in ARGoS, in which rotations are performed in\n"
180  "that order. Angles are expressed in degrees.\n\n"
182  "It is possible to add any number of colored LEDs to the box. In this way,\n"
183  "the box is visible with a robot camera. The position and color of the\n"
184  "LEDs is specified with the following syntax:\n\n"
185  " <arena ...>\n"
186  " ...\n"
187  " <box id=\"box1\" size=\"0.75,0.1,0.5\" movable=\"true\" mass=\"2.5\">\n"
188  " <body position=\"0.4,2.3,0\" orientation=\"45,0,0\" />\n"
189  " <leds medium=\"id_of_led_medium\">\n"
190  " <led offset=\" 0.15, 0.15,0.15\" anchor=\"origin\" color=\"white\" />\n"
191  " <led offset=\"-0.15, 0.15,0\" anchor=\"origin\" color=\"red\" />\n"
192  " <led offset=\" 0.15, 0.15,0\" anchor=\"origin\" color=\"blue\" />\n"
193  " <led offset=\" 0.15,-0.15,0\" anchor=\"origin\" color=\"green\" />\n"
194  " </leds>\n"
195  " </box>\n"
196  " ...\n"
197  " </arena>\n\n"
198  "In the example, four LEDs are added to the box. The LEDs have\n"
199  "different colors and are located one on the top and three\n"
200  "around the box. The LEDs are managed by the LED medium declared in\n"
201  "the <media> section of the configuration file with id \"id_of_led_medium\"",
202  "Usable"
203  );
205  /****************************************/
206  /****************************************/
210  /****************************************/
211  /****************************************/
213 }
A 3D vector class.
Definition: vector3.h:29
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
void AddLED(const CVector3 &c_offset, SAnchor &s_anchor, const CColor &c_color=CColor::BLACK)
Adds an LED to this entity.
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.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
REGISTER_ENTITY(CFloorEntity,"floor","Carlo Pinciroli []","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""(\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")
This entity is a link to a body in the physics engine.
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception...
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
void SetMedium(CLEDMedium &c_medium)
Sets the medium associated to this entity.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: box_entity.cpp:53
void EnableLEDs(CLEDMedium &c_medium)
Definition: box_entity.cpp:109
A container of CLEDEntity.
Basic class for an entity that contains other entities.
void SetMovable(bool b_movable)
Sets whether this entity is movable or not.
void AddComponent(CEntity &c_component)
Adds a component to this composable entity.
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.
CEmbodiedEntity & GetEmbodiedEntity()
Definition: box_entity.h:64
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
The exception that wraps all errors in ARGoS.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: entity.cpp:40
The basic color type.
Definition: color.h:25
T & GetMedium(const std::string &str_id)
Returns a reference to a medium.
Definition: simulator.h:129
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
Definition: box_entity.cpp:99
void AddLED(const CVector3 &c_offset, const CColor &c_color=CColor::BLACK)
Adds an LED to this entity.
Definition: box_entity.cpp:125
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
static CSimulator & GetInstance()
Returns the instance to the CSimulator class.
Definition: simulator.cpp:78
virtual void UpdateComponents()
Calls the Update() method on all the components.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...