7
7
namespace bitbots_localization {
8
8
9
9
RobotPoseObservationModel::RobotPoseObservationModel (std::shared_ptr<Map> map_lines, std::shared_ptr<Map> map_goals,
10
- std::shared_ptr<Map> map_field_boundary,
11
10
const bitbots_localization::Params &config,
12
11
const FieldDimensions &field_dimensions)
13
12
: particle_filter::ObservationModel<RobotState>(),
14
13
map_lines_ (map_lines),
15
14
map_goals_ (map_goals),
16
- map_field_boundary_ (map_field_boundary),
17
15
config_ (config),
18
16
field_dimensions_ (field_dimensions) {
19
17
particle_filter::ObservationModel<RobotState>::accumulate_weights_ = true ;
20
18
}
21
19
22
20
double RobotPoseObservationModel::calculate_weight_for_class (
23
21
const RobotState &state, const std::vector<std::pair<double , double >> &last_measurement, std::shared_ptr<Map> map,
24
- double element_weight) const {
22
+ double element_weight, const tf2::Transform &movement_since_measurement ) const {
25
23
double particle_weight_for_class;
26
24
if (!last_measurement.empty ()) {
27
- std::vector<double > ratings = map->Map ::provideRating (state, last_measurement);
25
+ // Subtract (reverse) the movement from our state to get the hypothetical state at the time of the measurement
26
+ const RobotState state_at_measurement (state.getTransform () * movement_since_measurement.inverse ());
27
+ // Get the ratings for for all points in the measurement based on the map
28
+ const std::vector<double > ratings = map->Map ::provideRating (state_at_measurement, last_measurement);
28
29
// Take the average of the ratings (functional)
29
30
particle_weight_for_class = std::pow (std::accumulate (ratings.begin (), ratings.end (), 0.0 ) / ratings.size (), 2 );
30
31
} else {
@@ -34,22 +35,19 @@ double RobotPoseObservationModel::calculate_weight_for_class(
34
35
}
35
36
36
37
double RobotPoseObservationModel::measure (const RobotState &state) const {
37
- double particle_weight_lines = calculate_weight_for_class (state, last_measurement_lines_, map_lines_,
38
- config_.particle_filter .confidences .line_element );
39
- double particle_weight_goal = calculate_weight_for_class (state, last_measurement_goal_, map_goals_,
40
- config_.particle_filter .confidences .goal_element );
41
- double particle_weight_field_boundary =
42
- calculate_weight_for_class (state, last_measurement_field_boundary_, map_field_boundary_,
43
- config_.particle_filter .confidences .field_boundary_element );
38
+ double particle_weight_lines =
39
+ calculate_weight_for_class (state, last_measurement_lines_, map_lines_,
40
+ config_.particle_filter .confidences .line_element , movement_since_line_measurement_);
41
+ double particle_weight_goal =
42
+ calculate_weight_for_class (state, last_measurement_goal_, map_goals_,
43
+ config_.particle_filter .confidences .goal_element , movement_since_goal_measurement_);
44
44
45
45
// Get relevant config values
46
46
auto scoring_config = config_.particle_filter .scoring ;
47
47
48
48
// Calculate weight for the particle
49
49
double weight = (((1 - scoring_config.lines .factor ) + scoring_config.lines .factor * particle_weight_lines) *
50
- ((1 - scoring_config.goal .factor ) + scoring_config.goal .factor * particle_weight_goal) *
51
- ((1 - scoring_config.field_boundary .factor ) +
52
- scoring_config.field_boundary .factor * particle_weight_field_boundary));
50
+ ((1 - scoring_config.goal .factor ) + scoring_config.goal .factor * particle_weight_goal));
53
51
54
52
if (weight < config_.particle_filter .weighting .min_weight ) {
55
53
weight = config_.particle_filter .weighting .min_weight ;
@@ -68,6 +66,7 @@ double RobotPoseObservationModel::measure(const RobotState &state) const {
68
66
}
69
67
70
68
void RobotPoseObservationModel::set_measurement_lines_pc (sm::msg::PointCloud2 measurement) {
69
+ // convert to polar
71
70
for (sm::PointCloud2ConstIterator<float > iter_xyz (measurement, " x" ); iter_xyz != iter_xyz.end (); ++iter_xyz) {
72
71
std::pair<double , double > linePolar = cartesianToPolar (iter_xyz[0 ], iter_xyz[1 ]);
73
72
last_measurement_lines_.push_back (linePolar);
@@ -82,39 +81,33 @@ void RobotPoseObservationModel::set_measurement_goalposts(sv3dm::msg::GoalpostAr
82
81
}
83
82
}
84
83
85
- void RobotPoseObservationModel::set_measurement_field_boundary (sv3dm::msg::FieldBoundary measurement) {
86
- // convert to polar
87
- for (gm::msg::Point &point : measurement.points ) {
88
- std::pair<double , double > fieldBoundaryPointPolar = cartesianToPolar (point.x , point.y );
89
- last_measurement_field_boundary_.push_back (fieldBoundaryPointPolar);
90
- }
91
- }
92
-
93
- std::vector<std::pair<double , double >> RobotPoseObservationModel::get_measurement_lines () const {
84
+ const std::vector<std::pair<double , double >> RobotPoseObservationModel::get_measurement_lines () const {
94
85
return last_measurement_lines_;
95
86
}
96
87
97
- std::vector<std::pair<double , double >> RobotPoseObservationModel::get_measurement_goals () const {
88
+ const std::vector<std::pair<double , double >> RobotPoseObservationModel::get_measurement_goals () const {
98
89
return last_measurement_goal_;
99
90
}
100
91
101
- std::vector<std::pair<double , double >> RobotPoseObservationModel::get_measurement_field_boundary () const {
102
- return last_measurement_field_boundary_;
103
- }
104
-
105
92
double RobotPoseObservationModel::get_min_weight () const { return config_.particle_filter .weighting .min_weight ; }
106
93
107
94
void RobotPoseObservationModel::clear_measurement () {
108
95
last_measurement_lines_.clear ();
109
96
last_measurement_goal_.clear ();
110
- last_measurement_field_boundary_.clear ();
111
97
}
112
98
113
99
bool RobotPoseObservationModel::measurements_available () {
114
100
bool available = false ;
115
101
available |= !last_measurement_lines_.empty ();
116
102
available |= !last_measurement_goal_.empty ();
117
- available |= !last_measurement_field_boundary_.empty ();
118
103
return available;
119
104
}
105
+
106
+ void RobotPoseObservationModel::set_movement_since_line_measurement (const tf2::Transform movement) {
107
+ movement_since_line_measurement_ = movement;
108
+ }
109
+
110
+ void RobotPoseObservationModel::set_movement_since_goal_measurement (const tf2::Transform movement) {
111
+ movement_since_goal_measurement_ = movement;
112
+ }
120
113
} // namespace bitbots_localization
0 commit comments