3 #include <std_msgs/Float32.h>
4 #include <std_msgs/Bool.h>
5 #include <sensor_msgs/JointState.h>
10 void rvizUpdater(
const std_msgs::Float32::ConstPtr&);
11 void shutdown(
const std_msgs::Bool::ConstPtr&);
36 int main(
int argc,
char **argv){
40 ros::Subscriber subscriber = n.subscribe(
"gripper_state", 1000,
rvizUpdater);
41 ros::Subscriber sd = n.subscribe(
"shutdown", 1,
shutdown);
43 ros::Publisher joint_pub = n.advertise<sensor_msgs::JointState>(
"jstates", 1);
44 ros::Rate loop_rate(
freq);
47 const double bmdll_max = 0.85;
48 const double mdlltp_max = 0.80;
49 const double bmdll_start = -0.96;
50 const double mdlltp_start = -0.3;
51 double bm_angle, mt_angle, step_size = 0.004, cf = 1.5, motor_state = 0;
52 double angle_step = 1/(bmdll_max + mdlltp_max*cf);
54 sensor_msgs::JointState joint_state;
58 if((
opens == 1 && motor_state < (1-step_size)) || (
opens == 0 && motor_state > step_size)){
60 motor_state = motor_state - step_size;
63 motor_state = motor_state + step_size;
66 if((motor_state/angle_step) < bmdll_max){
67 mt_angle = mdlltp_start;
68 bm_angle = motor_state/angle_step+bmdll_start;
70 bm_angle = bmdll_start+bmdll_max;
71 mt_angle = (motor_state/angle_step)-bmdll_max+mdlltp_start;
73 joint_state.header.stamp = ros::Time::now();
74 joint_state.name.resize(2);
75 joint_state.position.resize(2);
77 joint_state.name[0]=
"rght_base2mdll";
78 joint_state.position[0] = bm_angle;
80 joint_state.name[1]=
"rght_mdll2tip";
81 joint_state.position[1] = mt_angle;
82 joint_pub.publish(joint_state);
99 ROS_INFO(
"open or close: %f", msg->data);
108 void shutdown(
const std_msgs::Bool::ConstPtr& b){