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 effort_;
00155
00156
00157 JointStatistics joint_statistics_;
00158
00160 double commanded_position_;
00161
00163 double commanded_velocity_;
00164
00166 double commanded_effort_;
00167
00169 bool calibrated_;
00170
00172 double reference_position_;
00173
00175 JointState() :
00176 position_(0.0),
00177 velocity_(0.0),
00178 effort_(0.0),
00179 commanded_position_(0.0),
00180 commanded_velocity_(0.0),
00181 commanded_effort_(0.0),
00182 calibrated_(false),
00183 reference_position_(0.0)
00184 {
00185 }
00186 };
00187 inline void JointStatistics::update(JointState *jnt)
00188 {
00189 if (initialized_)
00190 {
00191 if (jnt->joint_->safety && jnt->joint_->limits
00192 && (fabs(jnt->commanded_effort_) > fabs(jnt->effort_)))
00193 violated_limits_ = true;
00194 min_position_ = fmin(jnt->position_, min_position_);
00195 max_position_ = fmax(jnt->position_, max_position_);
00196 max_abs_velocity_ = fmax(fabs(jnt->velocity_), max_abs_velocity_);
00197 max_abs_effort_ = fmax(fabs(jnt->effort_), max_abs_effort_);
00198 }
00199 else
00200 {
00201 min_position_ = jnt->position_;
00202 max_position_ = jnt->position_;
00203 initialized_ = true;
00204 }
00205 old_position_ = jnt->position_;
00206 }
00207
00208 }
00209
00210 #endif