From f6fd6b41b1b54399b438ec74970d9a3fbfa92892 Mon Sep 17 00:00:00 2001 From: Sid Parikh Date: Mon, 13 Nov 2023 22:19:22 -0500 Subject: [PATCH] uncommit python files; make pretty-lines --- launch/config_server.launch.py | 18 +- launch/global_param_server.launch.py | 20 +- launch/soccer.launch.py | 312 +++++++++--------- launch/test_motion.launch.py | 22 +- .../rj_gameplay/play/test_motion_planning.py | 26 +- rj_gameplay/rj_gameplay/tactic/wall_tactic.py | 6 +- .../stp/formations/diamond_formation.py | 10 +- rj_gameplay/stp/formations/x_formation.py | 10 +- rj_gameplay/stp/tactic/__init__.py | 16 +- .../stp/utils/world_state_converter.py | 10 +- .../tests/stp/utils/test_typed_key_dict.py | 6 +- soccer/src/soccer/planning/global_state.hpp | 7 +- util/clang-format-diff.py | 6 +- util/yapf-diff.py | 6 +- 14 files changed, 248 insertions(+), 227 deletions(-) diff --git a/launch/config_server.launch.py b/launch/config_server.launch.py index abe1e3383bb..0222a9d555a 100644 --- a/launch/config_server.launch.py +++ b/launch/config_server.launch.py @@ -5,11 +5,13 @@ def generate_launch_description(): - return LaunchDescription([ - launch_ros.actions.Node( - package="rj_robocup", - executable="config_server", - output="screen", - on_exit=launch.actions.Shutdown(), - ) - ]) + return LaunchDescription( + [ + launch_ros.actions.Node( + package="rj_robocup", + executable="config_server", + output="screen", + on_exit=launch.actions.Shutdown(), + ) + ] + ) diff --git a/launch/global_param_server.launch.py b/launch/global_param_server.launch.py index 6dea6e98dab..9fbc6aebdec 100644 --- a/launch/global_param_server.launch.py +++ b/launch/global_param_server.launch.py @@ -13,12 +13,14 @@ def generate_launch_description(): config = os.path.join( get_package_share_directory("rj_robocup"), "config", "sim.yaml" ) - return LaunchDescription([ - launch_ros.actions.Node( - package="rj_robocup", - executable="global_param_server_node", - output="screen", - on_exit=launch.actions.Shutdown(), - parameters=[config], - ) - ]) + return LaunchDescription( + [ + launch_ros.actions.Node( + package="rj_robocup", + executable="global_param_server_node", + output="screen", + on_exit=launch.actions.Shutdown(), + parameters=[config], + ) + ] + ) diff --git a/launch/soccer.launch.py b/launch/soccer.launch.py index afdbca828d5..5efa2dad956 100644 --- a/launch/soccer.launch.py +++ b/launch/soccer.launch.py @@ -68,159 +68,161 @@ def generate_launch_description(): PythonLaunchDescriptionSource(str(launch_dir / "global_param_server.launch.py")) ) - return LaunchDescription([ - # LaunchArguments are declared here to be filled in by CLI arg, - # e.g. - # > ros2 launch rj_robocup soccer.launch.py run_sim:=True direction_flag:=plus - # will launch soccer with run_sim=True, direction_flag=+x - DeclareLaunchArgument( - "server_port", default_value=TextSubstitution(text="25565") - ), - DeclareLaunchArgument( - "team_name", default_value=TextSubstitution(text="RoboJackets") - ), - DeclareLaunchArgument("team_flag", default_value="-y"), - DeclareLaunchArgument("ref_flag", default_value="-noref"), - DeclareLaunchArgument("direction_flag", default_value="plus"), - DeclareLaunchArgument("use_internal_ref", default_value="True"), - DeclareLaunchArgument("run_sim", default_value="True"), - DeclareLaunchArgument("sim_flag", default_value="-sim"), - DeclareLaunchArgument( - "param_config", - default_value=PythonExpression([ - "'sim_params.yaml' if ", run_sim, " else 'real_params.yaml'" - ]), - ), - DeclareLaunchArgument("use_manual_control", default_value="False"), - DeclareLaunchArgument("use_sim_radio", default_value="True"), - # this launch arg shouldn't be used, is solely dependent on run_sim - # (above, param_config is defined by run_sim) - DeclareLaunchArgument( - "param_config_filepath", - default_value=[ - TextSubstitution( - text=os.path.join( - get_package_share_directory("rj_robocup"), "config", "" - ) + return LaunchDescription( + [ + # LaunchArguments are declared here to be filled in by CLI arg, + # e.g. + # > ros2 launch rj_robocup soccer.launch.py run_sim:=True direction_flag:=plus + # will launch soccer with run_sim=True, direction_flag=+x + DeclareLaunchArgument( + "server_port", default_value=TextSubstitution(text="25565") + ), + DeclareLaunchArgument( + "team_name", default_value=TextSubstitution(text="RoboJackets") + ), + DeclareLaunchArgument("team_flag", default_value="-y"), + DeclareLaunchArgument("ref_flag", default_value="-noref"), + DeclareLaunchArgument("direction_flag", default_value="plus"), + DeclareLaunchArgument("use_internal_ref", default_value="True"), + DeclareLaunchArgument("run_sim", default_value="True"), + DeclareLaunchArgument("sim_flag", default_value="-sim"), + DeclareLaunchArgument( + "param_config", + default_value=PythonExpression( + ["'sim_params.yaml' if ", run_sim, " else 'real_params.yaml'"] ), - param_config, - ], - ), - stdout_linebuf_envvar, - # Node spawns all of the ROS nodes, defined in main() of various - # cpp files, e.g. vision_receiver.cpp, planner_node_main.cpp - # Each of these take in the results of various - # LaunchConfiguration/Arguments above, e.g. param_config_filepath - # - # Note the order doesn't matter here: ROS nodes launch in some - # random order (there are Executors to change that) - Node( - package="rj_robocup", - executable="vision_receiver", - output="screen", - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - Node( - package="rj_robocup", - executable="config_server", - output="screen", - arguments=[team_flag, sim_flag, ref_flag, "-defend", direction_flag], - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - global_param_server, - Node( - package="rj_robocup", - executable="soccer", - output="screen", - arguments=[team_flag, sim_flag, ref_flag, "-defend", direction_flag], - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - Node( - condition=IfCondition(PythonExpression([run_sim])), - package="rj_robocup", - executable="sim_radio_node", - output="screen", - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - Node( - condition=IfCondition(PythonExpression(["not ", run_sim])), - package="rj_robocup", - executable="network_radio_node", - output="screen", - parameters=[ - param_config_filepath, - {"server_port": LaunchConfiguration("server_port")}, - ], - on_exit=Shutdown(), - ), - Node( - package="rj_robocup", - executable="control_node", - output="screen", - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - Node( - package="rj_robocup", - executable="planner_node", - output="screen", - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - # spawn manual node only if use_manual_control is True - Node( - condition=IfCondition(PythonExpression([use_manual_control])), - package="rj_robocup", - executable="manual_control_node", - output="screen", - on_exit=Shutdown(), - ), - # spawn strategy only if manual is not on - Node( - condition=IfCondition(PythonExpression(["not ", use_manual_control])), - package="rj_robocup", - executable="agent_action_client_node", - output="screen", - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - Node( - condition=IfCondition(PythonExpression(["not ", use_manual_control])), - package="rj_robocup", - executable="coach_node", - output="screen", - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - # spawn internal_ref/external_ref based on internal_ref LaunchArgument - Node( - condition=IfCondition(PythonExpression([use_internal_ref])), - package="rj_robocup", - executable="internal_referee_node", - output="screen", - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - Node( - condition=IfCondition(PythonExpression(["not ", use_internal_ref])), - package="rj_robocup", - executable="external_referee_node", - output="screen", - parameters=[ - param_config_filepath, - {"team_name": LaunchConfiguration("team_name")}, - ], - on_exit=Shutdown(), - ), - Node( - package="rj_robocup", - executable="rj_vision_filter", - output="screen", - parameters=[param_config_filepath], - on_exit=Shutdown(), - ), - ]) + ), + DeclareLaunchArgument("use_manual_control", default_value="False"), + DeclareLaunchArgument("use_sim_radio", default_value="True"), + # this launch arg shouldn't be used, is solely dependent on run_sim + # (above, param_config is defined by run_sim) + DeclareLaunchArgument( + "param_config_filepath", + default_value=[ + TextSubstitution( + text=os.path.join( + get_package_share_directory("rj_robocup"), "config", "" + ) + ), + param_config, + ], + ), + stdout_linebuf_envvar, + # Node spawns all of the ROS nodes, defined in main() of various + # cpp files, e.g. vision_receiver.cpp, planner_node_main.cpp + # Each of these take in the results of various + # LaunchConfiguration/Arguments above, e.g. param_config_filepath + # + # Note the order doesn't matter here: ROS nodes launch in some + # random order (there are Executors to change that) + Node( + package="rj_robocup", + executable="vision_receiver", + output="screen", + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + Node( + package="rj_robocup", + executable="config_server", + output="screen", + arguments=[team_flag, sim_flag, ref_flag, "-defend", direction_flag], + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + global_param_server, + Node( + package="rj_robocup", + executable="soccer", + output="screen", + arguments=[team_flag, sim_flag, ref_flag, "-defend", direction_flag], + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + Node( + condition=IfCondition(PythonExpression([run_sim])), + package="rj_robocup", + executable="sim_radio_node", + output="screen", + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + Node( + condition=IfCondition(PythonExpression(["not ", run_sim])), + package="rj_robocup", + executable="network_radio_node", + output="screen", + parameters=[ + param_config_filepath, + {"server_port": LaunchConfiguration("server_port")}, + ], + on_exit=Shutdown(), + ), + Node( + package="rj_robocup", + executable="control_node", + output="screen", + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + Node( + package="rj_robocup", + executable="planner_node", + output="screen", + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + # spawn manual node only if use_manual_control is True + Node( + condition=IfCondition(PythonExpression([use_manual_control])), + package="rj_robocup", + executable="manual_control_node", + output="screen", + on_exit=Shutdown(), + ), + # spawn strategy only if manual is not on + Node( + condition=IfCondition(PythonExpression(["not ", use_manual_control])), + package="rj_robocup", + executable="agent_action_client_node", + output="screen", + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + Node( + condition=IfCondition(PythonExpression(["not ", use_manual_control])), + package="rj_robocup", + executable="coach_node", + output="screen", + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + # spawn internal_ref/external_ref based on internal_ref LaunchArgument + Node( + condition=IfCondition(PythonExpression([use_internal_ref])), + package="rj_robocup", + executable="internal_referee_node", + output="screen", + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + Node( + condition=IfCondition(PythonExpression(["not ", use_internal_ref])), + package="rj_robocup", + executable="external_referee_node", + output="screen", + parameters=[ + param_config_filepath, + {"team_name": LaunchConfiguration("team_name")}, + ], + on_exit=Shutdown(), + ), + Node( + package="rj_robocup", + executable="rj_vision_filter", + output="screen", + parameters=[param_config_filepath], + on_exit=Shutdown(), + ), + ] + ) diff --git a/launch/test_motion.launch.py b/launch/test_motion.launch.py index dd13ce123a3..36f488b9221 100644 --- a/launch/test_motion.launch.py +++ b/launch/test_motion.launch.py @@ -70,13 +70,15 @@ def generate_launch_description(): on_exit=Shutdown(), ) - return LaunchDescription([ - grsim, - stdout_linebuf_envvar, - config_server, - radio, - control, - vision_receiver, - vision_filter, - ref_receiver, - ]) + return LaunchDescription( + [ + grsim, + stdout_linebuf_envvar, + config_server, + radio, + control, + vision_receiver, + vision_filter, + ref_receiver, + ] + ) diff --git a/rj_gameplay/rj_gameplay/play/test_motion_planning.py b/rj_gameplay/rj_gameplay/play/test_motion_planning.py index 568209bc299..81a13e36455 100644 --- a/rj_gameplay/rj_gameplay/play/test_motion_planning.py +++ b/rj_gameplay/rj_gameplay/play/test_motion_planning.py @@ -94,9 +94,9 @@ def __init__(self): self._offset = 2.0 def all_moves_done(self, world_state): - return self._move_skills and all([ - move_skill.is_done(world_state) for move_skill in self._move_skills - ]) + return self._move_skills and all( + [move_skill.is_done(world_state) for move_skill in self._move_skills] + ) def fill_move_skills(self, world_state, st_pt, end_pt): self._move_skills = [] @@ -129,14 +129,18 @@ def tick( elif self._state == AllBotsState.INIT_FAR: # evenly space pts along their goal side - st_pt = np.array([ - world_state.field.width_m / -2, - world_state.field.length_m - self._offset, - ]) - end_pt = np.array([ - world_state.field.width_m / 2, - world_state.field.length_m - self._offset, - ]) + st_pt = np.array( + [ + world_state.field.width_m / -2, + world_state.field.length_m - self._offset, + ] + ) + end_pt = np.array( + [ + world_state.field.width_m / 2, + world_state.field.length_m - self._offset, + ] + ) self.fill_move_skills(world_state, st_pt, end_pt) self._state = AllBotsState.FAR diff --git a/rj_gameplay/rj_gameplay/tactic/wall_tactic.py b/rj_gameplay/rj_gameplay/tactic/wall_tactic.py index 72f5b4c6844..4f06509ee2c 100644 --- a/rj_gameplay/rj_gameplay/tactic/wall_tactic.py +++ b/rj_gameplay/rj_gameplay/tactic/wall_tactic.py @@ -58,9 +58,9 @@ def find_wall_pts( # get vector to define walling direction ball_goal_dir = (ball_pt - goal_pt) / (np.linalg.norm(ball_pt - goal_pt) + 1e-9) - wall_dir = np.array([ - ball_goal_dir[1], -ball_goal_dir[0] - ]) # perp of above vector + wall_dir = np.array( + [ball_goal_dir[1], -ball_goal_dir[0]] + ) # perp of above vector # find endpoints of wall mid_pt = goal_pt + (ball_goal_dir * MIN_WALL_RAD) diff --git a/rj_gameplay/stp/formations/diamond_formation.py b/rj_gameplay/stp/formations/diamond_formation.py index 61e04cf4bcf..c793aa28536 100644 --- a/rj_gameplay/stp/formations/diamond_formation.py +++ b/rj_gameplay/stp/formations/diamond_formation.py @@ -66,10 +66,12 @@ def get_centroids(self) -> List: centroids = [] regions = self.get_regions for region in regions: - centroid = np.array([ - ((region[0] + region[1]) / 2), - ((region[2] + region[3]) / 2), - ]) + centroid = np.array( + [ + ((region[0] + region[1]) / 2), + ((region[2] + region[3]) / 2), + ] + ) centroids.append(centroid) return centroids diff --git a/rj_gameplay/stp/formations/x_formation.py b/rj_gameplay/stp/formations/x_formation.py index 2c4b38ece7e..5ad5132d432 100644 --- a/rj_gameplay/stp/formations/x_formation.py +++ b/rj_gameplay/stp/formations/x_formation.py @@ -66,10 +66,12 @@ def get_centroids(self) -> List: centroids = [] regions = self.get_regions for region in regions: - centroid = np.array([ - ((region[0] + region[1]) / 2), - ((region[2] + region[3]) / 2), - ]) + centroid = np.array( + [ + ((region[0] + region[1]) / 2), + ((region[2] + region[3]) / 2), + ] + ) centroids.append(centroid) return centroids diff --git a/rj_gameplay/stp/tactic/__init__.py b/rj_gameplay/stp/tactic/__init__.py index acb5ae7e9e4..a964ecb45df 100644 --- a/rj_gameplay/stp/tactic/__init__.py +++ b/rj_gameplay/stp/tactic/__init__.py @@ -89,11 +89,13 @@ def __repr__(self): text += ", ".join(temp) text += "\nRoles Assigned: " if self.assigned_roles: - text += ", ".join([ - f"({role.__class__.__name__}, {robot.id})" - for role, robot in itertools.zip_longest( - self.assigned_roles, self.assigned_robots - ) - if robot != None and role != None - ]) + text += ", ".join( + [ + f"({role.__class__.__name__}, {robot.id})" + for role, robot in itertools.zip_longest( + self.assigned_roles, self.assigned_robots + ) + if robot != None and role != None + ] + ) return text diff --git a/rj_gameplay/stp/utils/world_state_converter.py b/rj_gameplay/stp/utils/world_state_converter.py index c23000117a8..3f8291e28fb 100644 --- a/rj_gameplay/stp/utils/world_state_converter.py +++ b/rj_gameplay/stp/utils/world_state_converter.py @@ -173,10 +173,12 @@ def build_game_info( state, restart, our_restart, - np.array([ - play_state_msg.placement_point.x, - play_state_msg.placement_point.y, - ]), + np.array( + [ + play_state_msg.placement_point.x, + play_state_msg.placement_point.y, + ] + ), ) return game_info diff --git a/rj_gameplay/tests/stp/utils/test_typed_key_dict.py b/rj_gameplay/tests/stp/utils/test_typed_key_dict.py index 9b337be1f61..447a44728af 100644 --- a/rj_gameplay/tests/stp/utils/test_typed_key_dict.py +++ b/rj_gameplay/tests/stp/utils/test_typed_key_dict.py @@ -167,6 +167,6 @@ def test_tkdict_keys_values_items(): assert all([a == b for a, b in zip(tkdict.values(), expected_values)]) # Test .items(). - assert all([ - a == b for a, b in zip(tkdict.items(), zip(expected_keys, expected_values)) - ]) + assert all( + [a == b for a, b in zip(tkdict.items(), zip(expected_keys, expected_values))] + ) diff --git a/soccer/src/soccer/planning/global_state.hpp b/soccer/src/soccer/planning/global_state.hpp index aa92dd1de56..7bd5180140f 100644 --- a/soccer/src/soccer/planning/global_state.hpp +++ b/soccer/src/soccer/planning/global_state.hpp @@ -8,11 +8,12 @@ #include #include #include -#include #include -#include "world_state.hpp" -#include "game_state.hpp" +#include + #include "game_settings.hpp" +#include "game_state.hpp" +#include "world_state.hpp" namespace planning { diff --git a/util/clang-format-diff.py b/util/clang-format-diff.py index 600ad9e3446..2a91ef4992f 100644 --- a/util/clang-format-diff.py +++ b/util/clang-format-diff.py @@ -122,9 +122,9 @@ def main(): if line_count == 0: continue end_line = start_line + line_count - 1 - lines_by_file.setdefault(filename, []).extend([ - "-lines", str(start_line) + ":" + str(end_line) - ]) + lines_by_file.setdefault(filename, []).extend( + ["-lines", str(start_line) + ":" + str(end_line)] + ) # Reformat files containing changes in place. for filename, lines in lines_by_file.items(): diff --git a/util/yapf-diff.py b/util/yapf-diff.py index 79870c26ca4..d4a5c31d464 100644 --- a/util/yapf-diff.py +++ b/util/yapf-diff.py @@ -110,9 +110,9 @@ def main(): if line_count == 0: continue end_line = start_line + line_count - 1 - lines_by_file.setdefault(filename, []).extend([ - "--lines", str(start_line) + "-" + str(end_line) - ]) + lines_by_file.setdefault(filename, []).extend( + ["--lines", str(start_line) + "-" + str(end_line)] + ) # Reformat files containing changes in place. for filename, lines in lines_by_file.items():