spacenav_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("spacenav/joy", 1, &spaceNavToTwist::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  // The TwistStamped component goes to jogging, while buttons 0 & 1 control
29  // joints directly.
30  void joyCallback(const sensor_msgs::Joy::ConstPtr& msg)
31  {
32  // Cartesian jogging with the axes
33  geometry_msgs::TwistStamped twist;
34  twist.header.stamp = ros::Time::now();
35  twist.twist.linear.x = msg->axes[0];
36  twist.twist.linear.y = msg->axes[1];
37  twist.twist.linear.z = msg->axes[2];
38 
39  twist.twist.angular.x = msg->axes[3];
40  twist.twist.angular.y = msg->axes[4];
41  twist.twist.angular.z = msg->axes[5];
42 
43  // Joint jogging with the buttons
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 
48  // Button 0: positive on the wrist joint
49  // Button 1: negative on the wrist joint
50  joint_deltas.deltas.push_back(msg->buttons[0] - msg->buttons[1]);
51  joint_deltas.header.stamp = ros::Time::now();
52 
53  twist_pub_.publish(twist);
54  joint_delta_pub_.publish(joint_deltas);
55  }
56 };
57 } // end to_twist namespace
58 
59 int main(int argc, char** argv)
60 {
61  ros::init(argc, argv, "spacenav_to_twist");
62 
64 
65  return 0;
66 }
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())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static Time now()
void joyCallback(const sensor_msgs::Joy::ConstPtr &msg)
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