-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstates.py
85 lines (69 loc) · 3.04 KB
/
states.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import numpy as np
from utils import *
class IMUState(object):
# id for next IMU state
next_id = 0
# Gravity vector in the world frame
gravity = np.array([0., 0., -9.81])
# Transformation offset from the IMU frame to the body frame.
# The transformation takes a vector from the IMU frame to the
# body frame. The z axis of the body frame should point upwards.
# Normally, this transform should be identity.
T_imu_body = Isometry3d(np.identity(3), np.zeros(3))
def __init__(self, new_id=None):
# An unique identifier for the IMU state.
self.id = new_id
# Time when the state is recorded
self.timestamp = None
# Orientation
# Take a vector from the world frame to the IMU (body) frame.
self.orientation = np.array([0., 0., 0., 1.])
# Position of the IMU (body) frame in the world frame.
self.position = np.zeros(3)
# Velocity of the IMU (body) frame in the world frame.
self.velocity = np.zeros(3)
# Bias for measured angular velocity and acceleration.
self.gyro_bias = np.zeros(3)
self.acc_bias = np.zeros(3)
# These three variables should have the same physical
# interpretation with `orientation`, `position`, and
# `velocity`. There three variables are used to modify
# the transition matrices to make the observability matrix
# have proper null space.
self.orientation_null = np.array([0., 0., 0., 1.])
self.position_null = np.zeros(3)
self.velocity_null = np.zeros(3)
# Transformation between the IMU and the left camera (cam0)
self.R_imu_cam0 = np.identity(3)
self.t_cam0_imu = np.zeros(3)
class CAMState(object):
# id for next CAM state
next_id = 0
def __init__(self, new_id=None):
# An unique identifier for the CAM state.
self.id = new_id
# Time when the state is recorded
self.timestamp = None
# Orientation
# Take a vector from the world frame to the camera frame.
self.orientation = np.array([0., 0., 0., 1.])
# Position of the camera frame in the world frame.
self.position = np.zeros(3)
# These two variables should have the same physical
# interpretation with `orientation` and `position`.
# There two variables are used to modify the measurement
# Jacobian matrices to make the observability matrix
# have proper null space.
self.orientation_null = np.array([0., 0., 0., 1.])
self.position_null = np.zeros(3)
class StateServer(object):
"""
Store one IMU states and several camera states for constructing
measurement model.
"""
def __init__(self):
self.imu_state = IMUState()
self.cam_states = dict() # <CAMStateID, CAMState>, ordered dict
# State covariance matrix
self.state_cov = np.zeros((21, 21))
self.continuous_noise_cov = np.zeros((12, 12))