Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <pr2_hardware_interface/hardware_interface.h>
00044 #include <pr2_controller_interface/controller.h>
00045 #include <pr2_mechanism_model/joint.h>
00046 #include <pr2_gripper_sensor_controller/pressure_observer.h>
00047 #include <pr2_gripper_sensor_controller/acceleration_observer.h>
00048 #include <pr2_gripper_sensor_controller/digitalFilter.h>
00049
00050 #ifndef _GRIPPER_CONTROLLER
00051 #define _GRIPPER_CONTROLLER
00052
00053
00054 class gripperController{
00055
00056 public:
00057
00058 gripperController(pr2_mechanism_model::JointState* joint_state_, pressureObserver* pressure_observer_, accelerationObserver* acceleration_observer_);
00059 ~gripperController();
00060 bool velocityServo(double desiredVel);
00061 bool positionServo(double desiredPos, double desiredVel);
00062 void updateData();
00063 bool initializeGripper();
00064 bool forceServo2(double desired_Force);
00065 bool grabObject(double close_speed, int contactsDesired);
00066 bool slipServo2();
00067 bool forceRampTo(double force, double duration);
00068 bool place(int placeConditions,double acc_trigger, double slip_trigger);
00069
00070
00071
00072 double max_effort;
00073 double fingertip_force_limit;
00074 double positionMarker_limit;
00075 double positionMarker;
00076
00077
00078 bool slip_flag;
00079 bool deformation_limit_flag;
00080 bool force_limit_flag;
00081 bool dropped_flag;
00082
00083
00084
00085 double vel_integral;
00086 double vel_integral_vcontrol;
00087 double lpVelocity;
00088 double accThresh;
00089 digitalFilter *velocityLPFilt;
00090 double positionOpen;
00091 double positionClosed;
00092 double positionCurrent;
00093 double positionDropped;
00094 double servoForce;
00095 double objectForce;
00096 double positionContact;
00097 double forceContact;
00098 double forceContact_l, forceContact_r;
00099 double force_servo_force_tolerance;
00100
00101
00102 double gripper_state_now_measured_effort, gripper_state_now_position, gripper_state_now_velocity;
00103 double gripper_state_prev_measured_effort, gripper_state_prev_position, gripper_state_prev_velocity;
00104
00105 double kP;
00106 double kD;
00107 double dt;
00108 double coulomb;
00109
00110 pr2_mechanism_model::JointState* jointState;
00111 pressureObserver* myPressureObserver;
00112 accelerationObserver* myAccelerationObserver;
00113
00114 bool firstRamp;
00115 double ramp_start_time;
00116 double ramp_start_force;
00117
00118 private:
00119 double initialPosition;
00120 double time_prev, time_cur;
00121 };
00122
00123
00124
00125 void gripperController::updateData()
00126 {
00127
00128 time_prev = time_cur;
00129
00130 time_cur = ros::Time::now().toSec();
00131
00132
00133
00134 gripper_state_prev_measured_effort = gripper_state_now_measured_effort;
00135 gripper_state_prev_position = gripper_state_now_position;
00136 gripper_state_prev_velocity = gripper_state_now_velocity;
00137
00138
00139 gripper_state_now_measured_effort = jointState->measured_effort_;
00140 gripper_state_now_position = jointState->position_;
00141 gripper_state_now_velocity = jointState->velocity_;
00142 lpVelocity = velocityLPFilt->getNextFilteredValue(gripper_state_now_velocity);
00143
00144
00145 positionCurrent = gripper_state_now_position;
00146
00147
00148 myPressureObserver->spin();
00149 myAccelerationObserver->spin();
00150 }
00151
00152
00153
00154 bool gripperController::grabObject(double close_speed, int contactsDesired)
00155 {
00156
00157 if( !(myPressureObserver->graspContact(contactsDesired)) )
00158 {
00159 velocityServo(close_speed);
00160 return false;
00161 }
00162
00163 else
00164 {
00165
00166 positionContact = positionCurrent;
00167 if(-myPressureObserver->padForce_left_cur_nonbiased < forceContact_l)
00168 forceContact_l = -myPressureObserver->padForce_left_cur_nonbiased;
00169 if(-myPressureObserver->padForce_right_cur_nonbiased < forceContact_r)
00170 forceContact_r = -myPressureObserver->padForce_right_cur_nonbiased;
00171 if(-myPressureObserver->padForce_cur_nonbiased < forceContact)
00172 forceContact = -myPressureObserver->padForce_cur_nonbiased;
00173 return true;
00174 }
00175 }
00176
00177
00178
00179 bool gripperController::place(int placeConditions, double acc_trigger, double slip_trigger)
00180 {
00181 bool accContact = myAccelerationObserver->checkPlaceContact(acc_trigger);
00182 bool slipContact = myPressureObserver->checkPlaceContact(slip_trigger);
00183 int sideImpact = myPressureObserver->checkSideImpact(0.2);
00184 bool returnValue = false;
00185
00186 if(placeConditions == 0 )
00187 returnValue = accContact || (sideImpact != -1);
00188 else if(placeConditions == 1 )
00189 returnValue = accContact && slipContact;
00190 else if(placeConditions == 2 )
00191 returnValue = accContact || slipContact || (sideImpact != -1);
00192 else if(placeConditions == 3)
00193 returnValue = slipContact;
00194 else if(placeConditions == 4)
00195 returnValue = accContact;
00196
00197
00198 return returnValue;
00199 }
00200
00201
00202
00203 bool gripperController::slipServo2()
00204 {
00205
00206 double slipIncrementPercent = 0.002;
00207
00208 if( myPressureObserver->checkSlip())
00209 {
00210 servoForce = servoForce + servoForce*slipIncrementPercent;
00211 slip_flag = true;
00212 }
00213 else
00214 slip_flag = false;
00215
00216
00217 if(( servoForce <= fingertip_force_limit ) && (fingertip_force_limit <= 0.0))
00218 {
00219 force_limit_flag = true;
00220 servoForce = fingertip_force_limit;
00221 }
00222 else
00223 force_limit_flag = false;
00224
00225 forceServo2(servoForce);
00226
00227
00228
00229 if( (-myPressureObserver->padForce_cur_nonbiased > -((myPressureObserver->forceLightest)-0.25)) || positionCurrent <= positionDropped)
00230 {
00231 dropped_flag = true;
00232 positionMarker = positionCurrent;
00233 jointState->commanded_effort_ = -100.0;
00234 }
00235 else
00236 dropped_flag = false;
00237
00238
00239
00240 return true;
00241 }
00242
00243
00244
00245
00246
00247 bool gripperController::forceServo2(double desired_Force)
00248 {
00249
00250 if(desired_Force > -(myPressureObserver->forceLightest))
00251 desired_Force = -(myPressureObserver->forceLightest);
00252
00253
00254 servoForce = desired_Force;
00255
00256
00257 double minFingerForce = -std::min(myPressureObserver->padForce_left_cur_nonbiased,myPressureObserver->padForce_right_cur_nonbiased);
00258
00259
00260 double kP_f = 0.0008;
00261
00262 if( desired_Force-minFingerForce < 0)
00263 kP_f = 0.0016;
00264
00265
00266 double v_force = -kP_f * (minFingerForce - desired_Force);
00267
00268
00269 double v_bound = 0.50;
00270 if(v_force < -v_bound)
00271 v_force = -v_bound;
00272 else if(v_force > v_bound)
00273 v_force = v_bound;
00274
00275
00276
00277 double p_bound = 0.03;
00278 if( (((vel_integral-positionCurrent) > p_bound) && v_force*dt > 0) ||
00279 (((vel_integral-positionCurrent) < -p_bound) && v_force*dt < 0) )
00280 {}
00281 else
00282 {
00283
00284 vel_integral += v_force * dt;
00285 }
00286
00287
00288 double p_force = vel_integral;
00289
00290
00291 positionServo(p_force,v_force);
00292
00293
00294 if(fabs(minFingerForce-desired_Force) < force_servo_force_tolerance)
00295 return true;
00296 else
00297 return false;
00298 }
00299
00300
00301
00302 bool gripperController::forceRampTo(double force, double duration)
00303 {
00304
00305 if(firstRamp)
00306 {
00307
00308 ramp_start_time = time_cur;
00309 ramp_start_force = -std::max(myPressureObserver->padForce_left_cur_nonbiased,myPressureObserver->padForce_right_cur_nonbiased);
00310 firstRamp = false;
00311 return false;
00312 }
00313
00314
00315 else if(time_cur-ramp_start_time < duration)
00316 {
00317 forceServo2( ((force-ramp_start_force)*((time_cur - ramp_start_time)/duration)) + ramp_start_force);
00318 return false;
00319 }
00320
00321 return true;
00322
00323 }
00324
00325
00326 bool gripperController::velocityServo(double desiredVel)
00327 {
00328
00329 vel_integral_vcontrol += desiredVel * dt;
00330 return positionServo(vel_integral_vcontrol, desiredVel);
00331 }
00332
00333
00334
00335
00336
00337
00338 bool gripperController::positionServo(double desiredPos, double desiredVel)
00339 {
00340
00341
00342
00343
00344 if( (positionMarker_limit >= 0.0) && (positionCurrent < positionMarker-positionMarker_limit) && (desiredPos < positionCurrent) )
00345 desiredPos = positionMarker-positionMarker_limit;
00346 if( (positionMarker_limit >= 0.0) && (positionCurrent < positionMarker-positionMarker_limit) )
00347 deformation_limit_flag = true;
00348 else
00349 deformation_limit_flag = false;
00350
00351
00352
00353 double pos_force = -kP * (gripper_state_now_position - desiredPos);
00354 double vel_force = -kD * (gripper_state_now_velocity - desiredVel);
00355
00356
00357 if (desiredVel > 0.0) vel_force += coulomb;
00358 else if (desiredVel < 0.0) vel_force -= coulomb;
00359
00360 double fbk_force = pos_force + vel_force;
00361
00362
00363 if (max_effort >= 0.0)
00364 fbk_force = std::max(-max_effort, std::min(fbk_force, max_effort));
00365
00366
00367 jointState->commanded_effort_ = fbk_force;
00368
00369 return false;
00370 }
00371
00372
00373
00374 bool gripperController::initializeGripper()
00375 {
00376 return true;
00377 }
00378
00379
00380 gripperController::gripperController(pr2_mechanism_model::JointState* joint_state_, pressureObserver* pressure_observer_, accelerationObserver* acceleration_observer_)
00381 {
00382
00383 jointState = joint_state_;
00384
00385
00386 myPressureObserver = pressure_observer_;
00387
00388
00389 myAccelerationObserver = acceleration_observer_;
00390
00391
00392 kP = 20000;
00393 kD = 5000;
00394 coulomb = 7;
00395
00396
00397 positionOpen = 0.1;
00398 positionClosed = 0.0;
00399 vel_integral = 0.0;
00400 positionDropped = 0.003;
00401 servoForce = 0.0;
00402 accThresh = 4.0;
00403
00404
00405
00406 float b_vfilt[] = { 0.0155, 0.0155};
00407 float a_vfilt[] = {1.0, -0.9691};
00408 velocityLPFilt = new digitalFilter(1, true,b_vfilt,a_vfilt);
00409
00410
00411 dt = 0.001;
00412
00413
00414 initialPosition = jointState->position_;
00415
00416
00417 firstRamp = true;
00418
00419 }
00420
00421
00422
00423 gripperController::~gripperController()
00424 {}
00425
00426
00427 #endif // _GRIPPER_CONTROLLER