All Classes Namespaces Files Functions Variables Typedefs
console.cpp
Go to the documentation of this file.
1 #include <stdio.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 <ros/ros.h>
8 
9 using namespace std;
10 
11 float force = 0.5;
12 bool exit_cmd = false;
13 ros::Publisher force_ad;
15 void init();
16 
31 int main(int argc, char **argv)
32 {
33  ros::init(argc, argv, "gripper_console");
34  ros::NodeHandle n;
35  force_ad = n.advertise<std_msgs::Float32>("gripper_force", 1000);
36  ros::Publisher command_ad = n.advertise<std_msgs::String>("command", 1000);
37  ros::Publisher shutdown = n.advertise<std_msgs::Bool>("shutdown", 1);
38  init();
39 
40  while(exit_cmd == false){
41  string cmd;
42  printf(">> ");
43  cin >> cmd;
45  command.force = force;
46  if(cmd.compare("open") == 0){
47  std_msgs::String msg;
48  msg.data = "open";
49  command_ad.publish(msg);
50  }else if(cmd.compare("close") == 0){
51  std_msgs::String msg;
52  msg.data = "close";
53  command_ad.publish(msg);
54  }else if(cmd.compare("relax") == 0){
55  std_msgs::String msg;
56  msg.data = "relax";
57  command_ad.publish(msg);
58  }else if(cmd.compare("get_force") == 0){
59  printf("Force is: %f nM\n", force);
60  }else if(cmd.compare("force") == 0){
61  printf("Set force to: ");
62  cin >> force;
63  std_msgs::Float32 msg;
64  msg.data = force;
65  force_ad.publish(msg);
66  printf("Force set to: %f nM\n", force);
67  }else if(cmd.compare("exit") == 0){
68  exit_cmd = true;
69  std_msgs::Bool msg;
70  msg.data = true;
71  shutdown.publish(msg);
72  }else{
73  printf("Please use the commands 'open', 'close', 'relax', 'force', 'get_force' or 'exit'.\n");
74  }
75  }
76 
77  ros::shutdown();
78 
79  return 0;
80 }
81 
86 void init(){
87  std_msgs::Float32 msg;
88  msg.data = force;
89  force_ad.publish(msg);
90 }


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