stp.role
Subpackages
Submodules
Package Contents
Classes
Complex single-robot role, such as Goalie or Striker. Uses Skills to achieve behavior. |
|
An enum to represent priority of the role assignment. |
|
Protocol for CostFn. |
|
Protocol for ConstraintFn. |
|
Role Request. |
|
The result of role assignment. |
Functions
|
An unconstrained constraint fn, ie it always returns True. |
Attributes
- stp.role.BIG_STUPID_NUMBER_CONST_FOR_UNASSIGNED_COST_PLS_CHANGE = 9999
- class stp.role.Role(robot: stp.rc.Robot)
Bases:
abc.ABC
Complex single-robot role, such as Goalie or Striker. Uses Skills to achieve behavior.
- property robot: stp.rc.Robot
Returns self._robot. @property allows the getter to be called like this:
some_role = ConcreteRole() some_robot = some_role.robot
- abstract tick(world_state: stp.rc.WorldState) rj_msgs.msg.RobotIntent
Handle behavior of Role by handling which Skill is ticked, and with what params. Return the RobotIntent returned from ticking a Skill.
- abstract is_done(world_state: stp.rc.WorldState) bool
True if Role is done; False otherwise.
- class stp.role.Priority
Bases:
enum.IntEnum
An enum to represent priority of the role assignment.
- LOW = 0
- MEDIUM = 1
- HIGH = 2
- NUM_PRIORITIES = 3
- class stp.role.CostFn
Bases:
Protocol
Protocol for CostFn.
- __call__(robot: stp.rc.Robot, world_state: stp.rc.WorldState) float
Given a robot and the current world state, returns the cost of assigning that robot to a given role. :param robot: The current robot to check costs for. :param world_state: The current world state. :return:
- unassigned_cost_fn(prev_results: RoleResult | None, world_state: stp.rc.WorldState) float
Given the previous role assigment and current world state, returns the cost of not assigning any robot. :param prev_result: The previous role assignment result. :param world_state: The current world state. :return: cost of not assigning
- class stp.role.ConstraintFn
Bases:
Protocol
Protocol for ConstraintFn.
- __call__(robot: stp.rc.Robot, prev_result: RoleResult | None, world_state: stp.rc.WorldState) bool
Given a robot, the previous role assignment result, and the current world state, returns true if the assignment is valid. :param robot: The current robot to check costs for. :param prev_result: The previous role assignment result. :param world_state: The current world state. :return: True if the assignment is valid, false otherwise.
- stp.role.unconstrained_constraint_fn(robot: stp.rc.Robot, prev_result: RoleResult | None, world_state: stp.rc.WorldState) bool
An unconstrained constraint fn, ie it always returns True. :param robot: The current robot to check costs for. :param prev_result: The previous role assignment result. :param world_state: The current world state. :return: True.
- class stp.role.RoleRequest(priority: Priority, required: bool, cost_fn: CostFn, constraint_fn: ConstraintFn = unconstrained_constraint_fn)
Role Request.
- __slots__ = ['priority', 'required', 'cost_fn', 'constraint_fn']
- required: bool
- constraint_fn: ConstraintFn
- with_priority(priority: Priority) RoleRequest
Builder style method that modifies the priority and returns the current instance. :param priority: The priority to set the RoleRequest to. :return: self.
- with_required(required: bool) RoleRequest
Builder style method that modifies required and returns the current instance. :param required: Whether the tactic will fail if this RoleRequest is not fulfilled. :return: self.
- with_cost_fn(cost_fn: CostFn) RoleRequest
Builder style method that modifies the cost function and returns the current instance. :param cost_fn: The new cost function to use. :return: self.
- with_constraint_fn(constraint_fn: ConstraintFn) RoleRequest
Builder style method that modifies the cost function and returns the current instance. :param constraint_fn: The new constraint function to use. :return: self.
- __str__() str
Return str(self).
- __repr__() str
Return repr(self).
- class stp.role.RoleResult(request: RoleRequest, cost: float, role: Role)
The result of role assignment.
- __slots__ = ['request', 'cost', 'role']
- request: RoleRequest
- cost: float
- is_filled() bool
Returns true if the role request is filled. :return: True if the role request is filled.
- assign(robot: stp.rc.Robot, cost: float) None
Assigns self.role to the passed in robot, updating self.cost to the assignment cost. :param robot: Robot to use for the role. :param cost: The cost of the assignment.
- classmethod from_request(request: RoleRequest) RoleResult
Creates an unfilled RoleResult from a RoleRequest.
- __str__() str
Return str(self).
- __repr__() str
Return repr(self).