prototype_link_entity.cpp
Go to the documentation of this file.
1 
8 #include <argos3/core/simulator/entity/composable_entity.h>
9 #include <argos3/plugins/robots/prototype/simulator/prototype_entity.h>
10 
11 namespace argos {
12 
13  /****************************************/
14  /****************************************/
15 
17  CEntity(pc_parent),
18  m_eGeometry(EGeometry::BOX),
19  m_cExtents(0.0f, 0.0f, 0.0f),
20  m_fMass(0.0f),
21  m_psAnchor(nullptr) {}
22 
23  /****************************************/
24  /****************************************/
25 
27  try {
28  /* Init parent */
29  CEntity::Init(t_tree);
30  /* Parse link geometry and dimensions */
31  std::string strLinkGeometry;
32  GetNodeAttribute(t_tree, "geometry", strLinkGeometry);
33  if(strLinkGeometry == "box") {
34  m_eGeometry = BOX;
35  GetNodeAttribute(t_tree, "size", m_cExtents);
36  } else if(strLinkGeometry == "cylinder") {
37  m_eGeometry = CYLINDER;
38  Real fRadius;
39  Real fHeight;
40  GetNodeAttribute(t_tree, "height", fHeight);
41  GetNodeAttribute(t_tree, "radius", fRadius);
42  m_cExtents.Set(fRadius * 2.0f, fRadius * 2.0f, fHeight);
43  } else if(strLinkGeometry == "sphere") {
44  m_eGeometry = SPHERE;
45  Real fRadius;
46  GetNodeAttribute(t_tree, "radius", fRadius);
47  m_cExtents.Set(fRadius * 2.0f, fRadius * 2.0f, fRadius * 2.0f);
48  } else {
49  /* unknown geometry requested */
50  THROW_ARGOSEXCEPTION("Geometry \"" << strLinkGeometry << "\" is not implemented");
51  }
52  /* Parse link geometry and dimensions */
53  GetNodeAttribute(t_tree, "mass", m_fMass);
54  /* Get the offset position of the link */
55  CVector3 cOffsetPosition;
56  GetNodeAttributeOrDefault(t_tree, "position", cOffsetPosition, cOffsetPosition);
57  /* Get the offset orientation of the link */
58  CQuaternion cOffsetOrientation;
59  GetNodeAttributeOrDefault(t_tree, "orientation", cOffsetOrientation, cOffsetOrientation);
60  /* Create an anchor for this link */
62  m_psAnchor = &(cBody.AddAnchor(GetId(), cOffsetPosition, cOffsetOrientation));
63  /* Enable the anchor */
64  m_psAnchor->Enable();
65  }
66  catch(CARGoSException& ex) {
67  THROW_ARGOSEXCEPTION_NESTED("Error while initializing link entity", ex);
68  }
69  }
70 
71  /****************************************/
72  /****************************************/
73 
75 
76  /****************************************/
77  /****************************************/
78 
79 }
A 3D vector class.
Definition: vector3.h:29
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.
void Enable()
Enables the entity.
Definition: entity.h:265
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
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
The basic entity type.
Definition: entity.h:89
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
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...
CPrototypeLinkEntity(CComposableEntity *pc_parent)
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
Definition: vector3.h:143
Basic class for an entity that contains other entities.
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
REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(CEntity)
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
SAnchor & AddAnchor(const std::string &str_id, const CVector3 &c_rel_position=CVector3(), const CQuaternion &c_rel_orientation=CQuaternion())
Adds an anchor to the embodied entity.
CComposableEntity & GetParent()
Returns this entity's parent.
Definition: entity.cpp:91
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.