dragonrise_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  {
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 
34  twist.twist.linear.x = -msg->axes[0]; // left stick x (inversed)
35  twist.twist.linear.y = msg->axes[1]; // left stick y
36  twist.twist.linear.z = msg->axes[4]; // right stick y
37 
38  // buttons
39  twist.twist.angular.x = -msg->axes[5]; // dpad x (inversed)
40  twist.twist.angular.y = msg->axes[6]; // dpad y
41  // A binary button
42  twist.twist.angular.z = -msg->buttons[6] + msg->buttons[4]; // buttons L2 L1
43 
44  // Joint jogging
45  jog_msgs::JogJoint joint_deltas;
46  // This example is for a Phoenix hexapod : "femur_joint_r1" is the R1 femur
47  // joint (move leg up/down)
48  joint_deltas.joint_names.push_back("femur_joint_r1");
49  joint_deltas.deltas.push_back(msg->buttons[5] - msg->buttons[7]); // buttons R2 R1
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, "dragonrise_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())
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void joyCallback(const sensor_msgs::Joy::ConstPtr &msg)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static Time now()
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