All Classes Namespaces Files Functions Variables Typedefs
gripper_actuator.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/String.h>
5 #include <std_msgs/Bool.h>
6 #include <Grijper/command.h>
7 #include <threemxl/C3mxlROS.h>
8 
9 using namespace std;
10 
12 ros::Publisher gripper_state;
13 void shutdown(const std_msgs::Bool::ConstPtr&);
14 bool open();
15 bool close();
16 bool relax();
17 float calc_current(float);
18 float current = 0.04;
19 CDxlGeneric *motor_;
28 int main(int argc, char **argv){
29 
30  ros::init(argc, argv, "gripper_actuator");
31  CDxlConfig *config = new CDxlConfig();
32  ROS_INFO("Using direct connection");
33  motor_ = new C3mxl();
34  LxSerial serial_port_;
35  serial_port_.port_open("/dev/ttyUSB0", LxSerial::RS485_FTDI);
36  serial_port_.set_speed(LxSerial::S921600);
37  motor_->setSerialPort(&serial_port_);
38 
39  motor_->setConfig(config->setID(109));
40  motor_->init(false);
41  motor_->set3MxlMode(CURRENT_MODE);
42 
43  delete config;
44 
45  ros::NodeHandle n;
46  ros::Subscriber controller = n.subscribe("gripper_control", 1000, gripperControl);
47  gripper_state = n.advertise<std_msgs::Float32>("gripper_state", 1000);
48  ros::Subscriber sd = n.subscribe("shutdown", 1, shutdown);
49  ros::spin();
50 
51  return 0;
52 }
53 
64  string cmd = msg->cmd;
65  const char* c_cmd = cmd.c_str();
66  float force = msg->force;
67  current = calc_current(force);
68  ROS_INFO("Actuating gripper: %sing %fN -> %fA",c_cmd, force, current);
69  if(cmd.compare("open") == 0){
70  open();
71  }else if(cmd.compare("relax") == 0){
72  relax();
73  }else if(cmd.compare("close") == 0){
74  close();
75  }else{
76  ROS_INFO("Invalid command supplied");
77  }
78 }
79 
85 bool open(){
86  ROS_INFO("Opening gripper");
87  motor_->setCurrent(current);
88  std_msgs::Float32 msg;
89  msg.data = 0.0;
90  gripper_state.publish(msg);
91  return true;
92 }
93 
99 bool close(){
100  ROS_INFO("Closing gripper");
101  motor_->setCurrent(-1*current);
102  std_msgs::Float32 msg;
103  msg.data = 1.0;
104  gripper_state.publish(msg);
105  return true;
106 }
107 
113 bool relax(){
114  ROS_INFO("Relaxing gripper");
115  motor_->setCurrent(0);
116  std_msgs::Float32 msg;
117  msg.data = 0.5;
118  gripper_state.publish(msg);
119  return true;
120 }
121 
128 float calc_current(float force){
129  return force;
130 }
131 
137 void shutdown(const std_msgs::Bool::ConstPtr& b){
138  relax();
139  ros::shutdown();
140 }


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