2023-03-15 15:38:14 -04:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
class HoverTraj(object):
|
|
|
|
|
"""
|
|
|
|
|
This trajectory simply has the quadrotor hover at the origin indefinitely.
|
|
|
|
|
By modifying the initial condition, you can create step response
|
|
|
|
|
experiments.
|
|
|
|
|
"""
|
2024-11-26 13:44:28 -05:00
|
|
|
def __init__(self, x0=np.array([0, 0, 0])):
|
2023-03-15 15:38:14 -04:00
|
|
|
"""
|
|
|
|
|
This is the constructor for the Trajectory object. A fresh trajectory
|
|
|
|
|
object will be constructed before each mission.
|
|
|
|
|
"""
|
|
|
|
|
|
2024-11-26 13:44:28 -05:00
|
|
|
self.x0 = x0
|
|
|
|
|
|
2023-03-15 15:38:14 -04:00
|
|
|
def update(self, t):
|
|
|
|
|
"""
|
|
|
|
|
Given the present time, return the desired flat output and derivatives.
|
|
|
|
|
|
|
|
|
|
Inputs
|
|
|
|
|
t, time, s
|
|
|
|
|
Outputs
|
|
|
|
|
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
|
|
|
|
|
"""
|
2024-11-26 13:44:28 -05:00
|
|
|
x = self.x0
|
2023-03-15 15:38:14 -04:00
|
|
|
x_dot = np.zeros((3,))
|
|
|
|
|
x_ddot = np.zeros((3,))
|
|
|
|
|
x_dddot = np.zeros((3,))
|
|
|
|
|
x_ddddot = np.zeros((3,))
|
|
|
|
|
yaw = 0
|
|
|
|
|
yaw_dot = 0
|
2023-07-13 17:16:09 -04:00
|
|
|
yaw_ddot = 0
|
2023-03-15 15:38:14 -04:00
|
|
|
|
|
|
|
|
flat_output = { 'x':x, 'x_dot':x_dot, 'x_ddot':x_ddot, 'x_dddot':x_dddot, 'x_ddddot':x_ddddot,
|
2023-07-13 17:16:09 -04:00
|
|
|
'yaw':yaw, 'yaw_dot':yaw_dot, 'yaw_ddot':yaw_ddot}
|
2023-03-15 15:38:14 -04:00
|
|
|
return flat_output
|