56
56
#define SPACENAV_ZERO_WHEN_STATIC_PARAM_S " zero_when_static"
57
57
#define SPACENAV_STATIC_TRANS_DEADBAND_PARAM_S " static_trans_deadband"
58
58
#define SPACENAV_STATIC_ROT_DEADBAND_PARAM_S " static_rot_deadband"
59
+ #define SPACENAV_USE_TWIST_STAMPED_PARAM_S " use_twist_stamped"
59
60
60
61
using namespace std ::chrono_literals;
61
62
@@ -91,6 +92,7 @@ Spacenav::Spacenav(const rclcpp::NodeOptions & options)
91
92
// translation, or both.
92
93
this ->declare_parameter <double >(SPACENAV_STATIC_TRANS_DEADBAND_PARAM_S, 0.1 );
93
94
this ->declare_parameter <double >(SPACENAV_STATIC_ROT_DEADBAND_PARAM_S, 0.1 );
95
+ use_twist_stamped = this ->declare_parameter <bool >(SPACENAV_USE_TWIST_STAMPED_PARAM_S, false );
94
96
95
97
auto param_change_callback = [this ](
96
98
std::vector<rclcpp::Parameter> parameters) {
@@ -117,8 +119,13 @@ Spacenav::Spacenav(const rclcpp::NodeOptions & options)
117
119
" spacenav/offset" , 10 );
118
120
publisher_rot_offset = this ->create_publisher <geometry_msgs::msg::Vector3>(
119
121
" spacenav/rot_offset" , 10 );
120
- publisher_twist =
121
- this ->create_publisher <geometry_msgs::msg::Twist>(" spacenav/twist" , 10 );
122
+ if (use_twist_stamped) {
123
+ publisher_twist_stamped =
124
+ this ->create_publisher <geometry_msgs::msg::TwistStamped>(" spacenav/twist_stamped" , 10 );
125
+ } else {
126
+ publisher_twist =
127
+ this ->create_publisher <geometry_msgs::msg::Twist>(" spacenav/twist" , 10 );
128
+ }
122
129
publisher_joy =
123
130
this ->create_publisher <sensor_msgs::msg::Joy>(" spacenav/joy" , 10 );
124
131
@@ -288,7 +295,14 @@ void Spacenav::poll_spacenav()
288
295
289
296
publisher_offset->publish (std::move (msg_offset));
290
297
publisher_rot_offset->publish (std::move (msg_rot_offset));
291
- publisher_twist->publish (std::move (msg_twist));
298
+ if (use_twist_stamped) {
299
+ auto msg_twist_stamped = std::make_unique<geometry_msgs::msg::TwistStamped>();
300
+ msg_twist_stamped->header .stamp = msg_joystick->header .stamp ;
301
+ msg_twist_stamped->twist = *msg_twist;
302
+ publisher_twist_stamped->publish (std::move (msg_twist_stamped));
303
+ } else {
304
+ publisher_twist->publish (std::move (msg_twist));
305
+ }
292
306
293
307
no_motion_count = 0 ;
294
308
motion_stale = false ;
0 commit comments