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 #ifndef ROS_ETHERCAT_MODEL_JOINT_H
00036 #define ROS_ETHERCAT_MODEL_JOINT_H
00037
00038 #include <map>
00039 #include <string>
00040 #include <vector>
00041 #include <cfloat>
00042 #include <tinyxml.h>
00043 #include <urdf_model/joint.h>
00044
00045 namespace ros_ethercat_model
00046 {
00047
00048 enum
00049 {
00050 JOINT_NONE,
00051 JOINT_ROTARY,
00052 JOINT_CONTINUOUS,
00053 JOINT_PRISMATIC,
00054 JOINT_FIXED,
00055 JOINT_PLANAR,
00056 JOINT_TYPES_MAX
00057 };
00058
00059 class JointState;
00060
00061 class JointStatistics
00062 {
00063 public:
00064 JointStatistics() :
00065 min_position_(0), max_position_(0),
00066 max_abs_velocity_(0.0), max_abs_effort_(0.0),
00067 violated_limits_(false), initialized_(false)
00068 {
00069 }
00070
00071 void update(JointState *jnt);
00072 void reset()
00073 {
00074 double tmp = min_position_;
00075 min_position_ = max_position_;
00076 max_position_ = tmp;
00077 max_abs_velocity_ = 0.0;
00078 max_abs_effort_ = 0.0;
00079 violated_limits_ = false;
00080 }
00081
00082 double min_position_, max_position_;
00083 double max_abs_velocity_;
00084 double max_abs_effort_;
00085 bool violated_limits_;
00086
00087 private:
00088 bool initialized_;
00089 double old_position_;
00090 };
00091
00092 class JointState
00093 {
00094 public:
00096 void enforceLimits()
00097 {
00098 double effort_high, effort_low;
00099
00100 getLimits(effort_low, effort_high);
00101
00102
00103 commanded_effort_ = std::min(std::max(commanded_effort_, effort_low), effort_high);
00104 }
00105
00107 void getLimits(double &effort_low, double &effort_high)
00108 {
00109
00110 if (!joint_->safety || !joint_->limits)
00111 {
00112 effort_low = -std::numeric_limits<double>::max();
00113 effort_high = std::numeric_limits<double>::max();
00114 return;
00115 }
00116
00117 double vel_high = joint_->limits->velocity;
00118 double vel_low = -joint_->limits->velocity;
00119 effort_high = joint_->limits->effort;
00120 effort_low = -joint_->limits->effort;
00121
00122
00123 if (calibrated_ && (joint_->type == urdf::Joint::REVOLUTE || joint_->type == urdf::Joint::PRISMATIC))
00124 {
00125
00126
00127 vel_high = std::max(-joint_->limits->velocity,
00128 std::min(joint_->limits->velocity,
00129 -joint_->safety->k_position * (position_ - joint_->safety->soft_upper_limit)));
00130 vel_low = std::min(joint_->limits->velocity,
00131 std::max(-joint_->limits->velocity,
00132 -joint_->safety->k_position * (position_ - joint_->safety->soft_lower_limit)));
00133 }
00134
00135
00136 effort_high = std::max(-joint_->limits->effort,
00137 std::min(joint_->limits->effort,
00138 -joint_->safety->k_velocity * (velocity_ - vel_high)));
00139 effort_low = std::min(joint_->limits->effort,
00140 std::max(-joint_->limits->effort,
00141 -joint_->safety->k_velocity * (velocity_ - vel_low)));
00142 }
00143
00145 boost::shared_ptr<const urdf::Joint> joint_;
00146
00148 double position_;
00149
00151 double velocity_;
00152
00154 double measured_effort_;
00155
00156
00157 JointStatistics joint_statistics_;
00158
00160 double commanded_effort_;
00161
00163 bool calibrated_;
00164
00166 double reference_position_;
00167
00169 JointState() :
00170 position_(0.0),
00171 velocity_(0.0),
00172 measured_effort_(0.0),
00173 commanded_effort_(0.0),
00174 calibrated_(false),
00175 reference_position_(0.0)
00176 {
00177 }
00178 };
00179 inline void JointStatistics::update(JointState *jnt)
00180 {
00181 if (initialized_)
00182 {
00183 if (jnt->joint_->safety && jnt->joint_->limits
00184 && (fabs(jnt->commanded_effort_) > fabs(jnt->measured_effort_)))
00185 violated_limits_ = true;
00186 min_position_ = fmin(jnt->position_, min_position_);
00187 max_position_ = fmax(jnt->position_, max_position_);
00188 max_abs_velocity_ = fmax(fabs(jnt->velocity_), max_abs_velocity_);
00189 max_abs_effort_ = fmax(fabs(jnt->measured_effort_), max_abs_effort_);
00190 }
00191 else
00192 {
00193 min_position_ = jnt->position_;
00194 max_position_ = jnt->position_;
00195 initialized_ = true;
00196 }
00197 old_position_ = jnt->position_;
00198 }
00199
00200 }
00201
00202 #endif