xbox_to_twist.cpp
Go to the documentation of this file.
1 #include "geometry_msgs/TwistStamped.h"
2 #include "jog_msgs/JogJoint.h"
3 #include "ros/ros.h"
4 #include "sensor_msgs/Joy.h"
5 
6 namespace to_twist
7 {
9 {
10 public:
12  {
13  joy_sub_ = n_.subscribe("joy", 1, &xboxToTwist::joyCallback, this);
14  twist_pub_ = n_.advertise<geometry_msgs::TwistStamped>("jog_arm_server/delta_jog_cmds", 1);
15  joint_delta_pub_ = n_.advertise<jog_msgs::JogJoint>("jog_arm_server/joint_delta_jog_cmds", 1);
16 
17  spinner_.start();
19  };
20 
21 private:
26 
27  // Convert incoming joy commands to TwistStamped commands for jogging
28  void joyCallback(const sensor_msgs::Joy::ConstPtr& msg)
29  {
30  // Cartesian jogging
31  geometry_msgs::TwistStamped twist;
32  twist.header.stamp = ros::Time::now();
33  // This button is binary
34  twist.twist.linear.x = -msg->buttons[4] + msg->buttons[5];
35  // Double buttons
36  twist.twist.linear.y = msg->axes[0];
37  twist.twist.linear.z = msg->axes[1];
38  twist.twist.angular.x = -msg->axes[3];
39  twist.twist.angular.y = msg->axes[4];
40  // A binary button
41  twist.twist.angular.z = -msg->buttons[0] + msg->buttons[1];
42 
43  // Joint jogging
44  jog_msgs::JogJoint joint_deltas;
45  // This example is for a Motoman SIA5. joint_s is the base joint.
46  joint_deltas.joint_names.push_back("joint_s");
47  // Button 6: positive
48  // Button 7: negative
49  joint_deltas.deltas.push_back(msg->buttons[6] - msg->buttons[7]);
50  joint_deltas.header.stamp = ros::Time::now();
51 
52  twist_pub_.publish(twist);
53  joint_delta_pub_.publish(joint_deltas);
54  }
55 };
56 } // end to_twist namespace
57 
58 int main(int argc, char** argv)
59 {
60  ros::init(argc, argv, "xbox_to_twist");
61 
63 
64  return 0;
65 }
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())
ros::Subscriber joy_sub_
ros::NodeHandle n_
void joyCallback(const sensor_msgs::Joy::ConstPtr &msg)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Publisher joint_delta_pub_
int main(int argc, char **argv)
ros::Publisher twist_pub_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static Time now()
ros::AsyncSpinner spinner_
ROSCPP_DECL void waitForShutdown()


jog_arm
Author(s): Brian O'Neil, Andy Zelenak , Blake Anderson, Nitish Sharma, Alexander Rössler
autogenerated on Mon Jun 10 2019 13:47:53