Skip to content

Commit e696382

Browse files
committed
Merge branch 'Gamecontroller-update-for-HSL' of https://github.com/bit-bots/bitbots_main into Gamecontroller-update-for-HSL
2 parents 056339b + 1c162a6 commit e696382

5 files changed

Lines changed: 128 additions & 1 deletion

File tree

.rsyncignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ src/bitbots_misc/bitbots_parameter_blackboard/config/game_settings.yaml
1717
*.idea
1818
*.pyc
1919
*.vscode
20+
*.devcontainer
2021

2122
__pycache__
2223

pixi.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,17 @@ pyamdgpuinfo = ">=2.1.7, <3"
228228
[feature.ros.activation.env]
229229
ROS_AUTOMATIC_DISCOVERY_RANGE = "LOCALHOST"
230230
RCUTILS_COLORIZED_OUTPUT = "1"
231+
RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity}] [{name}]: {message} ({function_name}() at {file_name}:{line_number})"
231232
RMW_IMPLEMENTATION = "rmw_cyclonedds_cpp"
232233
COLCON_LOG_LEVEL = "30"
233234
PYTHONWARNINGS="ignore:::setuptools.command.install,ignore:::setuptools.command.easy_install,ignore:::pkg_resources,ignore:easy_install command is deprecated,ignore:setup.py install is deprecated"
234235
WEBOTS_HOME = "$CONDA_PREFIX/share/webots"
235236

236237
[feature.ros.activation]
237-
scripts = ["install/setup.sh"]
238+
scripts = [
239+
"install/setup.sh",
240+
"scripts/ros.plugin.sh",
241+
]
238242

239243
[environments]
240244
default = ["ros", "format"] # Full development environment (excluding robot-only deps)

scripts/ros.plugin.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
### Aliases and functions for ROS 2 and colcon usage.
2+
3+
rid() {
4+
export ROS_DOMAIN_ID="$1"
5+
echo "ROS_DOMAIN_ID set to $ROS_DOMAIN_ID"
6+
}
7+
8+
# Create a function to update the argcomplete and generate the completion
9+
# scripts so that tab completion works within `pixi shell` environments.
10+
update_argcompletes() {
11+
local tools=(
12+
ros2
13+
colcon
14+
)
15+
16+
if [[ -n "${CONDA_PREFIX:-}" ]]; then
17+
local completions_path="$CONDA_PREFIX/share/zsh/site-functions"
18+
19+
if ! [[ -d "$completions_path" ]]; then
20+
mkdir -p "$completions_path"
21+
fi
22+
23+
for tool in "${tools[@]}"; do
24+
if type "$tool" &> /dev/null; then
25+
local _completion="$(register-python-argcomplete "$tool")"
26+
27+
if ! [[ -f "$completions_path/_$tool" ]]; then
28+
echo "_completion" > "$completions_path/_$tool"
29+
fi
30+
fi
31+
done
32+
fi
33+
}
34+
35+
setup_alises() {
36+
# check if we are in subdir of $ROS_WORKSPACE and switch to it otherwise
37+
alias cdc='[[ "$PWD" = "$ROS_WORKSPACE"* ]] || cd "$ROS_WORKSPACE"'
38+
39+
alias psh='cdc && pixi shell'
40+
41+
# ros aliases
42+
alias ros2='cdc && pixi run ros2'
43+
alias rr='ros2 run'
44+
alias rl='ros2 launch'
45+
46+
alias rte='ros2 topic echo'
47+
alias rtl='ros2 topic list'
48+
alias rth='ros2 topic hz'
49+
alias rtp='ros2 topic pub'
50+
51+
alias rpl='ros2 param list'
52+
alias rpg='ros2 param get'
53+
54+
# colcon aliases
55+
alias colcon='cdc && pixi run colcon'
56+
alias cba='cdc && pixi run build'
57+
alias cbs='cba --packages-select'
58+
alias cb='cba --packages-up-to'
59+
60+
alias ct='pixi run test'
61+
alias cts='ct --packages-select'
62+
63+
alias cca='pixi run clean'
64+
65+
# deploy_robots tool aliases
66+
alias dp='pixi run deploy --sync --build --print-bit-bot'
67+
alias dpfull='dp --install --configure'
68+
alias dpclean='dp --clean'
69+
alias dplo='dp --skip-local-repo-check'
70+
71+
# Overwrite some aliases in pixi shell to allow for tab completion
72+
# by directly using ros2/colcon instead of the pixi tasks
73+
if [[ "$(ps -o comm= -p "$PPID")" == "pixi" ]]; then
74+
alias cdc='cd $PIXI_PROJECT_ROOT'
75+
76+
# ros aliases
77+
unalias ros2
78+
alias rr='ros2 run'
79+
alias rl='ros2 launch'
80+
81+
alias rte='ros2 topic echo'
82+
alias rtl='ros2 topic list'
83+
alias rth='ros2 topic hz'
84+
alias rtp='ros2 topic pub'
85+
86+
alias rpl='ros2 param list'
87+
alias rpg='ros2 param get'
88+
89+
# colcon aliases
90+
unalias colcon
91+
alias cba='cdc && colcon build --symlink-install --cmake-args -G "Unix Makefiles" --continue-on-error'
92+
alias cbs='cba --packages-select'
93+
alias cb='cba --packages-up-to'
94+
95+
alias ct='cdc && colcon test --event-handlers console_direct+ --return-code-on-test-failure'
96+
alias cts='ct --packages-select'
97+
fi
98+
}
99+
100+
update_argcompletes
101+
setup_alises

src/bitbots_behavior/bitbots_blackboard/bitbots_blackboard/capsules/game_status_capsule.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self, node, blackboard=None):
1313
super().__init__(node, blackboard)
1414
self.team_id: int = get_parameters_from_other_node(self._node, "parameter_blackboard", ["team_id"])["team_id"]
1515
self.own_id: int = get_parameters_from_other_node(self._node, "parameter_blackboard", ["bot_id"])["bot_id"]
16+
self.own_id: int = get_parameters_from_other_node(self._node, "parameter_blackboard", ["bot_id"])["bot_id"]
1617
self.gamestate = GameState()
1718
self.last_update: float = 0.0
1819
self.unpenalized_time: float = 0.0
@@ -35,6 +36,8 @@ def get_set_play(self) -> int:
3536
def get_secondary_team(self) -> int:
3637
#Team ID, wer in set Play den Baall hat
3738
return self.gamestate.kickingTeam
39+
#Team ID, wer in set Play den Baall hat
40+
return self.gamestate.kickingTeam
3841

3942
def has_kickoff(self) -> bool:
4043
#vegelcih mit eigener Teamnummer
@@ -47,6 +50,9 @@ def has_penalty_kick(self) -> bool:
4750
return(
4851
self.gamestate.set_play == GameState.SET_PLAY_PENALTY_KICK
4952
and self.gamestate.kickingTeam == self.team_id)
53+
return(
54+
self.gamestate.set_play == GameState.SET_PLAY_PENALTY_KICK
55+
and self.gamestate.kickingTeam == self.team_id)
5056

5157
def get_our_goals(self) -> int:
5258
return self.gamestate.own_score
@@ -64,19 +70,22 @@ def get_seconds_remaining(self) -> float:
6470
# Time from the message minus time passed since receiving it
6571
return max(
6672
self.gamestate.secs_remaining - (self._node.get_clock().now().nanoseconds / 1e9 - self.last_update), 0.0
73+
self.gamestate.secs_remaining - (self._node.get_clock().now().nanoseconds / 1e9 - self.last_update), 0.0
6774
)
6875

6976
def get_secondary_seconds_remaining(self) -> float:
7077
"""Seconds remaining for things like kickoff"""
7178
# Time from the message minus time passed since receiving it
7279
return max(
80+
self.gamestate.secondary_time
7381
self.gamestate.secondary_time
7482
- (self._node.get_clock().now().nanoseconds / 1e9 - self.last_update),
7583
0.0,
7684
)
7785

7886
def get_seconds_since_unpenalized(self) -> float:
7987
return self._node.get_clock().now().nanoseconds / 1e9 - self.seconds_till_unpenalized
88+
return self._node.get_clock().now().nanoseconds / 1e9 - self.seconds_till_unpenalized
8089

8190
def get_is_penalized(self) -> bool:
8291
return self.gamestate.penalized
@@ -98,24 +107,34 @@ def gamestate_callback(self, gamestate_msg: GameState) -> None:
98107
if gamestate_msg.rival_score > self.gamestate.rival_score:
99108
self.last_goal_time = self._node.get_clock().now().nanoseconds / 1e9
100109

110+
'''Anstoß im Falle von Overtime jetzt erstmal nicht genauer geregelt
101111
'''Anstoß im Falle von Overtime jetzt erstmal nicht genauer geregelt
102112
if (
103113
gamestate_msg.main_state == GameState.STATE_SET
104114
and self.gamestate.setPlay != 2
105115
and gamestate_msg.state == GameState.STATE_PLAYING
116+
gamestate_msg.main_state == GameState.STATE_SET
117+
and self.gamestate.setPlay != 2
118+
and gamestate_msg.state == GameState.STATE_PLAYING
106119
):
107120
# secondary action is now executed but we will not see this in the new messages.
108121
# it will look like a normal kick off, but we need to remember that this is some sort of free kick
109122
# we set the kickoff value accordingly, then we will not be allowed to move if it is a kick for the others
110123
self.free_kick_kickoff_team = gamestate_msg.kickingTeam
111124

112125

126+
if gamestate_msg.setPlay != 2 and gamestate_msg.secondaryTime == 0:
127+
self.free_kick_kickoff_team = gamestate_msg.kickingTeam
128+
129+
113130
if gamestate_msg.setPlay != 2 and gamestate_msg.secondaryTime == 0:
114131
self.free_kick_kickoff_team = None
115132

133+
116134

117135
if self.free_kick_kickoff_team is not None:
118136
gamestate_msg.has_kick_off = self.free_kick_kickoff_team == self.team_id
119137
'''
138+
'''
120139
self.last_update = self._node.get_clock().now().nanoseconds / 1e9
121140
self.gamestate = gamestate_msg

src/bitbots_behavior/bitbots_body_behavior/bitbots_body_behavior/behavior_dsd/decisions/game_state_decider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def perform(self, reevaluate=False):
2828
return "PLAYING"
2929
elif game_state_number == GameState.STATE_FINISHED:
3030
return "FINISHED"
31+
elif game_state_number == GameState.STATE_STANDBY:
32+
return "STANDBY"
3133

3234
def get_reevaluate(self):
3335
"""

0 commit comments

Comments
 (0)