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
00037 #include <vector>
00038 #include <string>
00039 #include <csignal>
00040 #include <ros/ros.h>
00041 #include <sensor_msgs/JointState.h>
00042 #include <robotiq_s_model_control/SModel_robot_input.h>
00043 #include <robotiq_s_model_control/SModel_robot_output.h>
00044
00045
00046 const double DEG_TO_RAD = M_PI/180.0;
00047
00051 class Finger {
00052 public:
00053 Finger() { position = 0; }
00054 Finger(int pos) { position = pos; }
00055 Finger(const Finger &f) { position = f.position; }
00056 inline double joint1() const;
00057 inline double joint2() const;
00058 inline double joint3() const;
00059 int position;
00060 };
00061
00066 inline double Finger::joint1() const {
00067 if(0 <= position && position <= 140) return (70.0/148.0 * DEG_TO_RAD) * position;
00068 else return 70.0 * DEG_TO_RAD;
00069 }
00070
00075 inline double Finger::joint2() const {
00076 if(0 <= position && position <= 140) return 0.0;
00077 else if(140 < position && position <= 240) return (90.0/100.0 * DEG_TO_RAD) * (position-140.0);
00078 else return 90.0 * DEG_TO_RAD;
00079 }
00080
00085 inline double Finger::joint3() const {
00086 if(0 <= position && position <= 140) return (-70.0/140.0 * DEG_TO_RAD) * position;
00087 else return -55.0 * DEG_TO_RAD;
00088 }
00089
00093 class Robotiq3 {
00094 public:
00096 Robotiq3() {
00097 scissor = 137;
00098 joint_positions.resize(11, 0.0);
00099 prefix = "";
00100 }
00101
00103 Robotiq3(std::string gripper_prefix) {
00104 scissor = 137;
00105 joint_positions.resize(11, 0.0);
00106 prefix = gripper_prefix;
00107 }
00108
00109 inline double scissorJoint() const;
00110 void callback(const robotiq_s_model_control::SModel_robot_input::ConstPtr &msg);
00111 Finger finger_left;
00112 Finger finger_right;
00113 Finger finger_middle;
00114 int scissor;
00115 std::string prefix;
00116 std::vector<std::string> jointNames();
00117 std::vector<double> joint_positions;
00118 };
00119
00123 inline double Robotiq3::scissorJoint() const {
00124
00125
00126
00127 if(0 <= scissor && scissor <= 15) return 11.0*DEG_TO_RAD;
00128 else if(15 < scissor && scissor <= 240) return (11.0-22.0*((scissor-15.0)/225.0))*DEG_TO_RAD;
00129 else return -11.0*DEG_TO_RAD;
00130 }
00131
00135 void Robotiq3::callback(const robotiq_s_model_control::SModel_robot_input::ConstPtr &msg) {
00136 finger_left = Finger(msg->gPOA);
00137 finger_right = Finger(msg->gPOB);
00138 finger_middle = Finger(msg->gPOC);
00139 scissor = msg->gPOS;
00140
00141
00142 joint_positions.at(0) = scissorJoint();
00143 joint_positions.at(1) = finger_left.joint1();
00144 joint_positions.at(2) = finger_left.joint2();
00145 joint_positions.at(3) = finger_left.joint3();
00146 joint_positions.at(4) = -joint_positions.at(0);
00147 joint_positions.at(5) = finger_right.joint1();
00148 joint_positions.at(6) = finger_right.joint2();
00149 joint_positions.at(7) = finger_right.joint3();
00150 joint_positions.at(8) = finger_middle.joint1();
00151 joint_positions.at(9) = finger_middle.joint2();
00152 joint_positions.at(10) = finger_middle.joint3();
00153 }
00154
00158 inline std::vector<std::string> Robotiq3::jointNames() {
00159
00160
00161 std::vector<std::string> joint_names(11, "");
00162 joint_names.at(0).assign(prefix + "palm_finger_1_joint");
00163 joint_names.at(1).assign(prefix + "finger_1_joint_1");
00164 joint_names.at(2).assign(prefix + "finger_1_joint_2");
00165 joint_names.at(3).assign(prefix + "finger_1_joint_3");
00166 joint_names.at(4).assign(prefix + "palm_finger_2_joint");
00167 joint_names.at(5).assign(prefix + "finger_2_joint_1");
00168 joint_names.at(6).assign(prefix + "finger_2_joint_2");
00169 joint_names.at(7).assign(prefix + "finger_2_joint_3");
00170 joint_names.at(8).assign(prefix + "finger_middle_joint_1");
00171 joint_names.at(9).assign(prefix + "finger_middle_joint_2");
00172 joint_names.at(10).assign(prefix + "finger_middle_joint_3");
00173 return joint_names;
00174 }
00175
00179 int main(int argc, char *argv[]) {
00180
00181
00182 ros::init(argc, argv, "s_model_joint_states");
00183 ros::NodeHandle nh;
00184 ros::NodeHandle pnh("~");
00185 ros::Rate loop_rate(20);
00186
00187
00188 std::string gripper_prefix;
00189 pnh.param<std::string>("prefix", gripper_prefix, "");
00190
00191
00192 Robotiq3 robotiq(gripper_prefix);
00193
00194
00195 ros::Publisher joint_pub;
00196 joint_pub = nh.advertise<sensor_msgs::JointState>("joint_states", 10);
00197
00198
00199 ros::Subscriber joint_sub;
00200 joint_sub = nh.subscribe("SModelRobotInput", 10, &Robotiq3::callback, &robotiq);
00201
00202
00203 sensor_msgs::JointState joint_msg;
00204
00205
00206 joint_msg.name = robotiq.jointNames();
00207
00208 while (ros::ok()) {
00209 joint_msg.position = robotiq.joint_positions;
00210 joint_msg.header.stamp = ros::Time::now();
00211 joint_pub.publish(joint_msg);
00212 ros::spinOnce();
00213 loop_rate.sleep();
00214 }
00215
00216 return 0;
00217 }