Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00744_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00744_source.php on line 2
The ARGoS Website

cylinder_entity.cpp
Go to the documentation of this file.
1 
7 #include "cylinder_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>
12 
13 namespace argos {
14 
15  /****************************************/
16  /****************************************/
17 
19  CComposableEntity(NULL),
20  m_pcEmbodiedEntity(NULL),
21  m_pcLEDEquippedEntity(NULL),
22  m_fMass(1.0f),
23  m_pcLEDMedium(NULL) {
24  }
25 
26  /****************************************/
27  /****************************************/
28 
29  CCylinderEntity::CCylinderEntity(const std::string& str_id,
30  const CVector3& c_position,
31  const CQuaternion& c_orientation,
32  bool b_movable,
33  Real f_radius,
34  Real f_height,
35  Real f_mass) :
36  CComposableEntity(NULL, str_id),
37  m_pcEmbodiedEntity(
38  new CEmbodiedEntity(this,
39  "body_0",
40  c_position,
41  c_orientation,
42  b_movable)),
43  m_pcLEDEquippedEntity(
44  new CLEDEquippedEntity(this, "leds_0")),
45  m_fRadius(f_radius),
46  m_fHeight(f_height),
47  m_fMass(f_mass) {
48  AddComponent(*m_pcEmbodiedEntity);
49  AddComponent(*m_pcLEDEquippedEntity);
50  }
51 
52  /****************************************/
53  /****************************************/
54 
56  try {
57  /* Init parent */
59  /* Parse XML to get the radius */
60  GetNodeAttribute(t_tree, "radius", m_fRadius);
61  /* Parse XML to get the height */
62  GetNodeAttribute(t_tree, "height", m_fHeight);
63  /* Parse XML to get the movable attribute */
64  bool bMovable;
65  GetNodeAttribute(t_tree, "movable", bMovable);
66  if(bMovable) {
67  /* Parse XML to get the mass */
68  GetNodeAttribute(t_tree, "mass", m_fMass);
69  }
70  else {
71  m_fMass = 0.0f;
72  }
73  /* Create embodied entity using parsed data */
74  m_pcEmbodiedEntity = new CEmbodiedEntity(this);
75  AddComponent(*m_pcEmbodiedEntity);
76  m_pcEmbodiedEntity->Init(GetNode(t_tree, "body"));
77  m_pcEmbodiedEntity->SetMovable(bMovable);
78  /* Init LED equipped entity component */
79  m_pcLEDEquippedEntity = new CLEDEquippedEntity(this);
80  AddComponent(*m_pcLEDEquippedEntity);
81  if(NodeExists(t_tree, "leds")) {
82  /* Create LED equipped entity
83  * NOTE: the LEDs are not added to the medium yet
84  */
85  m_pcLEDEquippedEntity->Init(GetNode(t_tree, "leds"));
86  /* Add the LEDs to the medium */
87  std::string strMedium;
88  GetNodeAttribute(GetNode(t_tree, "leds"), "medium", strMedium);
89  m_pcLEDMedium = &CSimulator::GetInstance().GetMedium<CLEDMedium>(strMedium);
90  m_pcLEDEquippedEntity->SetMedium(*m_pcLEDMedium);
91  m_pcLEDEquippedEntity->Enable();
92  }
94  }
95  catch(CARGoSException& ex) {
96  THROW_ARGOSEXCEPTION_NESTED("Failed to initialize the cylinder entity.", ex);
97  }
98  }
99 
100  /****************************************/
101  /****************************************/
102 
104  /* Reset all components */
105  m_pcEmbodiedEntity->Reset();
106  m_pcLEDEquippedEntity->Reset();
107  /* Update components */
109  }
110 
111  /****************************************/
112  /****************************************/
113 
115  m_pcLEDMedium = &c_medium;
116  m_pcLEDEquippedEntity->SetMedium(*m_pcLEDMedium);
117  m_pcLEDEquippedEntity->Enable();
118  }
119 
120  /****************************************/
121  /****************************************/
122 
124  m_pcLEDEquippedEntity->Disable();
125  }
126 
127  /****************************************/
128  /****************************************/
129 
130  void CCylinderEntity::AddLED(const CVector3& c_offset,
131  const CColor& c_color) {
132  m_pcLEDEquippedEntity->AddLED(c_offset,
133  GetEmbodiedEntity().GetOriginAnchor(),
134  c_color);
136  }
137 
138  /****************************************/
139  /****************************************/
140 
142  "cylinder",
143  "Carlo Pinciroli [ilpincy@gmail.com]",
144  "1.0",
145  "A stretchable cylinder.",
146  "The cylinder entity can be used to model obstacles or cylinder-shaped\n"
147  "grippable objects. The cylinder has a red LED on the center of one\n"
148  "of the circular surfaces, that allows perception using the cameras.\n"
149  "The cylinder can be movable or not. A movable object can be pushed\n"
150  "and gripped. An unmovable object is pretty much like a column.\n\n"
151  "REQUIRED XML CONFIGURATION\n\n"
152  "To declare an unmovable object (i.e., a column) you need the following:\n\n"
153  " <arena ...>\n"
154  " ...\n"
155  " <cylinder id=\"cyl1\" radius=\"0.8\" height=\"0.5\" movable=\"false\">\n"
156  " <body position=\"0.4,2.3,0\" orientation=\"45,0,0\" />\n"
157  " </cylinder>\n"
158  " ...\n"
159  " </arena>\n\n"
160  "To declare a movable object you need the following:\n\n"
161  " <arena ...>\n"
162  " ...\n"
163  " <cylinder id=\"cyl1\" radius=\"0.8\" height=\"0.5\"\n"
164  " movable=\"true\" mass=\"2.5\">\n"
165  " <body position=\"0.4,2.3,0\" orientation=\"45,0,0\" />\n"
166  " </cylinder>\n"
167  " ...\n"
168  " </arena>\n\n"
169  "The 'id' attribute is necessary and must be unique among the entities. If two\n"
170  "entities share the same id, initialization aborts.\n"
171  "The 'radius' and 'height' attributes specify the size of the cylinder. When\n"
172  "you add a cylinder, imagine it initially unrotated and centered in the origin.\n"
173  "The base of the cylinder, then, is parallel to the XY plane and its height\n"
174  "goes with the Z axis.\n"
175  "The 'movable' attribute specifies whether or not the object is movable. When\n"
176  "set to 'false', the object is unmovable: if another object pushes against it,\n"
177  "the cylinder won't move. When the attribute is set to 'true', the cylinder is\n"
178  "movable upon pushing or gripping. When an object is movable, the 'mass'\n"
179  "attribute is required.\n"
180  "The 'mass' attribute quantifies the mass of the cylinder in kg.\n"
181  "The 'body/position' attribute specifies the position of the base of the\n"
182  "cylinder in the arena. The three values are in the X,Y,Z order.\n"
183  "The 'body/orientation' attribute specifies the orientation of the cylinder. All\n"
184  "rotations are performed with respect to the center of mass. The order of the\n"
185  "angles is Z,Y,X, which means that the first number corresponds to the rotation\n"
186  "around the Z axis, the second around Y and the last around X. This reflects\n"
187  "the internal convention used in ARGoS, in which rotations are performed in\n"
188  "that order. Angles are expressed in degrees.\n\n"
189  "OPTIONAL XML CONFIGURATION\n\n"
190  "It is possible to add any number of colored LEDs to the cylinder. In this way,\n"
191  "the cylinder is visible with a robot camera. The position and color of the\n"
192  "LEDs is specified with the following syntax:\n\n"
193  " <arena ...>\n"
194  " ...\n"
195  " <cylinder id=\"cyl1\" radius=\"0.8\" height=\"0.5\"\n"
196  " movable=\"true\" mass=\"2.5\">\n"
197  " <body position=\"0.4,2.3,0\" orientation=\"45,0,0\" />\n"
198  " <leds medium=\"id_of_led_medium\">\n"
199  " <led offset=\" 0.15, 0.15,0.15\" anchor=\"origin\" color=\"white\" />\n"
200  " <led offset=\"-0.15, 0.15,0\" anchor=\"origin\" color=\"red\" />\n"
201  " <led offset=\" 0.15, 0.15,0\" anchor=\"origin\" color=\"blue\" />\n"
202  " <led offset=\" 0.15,-0.15,0\" anchor=\"origin\" color=\"green\" />\n"
203  " </leds>\n"
204  " </cylinder>\n"
205  " ...\n"
206  " </arena>\n\n"
207  "In the example, four LEDs are added around the cylinder. The LEDs have\n"
208  "different colors and are located around the cylinder. The LEDs are\n"
209  "managed by the LED medium declared in the <media> section of the\n"
210  "configuration file with id \"id_of_led_medium\"",
211  "Usable"
212  );
213 
214  /****************************************/
215  /****************************************/
216 
218 
219  /****************************************/
220  /****************************************/
221 
222 }
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.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
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")
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.
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.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
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.
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
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.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: entity.cpp:40
void EnableLEDs(CLEDMedium &c_medium)
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
CEmbodiedEntity & GetEmbodiedEntity()
REGISTER_STANDARD_SPACE_OPERATIONS_ON_COMPOSABLE(CComposableEntity)
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
void AddLED(const CVector3 &c_offset, const CColor &c_color=CColor::BLACK)
Adds an LED to this entity.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
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.