Skip to content

Commit 73c8a35

Browse files
adding boost dep (#579)
* adding boost dep * bump 3.1.1 * adding more destinations * fix deprecated interfaces * fixes * sep exe and lib * dest change lib * uncrustify fixes * adding rclcpp macro definition
1 parent a890b30 commit 73c8a35

33 files changed

+910
-614
lines changed

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ find_package(tf2_eigen REQUIRED)
2929
find_package(tf2_geometry_msgs REQUIRED)
3030
find_package(tf2_ros REQUIRED)
3131
find_package(Eigen3 REQUIRED)
32+
find_package(Boost REQUIRED)
3233

3334
find_package(PkgConfig REQUIRED)
3435
pkg_check_modules(YAML_CPP yaml-cpp)
@@ -211,7 +212,7 @@ if(BUILD_TESTING)
211212
target_link_libraries(test_ukf_localization_node_interfaces ${library_name})
212213
rosidl_target_interfaces(test_ukf_localization_node_interfaces
213214
${PROJECT_NAME} "rosidl_typesupport_cpp")
214-
add_dependencies(test_ukf_localization_node_interfaces ekf_node)
215+
add_dependencies(test_ukf_localization_node_interfaces ukf_node)
215216
ament_add_test(test_ukf_localization_node_interfaces
216217
GENERATE_RESULT_FOR_RETURN_CODE_ZERO
217218
TIMEOUT 300
@@ -307,8 +308,13 @@ install(
307308
ekf_node
308309
ukf_node
309310
robot_localization_listener_node
310-
${library_name}
311-
DESTINATION lib/${PROJECT_NAME}
311+
RUNTIME DESTINATION lib/${PROJECT_NAME}
312+
)
313+
314+
install(TARGETS ${library_name}
315+
ARCHIVE DESTINATION lib
316+
LIBRARY DESTINATION lib
317+
RUNTIME DESTINATION bin
312318
)
313319

314320
# Install params config files.

include/robot_localization/filter_base.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
#include <vector>
4747
#include <limits>
4848

49+
#include "rclcpp/macros.hpp"
50+
4951
namespace robot_localization
5052
{
5153

include/robot_localization/navsat_conversions.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ static inline void LLtoUTM(
259259
char zone_buf[] = {0, 0, 0, 0};
260260
// We &0x3fU to let GCC know the size of ZoneNumber. In this case, it's under
261261
// 63 (6bits)
262-
snprintf(zone_buf, sizeof(zone_buf), "%d%c", ZoneNumber & 0x3fU,
262+
snprintf(
263+
zone_buf, sizeof(zone_buf), "%d%c", ZoneNumber & 0x3fU,
263264
UTMLetterDesignator(Lat));
264265
UTMZone = std::string(zone_buf);
265266

launch/ekf.launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def generate_launch_description():
2727
return LaunchDescription([
2828
launch_ros.actions.Node(
2929
package='robot_localization',
30-
node_executable='ekf_node',
31-
node_name='ekf_filter_node',
30+
executable='ekf_node',
31+
name='ekf_filter_node',
3232
output='screen',
3333
parameters=[os.path.join(get_package_share_directory("robot_localization"), 'params', 'ekf.yaml')],
3434
),

launch/navsat_transform.launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def generate_launch_description():
2626
return LaunchDescription([
2727
launch_ros.actions.Node(
2828
package='robot_localization',
29-
node_executable='navsat_transform_node',
30-
node_name='navsat_transform_node',
29+
executable='navsat_transform_node',
30+
name='navsat_transform_node',
3131
output='screen',
3232
parameters=[os.path.join(get_package_share_directory("robot_localization"), 'params', 'navsat_transform.yaml')],
3333
),

launch/ukf.launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def generate_launch_description():
2727
return LaunchDescription([
2828
launch_ros.actions.Node(
2929
package='robot_localization',
30-
node_executable='ukf_node',
31-
node_name='ukf_filter_node',
30+
executable='ukf_node',
31+
name='ukf_filter_node',
3232
output='screen',
3333
parameters=[os.path.join(get_package_share_directory("robot_localization"), 'params', 'ukf.yaml')],
3434
),

package.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>robot_localization</name>
5-
<version>3.1.0</version>
5+
<version>3.1.1</version>
66
<description>Provides nonlinear state estimation through sensor fusion of an abritrary number of sensors.</description>
77

88
<author email="[email protected]">Tom Moore</author>
@@ -33,6 +33,7 @@
3333
<depend>tf2_geometry_msgs</depend>
3434
<depend>tf2_ros</depend>
3535
<depend>yaml-cpp</depend>
36+
<depend>boost</depend>
3637

3738
<test_depend>ament_cmake_gtest</test_depend>
3839
<test_depend>builtin_interfaces</test_depend>

src/ekf.cpp

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,22 @@ Ekf::~Ekf() {}
4747

4848
void Ekf::correct(const Measurement & measurement)
4949
{
50-
FB_DEBUG("---------------------- Ekf::correct ----------------------\n" <<
51-
"State is:\n" <<
52-
state_ <<
53-
"\n"
54-
"Topic is:\n" <<
55-
measurement.topic_name_ <<
56-
"\n"
57-
"Measurement is:\n" <<
58-
measurement.measurement_ <<
59-
"\n"
60-
"Measurement topic name is:\n" <<
61-
measurement.topic_name_ <<
62-
"\n\n"
63-
"Measurement covariance is:\n" <<
64-
measurement.covariance_ << "\n");
50+
FB_DEBUG(
51+
"---------------------- Ekf::correct ----------------------\n" <<
52+
"State is:\n" <<
53+
state_ <<
54+
"\n"
55+
"Topic is:\n" <<
56+
measurement.topic_name_ <<
57+
"\n"
58+
"Measurement is:\n" <<
59+
measurement.measurement_ <<
60+
"\n"
61+
"Measurement topic name is:\n" <<
62+
measurement.topic_name_ <<
63+
"\n\n"
64+
"Measurement covariance is:\n" <<
65+
measurement.covariance_ << "\n");
6566

6667
// We don't want to update everything, so we need to build matrices that only
6768
// update the measured parts of our state vector. Throughout prediction and
@@ -73,11 +74,13 @@ void Ekf::correct(const Measurement & measurement)
7374
if (measurement.update_vector_[i]) {
7475
// Handle nan and inf values in measurements
7576
if (std::isnan(measurement.measurement_(i))) {
76-
FB_DEBUG("Value at index " << i <<
77-
" was nan. Excluding from update.\n");
77+
FB_DEBUG(
78+
"Value at index " << i <<
79+
" was nan. Excluding from update.\n");
7880
} else if (std::isinf(measurement.measurement_(i))) {
79-
FB_DEBUG("Value at index " << i <<
80-
" was inf. Excluding from update.\n");
81+
FB_DEBUG(
82+
"Value at index " << i <<
83+
" was inf. Excluding from update.\n");
8184
} else {
8285
update_indices.push_back(i);
8386
}
@@ -117,10 +120,11 @@ void Ekf::correct(const Measurement & measurement)
117120
// than exclude the measurement or make up a covariance, just take
118121
// the absolute value.
119122
if (measurement_covariance_subset(i, i) < 0) {
120-
FB_DEBUG("WARNING: Negative covariance for index " <<
121-
i << " of measurement (value is" <<
122-
measurement_covariance_subset(i, i) <<
123-
"). Using absolute value...\n");
123+
FB_DEBUG(
124+
"WARNING: Negative covariance for index " <<
125+
i << " of measurement (value is" <<
126+
measurement_covariance_subset(i, i) <<
127+
"). Using absolute value...\n");
124128

125129
measurement_covariance_subset(i, i) =
126130
::fabs(measurement_covariance_subset(i, i));
@@ -133,9 +137,10 @@ void Ekf::correct(const Measurement & measurement)
133137
// measurement can be completely without error, so add a small
134138
// amount in that case.
135139
if (measurement_covariance_subset(i, i) < 1e-9) {
136-
FB_DEBUG("WARNING: measurement had very small error covariance for index " <<
137-
update_indices[i] <<
138-
". Adding some noise to maintain filter stability.\n");
140+
FB_DEBUG(
141+
"WARNING: measurement had very small error covariance for index " <<
142+
update_indices[i] <<
143+
". Adding some noise to maintain filter stability.\n");
139144

140145
measurement_covariance_subset(i, i) = 1e-9;
141146
}
@@ -148,12 +153,13 @@ void Ekf::correct(const Measurement & measurement)
148153
state_to_measurement_subset(i, update_indices[i]) = 1;
149154
}
150155

151-
FB_DEBUG("Current state subset is:\n" <<
152-
state_subset << "\nMeasurement subset is:\n" <<
153-
measurement_subset << "\nMeasurement covariance subset is:\n" <<
154-
measurement_covariance_subset <<
155-
"\nState-to-measurement subset is:\n" <<
156-
state_to_measurement_subset << "\n");
156+
FB_DEBUG(
157+
"Current state subset is:\n" <<
158+
state_subset << "\nMeasurement subset is:\n" <<
159+
measurement_subset << "\nMeasurement covariance subset is:\n" <<
160+
measurement_covariance_subset <<
161+
"\nState-to-measurement subset is:\n" <<
162+
state_to_measurement_subset << "\n");
157163

158164
// (1) Compute the Kalman gain: K = (PH') / (HPH' + R)
159165
Eigen::MatrixXd pht =
@@ -182,8 +188,9 @@ void Ekf::correct(const Measurement & measurement)
182188
}
183189

184190
// (2) Check Mahalanobis distance between mapped measurement and state.
185-
if (checkMahalanobisThreshold(innovation_subset, hphr_inverse,
186-
measurement.mahalanobis_thresh_))
191+
if (checkMahalanobisThreshold(
192+
innovation_subset, hphr_inverse,
193+
measurement.mahalanobis_thresh_))
187194
{
188195
// (3) Apply the gain to the difference between the state and measurement: x
189196
// = x + K(z - Hx)
@@ -218,9 +225,10 @@ void Ekf::predict(
218225
{
219226
const double delta_sec = filter_utilities::toSec(delta);
220227

221-
FB_DEBUG("---------------------- Ekf::predict ----------------------\n" <<
222-
"delta is " << filter_utilities::toSec(delta) << "\n" <<
223-
"state is " << state_ << "\n");
228+
FB_DEBUG(
229+
"---------------------- Ekf::predict ----------------------\n" <<
230+
"delta is " << filter_utilities::toSec(delta) << "\n" <<
231+
"state is " << state_ << "\n");
224232

225233
double roll = state_(StateMemberRoll);
226234
double pitch = state_(StateMemberPitch);
@@ -377,11 +385,12 @@ void Ekf::predict(
377385
transfer_function_jacobian_(StateMemberYaw, StateMemberRoll) = dFY_dR;
378386
transfer_function_jacobian_(StateMemberYaw, StateMemberPitch) = dFY_dP;
379387

380-
FB_DEBUG("Transfer function is:\n" <<
381-
transfer_function_ << "\nTransfer function Jacobian is:\n" <<
382-
transfer_function_jacobian_ << "\nProcess noise covariance is:\n" <<
383-
process_noise_covariance_ << "\nCurrent state is:\n" <<
384-
state_ << "\n");
388+
FB_DEBUG(
389+
"Transfer function is:\n" <<
390+
transfer_function_ << "\nTransfer function Jacobian is:\n" <<
391+
transfer_function_jacobian_ << "\nProcess noise covariance is:\n" <<
392+
process_noise_covariance_ << "\nCurrent state is:\n" <<
393+
state_ << "\n");
385394

386395
Eigen::MatrixXd * process_noise_covariance = &process_noise_covariance_;
387396

@@ -414,9 +423,10 @@ void Ekf::predict(
414423
// Handle wrapping
415424
wrapStateAngles();
416425

417-
FB_DEBUG("Predicted state is:\n" <<
418-
state_ << "\nCurrent estimate error covariance is:\n" <<
419-
estimate_error_covariance_ << "\n");
426+
FB_DEBUG(
427+
"Predicted state is:\n" <<
428+
state_ << "\nCurrent estimate error covariance is:\n" <<
429+
estimate_error_covariance_ << "\n");
420430

421431
// (3) Project the error forward: P = J * P * J' + Q
422432
estimate_error_covariance_ =

src/filter_base.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ void FilterBase::computeDynamicProcessNoiseCovariance(
147147
dynamic_process_noise_covariance_.block<TWIST_SIZE, TWIST_SIZE>(
148148
POSITION_OFFSET, POSITION_OFFSET) =
149149
velocity_matrix *
150-
process_noise_covariance_.block<TWIST_SIZE, TWIST_SIZE>(POSITION_OFFSET,
151-
POSITION_OFFSET) *
150+
process_noise_covariance_.block<TWIST_SIZE, TWIST_SIZE>(
151+
POSITION_OFFSET,
152+
POSITION_OFFSET) *
152153
velocity_matrix.transpose();
153154
}
154155

@@ -192,8 +193,9 @@ const Eigen::VectorXd & FilterBase::getState() {return state_;}
192193

193194
void FilterBase::processMeasurement(const Measurement & measurement)
194195
{
195-
FB_DEBUG("------ FilterBase::processMeasurement (" << measurement.topic_name_ <<
196-
") ------\n");
196+
FB_DEBUG(
197+
"------ FilterBase::processMeasurement (" << measurement.topic_name_ <<
198+
") ------\n");
197199

198200
rclcpp::Duration delta(0);
199201

@@ -256,8 +258,9 @@ void FilterBase::processMeasurement(const Measurement & measurement)
256258
last_measurement_time_ = measurement.time_;
257259
}
258260

259-
FB_DEBUG("------ /FilterBase::processMeasurement (" << measurement.topic_name_ <<
260-
") ------\n");
261+
FB_DEBUG(
262+
"------ /FilterBase::processMeasurement (" << measurement.topic_name_ <<
263+
") ------\n");
261264
}
262265

263266
void FilterBase::setControl(
@@ -357,10 +360,11 @@ void FilterBase::prepareControl(
357360
(reference_time - latest_control_time_ >= control_timeout_);
358361

359362
if (timed_out) {
360-
FB_DEBUG("Control timed out. Reference time was " <<
361-
reference_time.nanoseconds() << ", latest control time was " <<
362-
latest_control_time_.nanoseconds() << ", control timeout was " <<
363-
control_timeout_.nanoseconds() << "\n");
363+
FB_DEBUG(
364+
"Control timed out. Reference time was " <<
365+
reference_time.nanoseconds() << ", latest control time was " <<
366+
latest_control_time_.nanoseconds() << ", control timeout was " <<
367+
control_timeout_.nanoseconds() << "\n");
364368
}
365369

366370
for (size_t controlInd = 0; controlInd < TWIST_SIZE; ++controlInd) {
@@ -399,16 +403,17 @@ inline double FilterBase::computeControlAcceleration(
399403

400404
const double final_accel = std::min(std::max(gain * error, -limit), limit);
401405

402-
FB_DEBUG("Control value: " <<
403-
control << "\n" <<
404-
"State value: " << state << "\n" <<
405-
"Error: " << error << "\n" <<
406-
"Same sign: " << (same_sign ? "true" : "false") << "\n" <<
407-
"Set point: " << set_point << "\n" <<
408-
"Decelerating: " << (decelerating ? "true" : "false") << "\n" <<
409-
"Limit: " << limit << "\n" <<
410-
"Gain: " << gain << "\n" <<
411-
"Final is " << final_accel << "\n");
406+
FB_DEBUG(
407+
"Control value: " <<
408+
control << "\n" <<
409+
"State value: " << state << "\n" <<
410+
"Error: " << error << "\n" <<
411+
"Same sign: " << (same_sign ? "true" : "false") << "\n" <<
412+
"Set point: " << set_point << "\n" <<
413+
"Decelerating: " << (decelerating ? "true" : "false") << "\n" <<
414+
"Limit: " << limit << "\n" <<
415+
"Gain: " << gain << "\n" <<
416+
"Final is " << final_accel << "\n");
412417

413418
return final_accel;
414419
}

0 commit comments

Comments
 (0)