prototype_joints_default_sensor.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  /* get joint */
37  CPrototypeJointEntity& cJoint = m_pcJointEquippedEntity->GetJoint(strJointId);
38  /* get sensor */
39  CPrototypeJointEntity::SSensor& sInstance = cJoint.GetSensor();
40  /* configure sensor */
41  std::string strMode;
42  GetNodeAttribute(*itJoint, "mode", strMode);
43  if(strMode == "disabled") {
45  }
46  else if(strMode == "position") {
48  }
49  else if(strMode == "velocity") {
51  }
52  else {
53  THROW_ARGOSEXCEPTION("specified sensor mode for " << strJointId << " is not implemented");
54  }
55  /* create the sensor's interface */
56  m_vecSimulatedSensors.emplace_back(strJointId, sInstance);
57  }
58  for(SSimulatedSensor& s_sensor : m_vecSimulatedSensors) {
59  /* add joint actuators to the base class */
60  m_vecSensors.push_back(&s_sensor);
61  }
62  }
63 
64  /****************************************/
65  /****************************************/
66 
68  for(SSimulatedSensor& s_sensor : m_vecSimulatedSensors) {
69  s_sensor.Value = s_sensor.Instance.Value;
70  }
71  }
72 
73  /****************************************/
74  /****************************************/
75 
77  for(SSimulatedSensor& s_sensor : m_vecSimulatedSensors) {
78  s_sensor.Value = 0;
79  }
80  }
81 
82  /****************************************/
83  /****************************************/
84 
86  "joints", "default",
87  "Michael Allwright [allsey87@gmail.com]",
88  "1.0",
89  "The prototype joints sensor: monitors a prototype entity's joints.",
90  "This sensor is used to monitor the joints inside a prototype entity. To monitor\n"
91  "a joint, add a joint child node to the joints node. Each child node has two\n"
92  "required attributes.\n\n"
93  "REQUIRED XML CONFIGURATION\n\n"
94  " <controllers>\n"
95  " ...\n"
96  " <my_controller ...>\n"
97  " ...\n"
98  " <sensors>\n"
99  " ...\n"
100  " <joints implementation=\"default\">\n"
101  " <joint id=\"joint0\" mode=\"velocity\" />\n"
102  " <joint id=\"joint1\" mode=\"position\" />\n"
103  " ...\n"
104  " </joints>\n"
105  " ...\n"
106  " </sensors>\n"
107  " ...\n"
108  " </my_controller>\n"
109  " ...\n"
110  " </controllers>\n\n"
111  "The 'id' attribute specifies which joint in the prototype joint equipped entity\n"
112  "we are interested in monitoring. The 'mode' attribute has three options:\n"
113  "disabled, position, and velocity. The disabled mode is self-explanatory. The\n"
114  "position mode measures the displacement of the joint from its initial position\n"
115  "or orientation (depending on whether the specified joint is prismatic or\n"
116  "revolute). The reading from the joint is reported in either meters or radians\n"
117  "respectively. The velocity mode measures the how much the position or\n"
118  "orientation of the joint is changing every second.\n\n"
119  "OPTIONAL XML CONFIGURATION\n\n"
120  "None.",
121  "Usable"
122  );
123 
124  /****************************************/
125  /****************************************/
126 
127 }
virtual void Reset()
Resets the sensor to the state it had just after Init().
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.
virtual void Update()
Updates the state of the entity associated to this sensor.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Basic class for an entity that contains other entities.
ticpp::Iterator< ticpp::Element > TConfigurationNodeIterator
The iterator for the ARGoS configuration XML node.
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
CPrototypeJointEntity & GetJoint(UInt32 un_index)
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
REGISTER_SENSOR(CEyeBotLightRotZOnlySensor,"eyebot_light","rot_z_only","Carlo Pinciroli [ilpincy@gmail.com]","1.0","The eye-bot light sensor (optimized for 2D).","This sensor accesses a set of light sensors. The sensors all return a value\n""between 0 and 1, where 0 means nothing within range and 1 means the perceived\n""light saturates the sensor. Values between 0 and 1 depend on the distance of\n""the perceived light. Each reading R is calculated with R=(I/x)^2, where x is the\n""distance between a sensor and the light, and I is the reference intensity of the\n""perceived light. The reference intensity corresponds to the minimum distance at\n""which the light saturates a sensor. The reference intensity depends on the\n""individual light, and it is set with the \"intensity\" attribute of the light\n""entity. In case multiple lights are present in the environment, each sensor\n""reading is calculated as the sum of the individual readings due to each light.\n""In other words, light wave interference is not taken into account. In\n""controllers, you must include the ci_light_sensor.h header.\n\n""REQUIRED XML CONFIGURATION\n\n"" <controllers>\n"" ...\n"" <my_controller ...>\n"" ...\n"" <sensors>\n"" ...\n"" <eyebot_light implementation=\"rot_z_only\" />\n"" ...\n"" </sensors>\n"" ...\n"" </my_controller>\n"" ...\n"" </controllers>\n\n""OPTIONAL XML CONFIGURATION\n\n""It is possible to draw the rays shot by the light sensor in the OpenGL\n""visualization. This can be useful for sensor debugging but also to understand\n""what's wrong in your controller. In OpenGL, the rays are drawn in cyan when\n""they are not obstructed and in purple when they are. In case a ray is\n""obstructed, a black dot is drawn where the intersection occurred.\n""To turn this functionality on, add the attribute \"show_rays\" as in this\n""example:\n\n"" <controllers>\n"" ...\n"" <my_controller ...>\n"" ...\n"" <sensors>\n"" ...\n"" <eyebot_light implementation=\"rot_z_only\"\n"" show_rays=\"true\" />\n"" ...\n"" </sensors>\n"" ...\n"" </my_controller>\n"" ...\n"" </controllers>\n\n""It is possible to add uniform noise to the sensors, thus matching the\n""characteristics of a real robot better. This can be done with the attribute\n""\"noise_level\", whose allowed range is in [-1,1] and is added to the calculated\n""reading. The final sensor reading is always normalized in the [0-1] range.\n\n"" <controllers>\n"" ...\n"" <my_controller ...>\n"" ...\n"" <sensors>\n"" ...\n"" <eyebot_light implementation=\"rot_z_only\"\n"" noise_level=\"0.1\" />\n"" ...\n"" </sensors>\n"" ...\n"" </my_controller>\n"" ...\n"" </controllers>\n\n""OPTIONAL XML CONFIGURATION\n\n""None.\n","Usable")