Go to the documentation of this file.00001
00047 #include <math.h>
00048 #include <angles/angles.h>
00049 #include <tf/tf.h>
00050 #include <jaco_driver/jaco_types.h>
00051 #include <string>
00052
00053
00054 namespace jaco
00055 {
00056
00057
00058
00059
00060 float normalizeInRads(float rads)
00061 {
00062 return static_cast<float>(angles::normalize_angle_positive(rads));
00063 }
00064
00065
00066 float normalizePositiveInDegrees(float degrees)
00067 {
00068 return angles::to_degrees(angles::normalize_angle_positive(angles::from_degrees(degrees)));
00069 }
00070
00071
00072 float normalizeInDegrees(float degrees)
00073 {
00074 return angles::to_degrees(angles::normalize_angle(angles::from_degrees(degrees)));
00075 }
00076
00077
00078 bool areValuesClose(float first, float second, float tolerance)
00079 {
00080 return ((first <= second + tolerance) && (first >= second - tolerance));
00081 }
00082
00083
00084
00085
00086 JacoCommException::JacoCommException(const std::string& message, const int error_code)
00087 {
00088 std::stringstream ss;
00089 ss << "JacoCommException: " << message << " (return code: " << error_code << ")" << std::endl;
00090 desc_ = ss.str();
00091 }
00092
00093
00094 const char* JacoCommException::what() const throw()
00095 {
00096 return desc_.c_str();
00097 }
00098
00099
00100
00101
00102
00103 JacoPose::JacoPose(const geometry_msgs::Pose &pose)
00104 {
00105 double tx, ty, tz;
00106 tf::Quaternion q;
00107 tf::quaternionMsgToTF(pose.orientation, q);
00108
00109 tf::Matrix3x3 bt_q(q);
00110
00111 bt_q.getEulerYPR(tz, ty, tx);
00112
00113 X = static_cast<float>(pose.position.x);
00114 Y = static_cast<float>(pose.position.y);
00115 Z = static_cast<float>(pose.position.z);
00116
00117 ThetaX = normalizeInRads(tx);
00118 ThetaY = normalizeInRads(ty);
00119 ThetaZ = normalizeInRads(tz);
00120 }
00121
00122
00123 JacoPose::JacoPose(const CartesianInfo &pose)
00124 {
00125 X = pose.X;
00126 Y = pose.Y;
00127 Z = pose.Z;
00128
00129 ThetaX = normalizeInRads(pose.ThetaX);
00130 ThetaY = normalizeInRads(pose.ThetaY);
00131 ThetaZ = normalizeInRads(pose.ThetaZ);
00132 }
00133
00134
00135 geometry_msgs::Pose JacoPose::constructPoseMsg()
00136 {
00137 geometry_msgs::Pose pose;
00138 tf::Quaternion position_quaternion;
00139
00140 position_quaternion.setRPY(ThetaX, ThetaY, ThetaZ);
00141 tf::quaternionTFToMsg(position_quaternion, pose.orientation);
00142
00143 pose.position.x = X;
00144 pose.position.y = Y;
00145 pose.position.z = Z;
00146
00147 return pose;
00148 }
00149
00150
00151 bool JacoPose::isCloseToOther(const JacoPose &other, float tolerance) const
00152 {
00153 bool status = true;
00154 status = status && areValuesClose(X, other.X, tolerance);
00155 status = status && areValuesClose(Y, other.Y, tolerance);
00156 status = status && areValuesClose(Z, other.Z, tolerance);
00157 status = status && areValuesClose(ThetaX, other.ThetaX, tolerance);
00158 status = status && areValuesClose(ThetaY, other.ThetaY, tolerance);
00159 status = status && areValuesClose(ThetaZ, other.ThetaZ, tolerance);
00160 return status;
00161 }
00162
00163
00164 JacoAngles::JacoAngles(const jaco_msgs::JointAngles &angles)
00165 {
00166 Actuator1 = 180.0 - (angles.joint1 * (180.0 / M_PI));
00167 Actuator2 = normalizePositiveInDegrees((angles.joint2 * (180.0 / M_PI)) + 270.0);
00168 Actuator3 = normalizePositiveInDegrees(90.0 - (angles.joint3 * (180.0 / M_PI)));
00169 Actuator4 = 180.0 - (angles.joint4 * (180.0 / M_PI));
00170 Actuator5 = 180.0 - (angles.joint5 * (180.0 / M_PI));
00171 Actuator6 = 260.0 - (angles.joint6 * (180.0 / M_PI));
00172 }
00173
00174
00175 JacoAngles::JacoAngles(const AngularInfo &angles)
00176 {
00177 Actuator1 = angles.Actuator1;
00178 Actuator2 = normalizePositiveInDegrees(angles.Actuator2);
00179 Actuator3 = normalizePositiveInDegrees(angles.Actuator3);
00180 Actuator4 = angles.Actuator4;
00181 Actuator5 = angles.Actuator5;
00182 Actuator6 = angles.Actuator6;
00183 }
00184
00185
00186 jaco_msgs::JointAngles JacoAngles::constructAnglesMsg()
00187 {
00188 jaco_msgs::JointAngles angles;
00189 angles.joint1 = (180.0 - Actuator1) / (180.0 / M_PI);
00190 angles.joint2 = (Actuator2 - 270.0) / (180.0 / M_PI);
00191 angles.joint3 = (90.0 - Actuator3) / (180.0 / M_PI);
00192 angles.joint4 = (180.0 - Actuator4) / (180.0 / M_PI);
00193 angles.joint5 = (180.0 - Actuator5) / (180.0 / M_PI);
00194 angles.joint6 = (260.0 - Actuator6) / (180.0 / M_PI);
00195 return angles;
00196 }
00197
00198
00199 bool JacoAngles::isCloseToOther(const JacoAngles &other, float tolerance) const
00200 {
00201 bool status = true;
00202 status = status && areValuesClose(Actuator1, other.Actuator1, tolerance);
00203 status = status && areValuesClose(Actuator2, other.Actuator2, tolerance);
00204 status = status && areValuesClose(Actuator3, other.Actuator3, tolerance);
00205 status = status && areValuesClose(Actuator4, other.Actuator4, tolerance);
00206 status = status && areValuesClose(Actuator5, other.Actuator5, tolerance);
00207 status = status && areValuesClose(Actuator6, other.Actuator6, tolerance);
00208 return status;
00209 }
00210
00211
00212 FingerAngles::FingerAngles(const jaco_msgs::FingerPosition &position)
00213 {
00214 Finger1 = position.finger1;
00215 Finger2 = position.finger2;
00216 Finger3 = position.finger3;
00217 }
00218
00219
00220 FingerAngles::FingerAngles(const FingersPosition &angle)
00221 {
00222 Finger1 = angle.Finger1;
00223 Finger2 = angle.Finger2;
00224 Finger3 = angle.Finger3;
00225 }
00226
00227
00228 jaco_msgs::FingerPosition FingerAngles::constructFingersMsg()
00229 {
00230 jaco_msgs::FingerPosition angles;
00231 angles.finger1 = Finger1;
00232 angles.finger2 = Finger2;
00233 angles.finger3 = Finger3;
00234 return angles;
00235 }
00236
00237
00238 bool FingerAngles::isCloseToOther(const FingerAngles &other, float tolerance) const
00239 {
00240 bool status = true;
00241 status = status && areValuesClose(Finger1, other.Finger1, tolerance);
00242 status = status && areValuesClose(Finger2, other.Finger2, tolerance);
00243 status = status && areValuesClose(Finger3, other.Finger3, tolerance);
00244 return status;
00245 }
00246
00247 }