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,8 @@ 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
+ this ->declare_parameter <bool >(SPACENAV_USE_TWIST_STAMPED_PARAM_S, false );
96
+ this ->get_parameter <bool >(SPACENAV_USE_TWIST_STAMPED_PARAM_S, use_twist_stamped);
94
97
95
98
auto param_change_callback = [this ](
96
99
std::vector<rclcpp::Parameter> parameters) {
@@ -117,8 +120,13 @@ Spacenav::Spacenav(const rclcpp::NodeOptions & options)
117
120
" spacenav/offset" , 10 );
118
121
publisher_rot_offset = this ->create_publisher <geometry_msgs::msg::Vector3>(
119
122
" spacenav/rot_offset" , 10 );
120
- publisher_twist =
121
- this ->create_publisher <geometry_msgs::msg::Twist>(" spacenav/twist" , 10 );
123
+ if (use_twist_stamped) {
124
+ publisher_twist_stamped =
125
+ this ->create_publisher <geometry_msgs::msg::TwistStamped>(" spacenav/twist" , 10 );
126
+ } else {
127
+ publisher_twist =
128
+ this ->create_publisher <geometry_msgs::msg::Twist>(" spacenav/twist" , 10 );
129
+ }
122
130
publisher_joy =
123
131
this ->create_publisher <sensor_msgs::msg::Joy>(" spacenav/joy" , 10 );
124
132
@@ -288,7 +296,14 @@ void Spacenav::poll_spacenav()
288
296
289
297
publisher_offset->publish (std::move (msg_offset));
290
298
publisher_rot_offset->publish (std::move (msg_rot_offset));
291
- publisher_twist->publish (std::move (msg_twist));
299
+ if (use_twist_stamped) {
300
+ auto msg_twist_stamped = std::make_unique<geometry_msgs::msg::TwistStamped>();
301
+ msg_twist_stamped->header .stamp = msg_joystick->header .stamp ;
302
+ msg_twist_stamped->twist = *msg_twist;
303
+ publisher_twist_stamped->publish (std::move (msg_twist_stamped));
304
+ } else {
305
+ publisher_twist->publish (std::move (msg_twist));
306
+ }
292
307
293
308
no_motion_count = 0 ;
294
309
motion_stale = false ;
0 commit comments