4 #include <std_msgs/Float32.h>
5 #include <std_msgs/Bool.h>
6 #include <std_msgs/String.h>
11 void setForce(
const std_msgs::Float32::ConstPtr&);
14 void shutdown(
const std_msgs::Bool::ConstPtr&);
33 int main(
int argc,
char **argv){
35 ros::init(argc, argv,
"gripper_controller");
37 ros::Subscriber force_sub = n.subscribe(
"gripper_force", 1,
setForce);
38 ros::Subscriber command_sub = n.subscribe(
"command", 1000,
gripperCommand);
39 ros::Subscriber phidget_sub = n.subscribe(
"phidget_value", 1,
gripperPhidget);
40 ros::Subscriber sd = n.subscribe(
"shutdown", 1,
shutdown);
59 float distance = msg->data;
65 ROS_INFO(
"received distance: %f", distance);
67 ROS_INFO(
"Closing gripper");
75 ROS_INFO(
"Opening gripper");
84 ROS_INFO(
"Resetting force_open");
98 void setForce(
const std_msgs::Float32::ConstPtr& msg){
100 ROS_INFO(
"Setting controller force to: %f\n",
force);
114 string cmd = msg->data;
116 if(cmd.compare(
"open") == 0){
117 ROS_INFO(
"Opening gripper");
123 }
else if(cmd.compare(
"relax") == 0){
124 ROS_INFO(
"Relaxing gripper");
129 }
else if(cmd.compare(
"close") == 0){
130 ROS_INFO(
"Closing gripper");
137 ROS_INFO(
"Received invalid command: %s\n", cmd.c_str());
150 return distance < 7 && distance != 0;
162 return distance > 10;
170 void shutdown(
const std_msgs::Bool::ConstPtr& b){