1
+ import math
1
2
from unittest .mock import Mock
2
3
3
4
import pytest
@@ -37,7 +38,7 @@ def test_step_limits_forward_x_velocity(node, tf2_buffer, config, pose_opponent_
37
38
38
39
controller .step (path_to (pose_opponent_goal ))
39
40
40
- assert controller .last_cmd_vel .linear .x == config .controller .max_vel_x
41
+ assert controller .last_cmd_vel .linear .x == pytest . approx ( config .controller .max_vel_x )
41
42
assert controller .last_cmd_vel .linear .y == pytest .approx (0 )
42
43
assert controller .last_cmd_vel .linear .z == 0
43
44
@@ -47,7 +48,7 @@ def test_step_limits_backward_x_velocity(node, tf2_buffer, config, pose_own_goal
47
48
48
49
controller .step (path_to (pose_own_goal ))
49
50
50
- assert controller .last_cmd_vel .linear .x == config .controller .min_vel_x
51
+ assert controller .last_cmd_vel .linear .x == pytest . approx ( config .controller .min_vel_x )
51
52
assert controller .last_cmd_vel .linear .y == pytest .approx (0 )
52
53
assert controller .last_cmd_vel .linear .z == 0
53
54
@@ -58,7 +59,7 @@ def test_step_limits_forward_y_velocity(node, tf2_buffer, config, pose_left_line
58
59
controller .step (path_to (pose_left_line ))
59
60
60
61
assert controller .last_cmd_vel .linear .x == pytest .approx (0 )
61
- assert controller .last_cmd_vel .linear .y == config .controller .max_vel_y
62
+ assert controller .last_cmd_vel .linear .y == pytest . approx ( config .controller .max_vel_y )
62
63
assert controller .last_cmd_vel .linear .z == 0
63
64
64
65
@@ -68,7 +69,7 @@ def test_step_limits_backward_y_velocity(node, tf2_buffer, config, pose_right_li
68
69
controller .step (path_to (pose_right_line ))
69
70
70
71
assert controller .last_cmd_vel .linear .x == pytest .approx (0 )
71
- assert controller .last_cmd_vel .linear .y == - config .controller .max_vel_y
72
+ assert controller .last_cmd_vel .linear .y == pytest . approx ( - config .controller .max_vel_y )
72
73
assert controller .last_cmd_vel .linear .z == 0
73
74
74
75
@@ -77,8 +78,15 @@ def test_step_limits_forward_xy_velocities(node, tf2_buffer, config, pose_oppone
77
78
78
79
controller .step (path_to (pose_opponent_corner ))
79
80
80
- assert controller .last_cmd_vel .linear .x == pytest .approx (config .controller .max_vel_x )
81
- assert controller .last_cmd_vel .linear .y == pytest .approx (config .controller .max_vel_y )
81
+ goal_heading_angle = math .atan2 (pose_opponent_corner .pose .position .y , pose_opponent_corner .pose .position .x )
82
+ walk_command_angle = math .atan2 (controller .last_cmd_vel .linear .y , controller .last_cmd_vel .linear .x )
83
+
84
+ assert goal_heading_angle == pytest .approx (walk_command_angle )
85
+
86
+ walk_command_speed = math .hypot (controller .last_cmd_vel .linear .x , controller .last_cmd_vel .linear .y )
87
+
88
+ assert walk_command_speed < config .controller .max_vel_x
89
+ assert walk_command_speed < config .controller .max_vel_y
82
90
assert controller .last_cmd_vel .linear .z == 0
83
91
84
92
@@ -87,20 +95,27 @@ def test_step_limits_backward_xy_velocities(node, tf2_buffer, config, pose_own_c
87
95
88
96
controller .step (path_to (pose_own_corner ))
89
97
90
- assert controller .last_cmd_vel .linear .x == pytest .approx (config .controller .min_vel_x )
91
- assert controller .last_cmd_vel .linear .y == pytest .approx (- 0.066666666 )
98
+ goal_heading_angle = math .atan2 (pose_own_corner .pose .position .y , pose_own_corner .pose .position .x )
99
+ walk_command_angle = math .atan2 (controller .last_cmd_vel .linear .y , controller .last_cmd_vel .linear .x )
100
+
101
+ assert goal_heading_angle == pytest .approx (walk_command_angle )
102
+
103
+ walk_command_speed = math .hypot (controller .last_cmd_vel .linear .x , controller .last_cmd_vel .linear .y )
104
+
105
+ assert walk_command_speed < abs (config .controller .min_vel_x )
106
+ assert walk_command_speed < config .controller .max_vel_y
92
107
assert controller .last_cmd_vel .linear .z == 0
93
108
94
109
95
110
def test_step_limits_rotation (node , tf2_buffer , config , pose_left_line , pose_right_line ):
96
111
controller = setup_controller (node , tf2_buffer )
97
112
98
113
controller .step (path_to (pose_left_line ))
99
- assert controller .last_cmd_vel .angular .z == config .controller .max_rotation_vel
114
+ assert controller .last_cmd_vel .angular .z == pytest . approx ( config .controller .max_rotation_vel )
100
115
101
116
controller .last_update_time = None
102
117
controller .step (path_to (pose_right_line ))
103
- assert controller .last_cmd_vel .angular .z == - config .controller .max_rotation_vel
118
+ assert controller .last_cmd_vel .angular .z == pytest . approx ( - config .controller .max_rotation_vel )
104
119
105
120
106
121
def test_step_cmd_vel_smoothing (snapshot , node , tf2_buffer , config , pose_opponent_corner ):
0 commit comments