prototype_link_entity.cpp
Go to the documentation of this file.
1 
9 #include <argos3/core/simulator/entity/composable_entity.h>
10 #include <argos3/plugins/robots/prototype/simulator/prototype_entity.h>
11 
12 namespace argos {
13 
14  /****************************************/
15  /****************************************/
16 
18  CEntity(pc_parent),
19  m_eGeometry(EGeometry::BOX),
20  m_cExtents(0.0f, 0.0f, 0.0f),
21  m_fMass(0.0f),
22  m_psAnchor(nullptr) {}
23 
24  /****************************************/
25  /****************************************/
26 
28  try {
29  /* Init parent */
30  CEntity::Init(t_tree);
31  /* Parse link geometry and dimensions */
32  std::string strLinkGeometry;
33  GetNodeAttribute(t_tree, "geometry", strLinkGeometry);
34  if(strLinkGeometry == "box") {
35  m_eGeometry = BOX;
36  GetNodeAttribute(t_tree, "size", m_cExtents);
37  } else if(strLinkGeometry == "cylinder") {
38  m_eGeometry = CYLINDER;
39  Real fRadius;
40  Real fHeight;
41  GetNodeAttribute(t_tree, "height", fHeight);
42  GetNodeAttribute(t_tree, "radius", fRadius);
43  m_cExtents.Set(fRadius * 2.0f, fRadius * 2.0f, fHeight);
44  } else if(strLinkGeometry == "sphere") {
45  m_eGeometry = SPHERE;
46  Real fRadius;
47  GetNodeAttribute(t_tree, "radius", fRadius);
48  m_cExtents.Set(fRadius * 2.0f, fRadius * 2.0f, fRadius * 2.0f);
49  } else if(strLinkGeometry == "convex_hull") {
50  std::string strPoints;
51  std::vector<std::string> vecPoints;
52  CVector3 cPoint;
53  m_eGeometry = CONVEX_HULL;
54  m_cExtents.Set(0.0f, 0.0f, 0.0f);
55  /* Parse the points of the convex hull */
56  GetNodeText(t_tree, strPoints);
57  /* Remove any whitespace characters */
58  std::string::iterator itEraseBegin =
59  std::remove_if(std::begin(strPoints), std::end(strPoints), ::isspace);
60  strPoints.erase(itEraseBegin, std::end(strPoints));
61  /* Split into individual points */
62  Tokenize(strPoints, vecPoints, "()");
63  for(const std::string& str_point : vecPoints) {
64  std::istringstream(str_point) >> cPoint;
65  m_vecConvexHullPoints.push_back(cPoint);
66  }
67  CConvexHull cConvexHull(m_vecConvexHullPoints);
68  /* store the faces in this object */
69  m_vecConvexHullFaces = cConvexHull.GetFaces();
70  } else {
71  /* unknown geometry requested */
72  THROW_ARGOSEXCEPTION("Geometry \"" << strLinkGeometry << "\" is not implemented");
73  }
74  /* Parse link geometry and dimensions */
75  GetNodeAttribute(t_tree, "mass", m_fMass);
76  /* Get the offset position of the link */
77  CVector3 cOffsetPosition;
78  GetNodeAttributeOrDefault(t_tree, "position", cOffsetPosition, cOffsetPosition);
79  /* Get the offset orientation of the link */
80  CQuaternion cOffsetOrientation;
81  GetNodeAttributeOrDefault(t_tree, "orientation", cOffsetOrientation, cOffsetOrientation);
82  /* Create an anchor for this link */
83  auto& cBody = GetParent().GetParent().GetComponent<CEmbodiedEntity>("body");
84  m_psAnchor = &(cBody.AddAnchor(GetId(), cOffsetPosition, cOffsetOrientation));
85  /* Enable the anchor */
86  m_psAnchor->Enable();
87  }
88  catch(CARGoSException& ex) {
89  THROW_ARGOSEXCEPTION_NESTED("Error while initializing link entity", ex);
90  }
91  }
92 
93  /****************************************/
94  /****************************************/
95 
97 
98  /****************************************/
99  /****************************************/
100 
101 }
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
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.
void Tokenize(const std::string &str_string, std::vector< std::string > &vec_tokens, const std::string &str_delimiters)
Tokenizes the given string according to the wanted delimiters (by default just a " ").
void GetNodeText(TConfigurationNode &t_node, T &t_buffer)
Returns the text of the passed XML node A node text is as follows:
REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(CEntity)
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
Basic class for an entity that contains other entities.
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
This entity is a link to a body in the physics engine.
The basic entity type.
Definition: entity.h:90
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
void Enable()
Enables the entity.
Definition: entity.h:265
CComposableEntity & GetParent()
Returns this entity's parent.
Definition: entity.cpp:91
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: entity.cpp:40
The exception that wraps all errors in ARGoS.
const std::vector< SFace > & GetFaces() const
Definition: convex_hull.h:44
A 3D vector class.
Definition: vector3.h:31
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
Definition: vector3.h:155
CPrototypeLinkEntity(CComposableEntity *pc_parent)
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.