Showing trajectory and ground truth quantities
parent
ac57680dee
commit
cf07c22c2c
|
@ -46,7 +46,13 @@ class Scenario {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Scenario with constant twist 3D trajectory.
|
/**
|
||||||
|
* Scenario with constant twist 3D trajectory.
|
||||||
|
* Note that a plane flying level does not feel any acceleration: gravity is
|
||||||
|
* being perfectly compensated by the lift generated by the wings, and drag is
|
||||||
|
* compensated by thrust. The accelerometer will add the gravity component back
|
||||||
|
* in, as modeled by the specificForce method in ScenarioRunner.
|
||||||
|
*/
|
||||||
class ConstantTwistScenario : public Scenario {
|
class ConstantTwistScenario : public Scenario {
|
||||||
public:
|
public:
|
||||||
/// Construct scenario with constant twist [w,v]
|
/// Construct scenario with constant twist [w,v]
|
||||||
|
|
|
@ -9,6 +9,7 @@ import numpy as np
|
||||||
from mpl_toolkits.mplot3d import Axes3D
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
|
||||||
import gtsam
|
import gtsam
|
||||||
|
from gtsam_utils import plotPose3
|
||||||
|
|
||||||
class ImuFactorExample(object):
|
class ImuFactorExample(object):
|
||||||
|
|
||||||
|
@ -24,37 +25,54 @@ class ImuFactorExample(object):
|
||||||
W = np.array([0, -w, 0])
|
W = np.array([0, -w, 0])
|
||||||
V = np.array([v, 0, 0])
|
V = np.array([v, 0, 0])
|
||||||
self.scenario = gtsam.ConstantTwistScenario(W, V)
|
self.scenario = gtsam.ConstantTwistScenario(W, V)
|
||||||
|
self.dt = 0.5
|
||||||
|
self.realTimeFactor = 10.0
|
||||||
|
|
||||||
# Calculate time to do 1 loop
|
# Calculate time to do 1 loop
|
||||||
self.T = 2 * math.pi / w
|
self.radius = v / w
|
||||||
|
self.timeForOneLoop = 2 * math.pi / w
|
||||||
|
self.labels = list('xyz')
|
||||||
|
self.colors = list('rgb')
|
||||||
|
|
||||||
def plot(self, t, pose):
|
def plot(self, t, pose, omega_b, acceleration_n, acceleration_b):
|
||||||
# plot IMU
|
# plot angular velocity
|
||||||
plt.figure(1)
|
plt.figure(1)
|
||||||
times = np.arange(0, 10, 0.1)
|
for i, (label, color) in enumerate(zip(self.labels, self.colors)):
|
||||||
shape = len(times), 1
|
|
||||||
labels = list('xyz')
|
|
||||||
colors = list('rgb')
|
|
||||||
plt.clf()
|
|
||||||
for i, (label, color) in enumerate(zip(labels, colors)):
|
|
||||||
plt.subplot(3, 1, i + 1)
|
plt.subplot(3, 1, i + 1)
|
||||||
imu = np.random.randn(len(times), 1)
|
plt.scatter(t, omega_b[i], color=color, marker='.')
|
||||||
plt.plot(times, imu, color=color)
|
plt.xlabel(label)
|
||||||
# plt.axis([tmin, tmax, min,max])
|
|
||||||
|
# plot acceleration in nav
|
||||||
|
plt.figure(2)
|
||||||
|
for i, (label, color) in enumerate(zip(self.labels, self.colors)):
|
||||||
|
plt.subplot(3, 1, i + 1)
|
||||||
|
plt.scatter(t, acceleration_n[i], color=color, marker='.')
|
||||||
|
plt.xlabel(label)
|
||||||
|
|
||||||
|
# plot acceleration in body
|
||||||
|
plt.figure(3)
|
||||||
|
for i, (label, color) in enumerate(zip(self.labels, self.colors)):
|
||||||
|
plt.subplot(3, 1, i + 1)
|
||||||
|
plt.scatter(t, acceleration_b[i], color=color, marker='.')
|
||||||
plt.xlabel(label)
|
plt.xlabel(label)
|
||||||
|
|
||||||
# plot ground truth
|
# plot ground truth
|
||||||
fig = plt.figure(2)
|
plotPose3(4, pose, 1.0)
|
||||||
ax = fig.gca(projection='3d')
|
ax = plt.gca()
|
||||||
p = pose.translation()
|
ax.set_xlim3d(-self.radius, self.radius)
|
||||||
ax.scatter(p.x(), p.y(), p.z())
|
ax.set_ylim3d(-self.radius, self.radius)
|
||||||
|
ax.set_zlim3d(0, self.radius * 2)
|
||||||
|
|
||||||
plt.pause(0.1)
|
plt.pause(self.dt / self.realTimeFactor)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
for t in np.arange(0, self.T / 2, 1):
|
# simulate the loop up to the top
|
||||||
pose = self.scenario.pose(t)
|
for t in np.arange(0, self.timeForOneLoop, self.dt):
|
||||||
self.plot(t, pose)
|
self.plot(t,
|
||||||
|
self.scenario.pose(t),
|
||||||
|
self.scenario.omega_b(t),
|
||||||
|
self.scenario.acceleration_n(t),
|
||||||
|
self.scenario.acceleration_b(t))
|
||||||
|
|
||||||
plt.ioff()
|
plt.ioff()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
Loading…
Reference in New Issue