-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_quad_game.py
46 lines (38 loc) · 1.54 KB
/
run_quad_game.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
#!/usr/bin/env python3
import os
import sys
sys.path.append(os.getcwd()+'/LFC')
sys.path.append(os.getcwd()+'/JinEnv')
sys.path.append(os.getcwd()+'/lib')
import numpy as np
from casadi import *
import scipy.io as sio
import matplotlib.pyplot as pltdad
import time
import transforms3d
from dataclasses import dataclass, field
from QuadAlgorithm import QuadAlgorithm
from QuadStates import QuadStates
from QuadPara import QuadPara
if __name__ == '__main__':
# define the quadrotor dynamics parameters
QuadParaInput = QuadPara(inertial_list=[1.0, 1.0, 1.0], mass=1.0, l=1.0, c=0.02)
# define the initial condition
R = np.array([[1,0,0],[0,1,0],[0,0,1]]) # rotation matrix in numpy 2D array
QuadInitialCondition = QuadStates()
QuadInitialCondition.position = [-8, -8, 2]
QuadInitialCondition.velocity = [0, 0, 0]
QuadInitialCondition.attitude_quaternion = transforms3d.quaternions.mat2quat(R).tolist()
QuadInitialCondition.angular_velocity = [0, 0, 0]
# define the desired goal
R = np.array([[1,0,0],[0,1,0],[0,0,1]]) # rotation matrix in numpy 2D array
QuadDesiredStates = QuadStates()
QuadDesiredStates.position = [8, 2, 4]
QuadDesiredStates.velocity = [0, 0, 0]
QuadDesiredStates.attitude_quaternion = transforms3d.quaternions.mat2quat(R).tolist()
QuadDesiredStates.angular_velocity = [0, 0, 0]
# create the quadrotor algorithm solver
Solver = QuadAlgorithm(QuadParaInput)
# solve
Solver.run(QuadInitialCondition, QuadDesiredStates, \
iter_num=50, horizon=40, save_flag=False)