33 #include <sciplot/sciplot.hpp>
54 state1.
pose = manif::SE3<T>::Random();
56 state2.
pose = manif::SE3<T>::Random();
63 ARMARX_CHECK((state2.
pose - state3.
pose).coeffs().norm() < 10000 * std::numeric_limits<T>::epsilon()) << (state2.
pose - state3.
pose).coeffs().norm();
67 ARMARX_CHECK((sigma2 - sigma).
norm() < 10000 * std::numeric_limits<T>::epsilon()) << (sigma2 - sigma).
norm();
76 manif::SO3<T> rot = manif::SO3<T>(0, 0,
angle);
78 manif::SE3<T> pose(pos, rot);
80 manif::SE3Tangent<T> tangent = pose.log();
81 ARMARX_CHECK((tangent.coeffs().segment(0, 3) - pos).norm() < 1e-6);
86 void simulate_trajectory(std::vector<SystemModelT::StateT>& states, std::vector<SystemModelT::ControlT>& omegas) {
90 states.push_back(state);
93 const T t_prev =
dt * (i - 1);
100 manif::SE3Tangent<T> tangent(states.at(i-1).pose.log());
101 ARMARX_CHECK((states.at(i-1).pose.translation() - pos).norm() < 0.1);
105 const Vector acc_prev(- std::sin(t_prev *
c) * (
c *
c), -std::cos(t_prev *
c) * (
c*
c), 0);
108 manif::SO3<T> rot = manif::SO3<T>(roll, pitch, yaw);
114 control.velocity.coeffs() << state.
pose.asSO3().inverse().act(vel), angular_velocity;
117 manif::SE3Tangent<T> pro_tangent = propagated.
pose.log();
118 T pos_diff1 = (propagated.
pose.translation() - pos).
norm();
120 ARMARX_CHECK(pos_diff1 < 2e-5) <<
"Position is not the same: " << pos <<
" vs " << propagated.
pose.translation();
124 state.
pose = manif::SE3<T>(pos, rot);
125 states.push_back(propagated);
127 tangent = state.
pose.log();
138 void simulate_observation(
const std::vector<SystemModelT::StateT>& states, std::vector<SystemModelT::ObsT>& observations) {
139 for (
const auto& state : states) {
142 true_obs = state.pose.log().coeffs();
146 observations.push_back(obs +
obs_noise_std * SystemModelT::ObsT::Random());
155 std::vector<SystemModelT::StateT> states;
156 std::vector<SystemModelT::ControlT> omegas;
157 std::vector<SystemModelT::ObsT> observations;
161 ARMARX_INFO <<
"Num States: " << states.size() <<
" Num Controls: " << omegas.size() <<
" Num Obs: " << observations.size();
179 std::vector<SystemModelT::StateT> ukf_states;
180 std::vector<UnscentedKalmanFilter<SystemModelT>::StateCovT> ukf_Ps;
181 ukf_states.push_back(state0);
182 ukf_Ps.push_back(P0);
184 std::vector<T> x_true, y_true, z_true, x_obs, y_obs, z_obs, x_ukf, y_ukf, z_ukf;
185 std::vector<T> vx_true, vy_true, vz_true, vx_ukf, vy_ukf, vz_ukf;
186 std::vector<T> a_true, b_true, c_true, a_obs, b_obs, c_obs, a_ukf, b_ukf, c_ukf;
194 if ((i-1) % 100 == 0) {
196 ukf.
update(observations.at(i));
201 ARMARX_INFO <<
"Pose Diff: " << (states.at(i).pose - current_state.
pose).coeffs().norm();
207 x_true.push_back(states.at(i).pose.log().coeffs()(0));
208 y_true.push_back(states.at(i).pose.log().coeffs()(1));
209 z_true.push_back(states.at(i).pose.log().coeffs()(2));
211 x_obs.push_back(observations.at(i)(0));
212 y_obs.push_back(observations.at(i)(1));
213 z_obs.push_back(observations.at(i)(2));
227 a_true.push_back(states.at(i).pose.log().coeffs()(3));
228 b_true.push_back(states.at(i).pose.log().coeffs()(4));
229 c_true.push_back(states.at(i).pose.log().coeffs()(5));
231 a_obs.push_back(observations.at(i)(3, 0));
232 b_obs.push_back(observations.at(i)(4, 0));
233 c_obs.push_back(observations.at(i)(5, 0));
247 sciplot::Plot3D position_plot;
248 sciplot::Plot pos_plot;
250 position_plot.drawCurve(x_true, y_true, z_true).label(
"True").lineWidth(1);
251 position_plot.drawCurve(x_obs, y_obs, z_obs).label(
"Obs").lineWidth(1);
252 position_plot.drawCurve(x_ukf, y_ukf, z_ukf).label(
"UKF").lineWidth(1);
254 pos_plot.drawCurve(x_true, y_true).label(
"True");
255 pos_plot.drawCurve(x_obs, y_obs).label(
"Obs");
256 pos_plot.drawCurve(x_ukf, y_ukf).label(
"UKF");
264 sciplot::Plot3D orientation_plot;
266 orientation_plot.drawCurve(a_true, b_true, c_true).label(
"True").lineWidth(1);
267 orientation_plot.drawCurve(a_obs, b_obs, c_obs).label(
"Obs").lineWidth(1);
268 orientation_plot.drawCurve(a_ukf, b_ukf, c_ukf).label(
"UKF").lineWidth(1);
271 position_plot.show();
273 orientation_plot.show();