humotion / examples / yarp_icub / src / icub_jointinterface.cpp @ ade7a207
History | View | Annotate | Download (19.569 KB)
1 | 6a2d467f | Simon Schulz | /*
|
---|---|---|---|
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 "humotion_yarp_icub/icub_faceinterface.h" |
||
29 | #include "humotion_yarp_icub/icub_jointinterface.h" |
||
30 | 0d0f5ca1 | Simon Schulz | |
31 | 8c6c1163 | Simon Schulz | #include <yarp/os/Property.h> |
32 | 6a2d467f | Simon Schulz | #include <string> |
33 | 372eec67 | Simon Schulz | |
34 | 35b3ca25 | Simon Schulz | using std::cout;
|
35 | 372eec67 | Simon Schulz | using std::cerr;
|
36 | using std::string; |
||
37 | 8c6c1163 | Simon Schulz | |
38 | //! constructor
|
||
39 | 372eec67 | Simon Schulz | iCubJointInterface::iCubJointInterface(string _scope) : humotion::server::JointInterface() {
|
40 | 8c6c1163 | Simon Schulz | scope = _scope; |
41 | 1a35abea | Simon Schulz | |
42 | 35b3ca25 | Simon Schulz | // add mappings from icub ids to humotion ids
|
43 | init_id_map(); |
||
44 | |||
45 | // initialise the pd controller for the velocity and position mixer
|
||
46 | init_pv_mix_pid(); |
||
47 | 87b50988 | Simon Schulz | |
48 | 35b3ca25 | Simon Schulz | // intantiate the face interface
|
49 | face_interface_ = new iCubFaceInterface(scope);
|
||
50 | 87b50988 | Simon Schulz | |
51 | 35b3ca25 | Simon Schulz | // intantiate the polydriver
|
52 | 372eec67 | Simon Schulz | yarp::os::Property options; |
53 | 8c6c1163 | Simon Schulz | options.put("device", "remote_controlboard"); |
54 | options.put("local", "/local/head"); |
||
55 | 35b3ca25 | Simon Schulz | options.put("remote", scope + "/head"); |
56 | yarp_polydriver_.open(options); |
||
57 | |||
58 | // fetch yarp views:
|
||
59 | bool success = true; |
||
60 | 6a2d467f | Simon Schulz | // success &= yarp_polydriver_.view(yarp_iencs_);
|
61 | // success &= yarp_polydriver_.view(yarp_ipos_);
|
||
62 | 35b3ca25 | Simon Schulz | success &= yarp_polydriver_.view(yarp_ivel_); |
63 | success &= yarp_polydriver_.view(yarp_ilimits_); |
||
64 | success &= yarp_polydriver_.view(yarp_pid_); |
||
65 | success &= yarp_polydriver_.view(yarp_amp_); |
||
66 | |||
67 | if (!success) {
|
||
68 | cout << "ERROR: failed to fetch one or more yarp views... exiting\n";
|
||
69 | 8c6c1163 | Simon Schulz | exit(EXIT_FAILURE); |
70 | } |
||
71 | |||
72 | |||
73 | 6a2d467f | Simon Schulz | // tell humotion about min/max joint values:
|
74 | 8c6c1163 | Simon Schulz | init_joints(); |
75 | |||
76 | 6a2d467f | Simon Schulz | // initialise joint controller
|
77 | 35b3ca25 | Simon Schulz | init_controller(); |
78 | } |
||
79 | |||
80 | //! destructor
|
||
81 | 6a2d467f | Simon Schulz | iCubJointInterface::~iCubJointInterface() { |
82 | // stop velocity controller on exit
|
||
83 | 18e9b892 | Simon Schulz | yarp_ivel_->stop(); |
84 | 35b3ca25 | Simon Schulz | } |
85 | |||
86 | //! init the controller that allows to write target angles or velocities
|
||
87 | void iCubJointInterface::init_controller() {
|
||
88 | int number_of_joints;
|
||
89 | 8c6c1163 | Simon Schulz | |
90 | 372eec67 | Simon Schulz | // use position controller, first fetch no of axes:
|
91 | yarp_ivel_->getAxes(&number_of_joints); |
||
92 | 8c6c1163 | Simon Schulz | |
93 | 372eec67 | Simon Schulz | // set ref acceleration to a value for all axes:
|
94 | yarp_commands_.resize(number_of_joints); |
||
95 | 18e9b892 | Simon Schulz | yarp_commands_ = 1e6;
|
96 | 372eec67 | Simon Schulz | yarp_ivel_->setRefAccelerations(yarp_commands_.data()); |
97 | yarp_ivel_->setVelocityMode(); |
||
98 | 8c6c1163 | Simon Schulz | } |
99 | |||
100 | 35b3ca25 | Simon Schulz | //! initialise icub joint id to humotion joint id mappings
|
101 | void iCubJointInterface::init_id_map() {
|
||
102 | insert_icupid_to_humotionid_mapping(ICUB_ID_LIP_LEFT_UPPER, ID_LIP_LEFT_UPPER); |
||
103 | insert_icupid_to_humotionid_mapping(ICUB_ID_LIP_LEFT_LOWER, ID_LIP_LEFT_LOWER); |
||
104 | insert_icupid_to_humotionid_mapping(ICUB_ID_LIP_CENTER_UPPER, ID_LIP_CENTER_UPPER); |
||
105 | insert_icupid_to_humotionid_mapping(ICUB_ID_LIP_CENTER_LOWER, ID_LIP_CENTER_LOWER); |
||
106 | insert_icupid_to_humotionid_mapping(ICUB_ID_LIP_RIGHT_UPPER, ID_LIP_RIGHT_UPPER); |
||
107 | insert_icupid_to_humotionid_mapping(ICUB_ID_LIP_RIGHT_LOWER, ID_LIP_RIGHT_LOWER); |
||
108 | insert_icupid_to_humotionid_mapping(ICUB_ID_NECK_PAN, ID_NECK_PAN); |
||
109 | insert_icupid_to_humotionid_mapping(ICUB_ID_NECK_TILT, ID_NECK_TILT); |
||
110 | insert_icupid_to_humotionid_mapping(ICUB_ID_NECK_ROLL, ID_NECK_ROLL); |
||
111 | // FIXME: remove this hack tha repurposes LEFT/RIGHT eye pan from humotion as vergence/pan
|
||
112 | insert_icupid_to_humotionid_mapping(ICUB_ID_EYES_PAN, ID_EYES_LEFT_LR); |
||
113 | insert_icupid_to_humotionid_mapping(ICUB_ID_EYES_VERGENCE, ID_EYES_RIGHT_LR); |
||
114 | insert_icupid_to_humotionid_mapping(ICUB_ID_EYES_BOTH_UD, ID_EYES_BOTH_UD); |
||
115 | insert_icupid_to_humotionid_mapping(ICUB_ID_EYES_LEFT_LID_LOWER, ID_EYES_LEFT_LID_LOWER); |
||
116 | insert_icupid_to_humotionid_mapping(ICUB_ID_EYES_LEFT_LID_UPPER, ID_EYES_LEFT_LID_UPPER); |
||
117 | insert_icupid_to_humotionid_mapping(ICUB_ID_EYES_LEFT_BROW, ID_EYES_LEFT_BROW); |
||
118 | insert_icupid_to_humotionid_mapping(ICUB_ID_EYES_RIGHT_LID_LOWER, ID_EYES_RIGHT_LID_LOWER); |
||
119 | 6a2d467f | Simon Schulz | insert_icupid_to_humotionid_mapping(ICUB_ID_EYES_RIGHT_LID_UPPER, ID_EYES_RIGHT_LID_UPPER); |
120 | 35b3ca25 | Simon Schulz | insert_icupid_to_humotionid_mapping(ICUB_ID_EYES_RIGHT_BROW, ID_EYES_RIGHT_BROW); |
121 | } |
||
122 | 8c6c1163 | Simon Schulz | |
123 | 35b3ca25 | Simon Schulz | //! initialize the position and velocity mixer PD controller
|
124 | void iCubJointInterface::init_pv_mix_pid() {
|
||
125 | // init control variables and last error variable for the internal
|
||
126 | // position and velocity mixer PD controller:
|
||
127 | pv_mix_pid_p_.resize(ICUB_JOINT_ID_ENUM_SIZE); |
||
128 | pv_mix_pid_d_.resize(ICUB_JOINT_ID_ENUM_SIZE); |
||
129 | pv_mix_last_error_.resize(ICUB_JOINT_ID_ENUM_SIZE); |
||
130 | 8c6c1163 | Simon Schulz | |
131 | 35b3ca25 | Simon Schulz | enum_id_bimap_t::const_iterator it; |
132 | 6a2d467f | Simon Schulz | for (it = enum_id_bimap.begin(); it != enum_id_bimap.end(); ++it) {
|
133 | 35b3ca25 | Simon Schulz | int id = it->left;
|
134 | 07e68eb7 | sschulz | pv_mix_pid_p_[id] = 5.5; |
135 | 35b3ca25 | Simon Schulz | pv_mix_pid_d_[id] = 0.3; |
136 | pv_mix_last_error_[id] = 0.0; |
||
137 | 8c6c1163 | Simon Schulz | } |
138 | 35b3ca25 | Simon Schulz | } |
139 | 8c6c1163 | Simon Schulz | |
140 | 35b3ca25 | Simon Schulz | //! add mapping from icub joint ids to humotion ids
|
141 | //! this might look strange at the first sight but we need to have a generic
|
||
142 | //! way to acces joints from libhumotion. therefore the lib uses its enum with ID_* enum ids
|
||
143 | //! to access the joints. now we need to define a mapping to map those to the icub motor ids.
|
||
144 | void iCubJointInterface::insert_icupid_to_humotionid_mapping(int icubid, int humotionid) { |
||
145 | enum_id_bimap.insert(enum_id_bimap_entry_t(icubid, humotionid)); |
||
146 | 8c6c1163 | Simon Schulz | } |
147 | |||
148 | |||
149 | 35b3ca25 | Simon Schulz | |
150 | |||
151 | 6a2d467f | Simon Schulz | void iCubJointInterface::run() {
|
152 | 35b3ca25 | Simon Schulz | float loop_duration_ms = 1000.0 / MAIN_LOOP_FREQUENCY; |
153 | iCubDataReceiver *data_receiver = new iCubDataReceiver(loop_duration_ms, this); |
||
154 | 8c6c1163 | Simon Schulz | data_receiver->start(); |
155 | } |
||
156 | |||
157 | 35b3ca25 | Simon Schulz | //! stores the target position & velocity of a given joint
|
158 | 8c6c1163 | Simon Schulz | //! \param enum id of joint
|
159 | //! \param float value
|
||
160 | 6a2d467f | Simon Schulz | void iCubJointInterface::publish_target(int humotion_id, float position, float velocity) { |
161 | 35b3ca25 | Simon Schulz | // special handler for eye joints
|
162 | if ((humotion_id == JointInterface::ID_EYES_LEFT_LR) ||
|
||
163 | 6a2d467f | Simon Schulz | (humotion_id == JointInterface::ID_EYES_RIGHT_LR)) { |
164 | 35b3ca25 | Simon Schulz | // the icub has a combined pan angle for both eyes, so seperate this:
|
165 | float target_position_left = get_target_position(JointInterface::ID_EYES_LEFT_LR);
|
||
166 | float target_position_right = get_target_position(JointInterface::ID_EYES_RIGHT_LR);
|
||
167 | float target_velocity_left = get_target_velocity(JointInterface::ID_EYES_LEFT_LR);
|
||
168 | float target_velocity_right = get_target_velocity(JointInterface::ID_EYES_RIGHT_LR);
|
||
169 | |||
170 | 6c028e11 | Simon Schulz | |
171 | 35b3ca25 | Simon Schulz | // calculate target angles
|
172 | 6c028e11 | Simon Schulz | float target_position_pan = (target_position_right + target_position_left) / 2; |
173 | float target_position_vergence = (target_position_right - target_position_left);
|
||
174 | |||
175 | 07e68eb7 | sschulz | /*cout << "LR " << target_position_left << " " << target_position_right <<
|
176 | " PAN " << target_position_pan << " VERGENCE " << target_position_vergence << "\n";*/
|
||
177 | 35b3ca25 | Simon Schulz | |
178 | // calculate target velocities
|
||
179 | // for now just use the same velocity for pan and vergence
|
||
180 | float target_velocity_pan = (target_velocity_left + target_velocity_right) / 2.0; |
||
181 | 18e9b892 | Simon Schulz | float target_velocity_vergence = target_velocity_left - target_velocity_right;
|
182 | 35b3ca25 | Simon Schulz | |
183 | store_icub_joint_target(ICUB_ID_EYES_PAN, |
||
184 | target_position_pan, target_velocity_pan); |
||
185 | store_icub_joint_target(ICUB_ID_EYES_VERGENCE, |
||
186 | 18e9b892 | Simon Schulz | target_position_vergence, target_velocity_vergence); |
187 | 6a2d467f | Simon Schulz | } else {
|
188 | 35b3ca25 | Simon Schulz | // convert to icub joint id
|
189 | int icub_id = convert_humotion_jointid_to_icub(humotion_id);
|
||
190 | // store target data
|
||
191 | store_icub_joint_target(icub_id, position, velocity); |
||
192 | 8c6c1163 | Simon Schulz | } |
193 | } |
||
194 | |||
195 | |||
196 | 35b3ca25 | Simon Schulz | //! set the target data for a given icub joint
|
197 | 8c6c1163 | Simon Schulz | //! \param id of joint
|
198 | //! \param float value of position
|
||
199 | 35b3ca25 | Simon Schulz | void iCubJointInterface::store_icub_joint_target(int icub_id, float position, float velocity) { |
200 | 07e68eb7 | sschulz | //cout << "store_icub_joint_target(" << icub_id << ", " << position << ", ..)\n";
|
201 | d3aa8ab3 | Simon Schulz | |
202 | 6a2d467f | Simon Schulz | if ((icub_id == ICUB_ID_NECK_PAN) || (icub_id == ICUB_ID_EYES_VERGENCE)) {
|
203 | 6c028e11 | Simon Schulz | // icub uses an inverted neck pan specification
|
204 | position = -position; |
||
205 | velocity = -velocity; |
||
206 | } |
||
207 | d3aa8ab3 | Simon Schulz | |
208 | // store values
|
||
209 | 35b3ca25 | Simon Schulz | target_angle_[icub_id] = position; |
210 | target_velocity_[icub_id] = velocity; |
||
211 | 8c6c1163 | Simon Schulz | } |
212 | |||
213 | //! execute a move in velocity mode
|
||
214 | //! \param id of joint
|
||
215 | //! \param angle
|
||
216 | 35b3ca25 | Simon Schulz | void iCubJointInterface::set_target_in_velocitymode(int icub_id) { |
217 | // fetch humotion id from icub joint id
|
||
218 | 6c028e11 | Simon Schulz | int humotion_id = convert_icub_jointid_to_humotion(icub_id);
|
219 | 7adf90be | Simon Schulz | |
220 | 35b3ca25 | Simon Schulz | // fetch the target velocity
|
221 | float target_velocity = target_velocity_[icub_id];
|
||
222 | 7adf90be | Simon Schulz | |
223 | 18e9b892 | Simon Schulz | float vmax = 350.0; |
224 | 35b3ca25 | Simon Schulz | if (target_velocity > vmax) target_velocity = vmax;
|
225 | if (target_velocity < -vmax) target_velocity = -vmax;
|
||
226 | 497d9d24 | Simon Schulz | |
227 | 6a2d467f | Simon Schulz | // execute:
|
228 | 18e9b892 | Simon Schulz | if ((icub_id != ICUB_ID_NECK_PAN)
|
229 | 708960ff | Simon Schulz | && (icub_id != ICUB_ID_EYES_BOTH_UD) |
230 | && (icub_id != ICUB_ID_NECK_TILT) |
||
231 | 18e9b892 | Simon Schulz | && (icub_id != ICUB_ID_EYES_PAN) |
232 | && (icub_id != ICUB_ID_EYES_VERGENCE) |
||
233 | 6a2d467f | Simon Schulz | // && (icub_id != ICUB_ID_NECK_TILT)
|
234 | ) { |
||
235 | 35b3ca25 | Simon Schulz | // limit to some joints for debugging...
|
236 | return;
|
||
237 | 18e9b892 | Simon Schulz | } |
238 | 8c6c1163 | Simon Schulz | |
239 | 35b3ca25 | Simon Schulz | // we now add a pd control loop for velocity moves in order to handle position errors
|
240 | 6a2d467f | Simon Schulz | // FIXME: add position interpolation into future. this requires to enable the velocity
|
241 | // broadcast in the torso and head ini file and fetch that velocity in the
|
||
242 | // icub_data_receiver as well. TODO: check if the can bus has enough bandwidth for that
|
||
243 | 35b3ca25 | Simon Schulz | |
244 | // first: fetch the timstamp of the last known position
|
||
245 | humotion::Timestamp data_ts = get_ts_position(humotion_id).get_last_timestamp(); |
||
246 | |||
247 | 18e9b892 | Simon Schulz | // fetch current position & velocity
|
248 | float current_position = get_ts_position(humotion_id).get_interpolated_value(data_ts);
|
||
249 | float current_velocity = get_ts_speed(humotion_id).get_interpolated_value(data_ts);
|
||
250 | |||
251 | // the icub has a combined eye pan actuator, therefore
|
||
252 | // we have to calculate pan angle and vergence based on the left and right target angles:
|
||
253 | if (icub_id == ICUB_ID_EYES_PAN) {
|
||
254 | // fetch timestamp
|
||
255 | data_ts = get_ts_position(ID_EYES_LEFT_LR).get_last_timestamp(); |
||
256 | |||
257 | // get the left and right positions
|
||
258 | float pos_left = get_ts_position(ID_EYES_LEFT_LR).get_interpolated_value(data_ts);
|
||
259 | float pos_right = get_ts_position(ID_EYES_RIGHT_LR).get_interpolated_value(data_ts);
|
||
260 | current_position = (pos_left + pos_right) / 2.0; |
||
261 | |||
262 | // same for velocities:
|
||
263 | float vel_left = get_ts_speed(ID_EYES_LEFT_LR).get_interpolated_value(data_ts);
|
||
264 | float vel_right = get_ts_speed(ID_EYES_RIGHT_LR).get_interpolated_value(data_ts);
|
||
265 | current_velocity = (vel_left + vel_right) / 2.0; |
||
266 | |||
267 | 6a2d467f | Simon Schulz | } else if (icub_id == ICUB_ID_EYES_VERGENCE) { |
268 | 18e9b892 | Simon Schulz | // fetch timestamp
|
269 | data_ts = get_ts_position(ID_EYES_LEFT_LR).get_last_timestamp(); |
||
270 | |||
271 | // get the left and right positions
|
||
272 | float pos_left = get_ts_position(ID_EYES_LEFT_LR).get_interpolated_value(data_ts);
|
||
273 | float pos_right = get_ts_position(ID_EYES_RIGHT_LR).get_interpolated_value(data_ts);
|
||
274 | |||
275 | current_position = pos_left - pos_right; |
||
276 | |||
277 | // same for velocities:
|
||
278 | float vel_left = get_ts_speed(ID_EYES_LEFT_LR).get_interpolated_value(data_ts);
|
||
279 | float vel_right = get_ts_speed(ID_EYES_RIGHT_LR).get_interpolated_value(data_ts);
|
||
280 | current_velocity = (vel_left - vel_right); |
||
281 | } |
||
282 | |||
283 | 35b3ca25 | Simon Schulz | // calculate position error:
|
284 | 18e9b892 | Simon Schulz | float position_error = target_angle_[icub_id] - current_position;
|
285 | 35b3ca25 | Simon Schulz | |
286 | // calculate d term
|
||
287 | float error_d = (position_error - pv_mix_last_error_[icub_id]) / (framerate*1000.0); |
||
288 | pv_mix_last_error_[icub_id] = position_error; |
||
289 | |||
290 | // finally do a PD loop to get the target velocity
|
||
291 | float pv_mix_velocity = pv_mix_pid_p_[icub_id] * position_error
|
||
292 | + pv_mix_pid_p_[icub_id]*error_d |
||
293 | + target_velocity; |
||
294 | |||
295 | 18e9b892 | Simon Schulz | |
296 | 6a2d467f | Simon Schulz | /*cout << "\n"
|
297 | 18e9b892 | Simon Schulz | << current_position << " "
|
298 | d3aa8ab3 | Simon Schulz | << target_angle_[icub_id] << " "
|
299 | 18e9b892 | Simon Schulz | << current_velocity << " "
|
300 | d3aa8ab3 | Simon Schulz | << pv_mix_velocity << " "
|
301 | << target_velocity << " "
|
||
302 | << position_error << " "
|
||
303 | 6a2d467f | Simon Schulz | << " PID" << icub_id << "\n";*/
|
304 | 35b3ca25 | Simon Schulz | |
305 | // execute velocity move
|
||
306 | 18e9b892 | Simon Schulz | bool success;
|
307 | int count = 0; |
||
308 | 6a2d467f | Simon Schulz | do {
|
309 | 18e9b892 | Simon Schulz | success = yarp_ivel_->velocityMove(icub_id, pv_mix_velocity); |
310 | 6a2d467f | Simon Schulz | if (count++ >= 10) { |
311 | 18e9b892 | Simon Schulz | cerr << "ERROR: failed to send velocity move command! gave up after 10 trials\n";
|
312 | yarp_ivel_->stop(); |
||
313 | exit(EXIT_FAILURE); |
||
314 | } |
||
315 | 6a2d467f | Simon Schulz | } while (!success);
|
316 | 8c6c1163 | Simon Schulz | } |
317 | |||
318 | //! actually execute the scheduled motion commands
|
||
319 | 6a2d467f | Simon Schulz | void iCubJointInterface::execute_motion() {
|
320 | 372eec67 | Simon Schulz | // set up neck and eye motion commands in velocitymode
|
321 | 6a2d467f | Simon Schulz | for (int i = ICUB_ID_NECK_TILT; i <= ICUB_ID_EYES_VERGENCE; i++) { |
322 | 372eec67 | Simon Schulz | set_target_in_velocitymode(i); |
323 | 8c6c1163 | Simon Schulz | } |
324 | 18e9b892 | Simon Schulz | /*
|
325 | 1f748ce7 | Simon Schulz | // eyelids: unfortuantely the icub has only 1dof for eyelids
|
326 | // therefore we can only use an opening value
|
||
327 | float opening_left = target_angle_[ICUB_ID_EYES_LEFT_LID_UPPER]
|
||
328 | - target_angle_[ICUB_ID_EYES_LEFT_LID_LOWER];
|
||
329 | float opening_right = target_angle_[ICUB_ID_EYES_RIGHT_LID_UPPER]
|
||
330 | - target_angle_[ICUB_ID_EYES_RIGHT_LID_LOWER];
|
||
331 | float opening = (opening_left + opening_right) / 2.0;
|
||
332 | // send it to icub face if
|
||
333 | face_interface_->set_eyelid_angle(opening);
|
||
334 | 8c6c1163 | Simon Schulz | |
335 | //eyebrows are set using a special command as well:
|
||
336 | 35b3ca25 | Simon Schulz | face_interface_->set_eyebrow_angle(ICUB_ID_EYES_LEFT_BROW, target_angle_);
|
337 | face_interface_->set_eyebrow_angle(ICUB_ID_EYES_RIGHT_BROW, target_angle_);
|
||
338 | 8c6c1163 | Simon Schulz | |
339 | //mouth
|
||
340 | 35b3ca25 | Simon Schulz | face_interface_->set_mouth(target_angle_);
|
341 | 18e9b892 | Simon Schulz | */
|
342 | 8c6c1163 | Simon Schulz | |
343 | 6a2d467f | Simon Schulz | // store joint values which we do not handle on icub here:
|
344 | 35b3ca25 | Simon Schulz | double timestamp = humotion::Timestamp::now().to_seconds();
|
345 | 6a2d467f | Simon Schulz | JointInterface::store_incoming_position(ID_LIP_LEFT_UPPER, |
346 | target_angle_[ICUB_ID_LIP_LEFT_UPPER], timestamp); |
||
347 | JointInterface::store_incoming_position(ID_LIP_LEFT_LOWER, |
||
348 | target_angle_[ICUB_ID_LIP_LEFT_LOWER], timestamp); |
||
349 | JointInterface::store_incoming_position(ID_LIP_CENTER_UPPER, |
||
350 | target_angle_[ICUB_ID_LIP_CENTER_UPPER], timestamp); |
||
351 | JointInterface::store_incoming_position(ID_LIP_CENTER_LOWER, |
||
352 | target_angle_[ICUB_ID_LIP_CENTER_LOWER], timestamp); |
||
353 | JointInterface::store_incoming_position(ID_LIP_RIGHT_UPPER, |
||
354 | target_angle_[ICUB_ID_LIP_RIGHT_UPPER], timestamp); |
||
355 | JointInterface::store_incoming_position(ID_LIP_RIGHT_LOWER, |
||
356 | target_angle_[ICUB_ID_LIP_RIGHT_LOWER], timestamp); |
||
357 | 8c6c1163 | Simon Schulz | } |
358 | |||
359 | |||
360 | 372eec67 | Simon Schulz | void iCubJointInterface::set_joint_enable_state(int humotion_id, bool enable) { |
361 | int icub_jointid = convert_humotion_jointid_to_icub(humotion_id);
|
||
362 | /*
|
||
363 | 7adf90be | Simon Schulz | switch(e){
|
364 | default:
|
||
365 | break;
|
||
366 | 8c6c1163 | Simon Schulz | |
367 | 7adf90be | Simon Schulz | case(ID_NECK_PAN):
|
368 | icub_jointid = ICUB_ID_NECK_PAN;
|
||
369 | break;
|
||
370 | 8c6c1163 | Simon Schulz | |
371 | 7adf90be | Simon Schulz | case(ID_NECK_TILT):
|
372 | icub_jointid = ICUB_ID_NECK_TILT;
|
||
373 | break;
|
||
374 | 8c6c1163 | Simon Schulz | |
375 | 7adf90be | Simon Schulz | case(ID_NECK_ROLL):
|
376 | icub_jointid = ICUB_ID_NECK_ROLL;
|
||
377 | break;
|
||
378 | |||
379 | case(ID_EYES_BOTH_UD):
|
||
380 | icub_jointid = ICUB_ID_EYES_BOTH_UD;
|
||
381 | break;
|
||
382 | |||
383 | // icub handles eyes as pan angle + vergence...
|
||
384 | // -> hack: left eye enables pan and right eye enables vergence
|
||
385 | case(ID_EYES_LEFT_LR):
|
||
386 | icub_jointid = ICUB_ID_EYES_PAN;
|
||
387 | break;
|
||
388 | |||
389 | case(ID_EYES_RIGHT_LR):
|
||
390 | icub_jointid = ICUB_ID_EYES_VERGENCE;
|
||
391 | break;
|
||
392 | 8c6c1163 | Simon Schulz | }
|
393 | 372eec67 | Simon Schulz | */
|
394 | 8c6c1163 | Simon Schulz | |
395 | 372eec67 | Simon Schulz | if ((icub_jointid != -1) && (icub_jointid <= ICUB_ID_EYES_VERGENCE)) { |
396 | 7adf90be | Simon Schulz | if (enable) {
|
397 | 35b3ca25 | Simon Schulz | yarp_amp_->enableAmp(icub_jointid); |
398 | yarp_pid_->enablePid(icub_jointid); |
||
399 | 7adf90be | Simon Schulz | } else {
|
400 | 35b3ca25 | Simon Schulz | yarp_pid_->disablePid(icub_jointid); |
401 | yarp_amp_->disableAmp(icub_jointid); |
||
402 | 7adf90be | Simon Schulz | } |
403 | } |
||
404 | 8c6c1163 | Simon Schulz | } |
405 | |||
406 | //! prepare and enable a joint
|
||
407 | //! NOTE: this should also prefill the min/max positions for this joint
|
||
408 | //! \param the enum id of a joint
|
||
409 | 6a2d467f | Simon Schulz | void iCubJointInterface::enable_joint(int e) { |
410 | 7adf90be | Simon Schulz | set_joint_enable_state(e, true);
|
411 | } |
||
412 | 8c6c1163 | Simon Schulz | |
413 | 7adf90be | Simon Schulz | //! shutdown and disable a joint
|
414 | //! \param the enum id of a joint
|
||
415 | 6a2d467f | Simon Schulz | void iCubJointInterface::disable_joint(int e) { |
416 | 7adf90be | Simon Schulz | set_joint_enable_state(e, false);
|
417 | 8c6c1163 | Simon Schulz | } |
418 | |||
419 | 6a2d467f | Simon Schulz | void iCubJointInterface::store_min_max(yarp::dev::IControlLimits *ilimits, int icub_id) { |
420 | 8c6c1163 | Simon Schulz | double min, max;
|
421 | 372eec67 | Simon Schulz | int humotion_id = convert_icub_jointid_to_humotion(icub_id);
|
422 | |||
423 | ilimits->getLimits(icub_id, &min, &max); |
||
424 | joint_min[humotion_id] = min; |
||
425 | joint_max[humotion_id] = max; |
||
426 | 8c6c1163 | Simon Schulz | } |
427 | |||
428 | //! initialise a joint (set up controller mode etc)
|
||
429 | 6a2d467f | Simon Schulz | void iCubJointInterface::init_joints() {
|
430 | 372eec67 | Simon Schulz | store_min_max(yarp_ilimits_, ICUB_ID_NECK_TILT); |
431 | store_min_max(yarp_ilimits_, ICUB_ID_NECK_ROLL); |
||
432 | store_min_max(yarp_ilimits_, ICUB_ID_NECK_PAN); |
||
433 | store_min_max(yarp_ilimits_, ICUB_ID_EYES_BOTH_UD); |
||
434 | 8c6c1163 | Simon Schulz | |
435 | 6a2d467f | Simon Schulz | // icub handles eyes differently, we have to set pan angle + vergence
|
436 | 8c6c1163 | Simon Schulz | double pan_min, pan_max, vergence_min, vergence_max;
|
437 | 35b3ca25 | Simon Schulz | yarp_ilimits_->getLimits(ICUB_ID_EYES_PAN, &pan_min, &pan_max); |
438 | yarp_ilimits_->getLimits(ICUB_ID_EYES_VERGENCE, &vergence_min, &vergence_max); |
||
439 | 8c6c1163 | Simon Schulz | |
440 | 6a2d467f | Simon Schulz | // this is not 100% correct, should be fixed
|
441 | joint_min[ID_EYES_LEFT_LR] = pan_min; // - vergence_max/2;
|
||
442 | joint_max[ID_EYES_LEFT_LR] = pan_max; // - vergence_max/2;
|
||
443 | 8c6c1163 | Simon Schulz | joint_min[ID_EYES_RIGHT_LR] = joint_min[ID_EYES_LEFT_LR]; |
444 | joint_max[ID_EYES_RIGHT_LR] = joint_max[ID_EYES_LEFT_LR]; |
||
445 | |||
446 | 6a2d467f | Simon Schulz | // eyelids
|
447 | joint_min[ID_EYES_RIGHT_LID_UPPER] = -50; // 24-30; |
||
448 | joint_max[ID_EYES_RIGHT_LID_UPPER] = 50; // 48-30; |
||
449 | // lid_angle = joint_max[ID_EYES_RIGHT_LID_UPPER];
|
||
450 | 8c6c1163 | Simon Schulz | |
451 | 6a2d467f | Simon Schulz | // eyebrows
|
452 | 8c6c1163 | Simon Schulz | joint_min[ID_EYES_LEFT_BROW] = -50;
|
453 | joint_max[ID_EYES_LEFT_BROW] = 50;
|
||
454 | joint_min[ID_EYES_RIGHT_BROW] = joint_min[ID_EYES_LEFT_BROW]; |
||
455 | joint_max[ID_EYES_RIGHT_BROW] = joint_max[ID_EYES_LEFT_BROW]; |
||
456 | |||
457 | 6a2d467f | Simon Schulz | // mouth
|
458 | 8c6c1163 | Simon Schulz | joint_min[ID_LIP_CENTER_UPPER] = 5;
|
459 | joint_max[ID_LIP_CENTER_UPPER] = 50;
|
||
460 | joint_min[ID_LIP_CENTER_LOWER] = 5;
|
||
461 | joint_max[ID_LIP_CENTER_LOWER] = 50;
|
||
462 | joint_min[ID_LIP_LEFT_UPPER] = 5;
|
||
463 | joint_max[ID_LIP_LEFT_UPPER] = 50;
|
||
464 | joint_min[ID_LIP_LEFT_LOWER] = 5;
|
||
465 | joint_max[ID_LIP_LEFT_LOWER] = 50;
|
||
466 | joint_min[ID_LIP_RIGHT_UPPER] = 5;
|
||
467 | joint_max[ID_LIP_RIGHT_UPPER] = 50;
|
||
468 | joint_min[ID_LIP_RIGHT_LOWER] = 5;
|
||
469 | joint_max[ID_LIP_RIGHT_LOWER] = 50;
|
||
470 | 35b3ca25 | Simon Schulz | } |
471 | |||
472 | //! conversion table for humotion joint id to icub joint id
|
||
473 | //! \param int value for humotion joint id from JointInterface::JOINT_ID_ENUM
|
||
474 | //! \return int value of icub joint id
|
||
475 | 6a2d467f | Simon Schulz | int iCubJointInterface::convert_humotion_jointid_to_icub(int humotion_id) { |
476 | 35b3ca25 | Simon Schulz | enum_id_bimap_t::right_const_iterator it = enum_id_bimap.right.find(humotion_id); |
477 | 6a2d467f | Simon Schulz | if (it == enum_id_bimap.right.end()) {
|
478 | // key does not exist
|
||
479 | cerr << "ERROR: invalid humotion joint id (" << humotion_id <<
|
||
480 | ") given. can not convert this. exiting\n";
|
||
481 | 35b3ca25 | Simon Schulz | exit(EXIT_FAILURE); |
482 | } |
||
483 | return it->second;
|
||
484 | } |
||
485 | 8c6c1163 | Simon Schulz | |
486 | |||
487 | 35b3ca25 | Simon Schulz | //! conversion table for icub joint id to humotion joint id
|
488 | //! \param int value of icub joint id
|
||
489 | //! \return int value of humotion joint id from JointInterface::JOINT_ID_ENUM
|
||
490 | 6a2d467f | Simon Schulz | int iCubJointInterface::convert_icub_jointid_to_humotion(int icub_id) { |
491 | 35b3ca25 | Simon Schulz | enum_id_bimap_t::left_const_iterator it = enum_id_bimap.left.find(icub_id); |
492 | 6a2d467f | Simon Schulz | if (it == enum_id_bimap.left.end()) {
|
493 | // key does not exist
|
||
494 | 35b3ca25 | Simon Schulz | cout << "ERROR: invalid icub joint id given. can not convert this. exiting\n";
|
495 | exit(EXIT_FAILURE); |
||
496 | } |
||
497 | return it->second;
|
||
498 | 8c6c1163 | Simon Schulz | } |