svenzva_6axis_controller.cpp
Go to the documentation of this file.
1 // Software License Agreement (BSD License)
2 //
3 // Copyright (c) 2017 Svenzva Robotics
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 // * Neither the name of University of Arizona nor the names of its
17 // contributors may be used to endorse or promote products derived
18 // from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 
33 #include <ros/ros.h>
34 #include <geometry_msgs/Twist.h>
35 #include <sensor_msgs/Joy.h>
36 #include <svenzva_msgs/GripperAction.h>
38 
39 /*
40  * This handles the joystick / velocity interface for the
41  * Svenzva Robotics custom 3 + 3 axis joystick controller.
42  *
43  */
44 
46 
48 {
49 public:
51  sensor_msgs::Joy last_cmd;
52  bool valid;
54 
55 private:
56  void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
57 
59 
61  double l_scale_, a_scale_;
64  ros::Rate r;
65 };
66 
68  linear_x(0),
69  linear_y(1),
70  linear_z(4),
71  angular_x(4),
72  angular_y(4),
73  angular_z(4),
74  gripper_button(0),
75  rate_(20),
76  r(20)
77 {
78  nh_.param("rate", rate_, rate_);
79  nh_.param("axis_linear_x", linear_x, linear_x);
80  nh_.param("axis_linear_y", linear_y, linear_y);
81  nh_.param("axis_linear_z", linear_z, linear_z);
82  nh_.param("axis_angular_x", angular_x, angular_x);
83  nh_.param("axis_angular_y", angular_y, angular_y);
84  nh_.param("axis_angular_z", angular_z, angular_z);
85  nh_.param("gripper_button", gripper_button, gripper_button);
86  nh_.param("scale_angular", a_scale_, a_scale_);
87  nh_.param("scale_linear", l_scale_, l_scale_);
88 
89  valid = false;
90  r = ros::Rate(rate_);
91  vel_pub_ = nh_.advertise<geometry_msgs::Twist>("revel/eef_velocity", 1);
92  joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("joy", 1, &SvenzvaArmJoystick::joyCallback, this);
93 
94 }
95 
96 void SvenzvaArmJoystick::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
97 {
98  geometry_msgs::Twist twist;
99 
100  twist.linear.x = l_scale_*joy->axes[linear_x];
101  twist.linear.y = l_scale_*joy->axes[linear_y];
102  twist.linear.z = l_scale_*joy->axes[linear_z];
103  twist.angular.x = a_scale_*joy->axes[angular_x];
104  twist.angular.y = -1 * a_scale_*joy->axes[angular_y];
105  twist.angular.z = a_scale_*joy->axes[angular_z];
106  vel_pub_.publish(twist);
107  last_cmd = *joy;
108  valid = true;
109 }
110 
111 
112 int main(int argc, char** argv)
113 {
114  ros::init(argc, argv, "svenzva_6axis_controller");
115  SvenzvaArmJoystick svenzva_joy;
116  gripperClient gripper_action("/revel/gripper_action", true);
117  gripper_action.waitForServer();
118  bool gripper_open = true;
119 
120  while(svenzva_joy.valid == false){
121  ros::Duration(1.0).sleep();
122  ros::spinOnce();
123  }
124 
125  while(ros::ok()){
126  ros::spinOnce();
127  if(svenzva_joy.last_cmd.buttons[svenzva_joy.gripper_button] == 1){
128 
129  svenzva_msgs::GripperGoal goal;
130  if(gripper_open){
131  goal.target_action = goal.CLOSE;
132  goal.target_current = 200;
133  gripper_open = false;
134  }
135  else{
136  goal.target_action = goal.OPEN;
137  gripper_open = true;
138  }
139  gripper_action.sendGoalAndWait(goal);
140  ros::Duration(0.25).sleep();
141  }
142  ros::Rate(10).sleep();
143  }
144 
145 
146 }
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
actionlib::SimpleActionClient< svenzva_msgs::GripperAction > gripperClient
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void joyCallback(const sensor_msgs::Joy::ConstPtr &joy)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ROSCPP_DECL bool ok()
SimpleClientGoalState sendGoalAndWait(const Goal &goal, const ros::Duration &execute_timeout=ros::Duration(0, 0), const ros::Duration &preempt_timeout=ros::Duration(0, 0))
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool sleep()
int main(int argc, char **argv)
ROSCPP_DECL void spinOnce()


svenzva_joy
Author(s): Max Svetlik
autogenerated on Wed Oct 28 2020 03:31:29