prototype_joints_default_actuator.cpp
Go to the documentation of this file.
1 
8 
9 namespace argos {
10 
11  /****************************************/
12  /****************************************/
13 
15  m_pcJointEquippedEntity(nullptr) {
16  }
17 
18  /****************************************/
19  /****************************************/
20 
22  m_pcJointEquippedEntity = &(c_entity.GetComponent<CPrototypeJointEquippedEntity>("joints"));
23  }
24 
25  /****************************************/
26  /****************************************/
27 
29  TConfigurationNodeIterator itJoint("joint");
30  for(itJoint = itJoint.begin(&t_tree);
31  itJoint != itJoint.end();
32  ++itJoint) {
33  /* parse the joint id */
34  std::string strJointId;
35  GetNodeAttribute(*itJoint, "id", strJointId);
36  /* parse the maximum impulse */
37  Real fMaxImpulse;
38  GetNodeAttribute(*itJoint, "max_impulse", fMaxImpulse);
39  /* get joint */
40  CPrototypeJointEntity& cJoint = m_pcJointEquippedEntity->GetJoint(strJointId);
43  /* get actuator */
44  CPrototypeJointEntity::SActuator& sInstance = cJoint.GetActuator();
45  /* configure actuator */
46  std::string strMode;
47  GetNodeAttribute(*itJoint, "mode", strMode);
48  if(strMode == "disabled") {
50  }
51  else if(strMode == "position") {
53  }
54  else if(strMode == "velocity") {
56  }
57  else {
58  THROW_ARGOSEXCEPTION("Actuator mode \"" << strMode <<
59  "\" for joint \"" << strJointId <<
60  "\" " << " is not implemented");
61  }
62  sInstance.MaxImpulse = fMaxImpulse;
63  sInstance.Target = 0.0f;
64  /* create the actuator's interface */
65  m_vecSimulatedActuators.emplace_back(strJointId, 0.0, sInstance);
66  }
67  else {
68  THROW_ARGOSEXCEPTION("Actuators can only be set on prismatic or revolute joints");
69  }
70  }
71  for(SSimulatedActuator& s_actuator : m_vecSimulatedActuators) {
72  /* add joint actuators to the base class */
73  m_vecActuators.push_back(&s_actuator);
74  }
75  }
76 
77  /****************************************/
78  /****************************************/
79 
81  for(SSimulatedActuator& s_actuator : m_vecSimulatedActuators) {
82  s_actuator.Instance.Target = s_actuator.Target;
83  }
84  }
85 
86  /****************************************/
87  /****************************************/
88 
90  for(SSimulatedActuator& s_actuator : m_vecSimulatedActuators) {
91  s_actuator.Target = 0.0;
92  }
93  }
94 
95  /****************************************/
96  /****************************************/
97 
99  "joints", "default",
100  "Michael Allwright [allsey87@gmail.com]",
101  "1.0",
102  "The prototype joints actuator: controls a prototype entity's joints.",
103  "This actuator is used to control the joints inside a prototype entity. To\n"
104  "control a joint, add a joint child node to the joints node. Each child node has\n"
105  "three attributes, all of which are required.\n\n"
106  "REQUIRED XML CONFIGURATION\n\n"
107  " <controllers>\n"
108  " ...\n"
109  " <my_controller ...>\n"
110  " ...\n"
111  " <actuators>\n"
112  " ...\n"
113  " <joints implementation=\"default\">\n"
114  " <joint id=\"joint0\" mode=\"velocity\" max_impulse=\"0.002f\"/>\n"
115  " <joint id=\"joint1\" mode=\"position\" max_impulse=\"0.005f\"/>\n"
116  " ...\n"
117  " </joints>\n"
118  " ...\n"
119  " </actuators>\n"
120  " ...\n"
121  " </my_controller>\n"
122  " ...\n"
123  " </controllers>\n\n"
124  "The 'id' attribute specifies which joint in the prototype joint equipped entity\n"
125  "we are interested in controlling. The 'mode' attribute has three options:\n"
126  "disabled, position, and velocity. The disabled mode is self-explanatory. The\n"
127  "position and velocity modes enable closed loop position control and closed loop\n"
128  "velocity control. The 'max_impulse' attribute defines the maximum impulse of\n"
129  "the actuator in kg m/s for prismatic joints and kg m^2/s for revolute joints.\n\n"
130  "OPTIONAL XML CONFIGURATION\n\n"
131  "None.",
132  "Usable"
133  );
134 
135  /****************************************/
136  /****************************************/
137 
138 }
#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
ticpp::Iterator< ticpp::Element > TConfigurationNodeIterator
The iterator for the ARGoS configuration XML node.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
REGISTER_ACTUATOR(CFootBotDistanceScannerDefaultActuator, "footbot_distance_scanner", "default", "Carlo Pinciroli [ilpincy@gmail.com]", "1.0", "The foot-bot distance scanner actuator.", "This actuator controls the foot-bot distance scanner. For a complete\n" "description of its usage, refer to the ci_footbot_distance_scanner_actuator\n" "file.\n\n" "REQUIRED XML CONFIGURATION\n\n" " <controllers>\n" " ...\n" " <my_controller ...>\n" " ...\n" " <actuators>\n" " ...\n" " <footbot_distance_scanner implementation=\"default\" />\n" " ...\n" " </actuators>\n" " ...\n" " </my_controller>\n" " ...\n" " </controllers>\n\n" "OPTIONAL XML CONFIGURATION\n\n" "None for the time being.\n", "Usable")
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.
CPrototypeJointEntity & GetJoint(UInt32 un_index)
virtual void Init(TConfigurationNode &t_tree)
Initializes the actuator from the XML configuration tree.
virtual void Update()
Updates the state of the entity associated to this actuator.
virtual void Reset()
Resets the actuator to the state it had just after Init().
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this actuator.