Skip to content

Commit 12f4a6e

Browse files
committed
Addressing Akshara's changes
1 parent 20d562c commit 12f4a6e

File tree

6 files changed

+20
-48
lines changed

6 files changed

+20
-48
lines changed

Diff for: spot_rl_experiments/spot_rl/baselines/go_to_waypoint.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
def main(spot):
1212
parser = get_default_parser()
1313
parser.add_argument("-g", "--goal")
14-
parser.add_argument("-w", "--waypoints")
14+
parser.add_argument("-w", "--waypoint")
1515
parser.add_argument("-d", "--dock", action="store_true")
1616
parser.add_argument("-l", "--limit", action="store_true")
1717
args = parser.parse_args()
18-
if args.waypoints is not None:
19-
goal_x, goal_y, goal_heading = nav_target_from_waypoint(args.waypoints)
18+
if args.waypoint is not None:
19+
goal_x, goal_y, goal_heading = nav_target_from_waypoint(args.waypoint)
2020
else:
2121
assert args.goal is not None
2222
goal_x, goal_y, goal_heading = [float(i) for i in args.goal.split(",")]

Diff for: spot_rl_experiments/spot_rl/envs/nav_env.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
DOCK_ID = int(os.environ.get("SPOT_DOCK_ID", 520))
1818

19-
# Clean up this mess of paths
19+
# @Todo: Clean up this mess of paths
2020
this_dir = os.path.dirname(os.path.abspath(__file__))
2121
spot_rl_dir = os.path.join(os.path.dirname(this_dir))
2222
spot_rl_experiments_dir = os.path.join(os.path.dirname(spot_rl_dir))
@@ -43,7 +43,7 @@ def __init__(self, config, spot: Spot, record_trajectory=False) -> None:
4343
# Record robot's trajectory (i.e. waypoints)
4444
self.recording_in_progress = False
4545
self.start_time = 0.0
46-
self.robot_trajectory = [] # type: list[dict]
46+
self.robot_trajectory = [] # type: List[Dict]
4747
self.record_robot_trajectory = record_trajectory
4848

4949
# Setup
@@ -89,9 +89,9 @@ def execute(self, nav_targets) -> List[Dict[str, str]]:
8989
# Return waypoints back
9090
return self.robot_trajectory
9191

92-
def shutdown(self, dock=False) -> None:
92+
def shutdown(self, should_dock=False) -> None:
9393
try:
94-
if dock:
94+
if should_dock:
9595
self.nav_env.say("Executing automatic docking")
9696
dock_start_time = time.time()
9797
while time.time() - dock_start_time < 2:
@@ -166,7 +166,7 @@ def get_observations(self):
166166
try:
167167
robot_trajectory = wp_controller.execute(nav_targets=nav_targets)
168168
finally:
169-
wp_controller.shutdown(dock=args.dock)
169+
wp_controller.shutdown(should_dock=args.dock)
170170

171171
# @Todo: Make file_path as a compulsive argument when saving trajectory
172172
# @Todo: Add checks to ensure that filepath exists

Diff for: spot_rl_experiments/spot_rl/utils/calculate_distance.py

+7-37
Original file line numberDiff line numberDiff line change
@@ -44,52 +44,22 @@ def calculate_dtw_distance_between_trajectories(test_trajectory, reference_traje
4444

4545
def is_within_bounds(test_trajectory, reference_trajectories, threshold):
4646
"""
47-
Check if a test trajectory is within bounds of any reference trajectory.
47+
Check if a test trajectory is not within bounds of any reference trajectory.
4848
4949
Parameters:
5050
- test_trajectory (list): Test trajectory containing poses.
5151
- reference_trajectories (list): List of reference trajectories containing poses.
5252
- threshold (float): Threshold value for distance comparison.
5353
5454
Returns:
55-
- is_within (bool): True if the test trajectory is within bounds, False otherwise.
55+
- is_within (bool): True if the test trajectory is within bounds for all reference trajectories, False otherwise.
5656
"""
57-
test_start_pose = (
58-
test_trajectory[0]["pose"]["x"],
59-
test_trajectory[0]["pose"]["y"],
60-
test_trajectory[0]["pose"]["yaw"],
61-
)
62-
test_end_pose = (
63-
test_trajectory[-1]["pose"]["x"],
64-
test_trajectory[-1]["pose"]["y"],
65-
test_trajectory[-1]["pose"]["yaw"],
66-
)
67-
6857
for reference_trajectory in reference_trajectories:
69-
ref_start_pose = (
70-
reference_trajectory[0]["pose"]["x"],
71-
reference_trajectory[0]["pose"]["y"],
72-
reference_trajectory[0]["pose"]["yaw"],
73-
)
74-
ref_end_pose = (
75-
reference_trajectory[-1]["pose"]["x"],
76-
reference_trajectory[-1]["pose"]["y"],
77-
reference_trajectory[-1]["pose"]["yaw"],
58+
dtw_dist = calculate_dtw_distance_between_trajectories(
59+
test_trajectory, reference_trajectory
7860
)
79-
80-
start_distance = calculate_euclidean_distance_between_pose(
81-
test_start_pose, ref_start_pose
82-
)
83-
end_distance = calculate_euclidean_distance_between_pose(
84-
test_end_pose, ref_end_pose
85-
)
86-
87-
if start_distance <= threshold and end_distance <= threshold:
88-
dtw_dist = calculate_dtw_distance_between_trajectories(
89-
test_trajectory, reference_trajectory
90-
)
91-
print(f"FastDTW dist: {dtw_dist}")
92-
if dtw_dist > threshold:
93-
return False
61+
print(f"FastDTW dist: {dtw_dist}")
62+
if dtw_dist > threshold:
63+
return False
9464

9565
return True

Diff for: spot_rl_experiments/spot_rl/utils/json_helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def load_json_file(file_path):
4141

4242
def save_json_file(file_path, data):
4343
"""
44-
Save the contents of a Python object JSON file into a.
44+
Save the contents of a Python object into a JSON file.
4545
4646
Parameters:
4747
- file_path (str): Path to the JSON file.

Diff for: spot_rl_experiments/spot_rl/utils/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ def construct_config(opts=None):
5050
def nav_target_from_waypoint(waypoint, waypoints=WAYPOINTS):
5151
nav_target = waypoints.get(waypoint)
5252
if nav_target is None:
53+
default_waypoint = "dock"
54+
nav_target = waypoints.get(default_waypoint)
5355
raise Exception(
54-
f"waypoint - {waypoint} does not exist inside file waypoints.yaml, will go to `dock` waypoint instead"
56+
f"waypoint - {waypoint} does not exist inside file waypoints.yaml, will go to {default_waypoint} waypoint instead"
5557
)
5658
goal_x, goal_y, goal_heading = nav_target
5759
return goal_x, goal_y, np.deg2rad(goal_heading)

Diff for: tests/hardware_tests/test_nav_env.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_nav():
5252

5353
# ENSURE ROBOT GOES BACK TO DOCK IN THIS CASE
5454
finally:
55-
wp_controller.shutdown(dock=True)
55+
wp_controller.shutdown(should_dock=True)
5656

5757
print("test_robot_trajectory", robot_trajectory)
5858
assert robot_trajectory is not []

0 commit comments

Comments
 (0)