arm_joy_node.cpp
Go to the documentation of this file.
1 //
2 // Created by tom on 17/07/16.
3 //
4 
5 #include <ros/ros.h>
6 #include <sensor_msgs/Joy.h>
8 #include <control_msgs/GripperCommandAction.h>
10 #include <control_msgs/GripperCommandAction.h>
11 
12 #define DEBUG_JOY_ARM
13 
15 
16 class ArmJoyNode {
17 private:
27  // arm state
35 
36  //buttons and axis indexs
47 
49 
51  const control_msgs::GripperCommandResultConstPtr& result)
52  {
53  _gripperWorking = false;
54  }
55 
56  void joyCallback(const sensor_msgs::Joy::ConstPtr &msg) {
57  bool isDeadManActive = msg->buttons[_deadManIndex] == 1;
58 
59  if(!isDeadManActive) {
60  if(msg->axes[_hardProfileIndex] == -1.0) {
61  if(msg->axes[_rightLeftAxis] == 1) {
62  _rotation1State = 1;
63  } else if(msg->axes[_rightLeftAxis] == -1) {
64  _rotation1State = -1;
65  }
66 
67  if(msg->axes[_upDownAxis] == 1) {
68  _shoulder1State = -1;
69  } else if(msg->axes[_upDownAxis] == -1) {
70  _shoulder1State = 1;
71  }
72 
73  if(msg->buttons[_xButtonIndex] == 1) {
74  _rotation2State = -1;
75  } else if(msg->buttons[_bButtonIndex] == 1) {
76  _rotation2State = 1;
77  }
78  if(msg->buttons[_yButtonIndex] == 1) {
79  _shoulder2State = -1;
80  } else if(msg->buttons[_aButtonIndex] == 1) {
81  _shoulder2State = 1;
82  }
83 
84 
85  } else if(msg->axes[_softProfileIndex] == -1.0) {
86  if(msg->axes[_rightLeftAxis] == 1) {
87  _wristState = -1;
88  } else if(msg->axes[_rightLeftAxis] == -1) {
89  _wristState = 1;
90  }
91 
92  if(msg->axes[_upDownAxis] == 1) {
93  _shoulder3State = -1;
94  } else if (msg->axes[_upDownAxis] == -1) {
95  _shoulder3State = 1;
96  }
97 
98  if(msg->buttons[_yButtonIndex] == 1) {
99  _gripperState = 1;
100  } else if(msg->buttons[_aButtonIndex] == 1) {
101  _gripperState = -1;
102  }
103  }
104  }
105 
106  }
107  bool haveMoveGoal() {
108  return _rotation1State == 1 || _rotation1State == -1
109  || _rotation2State == 1 || _rotation2State == -1
110  || _shoulder1State == 1 || _shoulder1State == -1
111  || _shoulder2State == 1 || _shoulder2State == -1
112  || _shoulder3State == 1 || _shoulder3State == -1
113  || _wristState == 1 || _wristState == -1
114  || _gripperState == 1 || _gripperState == -1;
115  }
116 public:
117  ArmJoyNode(): _nodeHandle(), _spinner(2), _group("arm") {
118  ROS_INFO("[%s]: Arm joy node is active", ros::this_node::getName().c_str());
119  _rotation1State = 0;
120  _rotation2State = 0;
121  _shoulder1State = 0;
122  _shoulder2State = 0;
123  _shoulder3State = 0;
124  _wristState = 0;
125  _gripperState = 0;
126  _gripperWorking = false;
127  _joySub = _nodeHandle.subscribe<sensor_msgs::Joy>("joy", 10, &ArmJoyNode::joyCallback, this);
128  _group.setPlannerId("RRTConnectkConfigDefault");
129 
130 
131 
132  ros::param::param<int>("drive_joy_teleop_deadman_button", _deadManIndex, 8);
133  ros::param::param<int>("arm_joy_node_hard_profile_index", _hardProfileIndex, 4);
134  ros::param::param<int>("arm_joy_node_soft_profile_index", _softProfileIndex, 5);
135  ros::param::param<int>("arm_joy_node_x_button_index", _xButtonIndex, 3);
136  ros::param::param<int>("arm_joy_node_y_button_index", _yButtonIndex, 4);
137  ros::param::param<int>("arm_joy_node_a_button_index", _aButtonIndex, 0);
138  ros::param::param<int>("arm_joy_node_b_button_index", _bButtonIndex, 1);
139  ros::param::param<int>("arm_joy_node_up_down_index", _upDownAxis, 7);
140  ros::param::param<int>("arm_joy_node_left_right_index", _rightLeftAxis, 6);
141 
142  ros::param::param<float>("arm_joy_node_rotation1", _rotation1IncreamentValue, 0.05);
143  ros::param::param<float>("arm_joy_node_rotation2", _rotation2IncreamentValue, 0.1);
144  ros::param::param<float>("arm_joy_node_shoulder1", _shoulder1IncreamentValue, 0.05);
145  ros::param::param<float>("arm_joy_node_shoulder2", _shoulder2IncreamentValue, 0.05);
146  ros::param::param<float>("arm_joy_node_shoulder3", _shoulder3IncreamentValue, 0.05);
147  ros::param::param<float>("arm_joy_node_wrist", _wristIncreamentValue, 0.1);
148 
149  _spinner.start();
150  }
151 
152  void run() {
153  ros::Rate loopRate(50);
154  std::vector<double> group_variable_values;
155  _group.getCurrentState()->copyJointGroupPositions(
156  _group.getCurrentState()->getRobotModel()->getJointModelGroup(_group.getName()),
157  group_variable_values);
158 
159  while(ros::ok()) {
160  if(haveMoveGoal()) {
161 
162 
163  if(_rotation1State == -1) {
164  _rotation1State = 0;
165  group_variable_values[0] -= _rotation1IncreamentValue;
166  } else if(_rotation1State == 1) {
167  _rotation1State = 0;
168  group_variable_values[0] += _rotation1IncreamentValue;
169  }
170 
171  if(_shoulder1State == -1) {
172  _shoulder1State = 0;
173  group_variable_values[1] -= _shoulder1IncreamentValue;
174  } else if(_shoulder1State == 1) {
175  _shoulder1State = 0;
176  group_variable_values[1] += _shoulder1IncreamentValue;
177  }
178 
179  if(_shoulder2State == -1) {
180  _shoulder2State = 0;
181  group_variable_values[2] -= _shoulder2IncreamentValue;
182  } else if(_shoulder2State == 1) {
183  _shoulder2State = 0;
184  group_variable_values[2] += _shoulder2IncreamentValue;
185  }
186 
187  if(_rotation2State == -1) {
188  _rotation2State = 0;
189  group_variable_values[3] -= _rotation2IncreamentValue;
190  } else if(_rotation2State == 1) {
191  _rotation2State = 0;
192  group_variable_values[3] += _rotation2IncreamentValue;
193  }
194 
195  if(_shoulder3State == -1) {
196  _shoulder3State = 0;
197  group_variable_values[4] -= _shoulder3IncreamentValue;
198  } else if(_shoulder3State == 1) {
199  _shoulder3State = 0;
200  group_variable_values[4] += _shoulder3IncreamentValue;
201  }
202 
203  if(_wristState == -1) {
204  _wristState = 0;
205  group_variable_values[5] -= _wristIncreamentValue;
206  } else if(_wristState == 1) {
207  _wristState = 0;
208  group_variable_values[5] += _wristIncreamentValue;
209  }
210 
211  if(_gripperState == -1) {
212  _gripperState = 0;
213  if(!_gripperWorking) {
214 
215  } else {
216  ROS_WARN("[%s]: Gripper already have a goal please wait", ros::this_node::getName().c_str());
217  }
218 
219  } else if(_gripperState == 1) {
220  _gripperState = 0;
221  if (!_gripperWorking) {
222 
223  } else {
224  ROS_WARN("[%s]: Gripper already have a goal please wait", ros::this_node::getName().c_str());
225  }
226 
227  }
228 
229 
230 
231 
232  _group.setJointValueTarget(group_variable_values);
234  bool success = _group.plan(my_plan);
235  if (success) {
236  _group.move();
237  }
238  else {
239  ROS_WARN("[%s]: Invalid goal", ros::this_node::getName().c_str());
240  }
241  }
242 
243  loopRate.sleep();
244  }
245  }
246 
247 
248 
249 };
250 
251 int main(int argc, char** argv) {
252 
253  ros::init(argc, argv, "arm_joy_node");
254  ArmJoyNode armJoy;
255  armJoy.run();
256 
257  return 0;
258 
259 }
ros::AsyncSpinner _spinner
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool setJointValueTarget(const std::vector< double > &group_variable_values)
float _shoulder2IncreamentValue
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int _shoulder3State
ROSCPP_DECL const std::string & getName()
int main(int argc, char **argv)
float _shoulder3IncreamentValue
void setPlannerId(const std::string &planner_id)
bool haveMoveGoal()
#define ROS_WARN(...)
float _rotation2IncreamentValue
bool _gripperWorking
void joyCallback(const sensor_msgs::Joy::ConstPtr &msg)
void doneCb(const actionlib::SimpleClientGoalState &state, const control_msgs::GripperCommandResultConstPtr &result)
#define ROS_INFO(...)
int _rotation1State
ROSCPP_DECL bool ok()
float _rotation1IncreamentValue
ros::NodeHandle _nodeHandle
moveit::planning_interface::MoveGroup _group
actionlib::SimpleActionClient< control_msgs::GripperCommandAction > GripperClient
int _rightLeftAxis
bool sleep()
float _wristIncreamentValue
int _hardProfileIndex
ros::Subscriber _joySub
int _softProfileIndex
int _shoulder2State
robot_state::RobotStatePtr getCurrentState()
float _shoulder1IncreamentValue
int _shoulder1State
int _rotation2State


robotican_common
Author(s):
autogenerated on Wed Jan 3 2018 03:48:33