spacenav_to_twist.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * Title : spacenav_to_twist.cpp
3  * Project : moveit_servo
4  * Created : 1/11/2019
5  * Author : Brian O'Neil, Andy Zelenak, Blake Anderson
6  *
7  * BSD 3-Clause License
8  *
9  * Copyright (c) 2019, Los Alamos National Security, LLC
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * * Redistributions of source code must retain the above copyright notice, this
16  * list of conditions and the following disclaimer.
17  *
18  * * Redistributions in binary form must reproduce the above copyright notice,
19  * this list of conditions and the following disclaimer in the documentation
20  * and/or other materials provided with the distribution.
21  *
22  * * Neither the name of the copyright holder nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE
30  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *******************************************************************************/
38 
39 #include "geometry_msgs/TwistStamped.h"
40 #include "control_msgs/JointJog.h"
41 #include "ros/ros.h"
42 #include "sensor_msgs/Joy.h"
43 
44 namespace moveit_servo
45 {
46 static const int NUM_SPINNERS = 1;
47 static const int QUEUE_LENGTH = 1;
48 
49 class SpaceNavToTwist
50 {
51 public:
53  {
55  twist_pub_ = n_.advertise<geometry_msgs::TwistStamped>("servo_server/delta_twist_cmds", QUEUE_LENGTH);
56  joint_delta_pub_ = n_.advertise<control_msgs::JointJog>("servo_server/delta_joint_cmds", QUEUE_LENGTH);
57 
58  spinner_.start();
60  };
61 
62 private:
63  // Convert incoming joy commands to TwistStamped commands for servoing.
64  // The TwistStamped component goes to servoing, while buttons 0 & 1 control
65  // joints directly.
66  void joyCallback(const sensor_msgs::Joy::ConstPtr& msg)
67  {
68  // Cartesian servoing with the axes
69  geometry_msgs::TwistStamped twist;
70  twist.header.stamp = ros::Time::now();
71  twist.twist.linear.x = msg->axes[0];
72  twist.twist.linear.y = msg->axes[1];
73  twist.twist.linear.z = msg->axes[2];
74 
75  twist.twist.angular.x = msg->axes[3];
76  twist.twist.angular.y = msg->axes[4];
77  twist.twist.angular.z = msg->axes[5];
78 
79  // Joint servoing with the buttons
80  control_msgs::JointJog joint_deltas;
81  // This example is for a UR5.
82  joint_deltas.joint_names.push_back("shoulder_pan_joint");
83 
84  // Button 0: positive on the wrist joint
85  // Button 1: negative on the wrist joint
86  joint_deltas.velocities.push_back(msg->buttons[0] - msg->buttons[1]);
87  joint_deltas.header.stamp = ros::Time::now();
88 
89  twist_pub_.publish(twist);
90  joint_delta_pub_.publish(joint_deltas);
91  }
92 
97 };
98 } // namespace moveit_servo
99 
100 int main(int argc, char** argv)
101 {
102  ros::init(argc, argv, "spacenav_to_twist");
103 
105 
106  return 0;
107 }
moveit_servo::SpaceNavToTwist::twist_pub_
ros::Publisher twist_pub_
Definition: spacenav_to_twist.cpp:131
ros::Publisher
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros::AsyncSpinner::start
void start()
ros.h
moveit_servo::SpaceNavToTwist
Definition: spacenav_to_twist.cpp:85
moveit_servo::SpaceNavToTwist::SpaceNavToTwist
SpaceNavToTwist()
Definition: spacenav_to_twist.cpp:88
moveit_servo::SpaceNavToTwist::n_
ros::NodeHandle n_
Definition: spacenav_to_twist.cpp:129
ros::AsyncSpinner
moveit_servo::SpaceNavToTwist::joy_sub_
ros::Subscriber joy_sub_
Definition: spacenav_to_twist.cpp:130
moveit_servo::SpaceNavToTwist::spinner_
ros::AsyncSpinner spinner_
Definition: spacenav_to_twist.cpp:132
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
moveit_servo::SpaceNavToTwist::joyCallback
void joyCallback(const sensor_msgs::Joy::ConstPtr &msg)
Definition: spacenav_to_twist.cpp:102
main
int main(int argc, char **argv)
Definition: spacenav_to_twist.cpp:100
moveit_servo
Definition: collision_check.h:50
moveit_servo::NUM_SPINNERS
static const int NUM_SPINNERS
Definition: spacenav_to_twist.cpp:82
moveit_servo::QUEUE_LENGTH
static const int QUEUE_LENGTH
Definition: spacenav_to_twist.cpp:83
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
ros::waitForShutdown
ROSCPP_DECL void waitForShutdown()
moveit_servo::SpaceNavToTwist::joint_delta_pub_
ros::Publisher joint_delta_pub_
Definition: spacenav_to_twist.cpp:131
ros::NodeHandle
ros::Subscriber
ros::Time::now
static Time now()


moveit_servo
Author(s): Brian O'Neil, Andy Zelenak , Blake Anderson, Alexander Rössler , Tyler Weaver
autogenerated on Sat May 3 2025 02:27:56