Thunderbots Project
Loading...
Searching...
No Matches
Team Class Reference

#include <team.h>

Public Member Functions

 Team (const Duration &robot_expiry_buffer_duration=Duration::fromMilliseconds(50))
 
 Team (const std::vector< Robot > &team_robots, const Duration &robot_expiry_buffer_duration=Duration::fromMilliseconds(50))
 
 Team (const TbotsProto::Team &team_proto, const Duration &robot_expiry_buffer_duration=Duration::fromMilliseconds(50))
 
void updateRobots (const std::vector< Robot > &team_robots)
 
void updateState (const Team &new_team_data)
 
void removeExpiredRobots (const Timestamp &timestamp)
 
void removeRobotWithId (unsigned int robot_id)
 
void assignGoalie (RobotId new_goalie_id)
 
void clearGoalie ()
 
size_t numRobots () const
 
const DurationgetRobotExpiryBufferDuration () const
 
void setRobotExpiryBuffer (const Duration &new_robot_expiry_buffer_duration)
 
void setUnavailableRobotCapabilities (RobotId id, const std::set< RobotCapability > &new_unavailable_robot_capabilities)
 
std::optional< RobotgetRobotById (const unsigned int id) const
 
std::optional< Robotgoalie () const
 
std::optional< unsigned int > getGoalieId () const
 
const std::vector< Robot > & getAllRobots () const
 
std::vector< RobotgetAllRobotsExceptGoalie () const
 
std::optional< RobotgetNearestRobot (const Point &ref_point) const
 
void clearAllRobots ()
 
std::optional< Timestamptimestamp () const
 
bool operator== (const Team &other) const
 
bool operator!= (const Team &other) const
 
Timestamp getMostRecentTimestamp () const
 

Static Public Member Functions

static std::optional< RobotgetNearestRobot (const std::vector< Robot > &robots, const Point &ref_point)
 

Detailed Description

A team of robots

Constructor & Destructor Documentation

◆ Team() [1/3]

Team ( const Duration robot_expiry_buffer_duration = Duration::fromMilliseconds(50))
explicit

Create a new team

Parameters
robot_expiry_buffer_durationThe Duration for which a robot must not have been updated for before it is removed from the team

◆ Team() [2/3]

Team ( const std::vector< Robot > &  team_robots,
const Duration robot_expiry_buffer_duration = Duration::fromMilliseconds(50) 
)
explicit

Create a new team

Parameters
team_robotsThe robots on the team
robot_expiry_buffer_durationThe Duration for which a robot must not have been updated for before it is removed from the team

◆ Team() [3/3]

Team ( const TbotsProto::Team &  team_proto,
const Duration robot_expiry_buffer_duration = Duration::fromMilliseconds(50) 
)
explicit

Creates a new team based on the TbotsProto::Team protobuf representation

Parameters
team_protoThe TbotsProto::Team protobuf which this robot should be based on

Member Function Documentation

◆ assignGoalie()

void assignGoalie ( RobotId  new_goalie_id)

Assigns the goalie id for this team

Parameters
new_goalie_idThe id of the new goalie for this team

◆ clearAllRobots()

void clearAllRobots ( )

Removes all Robots from this team. Does not affect the goalie id.

◆ clearGoalie()

void clearGoalie ( )

Clears the goalie for this team. There will be no goalie assigned after this operation

◆ getAllRobots()

const std::vector< Robot > & getAllRobots ( ) const

Returns a vector of all the robots on this team.

Returns
a vector of all the robots on this team.

◆ getAllRobotsExceptGoalie()

std::vector< Robot > getAllRobotsExceptGoalie ( ) const

Returns a vector of all the robots on this team excluding the goalie

Returns
a vector of all the robots on this team excluding the goalie

◆ getGoalieId()

std::optional< unsigned int > getGoalieId ( ) const

Returns the ID of the goalie for this team, if one has been specified. Otherwise returns std::nullopt

Returns
The ID of the goalie robot for this team if one is specified, otherwise returns std::nullopt

◆ getMostRecentTimestamp()

Timestamp getMostRecentTimestamp ( ) const

Returns the most Timestamp corresponding to the most recent update to Field object

Returns
Timestamp : The Timestamp corresponding to the most recent update to the Field object

◆ getNearestRobot() [1/2]

std::optional< Robot > getNearestRobot ( const Point ref_point) const

Finds the robot on a team that is closest to the reference point

Parameters
ref_pointThe point where the distance to each robot will be measured.
Returns
Robot that is closest to the reference point. std::nullopt otherwise

◆ getNearestRobot() [2/2]

std::optional< Robot > getNearestRobot ( const std::vector< Robot > &  robots,
const Point ref_point 
)
static

Given a list of robots, finds the robot on that team that is closest to a reference point.

Parameters
robotsthe list of robots
ref_pointThe point where the distance to each robot will be measured.
Returns
Robot that is closest to the reference point.

◆ getRobotById()

std::optional< Robot > getRobotById ( const unsigned int  id) const

Returns the robot with the given id. If this team does not have that robot, returns an std::nullopt

Parameters
idthe id of the desired Robot
Returns
the Robot on the team with the given id if it exists, otherwise std::nullopt

◆ getRobotExpiryBufferDuration()

const Duration & getRobotExpiryBufferDuration ( ) const

Returns the Duration for which a Robot must not have been updated for before being removed from this team.

Returns
the Duration for which a Robot must not have been updated for before being removed from this team.

◆ goalie()

std::optional< Robot > goalie ( ) const

Returns the goalie robot for this team, if one is specified. Otherwise returns std::nullopt

Returns
the goalie robot for this team if one is specified, otherwise returns std::nullopt

◆ numRobots()

std::size_t numRobots ( ) const

Gets the number of robots on this team

Returns
the number of robots on this team

◆ operator!=()

bool operator!= ( const Team other) const

Defines the inequality operator for a Team.

Parameters
otherThe team to compare against for inequality
Returns
True if the other team is not equal to this team, and false otherwise

◆ operator==()

bool operator== ( const Team other) const

Defines the equality operator for a Team. Teams are equal if their robots are equal and have the same robot assigned as the goalie

Parameters
otherThe team to compare against for equality
Returns
True if the other team is equal to this team, and false otherwise

◆ removeExpiredRobots()

void removeExpiredRobots ( const Timestamp timestamp)

Removes expired robots from the team. Robots are expired if it has been more than the expiry_buffer time has passed since they were last updated. This would happen if a robot is removed from the field, so that it is no longer seen by the cameras. After a short amount of time, we should treat robots that we can no longer see (and therefore have not been updating) as removed from the field, so we should remove them from the team.

Parameters
timestampThe timestamp for when this removal is taking place

◆ removeRobotWithId()

void removeRobotWithId ( unsigned int  robot_id)

Remove the robot with the given ID from the team

If there is no robot with the given id on the team, does nothing

Parameters
robot_idThe id of the robot to remove

◆ setRobotExpiryBuffer()

void setRobotExpiryBuffer ( const Duration new_robot_expiry_buffer_duration)

Sets the Duration for which a Robot must not have been updated for before being removed from this team.

Parameters
new_robot_expiry_buffer_durationthe Duration for which a Robot must not have been updated for before being removed from this team.

◆ setUnavailableRobotCapabilities()

void setUnavailableRobotCapabilities ( RobotId  id,
const std::set< RobotCapability > &  new_unavailable_robot_capabilities 
)

Updates the unavailable capabilities of a specific robot. If the team does not have that robot, does not do anything.

Parameters
idthe id of the desired Robot
new_unavailable_robot_capabilitiesa set of the updated unavailable robot capabilities

◆ timestamp()

std::optional< Timestamp > timestamp ( ) const

Returns the timestamp of the most recently updated robot on this team

Returns
the timestamp of the most recently updated robot on this team, or std::nullopt if this team is empty

◆ updateRobots()

void updateRobots ( const std::vector< Robot > &  team_robots)

Updates this team with new robots.

Exceptions
std::invalid_argumentif multiple robots have the same id
Parameters
team_robotsthe new robots for this team

◆ updateState()

void updateState ( const Team new_team_data)

Updates this team with new data from the given team object. This is different from a copy constructor because the team object is only used to store data, we don't take the entire state of the new_team_data. For example, the robots on this team may have complex internal state for predicting movement. The "simple" robot data such as position, velocity... from the new_team_data is used to update the state of the robots on this team, rather than the robots simply being copied over (because if we copied we would lose our state).

Parameters
new_team_dataA team with the new team data

The documentation for this class was generated from the following files: