ARGoS  3
A parallel, multi-engine simulator for swarm robotics
gripper_equipped_entity.cpp
Go to the documentation of this file.
1 
8 #include <argos3/core/simulator/space/space.h>
9 
10 namespace argos {
11 
12  /****************************************/
13  /****************************************/
14 
15  CRange<Real> UNIT(0.0f, 1.0f);
16 
17  /****************************************/
18  /****************************************/
19 
21  CEntity(pc_parent),
22  m_fLockState(0.0f),
23  m_fLockThreshold(0.5f),
24  m_pcGrippedEntity(NULL) {
25  Disable();
26  }
27 
28  /****************************************/
29  /****************************************/
30 
32  const std::string& str_id,
33  const CVector3& c_offset,
34  const CVector3& c_direction,
35  Real f_lock_threshold) :
36  CEntity(pc_parent,
37  str_id),
38  m_cOffset(c_offset),
39  m_cInitOffset(c_offset),
40  m_cDirection(c_direction),
41  m_cInitDirection(c_direction),
42  m_fLockState(0.0f),
43  m_fLockThreshold(f_lock_threshold),
44  m_pcGrippedEntity(NULL) {
45  Disable();
46  }
47 
48  /****************************************/
49  /****************************************/
50 
52  try {
53  /* Parse id */
54  CEntity::Init(t_tree);
55  /* Parse gripper attributes */
56  GetNodeAttribute(t_tree, "offset", m_cOffset);
57  m_cInitOffset = m_cOffset;
58  GetNodeAttribute(t_tree, "direction", m_cDirection);
59  m_cInitDirection = m_cDirection;
60  GetNodeAttributeOrDefault(t_tree, "lock_threshold", m_fLockThreshold, m_fLockThreshold);
61  }
62  catch(CARGoSException& ex) {
63  THROW_ARGOSEXCEPTION_NESTED("Error while initializing the gripper entity \"" << GetId() << "\"", ex);
64  }
65  }
66 
67  /****************************************/
68  /****************************************/
69 
71  m_fLockState = 0.0f;
72  m_cOffset = m_cInitOffset;
73  m_cDirection = m_cInitDirection;
75  }
76 
77  /****************************************/
78  /****************************************/
79 
81  UNIT.TruncValue(f_lock_state);
82  m_fLockState = f_lock_state;
83  }
84 
85  /****************************************/
86  /****************************************/
87 
89  UNIT.TruncValue(f_lock_threshold);
90  m_fLockThreshold = f_lock_threshold;
91  }
92 
93  /****************************************/
94  /****************************************/
95 
97  if(m_pcGrippedEntity != NULL) {
98  return *m_pcGrippedEntity;
99  }
100  else {
101  THROW_ARGOSEXCEPTION("Entity \"" << GetId() << "\" is not gripping anything.");
102  }
103  }
104 
105  /****************************************/
106  /****************************************/
107 
109 
110  /****************************************/
111  /****************************************/
112 
113 }
argos::CEntity::GetId
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
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::CARGoSException
The exception that wraps all errors in ARGoS.
Definition: argos_exception.h:61
argos::CGripperEquippedEntity::CGripperEquippedEntity
CGripperEquippedEntity(CComposableEntity *pc_parent)
Class constructor.
Definition: gripper_equipped_entity.cpp:20
argos::REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY
REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(CEntity)
argos::CEmbodiedEntity
This entity is a link to a body in the physics engine.
Definition: embodied_entity.h:48
argos::CGripperEquippedEntity::SetLockThreshold
void SetLockThreshold(Real f_lock_threshold)
Sets the lock threshold of the gripper.
Definition: gripper_equipped_entity.cpp:88
argos::TConfigurationNode
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Definition: argos_configuration.h:27
argos::CGripperEquippedEntity
An entity that stores the state of a robot gripper.
Definition: gripper_equipped_entity.h:37
argos::CGripperEquippedEntity::GetGrippedEntity
CEmbodiedEntity & GetGrippedEntity()
Returns the embodied entity currently gripped by this gripper.
Definition: gripper_equipped_entity.cpp:96
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
THROW_ARGOSEXCEPTION
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
Definition: argos_exception.h:111
gripper_equipped_entity.h
argos::CRange::TruncValue
void TruncValue(T &t_value) const
Definition: range.h:97
argos::CEntity
The basic entity type.
Definition: entity.h:89
argos::CGripperEquippedEntity::SetLockState
void SetLockState(Real f_lock_state)
Sets the lock state of the gripper.
Definition: gripper_equipped_entity.cpp:80
argos::GetNodeAttributeOrDefault
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.
Definition: argos_configuration.h:318
argos::CGripperEquippedEntity::Reset
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or one of the standalone constructors ...
Definition: gripper_equipped_entity.cpp:70
argos::CEntity::Disable
void Disable()
Disables the entity.
Definition: entity.h:249
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::CGripperEquippedEntity::Init
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: gripper_equipped_entity.cpp:51
Real
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
argos::CGripperEquippedEntity::ClearGrippedEntity
void ClearGrippedEntity()
Clears the reference to the embodied entity currently gripped by this gripper.
Definition: gripper_equipped_entity.h:217
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::UNIT
CRange< Real > UNIT(0.0f, 1.0f)