Go to the documentation of this file.00001
00047 #include <jaco_driver/jaco_types.h>
00048 #include <tf/tf.h>
00049 #include <math.h>
00050
00051 namespace jaco
00052 {
00053
00054 bool CompareValues(float first, float second, float tolerance)
00055 {
00056 return ((first <= second + tolerance) && (first >= second - tolerance));
00057 }
00058
00059
00060 JacoPose::JacoPose(const geometry_msgs::Pose &pose)
00061 {
00062 double tx, ty, tz;
00063 tf::Quaternion q;
00064 tf::quaternionMsgToTF(pose.orientation, q);
00065
00066 tf::Matrix3x3 bt_q(q);
00067
00068 bt_q.getEulerYPR(tz, ty, tx);
00069
00070 X = (float) pose.position.x;
00071 Y = (float) pose.position.y;
00072 Z = (float) pose.position.z;
00073
00074 ThetaX = Normalize(tx);
00075 ThetaY = Normalize(ty);
00076 ThetaZ = Normalize(tz);
00077 }
00078
00079 JacoPose::JacoPose(const CartesianInfo &pose)
00080 {
00081 X = pose.X;
00082 Y = pose.Y;
00083 Z = pose.Z;
00084
00085 ThetaX = Normalize(pose.ThetaX);
00086 ThetaY = Normalize(pose.ThetaY);
00087 ThetaZ = Normalize(pose.ThetaZ);
00088 }
00089
00090 geometry_msgs::Pose JacoPose::Pose()
00091 {
00092 geometry_msgs::Pose pose;
00093 tf::Quaternion position_quaternion;
00094
00095 position_quaternion.setRPY(ThetaX, ThetaY, ThetaZ);
00096 tf::quaternionTFToMsg(position_quaternion, pose.orientation);
00097
00098 pose.position.x = X;
00099 pose.position.y = Y;
00100 pose.position.z = Z;
00101
00102 return pose;
00103 }
00104
00105 bool JacoPose::Compare(const JacoPose &other, float tolerance) const
00106 {
00107 bool status = true;
00108
00109 status = status && CompareValues(X, other.X, tolerance);
00110 status = status && CompareValues(Y, other.Y, tolerance);
00111 status = status && CompareValues(Z, other.Z, tolerance);
00112 status = status && CompareValues(ThetaX, other.ThetaX, tolerance);
00113 status = status && CompareValues(ThetaY, other.ThetaY, tolerance);
00114 status = status && CompareValues(ThetaZ, other.ThetaZ, tolerance);
00115
00116 return status;
00117 }
00118
00119 float JacoPose::Normalize(float value)
00120 {
00121 while (value > 2 * M_PI)
00122 value -= 2 * M_PI;
00123 while (value < 0)
00124 value += 2 * M_PI;
00125
00126 return value;
00127 }
00128
00129 JacoAngles::JacoAngles(const jaco_driver::JointAngles &angles)
00130 {
00131 Actuator1 = Normalize(180.0 - (angles.Angle_J1 * (180.0 / M_PI)));
00132 Actuator2 = Normalize((angles.Angle_J2 * (180.0 / M_PI)) + 270.0);
00133 Actuator3 = Normalize(90.0 - (angles.Angle_J3 * (180.0 / M_PI)));
00134 Actuator4 = Normalize(180.0 - (angles.Angle_J4 * (180.0 / M_PI)));
00135 Actuator5 = Normalize(180.0 - (angles.Angle_J5 * (180.0 / M_PI)));
00136 Actuator6 = Normalize(260.0 - (angles.Angle_J6 * (180.0 / M_PI)));
00137 }
00138
00139 JacoAngles::JacoAngles(const AngularInfo &angles)
00140 {
00141 Actuator1 = Normalize(angles.Actuator1);
00142 Actuator2 = Normalize(angles.Actuator2);
00143 Actuator3 = Normalize(angles.Actuator3);
00144 Actuator4 = Normalize(angles.Actuator4);
00145 Actuator5 = Normalize(angles.Actuator5);
00146 Actuator6 = Normalize(angles.Actuator6);
00147 }
00148
00149 jaco_driver::JointAngles JacoAngles::Angles()
00150 {
00151 jaco_driver::JointAngles angles;
00152 angles.Angle_J1 = (180.0 - Actuator1) / (180.0 / M_PI);
00153 angles.Angle_J2 = (Actuator2 - 270.0) / (180.0 / M_PI);
00154 angles.Angle_J3 = (90.0 - Actuator3) / (180.0 / M_PI);
00155 angles.Angle_J4 = (180.0 - Actuator4) / (180.0 / M_PI);
00156 angles.Angle_J5 = (180.0 - Actuator5) / (180.0 / M_PI);
00157 angles.Angle_J6 = (260.0 - Actuator6) / (180.0 / M_PI);
00158
00159 return angles;
00160 }
00161
00162 bool JacoAngles::Compare(const JacoAngles &other, float tolerance) const
00163 {
00164 bool status = true;
00165
00166 status = status && CompareValues(Actuator1, other.Actuator1, tolerance);
00167 status = status && CompareValues(Actuator2, other.Actuator2, tolerance);
00168 status = status && CompareValues(Actuator3, other.Actuator3, tolerance);
00169 status = status && CompareValues(Actuator4, other.Actuator4, tolerance);
00170 status = status && CompareValues(Actuator5, other.Actuator5, tolerance);
00171 status = status && CompareValues(Actuator6, other.Actuator6, tolerance);
00172
00173 return status;
00174 }
00175
00176 float JacoAngles::Normalize(float value)
00177 {
00178 while (value > 360.0)
00179 value -= 360.0;
00180 while (value < 0.0)
00181 value += 360.0;
00182
00183 return value;
00184 }
00185
00186 FingerAngles::FingerAngles(const jaco_driver::FingerPosition &position)
00187 {
00188 Finger1 = position.Finger_1;
00189 Finger2 = position.Finger_2;
00190 Finger3 = position.Finger_3;
00191 }
00192
00193 FingerAngles::FingerAngles(const FingersPosition &angle)
00194 {
00195 Finger1 = angle.Finger1;
00196 Finger2 = angle.Finger2;
00197 Finger3 = angle.Finger3;
00198 }
00199
00200 jaco_driver::FingerPosition FingerAngles::Fingers()
00201 {
00202 jaco_driver::FingerPosition angles;
00203 angles.Finger_1 = Finger1;
00204 angles.Finger_2 = Finger2;
00205 angles.Finger_3 = Finger3;
00206
00207 return angles;
00208 }
00209
00210 bool FingerAngles::Compare(const FingerAngles &other, float tolerance) const
00211 {
00212 bool status = true;
00213
00214 status = status && CompareValues(Finger1, other.Finger1, tolerance);
00215 status = status && CompareValues(Finger2, other.Finger2, tolerance);
00216 status = status && CompareValues(Finger3, other.Finger3, tolerance);
00217
00218 return status;
00219 }
00220
00221 }