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 #include <pr2_mechanism_model/joint.h>
00036 #include <map>
00037 #include <string>
00038 #include <vector>
00039 #include <cfloat>
00040
00041
00042 using namespace std;
00043 using namespace pr2_mechanism_model;
00044
00045
00046 void JointStatistics::update(JointState* jnt)
00047 {
00048 if (initialized_){
00049 odometer_ += fabs(old_position_ - jnt->position_);
00050 if (jnt->joint_->safety && jnt->joint_->limits && (fabs(jnt->commanded_effort_) > fabs(jnt->measured_effort_)))
00051 violated_limits_ = true;
00052 min_position_ = fmin(jnt->position_, min_position_);
00053 max_position_ = fmax(jnt->position_, max_position_);
00054 max_abs_velocity_ = fmax(fabs(jnt->velocity_), max_abs_velocity_);
00055 max_abs_effort_ = fmax(fabs(jnt->measured_effort_), max_abs_effort_);
00056 }
00057 else{
00058 min_position_ = jnt->position_;
00059 max_position_ = jnt->position_;
00060 initialized_ = true;
00061 }
00062 old_position_ = jnt->position_;
00063 }
00064
00065
00066 void JointStatistics::reset()
00067 {
00068 double tmp = min_position_;
00069 min_position_ = max_position_;
00070 max_position_ = tmp;
00071 max_abs_velocity_ = 0.0;
00072 max_abs_effort_ = 0.0;
00073 violated_limits_ = false;
00074 }
00075
00076
00077 void JointState::enforceLimits()
00078 {
00079 double effort_high, effort_low;
00080
00081 getLimits(effort_low, effort_high);
00082
00083
00084 commanded_effort_ =
00085 min( max(commanded_effort_, effort_low), effort_high);
00086 }
00087
00088 void JointState::getLimits(double &effort_low, double &effort_high)
00089 {
00090
00091 if (!joint_->safety || !joint_->limits) {
00092 effort_low = -std::numeric_limits<double>::max();
00093 effort_high = std::numeric_limits<double>::max();
00094 return;
00095 }
00096
00097 double vel_high = joint_->limits->velocity;
00098 double vel_low = -joint_->limits->velocity;
00099 effort_high = joint_->limits->effort;
00100 effort_low = -joint_->limits->effort;
00101
00102
00103 if (calibrated_ && (joint_->type == urdf::Joint::REVOLUTE || joint_->type == urdf::Joint::PRISMATIC))
00104 {
00105
00106
00107 vel_high = max(-joint_->limits->velocity,
00108 min(joint_->limits->velocity,
00109 -joint_->safety->k_position * (position_ - joint_->safety->soft_upper_limit)));
00110 vel_low = min(joint_->limits->velocity,
00111 max(-joint_->limits->velocity,
00112 -joint_->safety->k_position * (position_ - joint_->safety->soft_lower_limit)));
00113 }
00114
00115
00116 effort_high = max(-joint_->limits->effort,
00117 min(joint_->limits->effort,
00118 -joint_->safety->k_velocity * (velocity_ - vel_high)));
00119 effort_low = min(joint_->limits->effort,
00120 max(-joint_->limits->effort,
00121 -joint_->safety->k_velocity * (velocity_ - vel_low)));
00122 }
00123
00124