Revision 473a6a6c examples/meka/src/mekajointinterface.cpp
examples/meka/src/mekajointinterface.cpp | ||
---|---|---|
4 | 4 |
//WARNING: DO NOT CHANGE THIS; VELOCITYMODE IS NOT YET IMPLEMENTED |
5 | 5 |
#define POSITION_CONTROL 1 |
6 | 6 |
|
7 |
void MekaJointInterface::incoming_jointstates(const sensor_msgs::JointState & msg){ |
|
8 |
//joint_pos_global = msg.position[3]; |
|
9 |
cout << msg; |
|
10 |
} |
|
11 |
|
|
7 | 12 |
//! constructor |
8 | 13 |
MekaJointInterface::MekaJointInterface(string _scope) : humotion::server::JointInterface(){ |
9 | 14 |
scope = _scope; |
10 | 15 |
|
16 |
//subscribe to meka joint states |
|
17 |
ros::NodeHandle n; |
|
18 |
joint_state_subscriber = n.subscribe(scope + "joint_states", 150, &MekaJointInterface::incoming_jointstates , this); |
|
19 |
|
|
20 |
|
|
11 | 21 |
//add mapping from ids to enums: |
12 | 22 |
//this might look strange at the first sight but we need to have a generic |
13 | 23 |
//way to acces joints from libhumotion. therefore the lib uses its enum with ID_* enum ids |
... | ... | |
103 | 113 |
MekaJointInterface::~MekaJointInterface(){ |
104 | 114 |
} |
105 | 115 |
|
106 |
/* |
|
116 |
|
|
117 |
|
|
118 |
void MekaJointInterface::run(){ |
|
119 |
//iCubDataReceiver *data_receiver = new iCubDataReceiver(10/*1000.0 / MAIN_LOOP_FREQUENCY*/, iencs, this); |
|
120 |
//data_receiver->start(); |
|
121 |
} |
|
122 |
|
|
123 |
|
|
124 |
//! set the target position of a joint |
|
125 |
//! \param enum id of joint |
|
126 |
//! \param float value |
|
127 |
void MekaJointInterface::publish_target_position(int e){ |
|
128 |
#if 0 |
|
129 |
//first: convert humotion enum to our enum: |
|
130 |
int id = convert_enum_to_motorid(e); |
|
131 |
if (id == -1){ |
|
132 |
return; //we are not interested in that data, so we just return here |
|
133 |
} |
|
134 |
|
|
135 |
if (id == ICUB_ID_NECK_PAN){ |
|
136 |
//PAN seems to be swapped |
|
137 |
store_joint(ICUB_ID_NECK_PAN, -joint_target[e]); |
|
138 |
}else if ((id == ICUB_ID_EYES_LEFT_LR) || ( id == ICUB_ID_EYES_RIGHT_LR)){ |
|
139 |
//icub handles eyes differently, we have to set pan angle + vergence |
|
140 |
float pan = (joint_target[ID_EYES_LEFT_LR] + joint_target[ID_EYES_RIGHT_LR]) / 2; |
|
141 |
float vergence = (joint_target[ID_EYES_LEFT_LR] - joint_target[ID_EYES_RIGHT_LR]); |
|
142 |
//printf("EYEDBG %3.2f %3.2f --_> pan %3.2f verg=%3.2f\n",joint_target[ID_EYES_LEFT_LR], joint_target[ID_EYES_RIGHT_LR],pan,vergence); |
|
143 |
|
|
144 |
store_joint(ICUB_ID_EYES_PAN, pan); |
|
145 |
store_joint(ICUB_ID_EYES_VERGENCE, vergence); |
|
146 |
}else{ |
|
147 |
store_joint(id, joint_target[e]); |
|
148 |
} |
|
149 |
#endif |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
//! actually execute the scheduled motion commands |
|
154 |
void MekaJointInterface::execute_motion(){ |
|
155 |
#if 0 |
|
156 |
// set up neck and eye motion commands: |
|
157 |
if (POSITION_CONTROL){ |
|
158 |
//position control |
|
159 |
for(int i=ICUB_ID_NECK_TILT; i<=ICUB_ID_EYES_VERGENCE; i++){ |
|
160 |
set_target_in_positionmode(i, target_angle[i]); |
|
161 |
} |
|
162 |
}else{ |
|
163 |
//velocity control |
|
164 |
for(int i=ICUB_ID_NECK_TILT; i<=ICUB_ID_EYES_VERGENCE; i++){ |
|
165 |
set_target_in_velocitymode(i, target_angle[i]); |
|
166 |
} |
|
167 |
} |
|
168 |
//printf("> TARGET PAN = %3.2f\n",target_angle[ICUB_ID_NECK_PAN]); |
|
169 |
|
|
170 |
|
|
171 |
//eyelids: unfortuantely the icub has only 1dof for eyelids, so we use only one dof here: |
|
172 |
set_eyelid_angle(target_angle[ICUB_ID_EYES_RIGHT_LID_UPPER]); |
|
173 |
|
|
174 |
//eyebrows are set using a special command as well: |
|
175 |
set_eyebrow_angle(ICUB_ID_EYES_LEFT_BROW); |
|
176 |
set_eyebrow_angle(ICUB_ID_EYES_RIGHT_BROW); |
|
177 |
|
|
178 |
//mouth |
|
179 |
set_mouth(); |
|
180 |
|
|
181 |
#endif |
|
182 |
} |
|
183 |
|
|
184 |
|
|
185 |
//! prepare and enable a joint |
|
186 |
//! NOTE: this should also prefill the min/max positions for this joint |
|
187 |
//! \param the enum id of a joint |
|
188 |
void MekaJointInterface::enable_joint(int e){ |
|
189 |
#if 0 |
|
190 |
//FIXME ADD THIS: |
|
191 |
// enable the amplifier and the pid controller on each joint |
|
192 |
/*for (i = 0; i < nj; i++) { |
|
193 |
amp->enableAmp(i); |
|
194 |
pid->enablePid(i); |
|
195 |
}*/ |
|
196 |
|
|
197 |
|
|
198 |
//set up smooth motion controller |
|
199 |
//step1: set up framerate |
|
200 |
//dev->set_register_blocking(XSC3_REGISTER_PID_RAMP, framerate, true); |
|
201 |
|
|
202 |
//step2: set controllertype: |
|
203 |
//printf("> activating smooth motion control for joint id 0x%02X (%s)\n", motor_id, joint_name.c_str()); |
|
204 |
//dev->set_register_blocking(XSC3_REGISTER_PID_CONTROLLER, XSC3_PROTOCOL_PID_CONTROLLERTYPE_SMOOTH_PLAYBACK, true); |
|
205 |
|
|
206 |
//step3: set pid controller: |
|
207 |
/*if ((e == ID_LIP_LEFT_UPPER) || (e == ID_LIP_LEFT_LOWER) || (e == ID_LIP_CENTER_UPPER) || (e == ID_LIP_CENTER_LOWER) || (e == ID_LIP_RIGHT_UPPER) || (e == ID_LIP_RIGHT_LOWER)){ |
|
208 |
printf("> fixing PID i controller value for smooth motion (FIXME: restore old value!!)\n"); |
|
209 |
dev->set_register_blocking(XSC3_REGISTER_CONST_I, 10, true); |
|
210 |
}*/ |
|
211 |
|
|
212 |
//uint16_t result = dev->get_register_blocking_raw(XSC3_REGISTER_PID_CONTROLLER); |
|
213 |
|
|
214 |
//check if setting pid controllertype was successfull: |
|
215 |
/*if (result != XSC3_PROTOCOL_PID_CONTROLLERTYPE_SMOOTH_PLAYBACK){ |
|
216 |
printf("> failed to set smooth motion controller for joint %s (res=0x%04X)\n",joint_name.c_str(),result); |
|
217 |
exit(1); |
|
218 |
}*/ |
|
219 |
|
|
220 |
//fetch min/max: |
|
221 |
// init_joint(e); |
|
222 |
|
|
223 |
//ok fine, now enable motor: |
|
224 |
//printf("> enabling motor %s\n", joint_name.c_str()); |
|
225 |
//dev->set_register_blocking(XSC3_REGISTER_STATUS, XSC3_PROTOCOL_STATUS_BITMASK_MOTOR_ENABLE, true); |
|
226 |
#endif |
|
227 |
} |
|
228 |
|
|
229 |
//! shutdown and disable a joint |
|
230 |
//! \param the enum id of a joint |
|
231 |
void MekaJointInterface::disable_joint(int e){ |
|
232 |
/* |
|
233 |
//first: convert humotion enum to our enum: |
|
234 |
int motor_id = convert_enum_to_motorid(e); |
|
235 |
if (motor_id == -1){ |
|
236 |
return; //we are not interested in that data, so we just return here |
|
237 |
} |
|
238 |
|
|
239 |
//fetch device: |
|
240 |
Device *dev = get_device(motor_id); |
|
241 |
printf("> FIXME: ADD DISABLE CODE\n"); |
|
242 |
printf("> FIXME: ADD DISABLE CODE\n"); |
|
243 |
printf("> FIXME: ADD DISABLE CODE\n"); |
|
244 |
printf("> FIXME: ADD DISABLE CODE\n"); |
|
245 |
printf("> FIXME: ADD DISABLE CODE\n"); |
|
246 |
printf("> FIXME: ADD DISABLE CODE\n"); |
|
247 |
printf("> FIXME: ADD DISABLE CODE\n"); |
|
248 |
printf("> FIXME: ADD DISABLE CODE\n"); |
|
249 |
printf("> FIXME: ADD DISABLE CODE\n"); |
|
250 |
*/ |
|
251 |
} |
|
252 |
|
|
253 |
#if 0 |
|
107 | 254 |
|
108 | 255 |
//! conversion table for humotion motor ids to our ids: |
109 | 256 |
//! \param enum from JointInterface::JOINT_ID_ENUM |
... | ... | |
704 | 851 |
printf("> FIXME: ADD DISABLE CODE\n"); |
705 | 852 |
*/ |
706 | 853 |
} |
854 |
#endif |
Also available in: Unified diff