Skip to content

Commit 104a19a

Browse files
authored
Merge pull request #39 from ye-luo-xi-tui/imu_filter
Deprecated imu_extra_handle and add imu_filter into hardware resource layer
2 parents 8cfcfdc + 6865904 commit 104a19a

File tree

25 files changed

+310
-154
lines changed

25 files changed

+310
-154
lines changed

rm_common/CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
Changelog for package rm_common
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
0.1.9 (2022-3-28)
6+
------------------
7+
* Add imu_filter and deprecated imu_extra_handle(Since the update frequency of the control loop is not stable, some of
8+
the camera trigger signals of imu will be lost. We put the imu filter down to the hardware resource layer, so
9+
imu_extra_handle is breaking. )
10+
* Add tof sensor interface
11+
* Contributors: Edwinlinks, Jie j, QiayuanLiao, yezi
12+
513
0.1.8 (2021-12-7)
614
------------------
715
* Merge branch 'master' into master

rm_common/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ find_package(catkin REQUIRED
2020
geometry_msgs
2121
control_msgs
2222
controller_manager_msgs
23+
imu_complementary_filter
24+
imu_filter_madgwick
2325
realtime_tools
2426
dynamic_reconfigure
2527
)
@@ -34,6 +36,8 @@ catkin_package(
3436
geometry_msgs
3537
control_msgs
3638
controller_manager_msgs
39+
imu_complementary_filter
40+
imu_filter_madgwick
3741
roscpp
3842
dynamic_reconfigure
3943
DEPENDS
@@ -47,7 +51,7 @@ include_directories(
4751
${EIGEN3_INCLUDE_DIR}
4852
)
4953

50-
file(GLOB_RECURSE sources "src/*.cpp" "src/decision/*.cpp")
54+
file(GLOB_RECURSE sources "src/*.cpp" "src/decision/*.cpp" "src/filter/*.cpp")
5155

5256
add_library(rm_common SHARED ${sources} include/rm_common/referee/data.h)
5357
#add_executable(test_traj test/test_traj.cpp)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Created by yezi on 2022/3/26.
3+
//
4+
5+
#pragma once
6+
7+
#include <rm_common/filters/imu_filter_base.h>
8+
#include <imu_complementary_filter/complementary_filter.h>
9+
10+
namespace rm_common
11+
{
12+
class ImuComplementaryFilter : public ImuFilterBase
13+
{
14+
public:
15+
ImuComplementaryFilter() = default;
16+
void getOrientation(double& q0, double& q1, double& q2, double& q3) override;
17+
18+
private:
19+
void filterUpdate(double ax, double ay, double az, double wx, double wy, double wz, double dt) override;
20+
bool getFilterParam(XmlRpc::XmlRpcValue& imu_data) override;
21+
// Parameters:
22+
bool use_mag_;
23+
// State variables:
24+
imu_tools::ComplementaryFilter filter_;
25+
};
26+
} // namespace rm_common
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Created by yezi on 2022/3/26.
3+
//
4+
5+
#pragma once
6+
7+
#include <ros/ros.h>
8+
#include <sensor_msgs/Imu.h>
9+
#include <sensor_msgs/Temperature.h>
10+
#include <sensor_msgs/TimeReference.h>
11+
#include <realtime_tools/realtime_publisher.h>
12+
13+
namespace rm_common
14+
{
15+
class ImuFilterBase
16+
{
17+
public:
18+
bool init(XmlRpc::XmlRpcValue& imu_data, const std::string& name);
19+
void update(ros::Time time, double* accel, double* omega, double* ori, double* accel_cov, double* omega_cov,
20+
double* ori_cov, double temp, bool camera_trigger);
21+
virtual void getOrientation(double& q0, double& q1, double& q2, double& q3) = 0;
22+
23+
protected:
24+
virtual bool getFilterParam(XmlRpc::XmlRpcValue& imu_data) = 0;
25+
virtual void filterUpdate(double ax, double ay, double az, double wx, double wy, double wz, double dt) = 0;
26+
ros::Time last_update_;
27+
bool initialized_filter_{ false };
28+
std::string frame_id_;
29+
std::shared_ptr<realtime_tools::RealtimePublisher<sensor_msgs::Imu> > imu_data_pub_;
30+
std::shared_ptr<realtime_tools::RealtimePublisher<sensor_msgs::Temperature> > imu_temp_pub_;
31+
std::shared_ptr<realtime_tools::RealtimePublisher<sensor_msgs::TimeReference> > trigger_time_pub_;
32+
};
33+
} // namespace rm_common

rm_common/include/rm_common/hardware_interface/imu_extra_interface.h

Lines changed: 0 additions & 118 deletions
This file was deleted.

rm_common/package.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<package format="2">
33
<name>rm_common</name>
4-
<version>0.1.8</version>
4+
<version>0.1.9</version>
55
<description>The rm_common package</description>
66

77
<maintainer email="liaoqiayuan@gmail.com">qiayuan</maintainer>
@@ -16,6 +16,8 @@
1616
<depend>geometry_msgs</depend>
1717
<depend>realtime_tools</depend>
1818
<depend>rm_msgs</depend>
19+
<depend>imu_complementary_filter</depend>
20+
<depend>imu_filter_madgwick</depend>
1921
<depend>dynamic_reconfigure</depend>
2022
<depend>eigen</depend>
2123
<depend>control_msgs</depend>
File renamed without changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Created by yezi on 2022/3/26.
3+
//
4+
5+
#include <rm_common/filters/imu_complementary_filter.h>
6+
7+
namespace rm_common
8+
{
9+
void ImuComplementaryFilter::filterUpdate(double ax, double ay, double az, double wx, double wy, double wz, double dt)
10+
{
11+
filter_.update(ax, ay, az, wx, wy, wz, dt);
12+
}
13+
void ImuComplementaryFilter::getOrientation(double& q0, double& q1, double& q2, double& q3)
14+
{
15+
filter_.getOrientation(q0, q1, q2, q3);
16+
}
17+
bool ImuComplementaryFilter::getFilterParam(XmlRpc::XmlRpcValue& imu_data)
18+
{
19+
double gain_acc;
20+
double gain_mag;
21+
bool do_bias_estimation;
22+
double bias_alpha;
23+
bool do_adaptive_gain;
24+
auto it = imu_data.begin();
25+
use_mag_ = imu_data.hasMember("use_mag") && (bool)imu_data[it->first]["use_mag"];
26+
gain_acc = imu_data.hasMember("gain_acc") ? (double)imu_data[it->first]["gain_acc"] : 0.01;
27+
gain_mag = imu_data.hasMember("gain_mag") ? (double)imu_data[it->first]["gain_mag"] : 0.01;
28+
do_bias_estimation = !imu_data.hasMember("do_bias_estimation") || (bool)imu_data[it->first]["do_bias_estimation"];
29+
bias_alpha = imu_data.hasMember("bias_alpha") ? (double)imu_data[it->first]["bias_alpha"] : 0.01;
30+
do_adaptive_gain = !imu_data.hasMember("do_adaptive_gain") || (bool)imu_data[it->first]["do_adaptive_gain"];
31+
filter_.setDoBiasEstimation(do_bias_estimation);
32+
filter_.setDoAdaptiveGain(do_adaptive_gain);
33+
if (!filter_.setGainAcc(gain_acc))
34+
ROS_WARN("Invalid gain_acc passed to ComplementaryFilter.");
35+
if (use_mag_)
36+
{
37+
if (!filter_.setGainMag(gain_mag))
38+
ROS_WARN("Invalid gain_mag passed to ComplementaryFilter.");
39+
}
40+
if (do_bias_estimation)
41+
{
42+
if (!filter_.setBiasAlpha(bias_alpha))
43+
ROS_WARN("Invalid bias_alpha passed to ComplementaryFilter.");
44+
}
45+
return true;
46+
}
47+
} // namespace rm_common
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// Created by yezi on 2022/3/26.
3+
//
4+
5+
#include <rm_common/filters/imu_filter_base.h>
6+
7+
namespace rm_common
8+
{
9+
bool ImuFilterBase::init(XmlRpc::XmlRpcValue& imu_data, const std::string& name)
10+
{
11+
ros::NodeHandle nh("~");
12+
frame_id_ = (std::string)imu_data["frame_id"];
13+
getFilterParam(imu_data);
14+
imu_data_pub_.reset(new realtime_tools::RealtimePublisher<sensor_msgs::Imu>(nh, name + "/data", 100));
15+
imu_temp_pub_.reset(new realtime_tools::RealtimePublisher<sensor_msgs::Temperature>(nh, name + "/temperature", 100));
16+
trigger_time_pub_.reset(
17+
new realtime_tools::RealtimePublisher<sensor_msgs::TimeReference>(nh, name + "/trigger_time", 100));
18+
return true;
19+
}
20+
21+
void ImuFilterBase::update(ros::Time time, double* accel, double* omega, double* ori, double* accel_cov,
22+
double* omega_cov, double* ori_cov, double temp, bool camera_trigger)
23+
{
24+
if (!initialized_filter_)
25+
{
26+
initialized_filter_ = true;
27+
last_update_ = time;
28+
imu_data_pub_->msg_.header.frame_id = frame_id_;
29+
return;
30+
}
31+
32+
// Update the filter.
33+
filterUpdate(accel[0], accel[1], accel[2], omega[0], omega[1], omega[2], (time - last_update_).toSec());
34+
last_update_ = time;
35+
getOrientation(ori[3], ori[0], ori[1], ori[2]);
36+
if (camera_trigger)
37+
{
38+
if (imu_data_pub_->trylock())
39+
{
40+
imu_data_pub_->msg_.header.stamp = time;
41+
imu_data_pub_->msg_.angular_velocity.x = omega[0];
42+
imu_data_pub_->msg_.angular_velocity.y = omega[1];
43+
imu_data_pub_->msg_.angular_velocity.z = omega[2];
44+
imu_data_pub_->msg_.linear_acceleration.x = accel[0];
45+
imu_data_pub_->msg_.linear_acceleration.y = accel[1];
46+
imu_data_pub_->msg_.linear_acceleration.z = accel[2];
47+
imu_data_pub_->msg_.orientation.x = ori[0];
48+
imu_data_pub_->msg_.orientation.y = ori[1];
49+
imu_data_pub_->msg_.orientation.z = ori[2];
50+
imu_data_pub_->msg_.orientation.w = ori[3];
51+
imu_data_pub_->msg_.orientation_covariance = { ori_cov[0], 0., 0., 0., ori_cov[4], 0., 0., 0., ori_cov[8] };
52+
imu_data_pub_->msg_.angular_velocity_covariance = { omega_cov[0], 0., 0., 0., omega_cov[4],
53+
0., 0., 0., omega_cov[8] };
54+
imu_data_pub_->msg_.linear_acceleration_covariance = { accel_cov[0], 0., 0., 0., accel_cov[4],
55+
0., 0., 0., accel_cov[8] };
56+
imu_data_pub_->unlockAndPublish();
57+
}
58+
if (trigger_time_pub_->trylock())
59+
{
60+
trigger_time_pub_->msg_.header.stamp = time;
61+
trigger_time_pub_->msg_.time_ref = time;
62+
trigger_time_pub_->unlockAndPublish();
63+
}
64+
if (imu_temp_pub_->trylock())
65+
{
66+
imu_temp_pub_->msg_.header.stamp = time;
67+
imu_temp_pub_->msg_.temperature = temp;
68+
imu_temp_pub_->unlockAndPublish();
69+
}
70+
}
71+
}
72+
73+
} // namespace rm_common
File renamed without changes.

0 commit comments

Comments
 (0)