-
Notifications
You must be signed in to change notification settings - Fork 10
/
plotter.py
151 lines (121 loc) · 4.11 KB
/
plotter.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import numpy as np
import pylab as py
from collections import deque
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
def create_circle(x,y,r):
ang = np.linspace(0., 2*np.pi, 1000)
xp = r*np.cos(ang)
yp = r*np.sin(ang)
x_tot = x + xp
y_tot = y + yp
return x_tot, y_tot
class plotter(object):
def __init__(self):
self.actions = deque()
self.velocity = deque()
self.position = deque()
self.accelerations = deque()
self.i = []
self.set_point = []
self.done = deque()
self.wp = deque()
def update(self,velocities,action,accelerations,position):
self.actions.append(action)
self.velocity.append(velocities)
self.accelerations.append(accelerations)
self.position.append(position)
def update_goal(self,done,wp):
self.done.append(done)
self.wp.append(wp)
def plot(self, i):
py.plot(self.position)
py.xlabel('Time (time steps)')
py.ylabel('Position')
py.title('DDPG for AUV Control')
py.legend(('x','y','z','roll', 'pitch', 'yaw' ))
#py.axis([0, simulation_lenght, -0.5, 0.5])
py.savefig('Positions' + str(i) + '.png')
py.show()
py.plot(self.velocity)
py.xlabel('Time (time steps)')
py.ylabel('Velocities')
py.title('DDPG for AUV Control')
py.legend(('1', '2','3', '4' ,'5','6' ))
#py.axis([0, simulation_lenght, -1., 1.])
py.savefig('velocities' + str(i) + '.png')
py.show()
py.plot(self.actions)
py.xlabel('Time (time steps)')
py.ylabel('u')
py.title('DDPG for AUV Control')
py.legend(('1', '2','3', '4' ,'5','6' ))
#py.axis([0, simulation_lenght, -1., 1.])
py.savefig('U' + str(i) + '.png')
py.show()
x0 = np.array([_[0] for _ in self.position])
y0 = np.array([_[1] for _ in self.position])
z0 = np.array([_[2] for _ in self.position])
py.plot(x0,y0)
py.xlabel('x')
py.ylabel('y')
py.title('DDPG for AUV Control')
#py.legend(('x','y','z' ))
#py.axis([0, simulation_lenght, -0.5, 0.5])
py.savefig('pose' + str(i) + '.png')
py.show()
py.plot(x0,y0, 'b')
py.hold() # toggle hold
py.hold(True)
# plot origin
py.plot(0.0,0.0, 'ob')
#plot goal
scale = 0.
xsp = self.set_point[0] - scale
ysp = self.set_point[1] - scale
py.plot(xsp, ysp, 'or')
# create and plot circle
xc, yc = create_circle(xsp,ysp,1.)
py.plot(xc, yc, 'r')
py.xlabel('X [m]')
py.ylabel('Y [m]')
#py.title('Position Control Using Deep RL')
#py.legend(('x','y','z' ))
py.axis([-10., 10., -10., 10.])
py.savefig('pose_for_abstract.png')
py.show()
self.save()
def plot_map(self):
for _ in range(len(self.done)):
if self.done[_]:
py.plot(self.wp[_][0],self.wp[_][1],'ob')
else:
py.plot(self.wp[_][0],self.wp[_][1],'xr')
py.axis([-10., 10., -10., 10.])
py.savefig('sparse_map.png')
def reset(self, set_point):
self.actions = deque()
self.velocity = deque()
self.position = deque()
self.accelerations = deque()
self.set_point = set_point
def save(self):
np.save('actions', self.actions)
np.save('velocity', self.velocity)
np.save('position', self.position)
np.save('accelerations', self.accelerations)
np.save('i', self.i)
np.save('set_point', self.set_point)
def load(self):
self.actions = np.load('actions.npy')
self.velocity = np.load('velocity.npy')
self.position = np.load('position.npy')
self.accelerations = np.load('accelerations.npy')
self.i = np.load('i.npy')
self.set_point = np.load('set_point.npy')
return self.i
if __name__ == '__main__':
plot = plotter()
i = plot.load()
plot.plot(i)