bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
diff_drive_ekf.h
Go to the documentation of this file.
1#ifndef BITSIM_ESTIMATION_DIFF_DRIVE_EKF_H
2#define BITSIM_ESTIMATION_DIFF_DRIVE_EKF_H
3
8
9#include <array>
10#include <string>
11#include <vector>
12
13namespace bitsim
14{
15namespace estimation
16{
17
21struct Box2d
22{
27};
28
35{
36 public:
37 DiffDriveMap(const trajectory::RoundedRectangle &track, std::vector<Box2d> obstacles);
38
39 const trajectory::RoundedRectangle &track() const noexcept { return track_; }
40 const std::vector<Box2d> &obstacles() const noexcept { return obstacles_; }
41
46 real_t ray_cast(real_t x, real_t y, real_t angle, real_t max_range) const;
47
48 private:
50 std::vector<Box2d> obstacles_;
51};
52
71{
72 public:
75
76 struct Input
77 {
80 real_t dt{0.0};
81 };
83
85
89 state_type &evaluate(const Input &input);
90
91 state_type &get_state() { return state_; }
92 const state_type &get_state() const { return state_; }
93 real_t get_state_property(const std::string &name) const { return state_.get(name); }
94 const matrix_type &get_matrix(const std::string &name) const;
95
96 private:
97 state_type state_;
98 matrix_type F_;
99 matrix_type L_;
100};
101
124{
125 public:
135
136 struct Pose
137 {
138 real_t x{0.0};
139 real_t y{0.0};
141 };
142
157
165 DiffDriveEKF(const DiffDriveMap &map, const Pose &start, const Parameters &parameters,
166 const std::array<real_t, 3> &start_sigma = {0.02, 0.02, 0.005});
167
172 void predict(real_t distance, real_t gyro_z, real_t dt);
173
178 EKFUpdateResult update_line(const std::vector<std::array<real_t, 2>> &points, real_t sigma);
179
184 EKFUpdateResult update_range(const RangeSensor &sensor, real_t measured);
185
189 real_t predicted_range(const RangeSensor &sensor, const Pose &pose) const;
190
191 Pose pose() const;
192 real_t gyro_bias() const { return model_.get_state()[3]; }
193
197 const DynMat<real_t> &covariance() const { return ekf_["P"]; }
198
199 const Parameters &parameters() const noexcept { return p_; }
200 const DiffDriveMap &map() const noexcept { return map_; }
201
202 private:
203 void wrap_heading_();
204
205 DiffDriveMap map_;
206 Parameters p_;
207 DiffDriveGyroModel model_;
209};
210
211} // namespace estimation
212} // namespace bitsim
213
214#endif // BITSIM_ESTIMATION_DIFF_DRIVE_EKF_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
SysState utility class describing the state of a system.
Definition system_state.h:25
real_t gyro_bias() const
Definition diff_drive_ekf.h:192
const DiffDriveMap & map() const noexcept
Definition diff_drive_ekf.h:200
DiffDriveEKF(const DiffDriveMap &map, const Pose &start, const Parameters &parameters, const std::array< real_t, 3 > &start_sigma={0.02, 0.02, 0.005})
Definition diff_drive_ekf.cpp:241
Pose pose() const
Definition diff_drive_ekf.cpp:305
real_t predicted_range(const RangeSensor &sensor, const Pose &pose) const
What the sensor should read with the robot at pose.
Definition diff_drive_ekf.cpp:298
const DynMat< real_t > & covariance() const
The covariance of (x, y, yaw, bias).
Definition diff_drive_ekf.h:197
void predict(real_t distance, real_t gyro_z, real_t dt)
Predict over dt [s] in which the encoders say the robot drove distance [m] and the gyroscope read gyr...
Definition diff_drive_ekf.cpp:258
EKFUpdateResult update_line(const std::vector< std::array< real_t, 2 > > &points, real_t sigma)
Correct with points where the line is, relative to the centre of the axle [m], forward and to the lef...
Definition diff_drive_ekf.cpp:267
const Parameters & parameters() const noexcept
Definition diff_drive_ekf.h:199
EKFUpdateResult update_range(const RangeSensor &sensor, real_t measured)
Correct with the reading [m] of a range sensor. A reading at the sensor's max_range,...
Definition diff_drive_ekf.cpp:282
The motion model of DiffDriveEKF: a differential drive robot that knows how far it drove from its whe...
Definition diff_drive_ekf.h:71
const state_type & get_state() const
Definition diff_drive_ekf.h:92
const matrix_type & get_matrix(const std::string &name) const
Definition diff_drive_ekf.cpp:109
dynamics::SysState< 4 > state_type
Definition diff_drive_ekf.h:73
Input input_type
Definition diff_drive_ekf.h:82
DynMat< real_t > matrix_type
Definition diff_drive_ekf.h:74
DiffDriveGyroModel()
Definition diff_drive_ekf.cpp:70
real_t get_state_property(const std::string &name) const
Definition diff_drive_ekf.h:93
state_type & get_state()
Definition diff_drive_ekf.h:91
state_type & evaluate(const Input &input)
Move the state by one step, and work out F and L at the state before it.
Definition diff_drive_ekf.cpp:79
What a robot knows about where it drives: the line on the floor, a RoundedRectangle,...
Definition diff_drive_ekf.h:35
const trajectory::RoundedRectangle & track() const noexcept
Definition diff_drive_ekf.h:39
real_t ray_cast(real_t x, real_t y, real_t angle, real_t max_range) const
How far a ray from (x, y) at angle [rad] from the x axis goes before it meets an obstacle,...
Definition diff_drive_ekf.cpp:25
const std::vector< Box2d > & obstacles() const noexcept
Definition diff_drive_ekf.h:40
DiffDriveMap(const trajectory::RoundedRectangle &track, std::vector< Box2d > obstacles)
Definition diff_drive_ekf.cpp:20
The extended Kalman filter: it predicts the state with a non-linear motion model and corrects it with...
Definition extended_kalman_filter.h:68
A closed track in the plane: a rectangle centred on the origin with its sides along x and y,...
Definition rounded_rectangle.h:20
Definition diff_drive_ekf.cpp:12
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
Eigen::MatrixX< T > DynMat
Dynamically sized matrix to use around the library.
Definition bitsim_types.h:51
double real_t
real_t
Definition bitsim_types.h:20
An axis-aligned rectangle in the plane [m]: a wall or a box, seen from above.
Definition diff_drive_ekf.h:22
real_t y_min
Definition diff_drive_ekf.h:24
real_t y_max
Definition diff_drive_ekf.h:26
real_t x_min
Definition diff_drive_ekf.h:23
real_t x_max
Definition diff_drive_ekf.h:25
Definition diff_drive_ekf.h:127
real_t bias_walk
how fast the bias may wander [rad/s per square root of s]
Definition diff_drive_ekf.h:130
real_t range_noise
of an ultrasonic range [m]
Definition diff_drive_ekf.h:132
real_t gate
per measured value, on the squared Mahalanobis distance
Definition diff_drive_ekf.h:133
real_t gyro_noise
of each reading of the gyroscope [rad/s]
Definition diff_drive_ekf.h:129
real_t line_noise
of a point of the line [m]
Definition diff_drive_ekf.h:131
real_t distance_noise
of the encoders' distance [m per square root of m]
Definition diff_drive_ekf.h:128
Definition diff_drive_ekf.h:137
real_t yaw
Definition diff_drive_ekf.h:140
real_t y
Definition diff_drive_ekf.h:139
real_t x
Definition diff_drive_ekf.h:138
Where an ultrasonic sensor is on the robot, relative to the centre of the axle, and what it hears.
Definition diff_drive_ekf.h:148
real_t y
to the left [m]
Definition diff_drive_ekf.h:150
real_t x
ahead of the axle [m]
Definition diff_drive_ekf.h:149
real_t yaw
where it points, from straight ahead [rad]
Definition diff_drive_ekf.h:151
real_t beam_angle
the full width of its cone [rad]
Definition diff_drive_ekf.h:152
uint_t n_rays
how many rays its model casts across the cone
Definition diff_drive_ekf.h:153
real_t max_range
[m]; a reading this far is no echo
Definition diff_drive_ekf.h:155
real_t min_range
[m]
Definition diff_drive_ekf.h:154
Definition diff_drive_ekf.h:77
real_t gyro_z
the gyroscope's reading about the vertical [rad/s]
Definition diff_drive_ekf.h:79
real_t distance
driven over the step, from the encoders [m]
Definition diff_drive_ekf.h:78
real_t dt
the step [s]
Definition diff_drive_ekf.h:80