|
5 | 5 |
|
6 | 6 | # drone_name should match the name in ~/Document/AirSim/settings.json |
7 | 7 | class BaselineRacer(object): |
8 | | - def __init__(self, drone_name = "drone_1", plot_transform=True, viz_traj=False): |
| 8 | + def __init__(self, drone_name = "drone_1", plot_transform=True, viz_traj=True): |
9 | 9 | self.drone_name = drone_name |
10 | 10 | self.gate_poses_ground_truth = None |
11 | 11 | self.plot_transform = plot_transform |
12 | 12 | self.viz_traj = viz_traj |
13 | 13 | self.airsim_client = airsim.MultirotorClient() |
14 | 14 | self.airsim_client.confirmConnection() |
15 | 15 | self.level_name = None |
16 | | - print(self.viz_traj) |
17 | 16 |
|
18 | 17 | def load_level(self, level_name, sleep_sec = 2.0): |
19 | 18 | self.level_name = level_name |
@@ -63,19 +62,18 @@ def get_ground_truth_gate_poses(self): |
63 | 62 | # scale of the vector dictates speed of the velocity constraint |
64 | 63 | def get_gate_facing_vector_from_quaternion(self, airsim_quat, scale = 1.0): |
65 | 64 | import numpy as np |
66 | | - |
67 | | - q = np.array([airsim_quat.w_val, airsim_quat.x_val, airsim_quat.y_val, airsim_quat.z_val], dtype=np.float64, copy=True) |
| 65 | + # convert gate quaternion to rotation matrix. |
| 66 | + # ref: https://en.wikipedia.org/wiki/Rotation_matrix#Quaternion; https://www.lfd.uci.edu/~gohlke/code/transformations.py.html |
| 67 | + q = np.array([airsim_quat.w_val, airsim_quat.x_val, airsim_quat.y_val, airsim_quat.z_val], dtype=np.float64) |
68 | 68 | n = np.dot(q, q) |
69 | 69 | if n < np.finfo(float).eps: |
70 | | - return np.identity(4) |
| 70 | + return airsim.Vector3r(0.0, 1.0, 0.0) |
71 | 71 | q *= np.sqrt(2.0 / n) |
72 | 72 | q = np.outer(q, q) |
73 | | - rotation_matrix = np.array([ |
74 | | - [1.0-q[2, 2]-q[3, 3], q[1, 2]-q[3, 0], q[1, 3]+q[2, 0], 0.0], |
75 | | - [ q[1, 2]+q[3, 0], 1.0-q[1, 1]-q[3, 3], q[2, 3]-q[1, 0], 0.0], |
76 | | - [ q[1, 3]-q[2, 0], q[2, 3]+q[1, 0], 1.0-q[1, 1]-q[2, 2], 0.0], |
77 | | - [ 0.0, 0.0, 0.0, 1.0]]) |
78 | | - gate_facing_vector = rotation_matrix[:-1,1] |
| 73 | + rotation_matrix = np.array([[1.0-q[2, 2]-q[3, 3], q[1, 2]-q[3, 0], q[1, 3]+q[2, 0]], |
| 74 | + [ q[1, 2]+q[3, 0], 1.0-q[1, 1]-q[3, 3], q[2, 3]-q[1, 0]], |
| 75 | + [ q[1, 3]-q[2, 0], q[2, 3]+q[1, 0], 1.0-q[1, 1]-q[2, 2]]]) |
| 76 | + gate_facing_vector = rotation_matrix[:,1] |
79 | 77 | return airsim.Vector3r(scale * gate_facing_vector[0], scale * gate_facing_vector[1], scale * gate_facing_vector[2]) |
80 | 78 |
|
81 | 79 | def fly_through_all_gates_one_by_one_with_moveOnSpline(self): |
|
0 commit comments