Skip to content

Commit 8e18540

Browse files
committed
#28 fix edge case return val in gate_facing_vector, add ref
1 parent ad0419f commit 8e18540

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

baselines/baseline_racer.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55

66
# drone_name should match the name in ~/Document/AirSim/settings.json
77
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):
99
self.drone_name = drone_name
1010
self.gate_poses_ground_truth = None
1111
self.plot_transform = plot_transform
1212
self.viz_traj = viz_traj
1313
self.airsim_client = airsim.MultirotorClient()
1414
self.airsim_client.confirmConnection()
1515
self.level_name = None
16-
print(self.viz_traj)
1716

1817
def load_level(self, level_name, sleep_sec = 2.0):
1918
self.level_name = level_name
@@ -63,19 +62,18 @@ def get_ground_truth_gate_poses(self):
6362
# scale of the vector dictates speed of the velocity constraint
6463
def get_gate_facing_vector_from_quaternion(self, airsim_quat, scale = 1.0):
6564
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)
6868
n = np.dot(q, q)
6969
if n < np.finfo(float).eps:
70-
return np.identity(4)
70+
return airsim.Vector3r(0.0, 1.0, 0.0)
7171
q *= np.sqrt(2.0 / n)
7272
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]
7977
return airsim.Vector3r(scale * gate_facing_vector[0], scale * gate_facing_vector[1], scale * gate_facing_vector[2])
8078

8179
def fly_through_all_gates_one_by_one_with_moveOnSpline(self):

0 commit comments

Comments
 (0)