1 from __future__
import print_function, division
4 import matplotlib.pyplot
as plt
5 from collections
import OrderedDict
8 "check_trajectory_continuous_time",
9 "check_whether_trajectory_is_collision_free_by_subsampling",
10 "get_colliding_links",
11 "plot_task_cost_over_time",
18 robot_links = scene.get_collision_robot_links()
19 world_links = scene.get_collision_world_links()
20 for t
in range(1, trajectory.shape[0]):
21 q_t_1 = trajectory[t - 1, :]
22 q_t_2 = trajectory[t, :]
23 for r_l
in robot_links:
24 for w_l
in world_links:
26 T_r_l_1 = scene.fk(r_l)
27 T_w_l_1 = scene.fk(w_l)
29 T_r_l_2 = scene.fk(r_l)
30 T_w_l_2 = scene.fk(w_l)
31 p = scene.get_collision_scene().continuous_collision_check(
32 r_l, T_r_l_1, T_r_l_2, w_l, T_w_l_1, T_w_l_2
38 print(
"Continuous-time collision verification took", end_time - start_time)
43 scene, trajectory, num_subsamples=10, debug=
False 46 num_subsamples specifies how many steps are checked between two configurations. Returns True if trajectory is collision-free, and False otherwise. 48 TODO: Support setting time for Scene update. 51 trajectory_length = trajectory.shape[0]
52 for t
in range(1, trajectory_length):
53 q_t_1 = trajectory[t - 1, :]
54 q_t_2 = trajectory[t, :]
55 q_t_interpolation = np.linspace(q_t_1, q_t_2, num_subsamples)
56 for i
in range(num_subsamples):
57 scene.update(q_t_interpolation[i, :])
58 if not scene.is_state_valid(
True):
62 print(
"Trajectory transition collision check took", end_time - start_time)
67 scene, margin=0.0, safe_distance=0.0, check_self_collision=
True, debug=
False 69 robotLinks = scene.get_collision_robot_links()
70 world_links = scene.get_collision_world_links()
72 for r_l
in robotLinks:
73 for w_l
in world_links:
74 if scene.is_allowed_to_collide(r_l, w_l,
True):
75 if not scene.is_collision_free(r_l, w_l, margin):
76 d = scene.get_collision_distance(r_l, w_l)
77 if abs(d[0].distance) > safe_distance:
78 collisions.append((r_l, w_l, d[0].distance))
80 print(r_l,
"-", w_l,
"d=", d[0].distance)
81 if check_self_collision:
82 for w_l
in robotLinks:
84 if scene.is_allowed_to_collide(r_l, w_l,
True):
85 if not scene.is_collision_free(r_l, w_l, margin):
86 d = scene.get_collision_distance(r_l, w_l)
87 if abs(d[0].distance) > safe_distance:
88 collisions.append((r_l, w_l, d[0].distance))
90 print(r_l,
"-", w_l, d[0].distance)
96 Plots the task cost (task maps) over time given a problem. 99 for task_name
in problem.cost.task_maps:
100 costs[task_name] = np.zeros((problem.T,))
101 for t
in range(problem.T):
102 ydiff = problem.cost.get_task_error(task_name, t)
103 S = problem.cost.get_S(task_name, t)
104 cost = np.dot(np.dot(ydiff, S), ydiff.T)
105 costs[task_name][t] = cost
107 for task_name
in costs:
108 plt.plot(costs[task_name], label=task_name)
109 plt.title(
"Task cost over time")