-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstate.py
More file actions
55 lines (43 loc) · 1.81 KB
/
state.py
File metadata and controls
55 lines (43 loc) · 1.81 KB
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
import numpy as np
from scipy.spatial.transform import Rotation
from inekf import SE3
class State:
"""A uniform representation of our state from various sources.
Can come from a dictionary (HoloOcean), SE[2,6] object (InEKF library), or from a simple
numpy array.
State saved consists of position, velocity, rotation, angular velocity, and IMU bias.
"""
def __init__(self, state, last_meas_omega=None):
self.vec = np.zeros(12)
self.mat = np.eye(5)
self.bias = np.zeros(6)
# True State
if isinstance(state, dict):
self.vec[0:3] = state["PoseSensor"][:3,3]
self.vec[3:6] = state["VelocitySensor"]
self.vec[6:9] = rot_to_rpy(state["PoseSensor"][:3,:3])
self.vec[9:12] = state["IMUSensorClean"][1]
self.bias[0:3] = state["IMUSensor"][3]
self.bias[3:6] = state["IMUSensor"][2]
self.mat[:3,:3] = state["PoseSensor"][:3,:3]
self.mat[:3,3] = state["VelocitySensor"]
self.mat[:3,4] = state["PoseSensor"][:3,3]
# Estimated State
if isinstance(state, SE3[2,6]):
self.vec[0:3] = state[1]
self.vec[3:6] = state[0]
self.vec[6:9] = rot_to_rpy(state.mat[:3,:3].copy())
if last_meas_omega is None:
raise ValueError("Need a measurement for angular velocity")
self.vec[9:12] = last_meas_omega - state.aug[:3]
self.bias = state.aug
self.mat = state.mat
# Commanded State
if isinstance(state, np.ndarray):
self.vec = state
# TODO Matrix representation here too?
@property
def data_plot(self):
return np.append(self.vec[:9], self.bias)
def rot_to_rpy(mat):
return Rotation.from_matrix(mat).as_euler("xyz")*180/np.pi