20 import matplotlib.pyplot
as plt
22 CSV_HEADER =
"x,y,theta,kappa,d".split(
",")
25 with open(filename,
'r')
as f:
27 lines = [line.strip().split(
",")
for line
in f.readlines()]
33 return np.sqrt((x2 - x1)**2 + (y2 - y1)**2)
55 def load(self, fpath, fname):
56 if not os.path.exists(fpath + fname):
61 x = np.float(line[CSV_HEADER.index(
"x")])
62 y = np.float(line[CSV_HEADER.index(
"y")])
63 theta = np.float(line[CSV_HEADER.index(
"theta")])
64 kappa = np.float(line[CSV_HEADER.index(
"kappa")])
65 d = np.float(line[CSV_HEADER.index(
"d")])
70 self.
x = [state.x
for state
in self.
states]
71 self.
y = [state.y
for state
in self.
states]
74 self.
d = [state.d
for state
in self.
states]
79 s +=
distance(state1.x, state1.y, state2.x, state2.y)
84 if __name__ ==
"__main__":
89 path.load(filepath,
"path.csv")
93 f, axarr = plt.subplots(2, 2, figsize=(16, 8))
95 axarr[0, 0].plot(path.x, path.y)
96 axarr[0, 0].set_xlabel(
'$x$ [m]')
97 axarr[0, 0].set_ylabel(
'$y$ [m]')
98 axarr[0, 0].set_aspect(
'equal')
100 axarr[0, 1].plot(path.s, path.theta)
101 axarr[0, 1].set_xlabel(
'$s$ [m]')
102 axarr[0, 1].set_ylabel(
'$theta$ [rad]')
105 ax2 = axarr[1, 0].twinx()
106 handle1, = ax1.plot(path.s, path.kappa, label=
'$kappa$')
107 handle2, = ax2.plot(path.s, path.d, label=
'$d$', color=
'red', alpha=0.4)
108 axarr[1, 0].set_xlabel(
'$s$ [m]')
109 ax1.set_ylabel(
'$kappa$ [1/m]')
110 ax2.set_ylabel(
'$d$ [-]')
111 axarr[1, 0].legend(handles=[handle1, handle2])