|
1 | 1 | import matplotlib.pyplot as pl |
2 | 2 | import csv |
3 | 3 |
|
4 | | - |
5 | 4 | tauList = [] |
6 | 5 | tauDotList = [] |
7 | 6 | qList = [] |
|
19 | 18 | qListList = [] |
20 | 19 | qDotListList = [] |
21 | 20 | uListList = [] |
22 | | - |
23 | 21 | ''' position ''' |
24 | 22 | path = '../_build/cpp/resultsMPC.csv' |
25 | | -T=5; |
26 | | -N = 30; |
27 | | - |
28 | | - |
29 | | -with open(path,'r') as dataFile: |
| 23 | +T = 5 |
| 24 | +N = 30 |
| 25 | + |
| 26 | +with open(path, 'r') as dataFile: |
30 | 27 | reader = csv.reader(dataFile) |
31 | 28 | i = 0 |
32 | 29 | j = -1 |
33 | 30 | for row in reader: |
34 | | - if i ==2: |
35 | | - if(j<T): |
36 | | - tauList.append(float(row[0])) |
37 | | - tauDotList.append(float(row[1])) |
38 | | - qList.append(float(row[2])) |
39 | | - qDotList.append(float(row[3])) |
40 | | - uList.append((float(row[4]))) |
41 | | - j+=1 |
42 | | - else: |
43 | | - tauListList.append(tauList) |
44 | | - tauDotListList.append(tauDotList) |
45 | | - qListList.append(qList) |
46 | | - qDotListList.append(qDotList) |
47 | | - uListList.append(uList) |
48 | | - tauList = [float(row[0])] |
49 | | - tauDotList = [float(row[1])] |
50 | | - qList = [float(row[2])] |
51 | | - qDotList = [float(row[3])] |
52 | | - uList = [float(row[4])] |
53 | | - j = 0 |
54 | | - if i==1: |
55 | | - i = 2 |
56 | | - if i==0: |
57 | | - T = int(row[0]) |
58 | | - N = int(row[1]) - 1 |
59 | | - i = 1 |
60 | | - |
| 31 | + if i == 2: |
| 32 | + if (j < T): |
| 33 | + tauList.append(float(row[0])) |
| 34 | + tauDotList.append(float(row[1])) |
| 35 | + qList.append(float(row[2])) |
| 36 | + qDotList.append(float(row[3])) |
| 37 | + uList.append((float(row[4]))) |
| 38 | + j += 1 |
| 39 | + else: |
| 40 | + tauListList.append(tauList) |
| 41 | + tauDotListList.append(tauDotList) |
| 42 | + qListList.append(qList) |
| 43 | + qDotListList.append(qDotList) |
| 44 | + uListList.append(uList) |
| 45 | + tauList = [float(row[0])] |
| 46 | + tauDotList = [float(row[1])] |
| 47 | + qList = [float(row[2])] |
| 48 | + qDotList = [float(row[3])] |
| 49 | + uList = [float(row[4])] |
| 50 | + j = 0 |
| 51 | + if i == 1: |
| 52 | + i = 2 |
| 53 | + if i == 0: |
| 54 | + T = int(row[0]) |
| 55 | + N = int(row[1]) - 1 |
| 56 | + i = 1 |
| 57 | + |
61 | 58 | for i in range(N): |
62 | | - finaltauList.append(tauListList[i][0]) |
63 | | - finaltauDotList.append(tauDotListList[i][0]) |
64 | | - finalqList.append(qListList[i][0]) |
65 | | - finalqDotList.append(qDotListList[i][0]) |
66 | | - finaluList.append(uListList[i][0]) |
| 59 | + finaltauList.append(tauListList[i][0]) |
| 60 | + finaltauDotList.append(tauDotListList[i][0]) |
| 61 | + finalqList.append(qListList[i][0]) |
| 62 | + finalqDotList.append(qDotListList[i][0]) |
| 63 | + finaluList.append(uListList[i][0]) |
67 | 64 |
|
68 | | -#~ print len(tauListList[0]) |
69 | | -#~ print len(tauListList[1]) |
70 | | -#~ print len(tauListList[2]) |
71 | | -#~ print len(tauListList[3]) |
72 | | -#~ print tauListList[0] |
73 | | -#~ print tauListList[1] |
74 | | -#~ print tauListList[2] |
75 | | -#~ print tauListList[3] |
| 65 | +# print len(tauListList[0]) |
| 66 | +# print len(tauListList[1]) |
| 67 | +# print len(tauListList[2]) |
| 68 | +# print len(tauListList[3]) |
| 69 | +# print tauListList[0] |
| 70 | +# print tauListList[1] |
| 71 | +# print tauListList[2] |
| 72 | +# print tauListList[3] |
76 | 73 |
|
77 | 74 | fig1 = pl.figure() |
78 | 75 | fig2 = pl.figure() |
|
83 | 80 | dx1 = fig1.add_subplot(224) |
84 | 81 | ax2 = fig2.add_subplot(111) |
85 | 82 |
|
86 | | -for i in range(0,N,20): |
87 | | - ax1.plot(range(i,i+T+1,1),tauListList[i]) |
88 | | - bx1.plot(range(i,i+T+1,1),tauDotListList[i]) |
89 | | - cx1.plot(range(i,i+T+1,1),qListList[i]) |
90 | | - dx1.plot(range(i,i+T+1,1),qDotListList[i]) |
91 | | - ax2.plot(range(i,i+T+1,1),uListList[i]) |
92 | | - |
93 | | -ax1.plot(finaltauList,'g+') |
94 | | -bx1.plot(finaltauDotList,'g+') |
95 | | -cx1.plot(finalqList,'g+') |
96 | | -dx1.plot(finalqDotList,'g+') |
97 | | -ax2.plot(finaluList,'g+') |
| 83 | +for i in range(0, N, 20): |
| 84 | + ax1.plot(range(i, i + T + 1, 1), tauListList[i]) |
| 85 | + bx1.plot(range(i, i + T + 1, 1), tauDotListList[i]) |
| 86 | + cx1.plot(range(i, i + T + 1, 1), qListList[i]) |
| 87 | + dx1.plot(range(i, i + T + 1, 1), qDotListList[i]) |
| 88 | + ax2.plot(range(i, i + T + 1, 1), uListList[i]) |
| 89 | + |
| 90 | +ax1.plot(finaltauList, 'g+') |
| 91 | +bx1.plot(finaltauDotList, 'g+') |
| 92 | +cx1.plot(finalqList, 'g+') |
| 93 | +dx1.plot(finalqDotList, 'g+') |
| 94 | +ax2.plot(finaluList, 'g+') |
98 | 95 |
|
99 | 96 | ax1.grid() |
100 | 97 | bx1.grid() |
101 | 98 | cx1.grid() |
102 | 99 | dx1.grid() |
103 | 100 | ax2.grid() |
104 | 101 | pl.show() |
105 | | - |
0 commit comments