-
Notifications
You must be signed in to change notification settings - Fork 22
team_com disallowed robots to send messages if not intended, and reduces the rate if we get close to the budget end #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "team_com-message_budget-\"emergency-stop\""
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from bitbots_blackboard.body_blackboard import BodyBlackboard | ||
| from dynamic_stack_decider.abstract_decision_element import AbstractDecisionElement | ||
| from game_controller_hsl_interfaces.msg import GameState | ||
|
|
||
|
|
||
| class NumberPenalizedTeamMates(AbstractDecisionElement): | ||
| blackboard: BodyBlackboard | ||
|
|
||
| def __init__(self, blackboard, dsd, parameters): | ||
| super().__init__(blackboard, dsd, parameters) | ||
|
|
||
| def perform(self, reevaluate=False): | ||
| """ | ||
| Return number of penalized team mates | ||
| :param reevaluate: | ||
| :return: | ||
| """ | ||
| game_state_penalized_team_mates = self.blackboard.gamestate.get_penalized_team_mates() | ||
|
|
||
| if game_state_penalized_team_mates == 4: | ||
| return "FOUR" | ||
| elif game_state_penalized_team_mates == 3: | ||
| return "THREE" | ||
| elif game_state_penalized_team_mates == 2: | ||
| return "TWO" | ||
| elif game_state_penalized_team_mates == 1: | ||
| return "ONE" | ||
| else: | ||
| return "ZERO" | ||
|
|
||
| def get_reevaluate(self): | ||
| """ | ||
| Game state can change during the game | ||
| """ | ||
| return True | ||
|
|
||
| class NumberPenalizedRivals(AbstractDecisionElement): | ||
| blackboard: BodyBlackboard | ||
|
|
||
| def __init__(self, blackboard, dsd, parameters): | ||
| super().__init__(blackboard, dsd, parameters) | ||
|
|
||
| def perform(self, reevaluate=False): | ||
| """ | ||
| Return number of penalized rivals | ||
| :param reevaluate: | ||
| :return: | ||
| """ | ||
| game_state_penalized_rivals = self.blackboard.gamestate.get_penalized_rivals() | ||
|
|
||
| if game_state_penalized_rivals == 4: | ||
| return "FOUR" | ||
| elif game_state_penalized_rivals == 3: | ||
| return "THREE" | ||
| elif game_state_penalized_rivals == 2: | ||
| return "TWO" | ||
| elif game_state_penalized_rivals == 1: | ||
| return "ONE" | ||
| else: | ||
| return "ZERO" | ||
|
|
||
| def get_reevaluate(self): | ||
| """ | ||
| Game state can change during the game | ||
| """ | ||
| return True |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ def __init__(self): | |
| self.rate: int = self.node.get_parameter("rate").value | ||
| self.lifetime: int = self.node.get_parameter("lifetime").value | ||
| self.avg_walking_speed: float = self.node.get_parameter("avg_walking_speed").value | ||
| self.rate_is_reduced: bool = False | ||
|
|
||
| self.topics = get_parameter_dict(self.node, "topics") | ||
| self.map_frame: str = self.node.get_parameter("map_frame").value | ||
|
|
@@ -66,7 +67,7 @@ def __init__(self): | |
| self.run_spin_in_thread() | ||
| self.try_to_establish_connection() | ||
|
|
||
| self.node.create_timer(1 / self.rate, self.send_message, callback_group=MutuallyExclusiveCallbackGroup()) | ||
| self.timer = self.node.create_timer(1 / self.rate, self.send_message, callback_group=MutuallyExclusiveCallbackGroup()) | ||
| self.receive_forever() | ||
|
|
||
| def spin(self): | ||
|
|
@@ -263,6 +264,11 @@ def handle_message(self, string_message: bytes): | |
| self.team_data_publisher.publish(team_data) | ||
|
|
||
| def send_message(self): | ||
|
|
||
| if not self.rate_is_reduced: | ||
| if self.gamestate is not None and self.gamestate.secs_remaining > 180 and (self.gamestate.message_budget / self.gamestate.secs_remaining) < 11.2: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this logic to a method Please add some reasoning for the magic values. |
||
| self.reduce_rate() | ||
|
|
||
| if not self.is_robot_allowed_to_send_message(): | ||
| self.logger.debug("Robot is not allowed to send message") | ||
| return | ||
|
|
@@ -301,7 +307,17 @@ def should_message_be_discarded(self, message: Proto.Message) -> bool: | |
| return is_own_message or is_message_from_oposite_team | ||
|
|
||
| def is_robot_allowed_to_send_message(self) -> bool: | ||
| return self.gamestate is not None and not self.gamestate.penalized | ||
| #a penalized robot doesn't need to publish | ||
| if self.gamestate is not None and not self.gamestate.penalized: | ||
| return False | ||
| #if we are close to our message budget, we dont want to continue publishing | ||
| if self.gamestate is not None and (self.gamestate.message_budget > 40): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add reasoning about 40 and swapp > for < |
||
| return False | ||
| #we dont want to publish messages if only one robot is in a team. (this may never occure since this is the max team size, not the number of active players) | ||
| if self.gamestate is not None and self.gamestate.players_per_team == 1: | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
| def get_current_time(self) -> Time: | ||
| return self.node.get_clock().now() | ||
|
|
@@ -313,6 +329,13 @@ def extract_orientation_yaw_angle(self, quaternion: Quaternion): | |
|
|
||
| def convert_to_euler(self, quaternion: Quaternion): | ||
| return transforms3d.euler.quat2euler([quaternion.w, quaternion.x, quaternion.y, quaternion.z]) | ||
|
|
||
| def reduce_rate(self): | ||
| self.rate = 1 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a self.logger.warning message about reducing the rate. |
||
| self.timer.cancel() | ||
| self.timer = self.node.create_timer(1 / self.rate, self.send_message, callback_group=MutuallyExclusiveCallbackGroup()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this timer creation to a separate function, as this is duplicated from above. |
||
| self.rate_is_reduced = True | ||
|
|
||
|
|
||
|
|
||
| def main(): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a parameter
reduced_rateand use that instead of hardcoded 1