Thunderbots Project
Loading...
Searching...
No Matches
sensor_fusion.h
1#pragma once
2
3#include <google/protobuf/repeated_field.h>
4
5#include "proto/message_translation/ssl_detection.h"
6#include "proto/message_translation/ssl_geometry.h"
7#include "proto/message_translation/ssl_referee.h"
8#include "proto/parameters.pb.h"
9#include "proto/sensor_msg.pb.h"
10#include "software/sensor_fusion/filter/ball_filter.h"
11#include "software/sensor_fusion/filter/robot_team_filter.h"
12#include "software/sensor_fusion/filter/vision_detection.h"
13#include "software/sensor_fusion/possession/possession_tracker.h"
14#include "software/world/ball.h"
15#include "software/world/team.h"
16#include "software/world/world.h"
17
23{
24 public:
30 explicit SensorFusion(TbotsProto::SensorFusionConfig sensor_fusion_config);
31
32 virtual ~SensorFusion() = default;
33
40 void processSensorProto(const SensorProto &sensor_msg);
41
49 std::optional<World> getWorld() const;
50
51 // Number of vision packets to indicate that the vision client most likely reset,
52 // determined experimentally with the simulator
53 static constexpr unsigned int VISION_PACKET_RESET_COUNT_THRESHOLD = 5;
54 // Vision packets before this threshold time indicate that the vision client has just
55 // started, determined experimentally with the simulator
56 static constexpr double VISION_PACKET_RESET_TIME_THRESHOLD = 0.5;
57
58 // This is used for detecting if the breakbeam is at fault. The idea is that distance
59 // between the robot that has the ball is greater than the distance below, then we
60 // know that the breakbeam has a problem see for more:
61 // https://github.com/UBC-Thunderbots/Software/issues/3197
62 static constexpr double DISTANCE_THRESHOLD_FOR_BREAKBEAM_FAULT_DETECTION = 0.5;
63
64 private:
70 void updateWorld(const SSLProto::SSL_WrapperPacket &packet);
71 void updateWorld(const SSLProto::Referee &packet);
72 void updateWorld(const google::protobuf::RepeatedPtrField<TbotsProto::RobotStatus>
73 &robot_status_msgs);
74 void updateWorld(const SSLProto::SSL_GeometryData &geometry_packet);
75 void updateWorld(const SSLProto::SSL_DetectionFrame &ssl_detection_frame);
76
82 void updateBall(Ball new_ball);
83
91 std::optional<Ball> createBall(const std::vector<BallDetection> &ball_detections);
92
100 Team createFriendlyTeam(const std::vector<RobotDetection> &robot_detections);
101 Team createEnemyTeam(const std::vector<RobotDetection> &robot_detections);
102
103
112 std::optional<Point> getBallPlacementPoint(const SSLProto::Referee &packet);
113
121 RobotDetection invert(RobotDetection robot_detection) const;
122 BallDetection invert(BallDetection ball_detection) const;
123
128 void updateDribbleDisplacement();
129
136 bool checkForVisionReset(double t_capture);
137
141 void resetWorldComponents();
142
151 static bool teamHasBall(const Team &team, const Ball &ball);
152
161 bool shouldTrustRobotStatus();
162 TbotsProto::SensorFusionConfig sensor_fusion_config;
163 std::optional<Field> field;
164 std::optional<Ball> ball;
165 Team friendly_team;
166 Team enemy_team;
167 GameState game_state;
168 std::optional<RefereeStage> referee_stage;
169
170 // Points on the field where a friendly bot initially touched the ball
171 std::map<RobotId, Point> ball_contacts_by_friendly_robots;
172 // Segment representing the displacement of the ball (in metres) due to
173 // the friendly team continuously dribbling the ball across the field.
174 //
175 // - The start point of the segment is the point on the field where the friendly
176 // team started dribbling the ball.
177 //
178 // - The end point of the segment is the current position of the ball.
179 //
180 // - The length of the segment is the distance between where the friendly team
181 // started dribbling the ball and where the ball is now.
182 //
183 // If the friendly team does not have possession over the ball, this is std::nullopt.
184 std::optional<Segment> dribble_displacement;
185
186
187 BallFilter ball_filter;
188 RobotTeamFilter friendly_team_filter;
189 RobotTeamFilter enemy_team_filter;
190
191 TeamPossession possession;
192 std::shared_ptr<PossessionTracker> possession_tracker;
193
194 std::optional<RobotId> friendly_robot_id_with_ball_in_dribbler;
195
196 unsigned int friendly_goalie_id;
197 unsigned int enemy_goalie_id;
198 bool defending_positive_side;
199 int ball_in_dribbler_timeout;
200
201 // The number of "reset packets" we have received. These indicate that the
202 // vision time should be reset. Please see `checkForVisionReset` to see how
203 // this is defined.
204 unsigned int reset_time_vision_packets_detected;
205
206 // The timestamp, in seconds, of the most recently received vision packet
207 double last_t_capture;
208};
Definition ball_filter.h:31
Definition ball.h:11
Holds the state of the game according to the referee.
Definition game_state.h:80
Definition robot_team_filter.h:10
Definition sensor_fusion.h:23
void processSensorProto(const SensorProto &sensor_msg)
Definition sensor_fusion.cpp:51
std::optional< World > getWorld() const
Definition sensor_fusion.cpp:30
Definition team.h:15
Definition vision_detection.h:34
Definition vision_detection.h:14