Skip to content

Commit bf4e682

Browse files
Add speed limitation of the robot (AtsushiSakai#595)
* Added speed limitation of the robot * Removed leading underscores for global vars * Added unit test for robot speed limitation * Modified x/abs(x) to np.sign(x); fixed code style * Removed 'random' from test func header comment
1 parent d5aca66 commit bf4e682

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Control/move_to_pose/move_to_pose.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
Kp_beta = -3
2020
dt = 0.01
2121

22+
# Robot specifications
23+
MAX_LINEAR_SPEED = 15
24+
MAX_ANGULAR_SPEED = 7
25+
2226
show_animation = True
2327

2428

@@ -63,6 +67,12 @@ def move_to_pose(x_start, y_start, theta_start, x_goal, y_goal, theta_goal):
6367
if alpha > np.pi / 2 or alpha < -np.pi / 2:
6468
v = -v
6569

70+
if abs(v) > MAX_LINEAR_SPEED:
71+
v = np.sign(v) * MAX_LINEAR_SPEED
72+
73+
if abs(w) > MAX_ANGULAR_SPEED:
74+
w = np.sign(w) * MAX_ANGULAR_SPEED
75+
6676
theta = theta + w * dt
6777
x = x + v * np.cos(theta) * dt
6878
y = y + v * np.sin(theta) * dt

tests/test_move_to_pose.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,16 @@ def test_1():
77
m.main()
88

99

10+
def test_2():
11+
"""
12+
This unit test tests the move_to_pose.py program for a MAX_LINEAR_SPEED and
13+
MAX_ANGULAR_SPEED
14+
"""
15+
m.show_animation = False
16+
m.MAX_LINEAR_SPEED = 11
17+
m.MAX_ANGULAR_SPEED = 5
18+
m.main()
19+
20+
1021
if __name__ == '__main__':
1122
conftest.run_this_test(__file__)

0 commit comments

Comments
 (0)