ARGoS  3
A parallel, multi-engine simulator for swarm robotics
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->AddToMedium(*m_pcLEDMedium);
91  }
93  }
94  catch(CARGoSException& ex) {
95  THROW_ARGOSEXCEPTION_NESTED("Failed to initialize the cylinder entity.", ex);
96  }
97  }
98 
99  /****************************************/
100  /****************************************/
101 
103  /* Reset all components */
104  m_pcEmbodiedEntity->Reset();
105  m_pcLEDEquippedEntity->Reset();
106  /* Update components */
108  }
109 
110  /****************************************/
111  /****************************************/
112 
114  m_pcLEDEquippedEntity->AddToMedium(c_medium);
115  }
116 
117  /****************************************/
118  /****************************************/
119 
121  m_pcLEDEquippedEntity->RemoveFromMedium();
122  }
123 
124  /****************************************/
125  /****************************************/
126 
127  void CCylinderEntity::AddLED(const CVector3& c_offset,
128  const CColor& c_color) {
129  m_pcLEDEquippedEntity->AddLED(c_offset,
130  GetEmbodiedEntity().GetOriginAnchor(),
131  c_color);
133  }
134 
135  /****************************************/
136  /****************************************/
137 
139  "cylinder",
140  "Carlo Pinciroli [ilpincy@gmail.com]",
141  "1.0",
142  "A stretchable cylinder.",
143  "The cylinder entity can be used to model obstacles or cylinder-shaped\n"
144  "grippable objects. The cylinder has a red LED on the center of one\n"
145  "of the circular surfaces, that allows perception using the cameras.\n"
146  "The cylinder can be movable or not. A movable object can be pushed\n"
147  "and gripped. An unmovable object is pretty much like a column.\n\n"
148  "REQUIRED XML CONFIGURATION\n\n"
149  "To declare an unmovable object (i.e., a column) you need the following:\n\n"
150  " <arena ...>\n"
151  " ...\n"
152  " <cylinder id=\"cyl1\" radius=\"0.8\" height=\"0.5\" movable=\"false\">\n"
153  " <body position=\"0.4,2.3,0\" orientation=\"45,0,0\" />\n"
154  " </cylinder>\n"
155  " ...\n"
156  " </arena>\n\n"
157  "To declare a movable object you need the following:\n\n"
158  " <arena ...>\n"
159  " ...\n"
160  " <cylinder id=\"cyl1\" radius=\"0.8\" height=\"0.5\"\n"
161  " movable=\"true\" mass=\"2.5\">\n"
162  " <body position=\"0.4,2.3,0\" orientation=\"45,0,0\" />\n"
163  " </cylinder>\n"
164  " ...\n"
165  " </arena>\n\n"
166  "The 'id' attribute is necessary and must be unique among the entities. If two\n"
167  "entities share the same id, initialization aborts.\n"
168  "The 'radius' and 'height' attributes specify the size of the cylinder. When\n"
169  "you add a cylinder, imagine it initially unrotated and centered in the origin.\n"
170  "The base of the cylinder, then, is parallel to the XY plane and its height\n"
171  "goes with the Z axis.\n"
172  "The 'movable' attribute specifies whether or not the object is movable. When\n"
173  "set to 'false', the object is unmovable: if another object pushes against it,\n"
174  "the cylinder won't move. When the attribute is set to 'true', the cylinder is\n"
175  "movable upon pushing or gripping. When an object is movable, the 'mass'\n"
176  "attribute is required.\n"
177  "The 'mass' attribute quantifies the mass of the cylinder in kg.\n"
178  "The 'body/position' attribute specifies the position of the base of the\n"
179  "cylinder in the arena. The three values are in the X,Y,Z order.\n"
180  "The 'body/orientation' attribute specifies the orientation of the cylinder. All\n"
181  "rotations are performed with respect to the center of mass. The order of the\n"
182  "angles is Z,Y,X, which means that the first number corresponds to the rotation\n"
183  "around the Z axis, the second around Y and the last around X. This reflects\n"
184  "the internal convention used in ARGoS, in which rotations are performed in\n"
185  "that order. Angles are expressed in degrees.\n\n"
186  "OPTIONAL XML CONFIGURATION\n\n"
187  "It is possible to add any number of colored LEDs to the cylinder. In this way,\n"
188  "the cylinder is visible with a robot camera. The position and color of the\n"
189  "LEDs is specified with the following syntax:\n\n"
190  " <arena ...>\n"
191  " ...\n"
192  " <cylinder id=\"cyl1\" radius=\"0.8\" height=\"0.5\"\n"
193  " movable=\"true\" mass=\"2.5\">\n"
194  " <body position=\"0.4,2.3,0\" orientation=\"45,0,0\" />\n"
195  " <leds medium=\"id_of_led_medium\">\n"
196  " <led offset=\" 0.15, 0.15,0.15\" anchor=\"origin\" color=\"white\" />\n"
197  " <led offset=\"-0.15, 0.15,0\" anchor=\"origin\" color=\"red\" />\n"
198  " <led offset=\" 0.15, 0.15,0\" anchor=\"origin\" color=\"blue\" />\n"
199  " <led offset=\" 0.15,-0.15,0\" anchor=\"origin\" color=\"green\" />\n"
200  " </leds>\n"
201  " </cylinder>\n"
202  " ...\n"
203  " </arena>\n\n"
204  "In the example, four LEDs are added around the cylinder. The LEDs have\n"
205  "different colors and are located around the cylinder. The LEDs are\n"
206  "managed by the LED medium declared in the <media> section of the\n"
207  "configuration file with id \"id_of_led_medium\"",
208  "Usable"
209  );
210 
211  /****************************************/
212  /****************************************/
213 
215 
216  /****************************************/
217  /****************************************/
218 
219 }
argos::CSimulator::GetInstance
static CSimulator & GetInstance()
Returns the instance to the CSimulator class.
Definition: simulator.cpp:87
argos::CCylinderEntity::GetEmbodiedEntity
CEmbodiedEntity & GetEmbodiedEntity()
Definition: cylinder_entity.h:68
argos
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
argos::CVector3
A 3D vector class.
Definition: vector3.h:29
argos::CComposableEntity
Basic class for an entity that contains other entities.
Definition: composable_entity.h:32
argos::GetNode
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.
Definition: argos_configuration.h:63
argos::CARGoSException
The exception that wraps all errors in ARGoS.
Definition: argos_exception.h:61
argos::CEmbodiedEntity::SetMovable
void SetMovable(bool b_movable)
Sets whether this entity is movable or not.
Definition: embodied_entity.h:111
argos::CLEDEquippedEntity::Reset
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
Definition: led_equipped_entity.cpp:97
argos::CEmbodiedEntity
This entity is a link to a body in the physics engine.
Definition: embodied_entity.h:48
argos::TConfigurationNode
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Definition: argos_configuration.h:27
argos::CCylinderEntity::Reset
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
Definition: cylinder_entity.cpp:102
argos::CLEDMedium
Definition: led_medium.h:15
argos::CComposableEntity::AddComponent
void AddComponent(CEntity &c_component)
Adds a component to this composable entity.
Definition: composable_entity.cpp:72
argos::CLEDEquippedEntity
A container of CLEDEntity.
Definition: led_equipped_entity.h:36
argos::CCylinderEntity::EnableLEDs
void EnableLEDs(CLEDMedium &c_medium)
Definition: cylinder_entity.cpp:113
argos::CQuaternion
Definition: quaternion.h:14
argos::CCylinderEntity::CCylinderEntity
CCylinderEntity()
Definition: cylinder_entity.cpp:18
THROW_ARGOSEXCEPTION_NESTED
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
Definition: argos_exception.h:115
argos::REGISTER_STANDARD_SPACE_OPERATIONS_ON_COMPOSABLE
REGISTER_STANDARD_SPACE_OPERATIONS_ON_COMPOSABLE(CComposableEntity)
argos::CCylinderEntity::Init
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: cylinder_entity.cpp:55
argos::CLEDEquippedEntity::AddToMedium
void AddToMedium(CLEDMedium &c_medium)
Adds the LEDs to the wanted LED medium.
Definition: led_equipped_entity.cpp:256
argos::CComposableEntity::UpdateComponents
virtual void UpdateComponents()
Calls the Update() method on all the components.
Definition: composable_entity.cpp:59
argos::NodeExists
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.
Definition: argos_configuration.h:44
argos::CCylinderEntity
Definition: cylinder_entity.h:23
cylinder_entity.h
argos::CCylinderEntity::DisableLEDs
void DisableLEDs()
Definition: cylinder_entity.cpp:120
argos::REGISTER_ENTITY
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")
argos::CLEDEquippedEntity::Init
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: led_equipped_entity.cpp:54
argos::CColor
The basic color type.
Definition: color.h:25
argos::GetNodeAttribute
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
Definition: argos_configuration.h:208
argos::CEmbodiedEntity::Init
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: embodied_entity.cpp:68
argos::CCylinderEntity::AddLED
void AddLED(const CVector3 &c_offset, const CColor &c_color=CColor::BLACK)
Adds an LED to this entity.
Definition: cylinder_entity.cpp:127
argos::CEmbodiedEntity::Reset
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
Definition: embodied_entity.cpp:98
Real
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
argos::CEntity::Init
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: entity.cpp:36
argos::CLEDEquippedEntity::AddLED
void AddLED(const CVector3 &c_offset, SAnchor &s_anchor, const CColor &c_color=CColor::BLACK)
Adds an LED to this entity.
Definition: led_equipped_entity.cpp:128
argos::CSimulator::GetMedium
T & GetMedium(const std::string &str_id)
Returns a reference to a medium.
Definition: simulator.h:129
argos::CLEDEquippedEntity::RemoveFromMedium
void RemoveFromMedium()
Removes the LEDs from the associated LED medium.
Definition: led_equipped_entity.cpp:266