Init
This commit is contained in:
61
rotorpy/controllers/controller_template.py
Normal file
61
rotorpy/controllers/controller_template.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""
|
||||
Imports
|
||||
"""
|
||||
import numpy as np
|
||||
from scipy.spatial.transform import Rotation # This is a useful library for working with attitude.
|
||||
|
||||
class ControlTemplate(object):
|
||||
"""
|
||||
The controller is implemented as a class with two required methods: __init__() and update().
|
||||
The __init__() is used to instantiate the controller, and this is where any model parameters or
|
||||
controller gains should be set.
|
||||
In update(), the current time, state, and desired flat outputs are passed into the controller at
|
||||
each simulation step. The output of the controller should be the commanded motor speeds,
|
||||
commanded thrust, commanded moment, and commanded attitude (in quaternion [x,y,z,w] format).
|
||||
"""
|
||||
def __init__(self, vehicle_params):
|
||||
"""
|
||||
|
||||
Parameters:
|
||||
vehicle_params, dict with keys specified in a python file under /rotorpy/vehicles/
|
||||
|
||||
"""
|
||||
|
||||
def update(self, t, state, flat_output):
|
||||
"""
|
||||
This function receives the current time, true state, and desired flat
|
||||
outputs. It returns the command inputs.
|
||||
|
||||
Inputs:
|
||||
t, present time in seconds
|
||||
state, a dict describing the present state with keys
|
||||
x, position, m
|
||||
v, linear velocity, m/s
|
||||
q, quaternion [i,j,k,w]
|
||||
w, angular velocity, rad/s
|
||||
flat_output, a dict describing the present desired flat outputs with keys
|
||||
x, position, m
|
||||
x_dot, velocity, m/s
|
||||
x_ddot, acceleration, m/s**2
|
||||
x_dddot, jerk, m/s**3
|
||||
x_ddddot, snap, m/s**4
|
||||
yaw, yaw angle, rad
|
||||
yaw_dot, yaw rate, rad/s
|
||||
|
||||
Outputs:
|
||||
control_input, a dict describing the present computed control inputs with keys
|
||||
cmd_motor_speeds, rad/s
|
||||
cmd_thrust, N (for debugging and laboratory; not used by simulator)
|
||||
cmd_moment, N*m (for debugging; not used by simulator)
|
||||
cmd_q, quaternion [i,j,k,w] (for laboratory; not used by simulator)
|
||||
"""
|
||||
cmd_motor_speeds = np.zeros((4,))
|
||||
cmd_thrust = 0
|
||||
cmd_moment = np.zeros((3,))
|
||||
cmd_q = np.array([0,0,0,1])
|
||||
|
||||
control_input = {'cmd_motor_speeds':cmd_motor_speeds,
|
||||
'cmd_thrust':cmd_thrust,
|
||||
'cmd_moment':cmd_moment,
|
||||
'cmd_q':cmd_q}
|
||||
return control_input
|
||||
Reference in New Issue
Block a user