humotion / src / server / joint_interface.cpp @ bc171e0e
History | View | Annotate | Download (7.728 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_position(int joint_id, float position, float speed){ |
52 |
assert(joint_id < JOINT_ID_ENUM_SIZE); |
53 |
|
54 |
//update current value
|
55 |
joint_target[joint_id] = position; |
56 |
joint_target_speed[joint_id] = speed; |
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[joint_id];
|
64 |
} |
65 |
|
66 |
//! incoming position data
|
67 |
//! \param joint name
|
68 |
//! \param position
|
69 |
//! \param timestamp when the position was measured
|
70 |
void JointInterface::store_incoming_position(int joint_id, float position, Timestamp timestamp){ |
71 |
//lock the tsd_list for this access. by doing this we assure
|
72 |
//that no other thread accessing this element can diturb the
|
73 |
//following atomic instructions:
|
74 |
mutex::scoped_lock scoped_lock(joint_ts_position_map_access_mutex); |
75 |
|
76 |
//printf("> humotion: incoming joint position for joint id 0x%02X = %4.2f (ts=%.2f)\n",joint_id,position,timestamp.to_seconds());
|
77 |
joint_ts_position_map[joint_id].insert(timestamp, position); |
78 |
|
79 |
incoming_position_count++; |
80 |
} |
81 |
|
82 |
//! return incoming position data count & clear this counter
|
83 |
//! this can be used as a keep alive status check
|
84 |
//! \return number of incoming joint positions since the last call
|
85 |
unsigned int JointInterface::get_and_clear_incoming_position_count(){ |
86 |
unsigned int i = incoming_position_count; |
87 |
incoming_position_count = 0;
|
88 |
return i;
|
89 |
} |
90 |
|
91 |
//! incoming speed data
|
92 |
//! \param joint name
|
93 |
//! \param speed
|
94 |
//! \param timestamp when the position was measured
|
95 |
void JointInterface::store_incoming_speed(int joint_id, float speed, Timestamp timestamp){ |
96 |
//lock the tsd_list for this access. by doing this we assure
|
97 |
//that no other thread accessing this element can diturb the
|
98 |
//following atomic instructions:
|
99 |
mutex::scoped_lock scoped_lock(joint_ts_speed_map_access_mutex); |
100 |
|
101 |
//printf("> humotion: incoming joint speed for joint id 0x%02X = %4.2f (ts=%.2f)\n",joint_id,speed,timestamp.to_seconds());
|
102 |
joint_ts_speed_map[joint_id].insert(timestamp, speed); |
103 |
} |
104 |
|
105 |
//! return the timestamped float for the given joints position
|
106 |
TimestampedList JointInterface::get_ts_position(int joint_id){
|
107 |
//lock the tsd_list for this access. by doing this we assure
|
108 |
//that no other thread accessing this element can disturb the
|
109 |
//following atomic instructions:
|
110 |
mutex::scoped_lock scoped_lock(joint_ts_position_map_access_mutex); |
111 |
|
112 |
//search map:
|
113 |
joint_tsl_map_t::iterator it = joint_ts_position_map.find(joint_id); |
114 |
|
115 |
if (it == joint_ts_position_map.end()){
|
116 |
printf("> humotion: no ts_position for joint id 0x%02X found\n", joint_id);
|
117 |
return TimestampedList();
|
118 |
} |
119 |
|
120 |
//ok fine, we found our value:
|
121 |
return it->second;
|
122 |
} |
123 |
|
124 |
//! return the timestamped float for the given joints speed
|
125 |
TimestampedList JointInterface::get_ts_speed(int joint_id){
|
126 |
//lock the tsd_list for this access. by doing this we assure
|
127 |
//that no other thread accessing this element can diturb the
|
128 |
//following atomic instructions:
|
129 |
mutex::scoped_lock scoped_lock(joint_ts_speed_map_access_mutex); |
130 |
|
131 |
//search map:
|
132 |
joint_tsl_map_t::iterator it = joint_ts_speed_map.find(joint_id); |
133 |
|
134 |
if (it == joint_ts_speed_map.end()){
|
135 |
printf("> humotion: no ts_speed for joint id 0x%02X found\n", joint_id);
|
136 |
return TimestampedList();
|
137 |
} |
138 |
|
139 |
//ok fine, we found our value:
|
140 |
return it->second;
|
141 |
} |
142 |
|
143 |
//! set framerate
|
144 |
void JointInterface::set_framerate(float f){ |
145 |
framerate = f; |
146 |
} |
147 |
|
148 |
//! enable all mouth joints
|
149 |
void JointInterface::enable_mouth_joints(){
|
150 |
//already enabled? skip this
|
151 |
if (mouth_enabled){
|
152 |
return;
|
153 |
} |
154 |
|
155 |
printf("> humotion: ENABLING MOUTH JOINTS\n");
|
156 |
enable_joint(ID_LIP_LEFT_UPPER); |
157 |
enable_joint(ID_LIP_LEFT_LOWER); |
158 |
enable_joint(ID_LIP_CENTER_UPPER); |
159 |
enable_joint(ID_LIP_CENTER_LOWER); |
160 |
enable_joint(ID_LIP_RIGHT_UPPER); |
161 |
enable_joint(ID_LIP_RIGHT_LOWER); |
162 |
mouth_enabled = true;
|
163 |
} |
164 |
|
165 |
|
166 |
//! disable all mouth joints
|
167 |
void JointInterface::disable_mouth_joints(){
|
168 |
//already disabled? skip this
|
169 |
if (!mouth_enabled){
|
170 |
return;
|
171 |
} |
172 |
|
173 |
printf("> humotion: DISABLING MOUTH JOINTS\n");
|
174 |
disable_joint(ID_LIP_LEFT_UPPER); |
175 |
disable_joint(ID_LIP_LEFT_LOWER); |
176 |
disable_joint(ID_LIP_CENTER_UPPER); |
177 |
disable_joint(ID_LIP_CENTER_LOWER); |
178 |
disable_joint(ID_LIP_RIGHT_UPPER); |
179 |
disable_joint(ID_LIP_RIGHT_LOWER); |
180 |
mouth_enabled = false;
|
181 |
} |
182 |
|
183 |
//! enable all gaze joints
|
184 |
void JointInterface::enable_gaze_joints(){
|
185 |
//already enabled? skip this
|
186 |
if (gaze_enabled){
|
187 |
return;
|
188 |
} |
189 |
|
190 |
printf("> humotion: ENABLING GAZE JOINTS\n");
|
191 |
enable_joint(ID_EYES_LEFT_LR); |
192 |
enable_joint(ID_EYES_RIGHT_LR); |
193 |
enable_joint(ID_EYES_BOTH_UD); |
194 |
|
195 |
enable_joint(ID_EYES_LEFT_LID_UPPER); |
196 |
enable_joint(ID_EYES_LEFT_LID_LOWER); |
197 |
enable_joint(ID_EYES_RIGHT_LID_UPPER); |
198 |
enable_joint(ID_EYES_RIGHT_LID_LOWER); |
199 |
|
200 |
enable_joint(ID_EYES_LEFT_BROW); |
201 |
enable_joint(ID_EYES_RIGHT_BROW); |
202 |
|
203 |
enable_joint(ID_NECK_PAN); |
204 |
enable_joint(ID_NECK_TILT); |
205 |
enable_joint(ID_NECK_ROLL); |
206 |
|
207 |
gaze_enabled = true;
|
208 |
} |
209 |
|
210 |
//! disable all gaze joints
|
211 |
void JointInterface::disable_gaze_joints(){
|
212 |
//already disabled? skip this
|
213 |
if (!gaze_enabled){
|
214 |
return;
|
215 |
} |
216 |
|
217 |
printf("> humotion: DISABLING GAZE JOINTS\n");
|
218 |
disable_joint(ID_EYES_LEFT_LR); |
219 |
disable_joint(ID_EYES_RIGHT_LR); |
220 |
disable_joint(ID_EYES_BOTH_UD); |
221 |
|
222 |
disable_joint(ID_EYES_LEFT_LID_UPPER); |
223 |
disable_joint(ID_EYES_LEFT_LID_LOWER); |
224 |
disable_joint(ID_EYES_RIGHT_LID_UPPER); |
225 |
disable_joint(ID_EYES_RIGHT_LID_LOWER); |
226 |
|
227 |
disable_joint(ID_EYES_LEFT_BROW); |
228 |
disable_joint(ID_EYES_RIGHT_BROW); |
229 |
|
230 |
disable_joint(ID_NECK_PAN); |
231 |
disable_joint(ID_NECK_TILT); |
232 |
disable_joint(ID_NECK_ROLL); |
233 |
|
234 |
gaze_enabled = false;
|
235 |
} |
236 |
|
237 |
//! fetch maximum allowable joint position
|
238 |
//! \return max position
|
239 |
float JointInterface::get_joint_max(int joint_id){ |
240 |
assert((joint_id > 0) && (joint_id < JOINT_ID_ENUM_SIZE));
|
241 |
return joint_max[joint_id];
|
242 |
} |
243 |
|
244 |
//! fetch minimum allowable joint position
|
245 |
//! \return min position
|
246 |
float JointInterface::get_joint_min(int joint_id){ |
247 |
assert((joint_id > 0) && (joint_id < JOINT_ID_ENUM_SIZE));
|
248 |
return joint_min[joint_id];
|
249 |
} |
250 |
|
251 |
//! check if joint position map is empty
|
252 |
//! \return true if empty
|
253 |
bool JointInterface::get_joint_position_map_empty(){
|
254 |
return (joint_ts_position_map.empty());
|
255 |
} |