humotion / src / server / joint_interface.cpp @ d3aa8ab3
History | View | Annotate | Download (8.174 KB)
1 |
/*
|
---|---|
2 |
* This file is part of humotion
|
3 |
*
|
4 |
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
5 |
* http://opensource.cit-ec.de/projects/humotion
|
6 |
*
|
7 |
* This file may be licensed under the terms of the
|
8 |
* GNU Lesser General Public License Version 3 (the ``LGPL''),
|
9 |
* or (at your option) any later version.
|
10 |
*
|
11 |
* Software distributed under the License is distributed
|
12 |
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
|
13 |
* express or implied. See the LGPL for the specific language
|
14 |
* governing rights and limitations.
|
15 |
*
|
16 |
* You should have received a copy of the LGPL along with this
|
17 |
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
|
18 |
* or write to the Free Software Foundation, Inc.,
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
20 |
*
|
21 |
* The development of this software was supported by the
|
22 |
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
|
23 |
* The Excellence Cluster EXC 277 is a grant of the Deutsche
|
24 |
* Forschungsgemeinschaft (DFG) in the context of the German
|
25 |
* Excellence Initiative.
|
26 |
*/
|
27 |
|
28 |
#include "server/joint_interface.h" |
29 |
#include "server/controller.h" |
30 |
|
31 |
using namespace std; |
32 |
using namespace humotion; |
33 |
using namespace humotion::server; |
34 |
using namespace boost; |
35 |
|
36 |
|
37 |
//! constructor
|
38 |
JointInterface::JointInterface(){ |
39 |
framerate = 50.0; |
40 |
mouth_enabled = false;
|
41 |
gaze_enabled = false;
|
42 |
} |
43 |
|
44 |
//! destructor
|
45 |
JointInterface::~JointInterface(){ |
46 |
} |
47 |
|
48 |
//! set joint target position
|
49 |
//! \param joint_id of joint
|
50 |
//! \param float position
|
51 |
void JointInterface::set_target(int joint_id, float position, float velocity){ |
52 |
assert(joint_id < JOINT_ID_ENUM_SIZE); |
53 |
|
54 |
//update current value
|
55 |
joint_target_position_[joint_id] = position; |
56 |
joint_target_velocity_[joint_id] = velocity; |
57 |
} |
58 |
|
59 |
//! fetch target position
|
60 |
//! \param joint_id of joint
|
61 |
float JointInterface::get_target_position(int joint_id){ |
62 |
assert(joint_id < JOINT_ID_ENUM_SIZE); |
63 |
return joint_target_position_[joint_id];
|
64 |
} |
65 |
|
66 |
//! fetch target velocity
|
67 |
//! \param joint_id of joint
|
68 |
float JointInterface::get_target_velocity(int joint_id){ |
69 |
assert(joint_id < JOINT_ID_ENUM_SIZE); |
70 |
return joint_target_velocity_[joint_id];
|
71 |
} |
72 |
|
73 |
//! incoming position data
|
74 |
//! \param joint name
|
75 |
//! \param position
|
76 |
//! \param timestamp when the position was measured
|
77 |
void JointInterface::store_incoming_position(int joint_id, float position, Timestamp timestamp){ |
78 |
//lock the tsd_list for this access. by doing this we assure
|
79 |
//that no other thread accessing this element can diturb the
|
80 |
//following atomic instructions:
|
81 |
mutex::scoped_lock scoped_lock(joint_ts_position_map_access_mutex); |
82 |
|
83 |
printf("> humotion: incoming joint position for joint id 0x%02X = %4.2f (ts=%.2f)\n",joint_id,position,timestamp.to_seconds());
|
84 |
joint_ts_position_map[joint_id].insert(timestamp, position); |
85 |
|
86 |
incoming_position_count++; |
87 |
} |
88 |
|
89 |
//! return incoming position data count & clear this counter
|
90 |
//! this can be used as a keep alive status check
|
91 |
//! \return number of incoming joint positions since the last call
|
92 |
unsigned int JointInterface::get_and_clear_incoming_position_count(){ |
93 |
unsigned int i = incoming_position_count; |
94 |
incoming_position_count = 0;
|
95 |
return i;
|
96 |
} |
97 |
|
98 |
//! incoming speed data
|
99 |
//! \param joint name
|
100 |
//! \param speed
|
101 |
//! \param timestamp when the position was measured
|
102 |
void JointInterface::store_incoming_velocity(int joint_id, float velocity, Timestamp timestamp){ |
103 |
//lock the tsd_list for this access. by doing this we assure
|
104 |
//that no other thread accessing this element can diturb the
|
105 |
//following atomic instructions:
|
106 |
mutex::scoped_lock scoped_lock(joint_ts_speed_map_access_mutex); |
107 |
|
108 |
//printf("> humotion: incoming joint velocity for joint id 0x%02X = %4.2f (ts=%.2f)\n",joint_id,velocity,timestamp.to_seconds());
|
109 |
joint_ts_speed_map[joint_id].insert(timestamp, velocity); |
110 |
} |
111 |
|
112 |
//! return the timestamped float for the given joints position
|
113 |
TimestampedList JointInterface::get_ts_position(int joint_id){
|
114 |
//lock the tsd_list for this access. by doing this we assure
|
115 |
//that no other thread accessing this element can disturb the
|
116 |
//following atomic instructions:
|
117 |
mutex::scoped_lock scoped_lock(joint_ts_position_map_access_mutex); |
118 |
|
119 |
//search map:
|
120 |
joint_tsl_map_t::iterator it = joint_ts_position_map.find(joint_id); |
121 |
|
122 |
if (it == joint_ts_position_map.end()){
|
123 |
printf("> humotion: no ts_position for joint id 0x%02X found\n", joint_id);
|
124 |
return TimestampedList();
|
125 |
} |
126 |
|
127 |
//ok fine, we found our value:
|
128 |
return it->second;
|
129 |
} |
130 |
|
131 |
//! return the timestamped float for the given joints speed
|
132 |
TimestampedList JointInterface::get_ts_speed(int joint_id){
|
133 |
//lock the tsd_list for this access. by doing this we assure
|
134 |
//that no other thread accessing this element can diturb the
|
135 |
//following atomic instructions:
|
136 |
mutex::scoped_lock scoped_lock(joint_ts_speed_map_access_mutex); |
137 |
|
138 |
//search map:
|
139 |
joint_tsl_map_t::iterator it = joint_ts_speed_map.find(joint_id); |
140 |
|
141 |
if (it == joint_ts_speed_map.end()){
|
142 |
printf("> humotion: no ts_speed for joint id 0x%02X found\n", joint_id);
|
143 |
return TimestampedList();
|
144 |
} |
145 |
|
146 |
//ok fine, we found our value:
|
147 |
return it->second;
|
148 |
} |
149 |
|
150 |
//! set framerate
|
151 |
void JointInterface::set_framerate(float f){ |
152 |
framerate = f; |
153 |
} |
154 |
|
155 |
//! enable all mouth joints
|
156 |
void JointInterface::enable_mouth_joints(){
|
157 |
//already enabled? skip this
|
158 |
if (mouth_enabled){
|
159 |
return;
|
160 |
} |
161 |
|
162 |
printf("> humotion: ENABLING MOUTH JOINTS\n");
|
163 |
enable_joint(ID_LIP_LEFT_UPPER); |
164 |
enable_joint(ID_LIP_LEFT_LOWER); |
165 |
enable_joint(ID_LIP_CENTER_UPPER); |
166 |
enable_joint(ID_LIP_CENTER_LOWER); |
167 |
enable_joint(ID_LIP_RIGHT_UPPER); |
168 |
enable_joint(ID_LIP_RIGHT_LOWER); |
169 |
mouth_enabled = true;
|
170 |
} |
171 |
|
172 |
|
173 |
//! disable all mouth joints
|
174 |
void JointInterface::disable_mouth_joints(){
|
175 |
//already disabled? skip this
|
176 |
if (!mouth_enabled){
|
177 |
return;
|
178 |
} |
179 |
|
180 |
printf("> humotion: DISABLING MOUTH JOINTS\n");
|
181 |
disable_joint(ID_LIP_LEFT_UPPER); |
182 |
disable_joint(ID_LIP_LEFT_LOWER); |
183 |
disable_joint(ID_LIP_CENTER_UPPER); |
184 |
disable_joint(ID_LIP_CENTER_LOWER); |
185 |
disable_joint(ID_LIP_RIGHT_UPPER); |
186 |
disable_joint(ID_LIP_RIGHT_LOWER); |
187 |
mouth_enabled = false;
|
188 |
} |
189 |
|
190 |
//! enable all gaze joints
|
191 |
void JointInterface::enable_gaze_joints(){
|
192 |
//already enabled? skip this
|
193 |
if (gaze_enabled){
|
194 |
return;
|
195 |
} |
196 |
|
197 |
printf("> humotion: ENABLING GAZE JOINTS\n");
|
198 |
enable_joint(ID_EYES_LEFT_LR); |
199 |
enable_joint(ID_EYES_RIGHT_LR); |
200 |
enable_joint(ID_EYES_BOTH_UD); |
201 |
|
202 |
enable_joint(ID_EYES_LEFT_LID_UPPER); |
203 |
enable_joint(ID_EYES_LEFT_LID_LOWER); |
204 |
enable_joint(ID_EYES_RIGHT_LID_UPPER); |
205 |
enable_joint(ID_EYES_RIGHT_LID_LOWER); |
206 |
|
207 |
enable_joint(ID_EYES_LEFT_BROW); |
208 |
enable_joint(ID_EYES_RIGHT_BROW); |
209 |
|
210 |
enable_joint(ID_NECK_PAN); |
211 |
enable_joint(ID_NECK_TILT); |
212 |
enable_joint(ID_NECK_ROLL); |
213 |
|
214 |
gaze_enabled = true;
|
215 |
} |
216 |
|
217 |
//! disable all gaze joints
|
218 |
void JointInterface::disable_gaze_joints(){
|
219 |
//already disabled? skip this
|
220 |
if (!gaze_enabled){
|
221 |
return;
|
222 |
} |
223 |
|
224 |
printf("> humotion: DISABLING GAZE JOINTS\n");
|
225 |
disable_joint(ID_EYES_LEFT_LR); |
226 |
disable_joint(ID_EYES_RIGHT_LR); |
227 |
disable_joint(ID_EYES_BOTH_UD); |
228 |
|
229 |
disable_joint(ID_EYES_LEFT_LID_UPPER); |
230 |
disable_joint(ID_EYES_LEFT_LID_LOWER); |
231 |
disable_joint(ID_EYES_RIGHT_LID_UPPER); |
232 |
disable_joint(ID_EYES_RIGHT_LID_LOWER); |
233 |
|
234 |
disable_joint(ID_EYES_LEFT_BROW); |
235 |
disable_joint(ID_EYES_RIGHT_BROW); |
236 |
|
237 |
disable_joint(ID_NECK_PAN); |
238 |
disable_joint(ID_NECK_TILT); |
239 |
disable_joint(ID_NECK_ROLL); |
240 |
|
241 |
gaze_enabled = false;
|
242 |
} |
243 |
|
244 |
//! fetch maximum allowed joint position
|
245 |
//! \return max position
|
246 |
float JointInterface::get_joint_max(int joint_id){ |
247 |
assert((joint_id > 0) && (joint_id < JOINT_ID_ENUM_SIZE));
|
248 |
return joint_max[joint_id];
|
249 |
} |
250 |
|
251 |
//! fetch minimum allowed joint position
|
252 |
//! \return min position
|
253 |
float JointInterface::get_joint_min(int joint_id){ |
254 |
assert((joint_id > 0) && (joint_id < JOINT_ID_ENUM_SIZE));
|
255 |
return joint_min[joint_id];
|
256 |
} |
257 |
|
258 |
//! check if joint position map is empty
|
259 |
//! \return true if empty
|
260 |
bool JointInterface::get_joint_position_map_empty(){
|
261 |
return (joint_ts_position_map.empty());
|
262 |
} |
263 |
|
264 |
//! call the virtual store function with given position and velocities
|
265 |
void JointInterface::publish_target(int joint_id) { |
266 |
publish_target(joint_id, joint_target_position_[joint_id], joint_target_velocity_[joint_id]); |
267 |
} |