@@ -49,18 +49,27 @@ ComplementaryFilterROS::ComplementaryFilterROS(
49
49
int queue_size = 5 ;
50
50
51
51
// Register publishers:
52
- imu_publisher_ = nh_.advertise <sensor_msgs::Imu>(" imu/data" , queue_size);
53
- roll_publisher_ = nh_.advertise <std_msgs::Float64>(" imu/roll" , queue_size);
54
- pitch_publisher_ = nh_.advertise <std_msgs::Float64>(" imu/pitch" , queue_size);
55
- yaw_publisher_ = nh_.advertise <std_msgs::Float64>(" imu/yaw" , queue_size);
56
-
52
+ imu_publisher_ = nh_.advertise <sensor_msgs::Imu>(ros::names::resolve (" imu" ) + " /data" , queue_size);
53
+
54
+ if (publish_debug_topics_)
55
+ {
56
+ rpy_publisher_ = nh_.advertise <geometry_msgs::Vector3Stamped>(
57
+ ros::names::resolve (" imu" ) + " /rpy/filtered" , queue_size);
58
+
59
+ if (filter_.getDoBiasEstimation ())
60
+ {
61
+ state_publisher_ = nh_.advertise <std_msgs::Bool>(
62
+ ros::names::resolve (" imu" ) + " /steady_state" , queue_size);
63
+ }
64
+ }
65
+
57
66
// Register IMU raw data subscriber.
58
- imu_subscriber_.reset (new ImuSubscriber (nh_, " imu/data_raw" , queue_size));
67
+ imu_subscriber_.reset (new ImuSubscriber (nh_, ros::names::resolve ( " imu" ) + " /data_raw" , queue_size));
59
68
60
69
// Register magnetic data subscriber.
61
70
if (use_mag_)
62
71
{
63
- mag_subscriber_.reset (new MagSubscriber (nh_, " imu/mag" , queue_size));
72
+ mag_subscriber_.reset (new MagSubscriber (nh_, ros::names::resolve ( " imu" ) + " /mag" , queue_size));
64
73
65
74
sync_.reset (new Synchronizer (
66
75
SyncPolicy (queue_size), *imu_subscriber_, *mag_subscriber_));
@@ -72,12 +81,6 @@ ComplementaryFilterROS::ComplementaryFilterROS(
72
81
imu_subscriber_->registerCallback (
73
82
&ComplementaryFilterROS::imuCallback, this );
74
83
}
75
-
76
- if (filter_.getDoBiasEstimation ())
77
- {
78
- state_publisher_ = nh_.advertise <std_msgs::Bool>(" imu/steady_state" ,
79
- queue_size);
80
- }
81
84
}
82
85
83
86
ComplementaryFilterROS::~ComplementaryFilterROS ()
@@ -97,6 +100,14 @@ void ComplementaryFilterROS::initializeParams()
97
100
fixed_frame_ = " odom" ;
98
101
if (!nh_private_.getParam (" use_mag" , use_mag_))
99
102
use_mag_ = false ;
103
+ if (!nh_private_.getParam (" publish_tf" , publish_tf_))
104
+ publish_tf_ = false ;
105
+ if (!nh_private_.getParam (" reverse_tf" , reverse_tf_))
106
+ reverse_tf_ = false ;
107
+ if (!nh_private_.getParam (" constant_dt" , constant_dt_))
108
+ constant_dt_ = 0.0 ;
109
+ if (!nh_private_.getParam (" publish_debug_topics" , publish_debug_topics_))
110
+ publish_debug_topics_ = false ;
100
111
if (!nh_private_.getParam (" gain_acc" , gain_acc))
101
112
gain_acc = 0.01 ;
102
113
if (!nh_private_.getParam (" gain_mag" , gain_mag))
@@ -123,6 +134,15 @@ void ComplementaryFilterROS::initializeParams()
123
134
if (!filter_.setBiasAlpha (bias_alpha))
124
135
ROS_WARN (" Invalid bias_alpha passed to ComplementaryFilter." );
125
136
}
137
+
138
+ // check for illegal constant_dt values
139
+ if (constant_dt_ < 0.0 )
140
+ {
141
+ // if constant_dt_ is 0.0 (default), use IMU timestamp to determine dt
142
+ // otherwise, it will be constant
143
+ ROS_WARN (" constant_dt parameter is %f, must be >= 0.0. Setting to 0.0" , constant_dt_);
144
+ constant_dt_ = 0.0 ;
145
+ }
126
146
}
127
147
128
148
void ComplementaryFilterROS::imuCallback (const ImuMsg::ConstPtr& imu_msg_raw)
@@ -139,8 +159,13 @@ void ComplementaryFilterROS::imuCallback(const ImuMsg::ConstPtr& imu_msg_raw)
139
159
return ;
140
160
}
141
161
142
- // Calculate dt.
143
- double dt = (time - time_prev_).toSec ();
162
+ // determine dt: either constant, or from IMU timestamp
163
+ double dt;
164
+ if (constant_dt_ > 0.0 )
165
+ dt = constant_dt_;
166
+ else
167
+ dt = (time - time_prev_).toSec ();
168
+
144
169
time_prev_ = time;
145
170
146
171
// Update the filter.
@@ -215,38 +240,50 @@ void ComplementaryFilterROS::publish(
215
240
216
241
imu_publisher_.publish (imu_msg);
217
242
218
- // Create and publish roll, pitch, yaw angles
219
- double roll, pitch, yaw;
220
- tf::Matrix3x3 M;
221
- M.setRotation (q);
222
- M.getRPY (roll, pitch, yaw);
223
- std_msgs::Float64 roll_msg;
224
- std_msgs::Float64 pitch_msg;
225
- std_msgs::Float64 yaw_msg;
226
- roll_msg.data = roll;
227
- pitch_msg.data = pitch;
228
- yaw_msg.data = yaw;
229
- roll_publisher_.publish (roll_msg);
230
- pitch_publisher_.publish (pitch_msg);
231
- yaw_publisher_.publish (yaw_msg);
232
-
233
- // Publish whether we are in the steady state, when doing bias estimation
234
- if (filter_.getDoBiasEstimation ())
243
+ if (publish_debug_topics_)
235
244
{
236
- std_msgs::Bool state_msg;
237
- state_msg.data = filter_.getSteadyState ();
238
- state_publisher_.publish (state_msg);
245
+ // Create and publish roll, pitch, yaw angles
246
+ geometry_msgs::Vector3Stamped rpy;
247
+ rpy.header = imu_msg_raw->header ;
248
+
249
+ tf::Matrix3x3 M;
250
+ M.setRotation (q);
251
+ M.getRPY (rpy.vector .x , rpy.vector .y , rpy.vector .z );
252
+ rpy_publisher_.publish (rpy);
253
+
254
+ // Publish whether we are in the steady state, when doing bias estimation
255
+ if (filter_.getDoBiasEstimation ())
256
+ {
257
+ std_msgs::Bool state_msg;
258
+ state_msg.data = filter_.getSteadyState ();
259
+ state_publisher_.publish (state_msg);
260
+ }
239
261
}
240
262
241
- // Create and publish the ROS tf.
242
- tf::Transform transform;
243
- transform.setOrigin (tf::Vector3 (0.0 , 0.0 , 0.0 ));
244
- transform.setRotation (q);
245
- tf_broadcaster_.sendTransform (
246
- tf::StampedTransform (transform,
247
- imu_msg_raw->header .stamp ,
248
- fixed_frame_,
249
- imu_msg_raw->header .frame_id ));
263
+ if (publish_tf_)
264
+ {
265
+ // Create and publish the ROS tf.
266
+ tf::Transform transform;
267
+ transform.setOrigin (tf::Vector3 (0.0 , 0.0 , 0.0 ));
268
+ transform.setRotation (q);
269
+
270
+ if (reverse_tf_)
271
+ {
272
+ tf_broadcaster_.sendTransform (
273
+ tf::StampedTransform (transform.inverse (),
274
+ imu_msg_raw->header .stamp ,
275
+ imu_msg_raw->header .frame_id ,
276
+ fixed_frame_));
277
+ }
278
+ else
279
+ {
280
+ tf_broadcaster_.sendTransform (
281
+ tf::StampedTransform (transform,
282
+ imu_msg_raw->header .stamp ,
283
+ fixed_frame_,
284
+ imu_msg_raw->header .frame_id ));
285
+ }
286
+ }
250
287
}
251
288
252
289
} // namespace imu_tools
0 commit comments