-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_defined_controller.py
59 lines (42 loc) · 1.64 KB
/
user_defined_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
55
56
57
58
import numpy as np
# import multiprocessing as mp
from pylot.controllers import BaseController
from HorizonAircraft import generateControlFunctions
import controlMapping as cm
class UserDefinedController(BaseController):
"""
Controller based on time only
Parameters
----------
control_dict : dict
A dictionary of control names and specifications.
"""
def __init__(self, control_dict, quit_flag, view_flag, pause_flag, data_flag, enable_interface, control_output):
super().__init__(control_dict, quit_flag, view_flag, pause_flag, data_flag, enable_interface, control_output)
def get_control(self, t, state_vec, prev_controls):
"""Returns the controls based on the inputted state and keyboard/joystick inputs.
Parameters
----------
t : float
simulation time
state_vec : list
State vector of the entity being controlled.
prev_controls : dict
Previous control values.
Returns
-------
controls : dict
Dictionary of controls.
"""
thr, dL, dl, dm = cm.mode2Trim()
if thr > 1.: thr = 1.
if thr < 0.: thr = 0.
if dm > 1.: dm = 1.
if dm < -1.: dm = -1.
if dl > 1.: dl = 1.
if dl < -1.: dl = -1.
if dL < 0.: dL = 0.
if dL > 1.: dL = 1.
symDefl, asymDefl = cm.mode2(dL, dl, dm)
Sym, Asym = generateControlFunctions(symDefl, asymDefl)
return {'sym' : Sym, 'asym' : Asym, 'throttle' : thr}