-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
54 lines (43 loc) · 1.61 KB
/
controller.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
import de2bot
import numpy as np
from localization import Localizer
class Controller:
def __init__(self, start_pose: np.matrix, sensor_angles, config: de2bot.DE2Config, beacons):
state = de2bot.State(start_pose)
self.angles = sensor_angles
self.prev_controls = np.asmatrix([0, 0.]).T
self.next_sense = 0
self.last_sense = None
self.localization = Localizer(state, config, sensor_angles, beacons)
def estimated_position(self):
return self.localization.robot.state.pose
def update(self, encoders: np.matrix, meas_dist: float, can_sense: bool, delta_time: float):
"""
Update logic for the controller. Called at 100Hz.
Parameters:
encoders: wheel velocities
meas_dist: previous sonar measurement distance, or None
can_sense: are we able to sense from sonar
delta_time: time since last update
Return:
(controls, sensor number)
"""
controls = np.asmatrix([
[0.2],
[0.3],
])
# Kalman Filter predict step
self.localization.predict(encoders, delta_time)
# R = np.asmatrix([[1, 0],[0, 1]])
R = None
if meas_dist is not None:
# Update EKF
# pass
R = self.localization.update_beacon(meas_dist, self.last_sense)
self.prev_controls = controls
sensor = None
if can_sense:
sensor = self.next_sense
self.last_sense = sensor
self.next_sense = (self.next_sense + 1) % len(self.angles)
return controls, sensor, R