-
Notifications
You must be signed in to change notification settings - Fork 12
/
example.py
56 lines (40 loc) · 1.62 KB
/
example.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
"""A very simple example using the provided templates"""
import numpy as np
import matplotlib.pyplot as plt
from quadrotor.dynamics import QuadrotorDynamicsBase, QuadrotorState
from quadrotor.controller import ControllerBase, QuadrotorCommands
from quadrotor.trajectory import TrajectoryBase, TrajectoryState
from quadrotor.simulator import SimulatorBase
from quadrotor.renderer import animate
# Spoofed dynamics
class SpoofedQuadrotorDynamics(QuadrotorDynamicsBase):
def __init__(self, spoofed_position: np.ndarray = np.zeros(3)) -> None:
super().__init__()
self.spoofed_position = spoofed_position
def step(self, t: float, input: QuadrotorCommands) -> QuadrotorState:
return QuadrotorState(position=self.spoofed_position)
# Trajectory that just outputs zeros all the time
class UselessTrajectory(TrajectoryBase):
def eval(self, t: float) -> TrajectoryState:
return TrajectoryState(t, position=np.zeros(3))
# Controller that does nothing
class UselessController(ControllerBase):
def __init__(self, rotor_rate: float = 500.0) -> None:
self.rotor_rates = np.ones(4) * rotor_rate
def step(self, *args) -> QuadrotorCommands:
return QuadrotorCommands(np.zeros(4))
if __name__ == "__main__":
dt = 0.01
# 1 meter above the ground
position = np.array([0.0, 0.0, 1.0])
sim = SimulatorBase(
dt=0.01,
dynamics=SpoofedQuadrotorDynamics(position),
controller=UselessController(),
trajectory=UselessTrajectory(),
)
# Run the simulator
output = sim.simulate()
# Render the output
ani = animate(output)
plt.show()