-
Notifications
You must be signed in to change notification settings - Fork 348
/
test_base_controllers.py
144 lines (114 loc) · 4.26 KB
/
test_base_controllers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import pytest
import time
import numpy as np
from pyrobot import Robot
from pyrobot.locobot.base_control_utils import (
get_trajectory_circle,
get_trajectory_negcircle,
_get_absolute_pose,
)
from pyrobot.locobot.bicycle_model import wrap_theta
# Launch for running the following tests:
# roslaunch locobot_control main.launch use_arm:=false use_base:=true base:=create use_rviz:=false use_sim:=true
@pytest.fixture(scope="module")
def create_robot():
return Robot("locobot", use_arm=False, use_camera=False)
@pytest.mark.parametrize("base_controller", ["ilqr"])
@pytest.mark.parametrize("base_planner", ["none"])
@pytest.mark.parametrize("close_loop", [True, False])
def test_trajectory_tracking_circle(
create_robot, base_controller, base_planner, close_loop
):
bot = create_robot
bot.base.load_controller(base_controller)
bot.base.load_planner(base_planner)
dt = 1.0 / bot.configs.BASE.BASE_CONTROL_RATE
v = bot.configs.BASE.MAX_ABS_FWD_SPEED / 2.0
w = bot.configs.BASE.MAX_ABS_TURN_SPEED / 2.0
r = v / w
start_state = np.array(bot.base.get_state("odom"))
states, _ = get_trajectory_circle(start_state, dt, r, v, np.pi)
bot.base.track_trajectory(states, close_loop=close_loop)
end_state = np.array(bot.base.get_state("odom"))
dist = np.linalg.norm(states[-1, :2] - end_state[:2])
assert dist < 0.1
def _test_relative_position_control(
posn,
create_robot,
base_controller,
base_planner,
close_loop,
smooth,
trans_thresh,
angular_thresh,
):
bot = create_robot
bot.base.load_controller(base_controller)
bot.base.load_planner(base_planner)
start_state = np.array(bot.base.get_state("odom"))
desired_target = _get_absolute_pose(posn, start_state)
bot.base.go_to_relative(posn, use_map=False, close_loop=close_loop, smooth=smooth)
end_state = np.array(bot.base.get_state("odom"))
dist = np.linalg.norm(end_state[:2] - desired_target[:2])
angle = end_state[2] - desired_target[2]
angle = np.abs(wrap_theta(angle))
assert dist < trans_thresh
assert angle * 180.0 / np.pi < angular_thresh
posns = np.array(
[
[1.0, 0.0, 0.0],
[0.0, 0.0, np.pi],
[1.0, 1.0, np.pi / 2.0],
# [1.0, 1.0, 0.0],
# [-1.0, 0.0, 0.0],
],
dtype=np.float32,
)
posns_movebase = np.array(
[[2.0, -2.0, np.pi/2]],
dtype=np.float32,
)
@pytest.mark.parametrize("base_controller", ["proportional"])
@pytest.mark.parametrize("base_planner", ["none"])
@pytest.mark.parametrize("close_loop", [True])
@pytest.mark.parametrize("smooth", [False])
@pytest.mark.parametrize("posn", posns)
def test_relative_position_control1(
create_robot, posn, base_controller, base_planner, close_loop, smooth
):
_test_relative_position_control(
posn, create_robot, base_controller, base_planner, close_loop, smooth, 0.05, 10
)
@pytest.mark.parametrize("base_controller", ["movebase"])
@pytest.mark.parametrize("base_planner", ["none"])
@pytest.mark.parametrize("close_loop", [True])
@pytest.mark.parametrize("smooth", [False])
@pytest.mark.parametrize("posn", posns_movebase)
def test_relative_position_control1_movebase(
create_robot, posn, base_controller, base_planner, close_loop, smooth
):
_test_relative_position_control(
posn, create_robot, base_controller, base_planner, close_loop, smooth, 0.25, 20
)
@pytest.mark.parametrize("base_controller", ["ilqr"])
@pytest.mark.parametrize("base_planner", ["none"])
@pytest.mark.parametrize("posn", posns)
def test_relative_position_control2_close_sharp(
create_robot, posn, base_controller, base_planner
):
_test_relative_position_control(
posn, create_robot, base_controller, base_planner, True, False, 0.05, 10
)
@pytest.mark.parametrize("base_controller", ["ilqr"])
@pytest.mark.parametrize("base_planner", ["none"])
@pytest.mark.parametrize("posn", posns)
def test_relative_position_control2_open_sharp(
create_robot, posn, base_controller, base_planner
):
_test_relative_position_control(
posn, create_robot, base_controller, base_planner, False, False, 0.10, 20
)