From d4672f23932db527f1fffc7f7b76f34884294924 Mon Sep 17 00:00:00 2001 From: Atsushi Sakai Date: Fri, 24 Jan 2025 13:14:27 +0900 Subject: [PATCH] Fix lint error --- .../arm_obstacle_navigation.py | 4 ++-- .../arm_obstacle_navigation_2.py | 4 ++-- .../dynamic_movement_primitives.py | 13 ++++++------- .../Eta3SplineTrajectory/eta3_spline_trajectory.py | 7 +++---- PathPlanning/RRT/sobol/sobol.py | 12 ++++++------ 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation.py b/ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation.py index e377897e54..593db42b34 100644 --- a/ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation.py +++ b/ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation.py @@ -158,7 +158,7 @@ def astar_torus(grid, start_node, goal_node): while parent_map[route[0][0]][route[0][1]] != (): route.insert(0, parent_map[route[0][0]][route[0][1]]) - print("The route found covers %d grid cells." % len(route)) + print(f"The route found covers {len(route)} grid cells.") for i in range(1, len(route)): grid[route[i]] = 6 plt.cla() @@ -212,7 +212,7 @@ def calc_heuristic_map(M, goal_node): return heuristic_map -class NLinkArm(object): +class NLinkArm: """ Class for controlling and plotting a planar arm with an arbitrary number of links. """ diff --git a/ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation_2.py b/ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation_2.py index 10f4615c34..5295b7ca3a 100644 --- a/ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation_2.py +++ b/ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation_2.py @@ -189,7 +189,7 @@ def astar_torus(grid, start_node, goal_node): while parent_map[route[0][0]][route[0][1]] != (): route.insert(0, parent_map[route[0][0]][route[0][1]]) - print("The route found covers %d grid cells." % len(route)) + print(f"The route found covers {len(route)} grid cells.") for i in range(1, len(route)): grid[route[i]] = 6 plt.cla() @@ -243,7 +243,7 @@ def calc_heuristic_map(M, goal_node): return heuristic_map -class NLinkArm(object): +class NLinkArm: """ Class for controlling and plotting a planar arm with an arbitrary number of links. """ diff --git a/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py b/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py index 468d3b9f97..aa34934c0e 100644 --- a/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py +++ b/PathPlanning/DynamicMovementPrimitives/dynamic_movement_primitives.py @@ -18,7 +18,7 @@ import numpy as np -class DMP(object): +class DMP: def __init__(self, training_data, data_period, K=156.25, B=25): """ @@ -215,21 +215,21 @@ def show_DMP_purpose(self): T_vals = np.linspace(T_orig, 2*T_orig, 20) for new_q0_value in q0_vals: - plot_title = "Initial Position = [%s, %s]" % \ - (round(new_q0_value[0], 2), round(new_q0_value[1], 2)) + plot_title = (f"Initial Position = [{round(new_q0_value[0], 2)}," + f" {round(new_q0_value[1], 2)}]") _, path = self.recreate_trajectory(new_q0_value, g_orig, T_orig) self.view_trajectory(path, title=plot_title, demo=True) for new_g_value in g_vals: - plot_title = "Goal Position = [%s, %s]" % \ - (round(new_g_value[0], 2), round(new_g_value[1], 2)) + plot_title = (f"Goal Position = [{round(new_g_value[0], 2)}," + f" {round(new_g_value[1], 2)}]") _, path = self.recreate_trajectory(q0_orig, new_g_value, T_orig) self.view_trajectory(path, title=plot_title, demo=True) for new_T_value in T_vals: - plot_title = "Period = %s [sec]" % round(new_T_value, 2) + plot_title = f"Period = {round(new_T_value, 2)} [sec]" _, path = self.recreate_trajectory(q0_orig, g_orig, new_T_value) self.view_trajectory(path, title=plot_title, demo=True) @@ -257,5 +257,4 @@ def example_DMP(): if __name__ == '__main__': - example_DMP() diff --git a/PathPlanning/Eta3SplineTrajectory/eta3_spline_trajectory.py b/PathPlanning/Eta3SplineTrajectory/eta3_spline_trajectory.py index d034cb8a32..2dab7a7add 100644 --- a/PathPlanning/Eta3SplineTrajectory/eta3_spline_trajectory.py +++ b/PathPlanning/Eta3SplineTrajectory/eta3_spline_trajectory.py @@ -26,8 +26,7 @@ class MaxVelocityNotReached(Exception): def __init__(self, actual_vel, max_vel): - self.message = 'Actual velocity {} does not equal desired max velocity {}!'.format( - actual_vel, max_vel) + self.message = f'Actual velocity {actual_vel} does not equal desired max velocity {max_vel}!' class eta3_trajectory(Eta3Path): @@ -42,7 +41,7 @@ def __init__(self, segments, max_vel, v0=0.0, a0=0.0, max_accel=2.0, max_jerk=5. # ensure that all inputs obey the assumptions of the model assert max_vel > 0 and v0 >= 0 and a0 >= 0 and max_accel > 0 and max_jerk > 0 \ and a0 <= max_accel and v0 <= max_vel - super(eta3_trajectory, self).__init__(segments=segments) + super(__class__, self).__init__(segments=segments) self.total_length = sum([s.segment_length for s in self.segments]) self.max_vel = float(max_vel) self.v0 = float(v0) @@ -166,7 +165,7 @@ def velocity_profile(self): try: assert np.isclose(self.vels[index], 0) except AssertionError as e: - print('The final velocity {} is not zero'.format(self.vels[index])) + print(f'The final velocity {self.vels[index]} is not zero') raise e self.seg_lengths[index] = s_sf diff --git a/PathPlanning/RRT/sobol/sobol.py b/PathPlanning/RRT/sobol/sobol.py index 428ba58a98..cddc9d7c72 100644 --- a/PathPlanning/RRT/sobol/sobol.py +++ b/PathPlanning/RRT/sobol/sobol.py @@ -370,8 +370,8 @@ def i4_sobol(dim_num, seed): if (dim_num < 1 or dim_max < dim_num): print('I4_SOBOL - Fatal error!') print(' The spatial dimension DIM_NUM should satisfy:') - print(' 1 <= DIM_NUM <= %d' % dim_max) - print(' But this input value is DIM_NUM = %d' % dim_num) + print(f' 1 <= DIM_NUM <= {dim_max:d}') + print(f' But this input value is DIM_NUM = {dim_num:d}') return None dim_num_save = dim_num @@ -443,7 +443,7 @@ def i4_sobol(dim_num, seed): # l_var = i4_bit_lo0(seed) - elif (seed <= seed_save): + elif seed <= seed_save: seed_save = 0 lastq = np.zeros(dim_num) @@ -471,8 +471,8 @@ def i4_sobol(dim_num, seed): if maxcol < l_var: print('I4_SOBOL - Fatal error!') print(' Too many calls!') - print(' MAXCOL = %d\n' % maxcol) - print(' L = %d\n' % l_var) + print(f' MAXCOL = {maxcol:d}\n') + print(f' L = {l_var:d}\n') return None @@ -819,7 +819,7 @@ def r8mat_write(filename, m, n, a): with open(filename, 'w') as output: for i in range(0, m): for j in range(0, n): - s = ' %g' % (a[i, j]) + s = f' {a[i, j]:g}' output.write(s) output.write('\n')