Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6345128
adding breakbream status to robot status and setting it in robot dete…
May 25, 2025
537c17d
working on compiliing
May 31, 2025
0509db4
ok i think it may all be for nothing since robotdetections are also i…
May 31, 2025
2d05a5c
frgttocommit
May 31, 2025
adbf0db
i think its working
Jun 1, 2025
cb83db5
working accessable
Jun 1, 2025
377b58d
removed comments not finished
Jun 1, 2025
9f9be4e
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 2, 2025
aee119d
adding breakbream status to robot status and setting it in robot dete…
May 25, 2025
1a20fb2
working on compiliing
May 31, 2025
52772ba
ok i think it may all be for nothing since robotdetections are also i…
May 31, 2025
db59c18
frgttocommit
May 31, 2025
1035d88
i think its working
Jun 1, 2025
79a548b
working accessable
Jun 1, 2025
8c8e022
removed comments not finished
Jun 1, 2025
7f80363
test fix
Jun 2, 2025
ae4a000
merge
Jun 2, 2025
1567cec
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 2, 2025
56a40e2
test improvements?
Jun 3, 2025
f4021e3
merge
Jun 3, 2025
a26ec53
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 3, 2025
34dd2c1
tests and docs
Jun 4, 2025
4a26315
Merge branch 'zane/brakebream_availability' of github.com:zuperzane/z…
Jun 4, 2025
42ae62b
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 4, 2025
0364416
space
Jun 4, 2025
3b62efa
Merge branch 'zane/brakebream_availability' of github.com:zuperzane/z…
Jun 4, 2025
5b08bdc
isneardribbler change
Jun 5, 2025
10058f2
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 5, 2025
817a279
tests and little bugs
Jun 6, 2025
832ce6b
merge
Jun 6, 2025
dc2b330
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 6, 2025
5690655
mini fixes
Jun 7, 2025
de6811e
docs
Jun 7, 2025
b3e475f
Merge branch 'zane/brakebream_availability' of github.com:zuperzane/z…
Jun 7, 2025
041ffc3
test fixes
Jun 9, 2025
57e6d5e
accidentally commited goalie changes
Jun 9, 2025
a9e1a4a
Update src/software/sensor_fusion/filter/robot_filter.h
zuperzane Jun 11, 2025
c8830d5
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 11, 2025
d796638
tests
Jun 11, 2025
937a41d
i forgot to edit this test lol
Jun 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/software/sensor_fusion/filter/robot_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ RobotFilter::RobotFilter(RobotDetection current_robot_state,
}

std::optional<Robot> RobotFilter::getFilteredData(
const std::vector<RobotDetection> &new_robot_data)
const std::vector<RobotDetection> &new_robot_data,
const std::optional<RobotId> breakbeam_tripped_id)
{
int data_num = 0;
Timestamp latest_timestamp = Timestamp().fromSeconds(0);
Expand Down Expand Up @@ -88,11 +89,14 @@ std::optional<Robot> RobotFilter::getFilteredData(
(filtered_data.timestamp.toSeconds() -
current_robot_state.timestamp().toSeconds());

// find breakbeam_status
bool breakbeam_tripped = breakbeam_tripped_id == getRobotId();

// update current_robot_state
this->current_robot_state =
Robot(this->getRobotId(), filtered_data.position, filtered_data.velocity,
filtered_data.orientation, filtered_data.angular_velocity,
filtered_data.timestamp);
filtered_data.timestamp, breakbeam_tripped);

return std::make_optional(this->current_robot_state);
}
Expand Down
7 changes: 6 additions & 1 deletion src/software/sensor_fusion/filter/robot_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ class RobotFilter
* The data does not all have to be for a particular Robot, the filter will only use
* the new Robot data that matches the robot id the filter was constructed with.
*
* @param breakbeam_tripped_id The id of the robot with the tripped breakbeam
* according to sensor fusion filtering logic (or none if no robot has a tripped
* beam).
*
* @return The filtered data for the robot
*/
std::optional<Robot> getFilteredData(
const std::vector<RobotDetection>& new_robot_data);
const std::vector<RobotDetection>& new_robot_data,
Comment thread
itsarune marked this conversation as resolved.
const std::optional<RobotId> breakbeam_tripped_id = std::nullopt);

/**
* Returns the id of the Robot that this filter is filtering for
Expand Down
6 changes: 4 additions & 2 deletions src/software/sensor_fusion/filter/robot_team_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ RobotTeamFilter::RobotTeamFilter() {}

Team RobotTeamFilter::getFilteredData(
const Team &current_team_state,
const std::vector<RobotDetection> &new_robot_detections)
const std::vector<RobotDetection> &new_robot_detections,
const std::optional<RobotId> breakbeam_tripped_id)
{
// Add filters for any robot we haven't seen before
for (auto detection : new_robot_detections)
Expand All @@ -28,7 +29,8 @@ Team RobotTeamFilter::getFilteredData(
std::vector<Robot> new_filtered_robot_data;
for (auto it = robot_filters.begin(); it != robot_filters.end(); it++)
{
auto data = it->second.getFilteredData(new_robot_detections);
auto data =
it->second.getFilteredData(new_robot_detections, breakbeam_tripped_id);
if (data)
{
new_filtered_robot_data.emplace_back(*data);
Expand Down
8 changes: 6 additions & 2 deletions src/software/sensor_fusion/filter/robot_team_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ class RobotTeamFilter
*
* @param current_team_state The current state of the Team
* @param new_robot_detections A list of new SSL Robot detections
* @param breakbeam_tripped_id The id of the robot with the tripped breakbeam
* according to sensor fusion
*
* @return The updated state of the team given the new data
*/
Team getFilteredData(const Team& current_team_state,
const std::vector<RobotDetection>& new_robot_detections);
Team getFilteredData(
Comment thread
itsarune marked this conversation as resolved.
const Team& current_team_state,
const std::vector<RobotDetection>& new_robot_detections,
const std::optional<RobotId> breakbeam_tripped_id = std::nullopt);


// A map used to store a separate robot filter for each robot on this team, so
Expand Down
7 changes: 4 additions & 3 deletions src/software/sensor_fusion/sensor_fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ std::optional<Ball> SensorFusion::createBall(

Team SensorFusion::createFriendlyTeam(const std::vector<RobotDetection> &robot_detections)
{
Team new_friendly_team =
friendly_team_filter.getFilteredData(friendly_team, robot_detections);
Team new_friendly_team = friendly_team_filter.getFilteredData(
friendly_team, robot_detections, friendly_robot_id_with_ball_in_dribbler);
return new_friendly_team;
}

Expand Down Expand Up @@ -427,7 +427,8 @@ void SensorFusion::updateDribbleDisplacement()

Team SensorFusion::createEnemyTeam(const std::vector<RobotDetection> &robot_detections)
{
Team new_enemy_team = enemy_team_filter.getFilteredData(enemy_team, robot_detections);
Team new_enemy_team =
enemy_team_filter.getFilteredData(enemy_team, robot_detections, false);
return new_enemy_team;
}

Expand Down
85 changes: 85 additions & 0 deletions src/software/sensor_fusion/sensor_fusion_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,3 +1010,88 @@ TEST_F(SensorFusionTest, breakbeam_fail_test_ssl)
// did it not use robot position
EXPECT_TRUE(ball_position != robot_state.position());
}

TEST_F(SensorFusionTest, breakbeam_in_robot_test)
{
// Check that breakbeam status is propagated to the Robot
SensorProto sensor_msg;

std::unique_ptr<SSLProto::SSL_DetectionFrame> frame = initDetectionFrame();
std::unique_ptr<SSLProto::SSL_DetectionFrame> frame_2 =
initDetectionFrameWithFutureTime();
// creating robot status
auto robot_msg = std::make_unique<TbotsProto::RobotStatus>();
robot_msg->set_robot_id(2);

auto power_status_msg = std::make_unique<TbotsProto::PowerStatus>();
power_status_msg->set_breakbeam_tripped(true);
*(robot_msg->mutable_power_status()) = *power_status_msg;

auto geometry_data = initSSLDivBGeomData();

// use frame 1 to create sensor_msg
auto ssl_wrapper_packet =
createSSLWrapperPacket(std::move(geometry_data), std::move(frame));
*(sensor_msg.mutable_ssl_vision_msg()) = *ssl_wrapper_packet;
*(sensor_msg.add_robot_status_msgs()) = *robot_msg;
sensor_fusion.processSensorProto(sensor_msg);

// use frame 2 that is at a future time to give sensor fusion
// a chance to use the breakbeam id it got from the previous sensor proto
auto ssl_wrapper_packet_2 =
createSSLWrapperPacket(std::move(geometry_data), std::move(frame_2));
*(sensor_msg.mutable_ssl_vision_msg()) = *ssl_wrapper_packet_2;
sensor_fusion.processSensorProto(sensor_msg);


std::optional<World> current_world = sensor_fusion.getWorld();
bool breakbeam_tripped =
current_world.value().friendlyTeam().getRobotById(2)->breakbeamTripped();

// is the breakbeam_tripped on the robot
EXPECT_TRUE(breakbeam_tripped);
}


TEST_F(SensorFusionTest, breakbeam_not_in_robot_test)
{
// Check that breakbeam status is false when propagated to the Robot
SensorProto sensor_msg;

std::unique_ptr<SSLProto::SSL_DetectionFrame> frame = initDetectionFrame();
std::unique_ptr<SSLProto::SSL_DetectionFrame> frame_2 =
initDetectionFrameWithFutureTime();
// creating robot status
auto robot_msg = std::make_unique<TbotsProto::RobotStatus>();
robot_msg->set_robot_id(2);

auto power_status_msg = std::make_unique<TbotsProto::PowerStatus>();
power_status_msg->set_breakbeam_tripped(false);
*(robot_msg->mutable_power_status()) = *power_status_msg;

// create ssl wrapper packet
auto geometry_data = initSSLDivBGeomData();


// use frame 1 to create sensor_msg
auto ssl_wrapper_packet =
createSSLWrapperPacket(std::move(geometry_data), std::move(frame));
*(sensor_msg.mutable_ssl_vision_msg()) = *ssl_wrapper_packet;
*(sensor_msg.add_robot_status_msgs()) = *robot_msg;
sensor_fusion.processSensorProto(sensor_msg);

// use frame 2 that is at a future time to give sensor fusion
// a chance to use the breakbeam id it got from the previous sensor proto
auto ssl_wrapper_packet_2 =
createSSLWrapperPacket(std::move(geometry_data), std::move(frame_2));
*(sensor_msg.mutable_ssl_vision_msg()) = *ssl_wrapper_packet_2;
sensor_fusion.processSensorProto(sensor_msg);


std::optional<World> current_world = sensor_fusion.getWorld();
bool breakbeam_tripped =
current_world.value().friendlyTeam().getRobotById(2)->breakbeamTripped();

// is the break_beam correct
EXPECT_FALSE(breakbeam_tripped);
}
27 changes: 24 additions & 3 deletions src/software/world/robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@
#include "software/ai/evaluation/time_to_travel.h"
#include "software/logger/logger.h"

Robot::Robot(RobotId id, const Point &position, const Vector &velocity,
const Angle &orientation, const AngularVelocity &angular_velocity,
const Timestamp &timestamp, bool breakbeam_tripped,
const std::set<RobotCapability> &unavailable_capabilities,
const RobotConstants_t &robot_constants)
: id_(id),
current_state_(position, velocity, orientation, angular_velocity,
breakbeam_tripped),
timestamp_(timestamp),
unavailable_capabilities_(unavailable_capabilities),
robot_constants_(robot_constants)
{
}

Robot::Robot(RobotId id, const Point &position, const Vector &velocity,
const Angle &orientation, const AngularVelocity &angular_velocity,
const Timestamp &timestamp,
const std::set<RobotCapability> &unavailable_capabilities,
const RobotConstants_t &robot_constants)
: id_(id),
current_state_(position, velocity, orientation, angular_velocity),
current_state_(position, velocity, orientation, angular_velocity, false),
timestamp_(timestamp),
unavailable_capabilities_(unavailable_capabilities),
robot_constants_(robot_constants)
Expand Down Expand Up @@ -90,6 +104,11 @@ Angle Robot::orientation() const
return current_state_.orientation();
}

bool Robot::breakbeamTripped() const
{
return current_state_.breakbeamTripped();
}

AngularVelocity Robot::angularVelocity() const
{
return current_state_.angularVelocity();
Expand All @@ -99,17 +118,19 @@ bool Robot::isNearDribbler(const Point &test_point, double TOLERANCE) const
{
const double POSSESSION_THRESHOLD_METERS = DIST_TO_FRONT_OF_ROBOT_METERS + TOLERANCE;

bool breakbeam = this->breakbeamTripped();
Vector vector_to_test_point = test_point - position();
if (vector_to_test_point.length() > POSSESSION_THRESHOLD_METERS)
{
return false;
return breakbeam;
}
else
{
// check that ball is in a 90-degree cone in front of the robot
auto ball_to_robot_angle =
orientation().minDiff(vector_to_test_point.orientation());
return (ball_to_robot_angle < Angle::fromDegrees(45.0));
bool vision_confirm_ball = (ball_to_robot_angle < Angle::fromDegrees(45.0));
return breakbeam || vision_confirm_ball;
Comment thread
itsarune marked this conversation as resolved.
Comment on lines +132 to +133

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an OR not an AND?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case vision noise is preventing AI from realizing the ball is in the breakbeam

}
}

Expand Down
31 changes: 30 additions & 1 deletion src/software/world/robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,38 @@ class Robot
* per second
* @param timestamp The timestamp at which the robot was observed to be in the given
* state
* @param breakbeam_tripped The new status of the breakbeam
* @param unavailable_capabilities The set of unavailable capabilities for this robot
* @param robot_constants The robot constants for this robot
*/
explicit Robot(RobotId id, const Point &position, const Vector &velocity,
const Angle &orientation, const AngularVelocity &angular_velocity,
const Timestamp &timestamp,
const Timestamp &timestamp, bool breakbeam_tripped = false,
Comment thread
itsarune marked this conversation as resolved.
const std::set<RobotCapability> &unavailable_capabilities =
std::set<RobotCapability>(),
const RobotConstants_t &robot_constants = DEFAULT_ROBOT_CONSTANTS);

/**
* Creates a new robot given robot data
*
* @param id The id of the robot to create
* @param position the new position of the robot. Coordinates are in metres.
* @param velocity the new velocity of the robot, in metres / second.
* @param orientation the new orientation of the robot, in Radians.
* @param angular_velocity the new angular velocity of the robot, in Radians
* per second
* @param timestamp The timestamp at which the robot was observed to be in the given
* state
* @param unavailable_capabilities The set of unavailable capabilities for this robot
* @param robot_constants The robot constants for this robot
*/
explicit Robot(RobotId id, const Point &position, const Vector &velocity,
const Angle &orientation, const AngularVelocity &angular_velocity,
const Timestamp &timestamp,
const std::set<RobotCapability> &unavailable_capabilities,
const RobotConstants_t &robot_constants);


/**
* Creates a new robot with the given initial state
*
Expand Down Expand Up @@ -114,6 +136,13 @@ class Robot
*/
Angle orientation() const;

/**
* Returns the current breakbeam status of the robot
*
* @return the current breakbeam status of the robot
*/
bool breakbeamTripped() const;

/**
* Returns the current angular velocity of the robot
*
Expand Down
14 changes: 11 additions & 3 deletions src/software/world/robot_state.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "software/world/robot_state.h"

RobotState::RobotState(const Point &position, const Vector &velocity,
const Angle &orientation, const AngularVelocity &angular_velocity)
const Angle &orientation, const AngularVelocity &angular_velocity,
const bool breakbeam_tripped)
: position_(position),
velocity_(velocity),
orientation_(orientation),
angular_velocity_(angular_velocity)
angular_velocity_(angular_velocity),
breakbeam_tripped_(breakbeam_tripped)
{
}

Expand All @@ -16,7 +18,8 @@ RobotState::RobotState(const TbotsProto::RobotState &robot_state_proto)
robot_state_proto.global_velocity().y_component_meters())),
orientation_(Angle::fromRadians(robot_state_proto.global_orientation().radians())),
angular_velocity_(AngularVelocity::fromRadians(
robot_state_proto.global_angular_velocity().radians_per_second()))
robot_state_proto.global_angular_velocity().radians_per_second())),
breakbeam_tripped_(false)
{
}

Expand All @@ -40,6 +43,11 @@ AngularVelocity RobotState::angularVelocity() const
return angular_velocity_;
}

bool RobotState::breakbeamTripped() const
{
return breakbeam_tripped_;
}

bool RobotState::operator==(const RobotState &other) const
{
return this->position() == other.position() && this->velocity() == other.velocity() &&
Expand Down
13 changes: 11 additions & 2 deletions src/software/world/robot_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ class RobotState
* @param velocity The velocity of the robot, in metres per second
* @param orientation The orientation of the robot
* @param angular_velocity The angular velocity of the robot
* @param breakbeam_tripped The breakbeam status of the robot
*/
explicit RobotState(const Point &position, const Vector &velocity,
const Angle &orientation,
const AngularVelocity &angular_velocity);
const Angle &orientation, const AngularVelocity &angular_velocity,
const bool breakbeam_tripped = false);

/**
* Creates a new robot state based on the TbotsProto::RobotState protobuf
Expand Down Expand Up @@ -68,6 +69,13 @@ class RobotState
*/
AngularVelocity angularVelocity() const;

/**
* Returns the breakbeam status of the robot represented by this state
*
* @return the breakbeam status of the robot represented by this state
*/
bool breakbeamTripped() const;

/**
* Defines the equality operator for a RobotState. RobotStates are equal if
* all their members are equal
Expand All @@ -94,6 +102,7 @@ class RobotState
Vector velocity_;
Angle orientation_;
AngularVelocity angular_velocity_;
bool breakbeam_tripped_;
};

/**
Expand Down
Loading