All Classes Namespaces Files Functions Variables Typedefs
rviz_gripper.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <string>
3 #include <std_msgs/Float32.h>
4 #include <std_msgs/Bool.h>
5 #include <sensor_msgs/JointState.h>
6 //#include <rvix> en dan nog wat dingen
7 
8 using namespace std;
9 
10 void rvizUpdater(const std_msgs::Float32::ConstPtr&);
11 void shutdown(const std_msgs::Bool::ConstPtr&);
12 float opens;
13 const int freq = 250;
36 int main(int argc, char **argv){
37 
38  ros::init(argc, argv, "rviz_gripper");
39  ros::NodeHandle n;
40  ros::Subscriber subscriber = n.subscribe("gripper_state", 1000, rvizUpdater);
41  ros::Subscriber sd = n.subscribe("shutdown", 1, shutdown);
42  ros::spinOnce();
43  ros::Publisher joint_pub = n.advertise<sensor_msgs::JointState>("jstates", 1);
44  ros::Rate loop_rate(freq);
45  ros::spinOnce();
46 
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);
53 
54  sensor_msgs::JointState joint_state;
55 
56  while (ros::ok())
57  {
58  if((opens == 1 && motor_state < (1-step_size)) || (opens == 0 && motor_state > step_size)){
59  if(opens == 0){
60  motor_state = motor_state - step_size;
61 
62  }else{
63  motor_state = motor_state + step_size;
64 
65  }
66  if((motor_state/angle_step) < bmdll_max){
67  mt_angle = mdlltp_start;
68  bm_angle = motor_state/angle_step+bmdll_start;
69  }else{
70  bm_angle = bmdll_start+bmdll_max;
71  mt_angle = (motor_state/angle_step)-bmdll_max+mdlltp_start;
72  }
73  joint_state.header.stamp = ros::Time::now();
74  joint_state.name.resize(2);
75  joint_state.position.resize(2);
76 
77  joint_state.name[0]="rght_base2mdll";
78  joint_state.position[0] = bm_angle;
79 
80  joint_state.name[1]="rght_mdll2tip";
81  joint_state.position[1] = mt_angle;
82  joint_pub.publish(joint_state);
83  }
84  ros::spinOnce();
85  loop_rate.sleep();
86 
87  }
88 
89  return 0;
90 }
91 
97 void rvizUpdater(const std_msgs::Float32::ConstPtr& msg){
98  opens = msg->data;
99  ROS_INFO("open or close: %f", msg->data);
100 }
101 
108 void shutdown(const std_msgs::Bool::ConstPtr& b){
109  ros::shutdown();
110 }


Grijper
Author(s): Stijn van Schooten, Wybren ten Cate, Florens Kreuk, Jan Wymenga,Joris Coenen, Roy Groot
autogenerated on Thu Oct 3 2013 22:59:42