forked from Bharath2/Quadrotor-Simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runsim.py
58 lines (45 loc) · 1.44 KB
/
runsim.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 matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as Axes3D
from PathPlanning import RRTStar, Map
from TrajGen import trajGenerator, Helix_waypoints, Circle_waypoints
from Quadrotor import QuadSim
import controller
np.random.seed(8)
# 3D boxes lx, ly, lz, hx, hy, hz
obstacles = [[-5, 25, 0, 20, 35, 60],
[30, 25, 0, 55, 35, 100],
[45, 35, 0, 55, 60, 60],
[45, 75, 0, 55, 85, 100],
[-5, 65, 0, 30, 70, 100],
[70, 50, 0, 80, 80, 100]]
# limits on map dimensions
bounds = np.array([0,100])
# create map with obstacles
mapobs = Map(obstacles, bounds, dim = 3)
#plan a path from start to goal
start = np.array([80,20,10])
goal = np.array([30,80,80])
rrt = RRTStar(start = start, goal = goal,
Map = mapobs, max_iter = 500,
goal_sample_rate = 0.1)
waypoints, min_cost = rrt.plan()
#scale the waypoints to real dimensions
waypoints = 0.02*waypoints
#Generate trajectory through waypoints
traj = trajGenerator(waypoints, max_vel = 10, gamma = 1e6)
#initialise simulation with given controller and trajectory
Tmax = traj.TS[-1]
des_state = traj.get_des_state
sim = QuadSim(controller,des_state,Tmax)
#create a figure
fig = plt.figure()
ax = Axes3D.Axes3D(fig)
ax.set_xlim((0,2))
ax.set_ylim((0,2))
ax.set_zlim((0,2))
#plot the waypoints and obstacles
rrt.draw_path(ax, waypoints)
mapobs.plotobs(ax, scale = 0.02)
#run simulation
sim.run(ax)