ARGoS 3
A parallel, multi-engine simulator for swarm robotics
prototype_joints_default_sensor.cpp
Go to the documentation of this file.
1
8
9namespace argos {
10
11 /****************************************/
12 /****************************************/
13
15 m_pcJointEquippedEntity(nullptr) {}
16
17 /****************************************/
18 /****************************************/
19
21 m_pcJointEquippedEntity = &(c_entity.GetComponent<CPrototypeJointEquippedEntity>("joints"));
22 }
23
24 /****************************************/
25 /****************************************/
26
28 TConfigurationNodeIterator itJoint("joint");
29 for(itJoint = itJoint.begin(&t_tree);
30 itJoint != itJoint.end();
31 ++itJoint) {
32 /* parse the joint id */
33 std::string strJointId;
34 GetNodeAttribute(*itJoint, "id", strJointId);
35 /* get joint */
36 CPrototypeJointEntity& cJoint = m_pcJointEquippedEntity->GetJoint(strJointId);
37 /* get sensor */
38 CPrototypeJointEntity::SSensor& sInstance = cJoint.GetSensor();
39 /* configure sensor */
40 std::string strMode;
41 GetNodeAttribute(*itJoint, "mode", strMode);
42 if(strMode == "disabled") {
44 }
45 else if(strMode == "position") {
47 }
48 else if(strMode == "velocity") {
50 }
51 else {
52 THROW_ARGOSEXCEPTION("specified sensor mode for " << strJointId << " is not implemented");
53 }
54 /* create the sensor's interface */
55 m_vecSimulatedSensors.emplace_back(strJointId, sInstance);
56 }
57 for(SSimulatedSensor& s_sensor : m_vecSimulatedSensors) {
58 /* add joint actuators to the base class */
59 m_vecSensors.push_back(&s_sensor);
60 }
61 /* sensor is enabled by default */
62 Enable();
63 }
64
65 /****************************************/
66 /****************************************/
67
69 /* sensor is disabled--nothing to do */
70 if (IsDisabled()) {
71 return;
72 }
73 for(SSimulatedSensor& s_sensor : m_vecSimulatedSensors) {
74 s_sensor.Value = s_sensor.Instance.Value;
75 }
76 }
77
78 /****************************************/
79 /****************************************/
80
82 for(SSimulatedSensor& s_sensor : m_vecSimulatedSensors) {
83 s_sensor.Value = 0;
84 }
85 }
86
87 /****************************************/
88 /****************************************/
89
91 "joints", "default",
92 "Michael Allwright [allsey87@gmail.com]",
93 "1.0",
94 "The prototype joints sensor: monitors a prototype entity's joints.",
95 "This sensor is used to monitor the joints inside a prototype entity. To monitor\n"
96 "a joint, add a joint child node to the joints node. Each child node has two\n"
97 "required attributes.\n\n"
98
99 "This sensor is enabled by default.\n\n"
100
101
102 "REQUIRED XML CONFIGURATION\n\n"
103
104 " <controllers>\n"
105 " ...\n"
106 " <my_controller ...>\n"
107 " ...\n"
108 " <sensors>\n"
109 " ...\n"
110 " <joints implementation=\"default\">\n"
111 " <joint id=\"joint0\" mode=\"velocity\" />\n"
112 " <joint id=\"joint1\" mode=\"position\" />\n"
113 " ...\n"
114 " </joints>\n"
115 " ...\n"
116 " </sensors>\n"
117 " ...\n"
118 " </my_controller>\n"
119 " ...\n"
120 " </controllers>\n\n"
121 "The 'id' attribute specifies which joint in the prototype joint equipped entity\n"
122 "we are interested in monitoring. The 'mode' attribute has three options:\n"
123 "disabled, position, and velocity. The disabled mode is self-explanatory. The\n"
124 "position mode measures the displacement of the joint from its initial position\n"
125 "or orientation (depending on whether the specified joint is prismatic or\n"
126 "revolute). The reading from the joint is reported in either meters or radians\n"
127 "respectively. The velocity mode measures the how much the position or\n"
128 "orientation of the joint is changing every second.\n\n"
129 "OPTIONAL XML CONFIGURATION\n\n"
130 "None.",
131 "Usable"
132 );
133
134 /****************************************/
135 /****************************************/
136
137}
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
#define REGISTER_SENSOR(CLASSNAME, LABEL, IMPLEMENTATION, AUTHOR, VERSION, BRIEF_DESCRIPTION, LONG_DESCRIPTION, STATUS)
Registers a new sensor model inside ARGoS.
Definition sensor.h:63
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.
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
virtual void Enable()
Enables updating of sensor information in the event loop.
Definition ci_sensor.h:78
bool IsDisabled() const
Definition ci_sensor.h:86
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 SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
virtual void Reset()
Resets the sensor to the state it had just after Init().
virtual void Update()
Updates the state of the entity associated to this sensor, if the sensor is currently enabled.
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.