Revision 0c8d22a5 src/server/joint_interface.cpp
src/server/joint_interface.cpp | ||
---|---|---|
25 | 25 |
* Excellence Initiative. |
26 | 26 |
*/ |
27 | 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; |
|
28 |
#include "humotion/server/joint_interface.h" |
|
29 |
#include "humotion/server/controller.h" |
|
35 | 30 |
|
31 |
using boost::mutex; |
|
32 |
using humotion::server::JointInterface; |
|
36 | 33 |
|
37 | 34 |
//! constructor |
38 |
JointInterface::JointInterface(){ |
|
35 |
JointInterface::JointInterface() {
|
|
39 | 36 |
framerate = 50.0; |
40 | 37 |
mouth_enabled = false; |
41 | 38 |
gaze_enabled = false; |
42 | 39 |
} |
43 | 40 |
|
44 | 41 |
//! destructor |
45 |
JointInterface::~JointInterface(){ |
|
42 |
JointInterface::~JointInterface() {
|
|
46 | 43 |
} |
47 | 44 |
|
48 | 45 |
//! set joint target position |
49 | 46 |
//! \param joint_id of joint |
50 | 47 |
//! \param float position |
51 |
void JointInterface::set_target(int joint_id, float position, float velocity){ |
|
48 |
void JointInterface::set_target(int joint_id, float position, float velocity) {
|
|
52 | 49 |
assert(joint_id < JOINT_ID_ENUM_SIZE); |
53 | 50 |
|
54 |
//update current value |
|
51 |
// update current value
|
|
55 | 52 |
joint_target_position_[joint_id] = position; |
56 | 53 |
joint_target_velocity_[joint_id] = velocity; |
57 | 54 |
} |
58 | 55 |
|
59 | 56 |
//! fetch target position |
60 | 57 |
//! \param joint_id of joint |
61 |
float JointInterface::get_target_position(int joint_id){ |
|
58 |
float JointInterface::get_target_position(int joint_id) {
|
|
62 | 59 |
assert(joint_id < JOINT_ID_ENUM_SIZE); |
63 | 60 |
return joint_target_position_[joint_id]; |
64 | 61 |
} |
65 | 62 |
|
66 | 63 |
//! fetch target velocity |
67 | 64 |
//! \param joint_id of joint |
68 |
float JointInterface::get_target_velocity(int joint_id){ |
|
65 |
float JointInterface::get_target_velocity(int joint_id) {
|
|
69 | 66 |
assert(joint_id < JOINT_ID_ENUM_SIZE); |
70 | 67 |
return joint_target_velocity_[joint_id]; |
71 | 68 |
} |
... | ... | |
74 | 71 |
//! \param joint name |
75 | 72 |
//! \param position |
76 | 73 |
//! \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()); |
|
74 |
void JointInterface::store_incoming_position(int joint_id, float position, Timestamp timestamp) { |
|
75 |
// lock the tsd_list for this access. by doing this we assure |
|
76 |
// that no other thread accessing this element can diturb the |
|
77 |
// following atomic instructions: |
|
78 |
mutex::scoped_lock sl(joint_ts_position_map_access_mutex); |
|
79 |
|
|
80 |
// printf("> humotion: incoming joint position for joint id 0x%02X " |
|
81 |
// "= %4.2f (ts=%.2f)\n",joint_id,position,timestamp.to_seconds()); |
|
84 | 82 |
joint_ts_position_map[joint_id].insert(timestamp, position); |
85 | 83 |
|
86 | 84 |
incoming_position_count++; |
... | ... | |
89 | 87 |
//! return incoming position data count & clear this counter |
90 | 88 |
//! this can be used as a keep alive status check |
91 | 89 |
//! \return number of incoming joint positions since the last call |
92 |
unsigned int JointInterface::get_and_clear_incoming_position_count(){ |
|
90 |
unsigned int JointInterface::get_and_clear_incoming_position_count() {
|
|
93 | 91 |
unsigned int i = incoming_position_count; |
94 | 92 |
incoming_position_count = 0; |
95 | 93 |
return i; |
... | ... | |
99 | 97 |
//! \param joint name |
100 | 98 |
//! \param speed |
101 | 99 |
//! \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: |
|
100 |
void JointInterface::store_incoming_velocity(int joint_id, float velocity, Timestamp timestamp) {
|
|
101 |
// lock the tsd_list for this access. by doing this we assure
|
|
102 |
// that no other thread accessing this element can disturb the
|
|
103 |
// following atomic instructions:
|
|
106 | 104 |
mutex::scoped_lock scoped_lock(joint_ts_speed_map_access_mutex); |
107 | 105 |
|
108 |
//printf("> humotion: incoming joint velocity for joint id 0x%02X = %4.2f (ts=%.2f)\n",joint_id,velocity,timestamp.to_seconds()); |
|
106 |
// printf("> humotion: incoming joint velocity for joint id 0x%02X = %4.2f " |
|
107 |
// "(ts=%.2f)\n",joint_id,velocity,timestamp.to_seconds()); |
|
109 | 108 |
joint_ts_speed_map[joint_id].insert(timestamp, velocity); |
110 | 109 |
} |
111 | 110 |
|
112 | 111 |
//! 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);
|
|
112 |
humotion::TimestampedList JointInterface::get_ts_position(int joint_id) {
|
|
113 |
// lock the tsd_list for this access. by doing this we assure
|
|
114 |
// that no other thread accessing this element can disturb the
|
|
115 |
// following atomic instructions
|
|
116 |
mutex::scoped_lock sl(joint_ts_position_map_access_mutex);
|
|
118 | 117 |
|
119 |
//search map:
|
|
118 |
// search map
|
|
120 | 119 |
joint_tsl_map_t::iterator it = joint_ts_position_map.find(joint_id); |
121 | 120 |
|
122 |
if (it == joint_ts_position_map.end()){ |
|
121 |
if (it == joint_ts_position_map.end()) {
|
|
123 | 122 |
printf("> humotion: no ts_position for joint id 0x%02X found\n", joint_id); |
124 | 123 |
return TimestampedList(); |
125 | 124 |
} |
126 | 125 |
|
127 |
//ok fine, we found our value:
|
|
126 |
// ok fine, we found the requested value
|
|
128 | 127 |
return it->second; |
129 | 128 |
} |
130 | 129 |
|
131 | 130 |
//! 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);
|
|
131 |
humotion::TimestampedList JointInterface::get_ts_speed(int joint_id) {
|
|
132 |
// lock the tsd_list for this access. by doing this we assure
|
|
133 |
// that no other thread accessing this element can diturb the
|
|
134 |
// following atomic instructions
|
|
135 |
mutex::scoped_lock sl(joint_ts_speed_map_access_mutex);
|
|
137 | 136 |
|
138 |
//search map:
|
|
137 |
// search map
|
|
139 | 138 |
joint_tsl_map_t::iterator it = joint_ts_speed_map.find(joint_id); |
140 | 139 |
|
141 |
if (it == joint_ts_speed_map.end()){ |
|
140 |
if (it == joint_ts_speed_map.end()) {
|
|
142 | 141 |
printf("> humotion: no ts_speed for joint id 0x%02X found\n", joint_id); |
143 |
return TimestampedList(); |
|
142 |
return humotion::TimestampedList();
|
|
144 | 143 |
} |
145 | 144 |
|
146 |
//ok fine, we found our value:
|
|
145 |
// ok fine, we found our value
|
|
147 | 146 |
return it->second; |
148 | 147 |
} |
149 | 148 |
|
150 | 149 |
//! set framerate |
151 |
void JointInterface::set_framerate(float f){ |
|
150 |
void JointInterface::set_framerate(float f) {
|
|
152 | 151 |
framerate = f; |
153 | 152 |
} |
154 | 153 |
|
155 | 154 |
//! enable all mouth joints |
156 |
void JointInterface::enable_mouth_joints(){ |
|
157 |
//already enabled? skip this |
|
158 |
if (mouth_enabled){ |
|
155 |
void JointInterface::enable_mouth_joints() {
|
|
156 |
// already enabled? skip this
|
|
157 |
if (mouth_enabled) {
|
|
159 | 158 |
return; |
160 | 159 |
} |
161 | 160 |
|
... | ... | |
171 | 170 |
|
172 | 171 |
|
173 | 172 |
//! disable all mouth joints |
174 |
void JointInterface::disable_mouth_joints(){ |
|
175 |
//already disabled? skip this |
|
176 |
if (!mouth_enabled){ |
|
173 |
void JointInterface::disable_mouth_joints() {
|
|
174 |
// already disabled? skip this
|
|
175 |
if (!mouth_enabled) {
|
|
177 | 176 |
return; |
178 | 177 |
} |
179 | 178 |
|
... | ... | |
188 | 187 |
} |
189 | 188 |
|
190 | 189 |
//! enable all gaze joints |
191 |
void JointInterface::enable_gaze_joints(){ |
|
192 |
//already enabled? skip this |
|
193 |
if (gaze_enabled){ |
|
190 |
void JointInterface::enable_gaze_joints() {
|
|
191 |
// already enabled? skip this
|
|
192 |
if (gaze_enabled) {
|
|
194 | 193 |
return; |
195 | 194 |
} |
196 | 195 |
|
... | ... | |
215 | 214 |
} |
216 | 215 |
|
217 | 216 |
//! disable all gaze joints |
218 |
void JointInterface::disable_gaze_joints(){ |
|
219 |
//already disabled? skip this |
|
220 |
if (!gaze_enabled){ |
|
217 |
void JointInterface::disable_gaze_joints() {
|
|
218 |
// already disabled? skip this
|
|
219 |
if (!gaze_enabled) {
|
|
221 | 220 |
return; |
222 | 221 |
} |
223 | 222 |
|
... | ... | |
243 | 242 |
|
244 | 243 |
//! fetch maximum allowed joint position |
245 | 244 |
//! \return max position |
246 |
float JointInterface::get_joint_max(int joint_id){ |
|
245 |
float JointInterface::get_joint_max(int joint_id) {
|
|
247 | 246 |
assert((joint_id > 0) && (joint_id < JOINT_ID_ENUM_SIZE)); |
248 | 247 |
return joint_max[joint_id]; |
249 | 248 |
} |
250 | 249 |
|
251 | 250 |
//! fetch minimum allowed joint position |
252 | 251 |
//! \return min position |
253 |
float JointInterface::get_joint_min(int joint_id){ |
|
252 |
float JointInterface::get_joint_min(int joint_id) {
|
|
254 | 253 |
assert((joint_id > 0) && (joint_id < JOINT_ID_ENUM_SIZE)); |
255 | 254 |
return joint_min[joint_id]; |
256 | 255 |
} |
257 | 256 |
|
258 | 257 |
//! check if joint position map is empty |
259 | 258 |
//! \return true if empty |
260 |
bool JointInterface::get_joint_position_map_empty(){ |
|
259 |
bool JointInterface::get_joint_position_map_empty() {
|
|
261 | 260 |
return (joint_ts_position_map.empty()); |
262 | 261 |
} |
263 | 262 |
|
Also available in: Unified diff