Skip to content

Commit 2f27f79

Browse files
authored
Better defaults in game settings script (#533)
2 parents 406017e + 05d1af4 commit 2f27f79

File tree

1 file changed

+19
-10
lines changed
  • bitbots_misc/bitbots_parameter_blackboard/bitbots_parameter_blackboard

1 file changed

+19
-10
lines changed

bitbots_misc/bitbots_parameter_blackboard/bitbots_parameter_blackboard/game_settings.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,28 @@ def main():
138138
settings["parameter_blackboard"]["ros__parameters"] = ros_parameters
139139

140140
options = provide_config(OPTIONS_PATH)
141+
142+
# As a special case, we try to get the robot_id from the hostname as a default value
143+
# Because the robots often play with theirs fixed numbers
144+
try:
145+
robot_id = int(os.uname()[1][-1]) # We assume the the hostname is in the form 'nucX'
146+
ros_parameters["bot_id"] = robot_id
147+
except ValueError:
148+
pass
149+
141150
while not is_config_correct:
142-
for key in options.keys():
143-
entry_value_type = locate(options[key]["type"])
144-
entry_options = options[key].get("options", None)
145-
entry_explanation = options[key]["explanation"]
146-
147-
if key in ros_parameters.keys():
148-
ros_parameters[key] = ask_for_config_option(
149-
key, entry_value_type, ros_parameters[key], entry_options, entry_explanation
151+
for param_name, param_template in options.items():
152+
entry_value_type = locate(param_template["type"])
153+
entry_options = param_template.get("options", None)
154+
entry_explanation = param_template["explanation"]
155+
156+
if param_name in ros_parameters.keys():
157+
ros_parameters[param_name] = ask_for_config_option(
158+
param_name, entry_value_type, ros_parameters[param_name], entry_options, entry_explanation
150159
)
151160
else:
152-
value = ask_for_config_option(key, entry_value_type, None, entry_options, entry_explanation)
153-
ros_parameters.update({key: value})
161+
value = ask_for_config_option(param_name, entry_value_type, None, entry_options, entry_explanation)
162+
ros_parameters.update({param_name: value})
154163

155164
settings_string = yaml.safe_dump(settings)
156165
print("=============== Current Settings ===============")

0 commit comments

Comments
 (0)