Repository navigation
Robot Kalman Filters - #3906
Robot Kalman Filters#3906sunghyuneun wants to merge 93 commits into
Conversation
…into sunghyuneun/robot_filter
|
Is this data suggesting that master is more accurate? Why?
|
| # Disable for kalman filter | ||
| #cc_test( | ||
| # name = "ball_filter_test", | ||
| # srcs = ["ball_filter_test.cpp"], | ||
| # deps = [ | ||
| # ":ball_filter", | ||
| # "//shared/test_util:tbots_gtest_main", | ||
| # "//software/world:field", | ||
| # ], | ||
| #) |
There was a problem hiding this comment.
re-bump, should this be removed
|
|
||
| std::optional<Robot> RobotFilter::getFilteredData( | ||
| const std::vector<RobotDetection>& new_robot_data, const Timestamp& capture_timestamp, | ||
| std::optional<Robot> RobotFilter::estimateRobotState( |
There was a problem hiding this comment.
re-bump, was this ever profiled?
| // 1. Whether it is physically possible to arrive the new destination at max | ||
| // velocity | ||
| // 2. Statistical gating using Mahalanobis distance | ||
| // TODO: mahalanobisDistance and update both calculate pseudoinverse. is this a |
There was a problem hiding this comment.
stray todo. link # or discard
| // because robots move using motors that stay on, unlike balls that just roll, i will | ||
| // be assuming that they keep moving with constant velocity |
| // Without a previous detection there is no interval to reason over, so we have no | ||
| // grounds to call this one impossible |
There was a problem hiding this comment.
why can we assume it is possible then?
There was a problem hiding this comment.
The explanation could be that we need to initialize the robot SOMEWHERE at the start. So we have to assume it is possible in order to start somewhere
Because of model tuning issues. The model is unsure whether to trust internal model more or the new update more, and so at high speeds which are unlikelier, Kalman believes its internal model more while master just says what it says. So perhaps process noise covariance needs to be increased. |
Yeah... And there are pros and cons for having high process covariance or low process covariance. The more engineering way to do this is to set a requirement of how much lag vs how much error we want, and then find the tuned value that satisfies it. |
StarrryNight
left a comment
There was a problem hiding this comment.
Left some comments, will add more later
| 0, 1, 0, delta_t, | ||
| 0, 0, 1, 0, | ||
| 0, 0, 0, 1; | ||
| ang_kalman_filter.process_model << 1, delta_t, |
There was a problem hiding this comment.
Can u explain why we are splitting angle state and position state? Is it because of the angle wrapping code?
| // Without a previous detection there is no interval to reason over, so we have no | ||
| // grounds to call this one impossible |
There was a problem hiding this comment.
The explanation could be that we need to initialize the robot SOMEWHERE at the start. So we have to assume it is possible in order to start somewhere
| void reset(const PosMeasurement& pos_measurement, | ||
| const AngMeasurement& ang_measurement, const Timestamp& current_time); | ||
|
|
||
| PosKalmanFilter pos_kalman_filter; |
There was a problem hiding this comment.
Imo the code will be a lot cleaner if its one kf. It is more consistent with the other kfs in the codebase asw
| #include "software/networking/unix/threaded_proto_unix_sender.hpp" | ||
| #include "software/simulation/er_force_simulator.h" | ||
|
|
||
| // CSV file that the filtered robot state is logged to, alongside the ground truth |
There was a problem hiding this comment.
I wouldnt pay much attention into diffs in this file except for the core logic. The eval code will be removed when we merge this PR anyway
| const Eigen::Vector<double, POS_STATE_SIZE> pos_state = | ||
| pos_kalman_filter.state_estimate; | ||
| const Eigen::Vector<double, ANG_STATE_SIZE> ang_state = | ||
| ang_kalman_filter.state_estimate; |
There was a problem hiding this comment.
No point creating a copy. Just alias by
` const auto& pos_state = pos_kalman_filter.state_estimate;
| const Angle robot_orientation = Angle::fromRadians(ang_state(POS_W)).clamp(); | ||
| const AngularVelocity robot_angular_velocity = | ||
| AngularVelocity::fromRadians(ang_state(VEL_W)); | ||
| bool breakbeam_tripped = breakbeam_tripped_id == getRobotId(); |
There was a problem hiding this comment.
why this one out of every variable is not const?
|
Btw @sunghyuneun did all gameplay tests pass on ur machine. Cuz from my experience my ball filter caused some tests to failed and I had to tune+add heuristics |
StarrryNight
left a comment
There was a problem hiding this comment.
left some more comments!
| acceleration_variance * delta_t_squared * delta_t_squared / 4.0; | ||
| const double correlation_noise = | ||
| acceleration_variance * delta_t_squared * delta_t / 2.0; | ||
| const double velocity_noise = acceleration_variance * delta_t_squared; |
There was a problem hiding this comment.
might as well make a delta_t_cubed and so
| // entirely, letting it converge onto the robot within a few frames. | ||
| constexpr double RF_INITIAL_POSITION_UNCERTAINTY_M = 1.0; | ||
| constexpr double RF_INITIAL_VELOCITY_UNCERTAINTY_M_PER_S = 6.5; | ||
| constexpr double RF_INITIAL_ORIENTATION_UNCERTAINTY_RAD = M_PI * M_PI / 3; |
There was a problem hiding this comment.
why is this
| std::optional<PosMeasurement> prev_pos_measurement; | ||
| std::optional<AngMeasurement> prev_ang_measurement; |
There was a problem hiding this comment.
now it is. but i deleted the ball one.
| prev_pos_measurement = pos_measurement; | ||
| prev_ang_measurement = ang_measurement; | ||
| prev_detection_timestamp = current_time; | ||
| } |
There was a problem hiding this comment.
Why are we only applying the gatings to position but not orientation?
There was a problem hiding this comment.
On the topic of that, I believe the code will be a lot cleaner if the two kfs are merged into one. In addition, you can just pass one state into a helper function that checks both ang and pos mahalanobis and within max speed.
There was a problem hiding this comment.
I thought that the angle (as it is gated between -pi and pi) could like have moment where it jumps?
| else if (isWithinMaxRobotSpeed(best_robot_detection->position, current_time) && | ||
| pos_kalman_filter.mahalanobisDistance(pos_measurement) < | ||
| RF_MAHALANOBIS_GATE_THRESHOLD) |
There was a problem hiding this comment.
In addition, this check happens AFTER we have run predict over dt. This means we are comparing whether measurement at
| consecutive_outliers(0), | ||
| expiry_buffer_duration(expiry_buffer_duration) | ||
| { | ||
| } |
There was a problem hiding this comment.
We have two very similar constructors. Do we need ever actually need to initialize with a robot detection at all? Can we keep only one of them?
There was a problem hiding this comment.
We initialize with robot detection in the team filter. If we were to remove one, it'd be initializing with the Robot.
|
|
||
| // If the current_time called is ahead of current time, then runs predict step | ||
| // Updates the last_predict_timestamp to the current time called. | ||
| // Therefore, we must keey estimating with further points ahead. |
There was a problem hiding this comment.
typo, and im not quite understand what this comment mean...
| const double velocity_noise = acceleration_variance * delta_t_squared; | ||
|
|
||
| // For angle kalman, we compute the angle process covariance with Continuous White | ||
| // Noise Acceleration model. i don't know anymore i just pray it works. |
There was a problem hiding this comment.
Bro we are not merging this comment. The reason why we use a continous white noise acceleration model instead of a continuus white noise velocity model is because our process model assumes constant velocity (no acceleration). So the noise model should depict the unmodelled noise in acceleration.
| constexpr double RF_ANG_ACCELERATION_NOISE_RAD_PER_S_SQUARED = 10.0; | ||
|
|
||
| // Maximum Mahalanobi's Distance before rejecting as outlier | ||
| constexpr double RF_MAHALANOBIS_GATE_THRESHOLD = 5; |
There was a problem hiding this comment.
Note that this will be a value need to be tuned as well
I was hoping for a little help? I was a little unsure about gameplay, I was thinking about talking to a pod or software lead tmr. |
…neun/tb-software into sunghyuneun/robot_filter
Description
Makes changes to robot filter. Notable changes:
Do not review any changes to
src/software/er_force_simulator_main.cppas all changes are for logging purposes. I can probably also delete the .gitignore change it was just bothering me.Testing with real robots is incomplete, and some constants should be changed.
Testing Done
MSE & Median Error Comparison
Error Distribution Comparison
Position Error (m)
Velocity Error (m/s)
Angle Error (rad)
Angular Velocity Error (rad/s)
Resolved Issues
Resolves #3701, fixes #1717.
Length Justification and Key Files to Review
Review Checklist
It is the reviewers responsibility to also make sure every item here has been covered
.hfile) should have a javadoc style comment at the start of them. For examples, see the functions defined inthunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.TODO(or similar) statements should either be completed or associated with a github issue