Hallo,
Was vandaag bezig met een project op de FPGA (Altera De2-115). Hierop draait Nios II waarop RTOS draait.
Ik was bezig met een for loopje waarin we in 2 float arrays alle sin en cosinus waarden in opslaan voor de waarde 0 tm 360. Als we die dan vervolgens in een oneindige loop proberen uit te lezen gaat dat goed voor de index 1 tm 359, maar bij 0 en 360 lijkt het alsof de waarde hier niet in gezet is. We krijgen bijvoorbeeld voor de sin array met index 0 de waarde 0 (klopt) en voor de cosinus array krijgen we bij de index 0 de waarde -0, terwijl dat 1 hoort te zijn (duh). Dit is wat ik tot nu toe heb (gedeelte waarvan ik dacht dat het relevant is):
Ik ben nog beginnende met c/rtos, maar ik snap er geen hout van waarom hij juist alleen bij die twee index waarden complete onzin waardes uitleest. Op internet is hier helaas weinig over te vinden. Misschien maak ik ergens een domme fout waar ik overheen lees, bij voorbaat dank als u dit kunt aanwijzen(en misschien ook uitleggen
)!
Was vandaag bezig met een project op de FPGA (Altera De2-115). Hierop draait Nios II waarop RTOS draait.
Ik was bezig met een for loopje waarin we in 2 float arrays alle sin en cosinus waarden in opslaan voor de waarde 0 tm 360. Als we die dan vervolgens in een oneindige loop proberen uit te lezen gaat dat goed voor de index 1 tm 359, maar bij 0 en 360 lijkt het alsof de waarde hier niet in gezet is. We krijgen bijvoorbeeld voor de sin array met index 0 de waarde 0 (klopt) en voor de cosinus array krijgen we bij de index 0 de waarde -0, terwijl dat 1 hoort te zijn (duh). Dit is wat ik tot nu toe heb (gedeelte waarvan ik dacht dat het relevant is):
C:
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
| float sinArray[360]; float cosArray[360]; int i; for(i = 0; i <= 360; i++){ sinArray[i] = sin(i / (180 / M_PI)); cosArray[i] = cos(i / (180 / M_PI)); printf("\nROTATION: %d, SIN: %.2f, COS: %.2f \n", i, sinArray[i], cosArray[i]); } int test[VALUES] = {-48,0,-2,-48,39,-1,-48,39,-1,-30,0,-2,-30,0,-2,-32,39,-1,-20,39,0,-19,-1,1,-8,38,-1,-20,39,0,-8,18,0,-21,18,0,-8,-1,-1,-19,-1,1,6,37,-1,6,-1,-1,25,-2,-1,6,-1,-1,25,-2,-1,25,37,0,6,37,-1,25,37,0,39,-1,-2,38,37,-1,38,37,-1,56,-1,-1,56,-1,-1,56,37,-1,-1,-53,-4,-24,-53,-1,-1,-53,-4,-1,-37,0,-1,-37,0,-23,-33,1,-1,-13,-1,-23,-12,1,-1,-37,0,-1,-13,-1,5,-55,1,20,-56,0,7,-36,-1,22,-35,-4,5,-55,1,7,-36,-1,22,-35,-4,20,-56,0,22,-13,-1,22,-35}; startEndnodes = test; //local array to perform rotation and zoom calculations on int temporaryStartEndNodes[VALUES]; while(1){ //wait for other task to stop accessing global values such as rotation, zoom and startendnodes array ALT_SEM_PEND(sem_objectDrawn, 0); //local start and end node values float startx = 0; float starty = 0; float startz = 0; float endx = 0; float endy = 0; float endz = 0; //local rotation values int localRotationX = rotation[0]; int localRotationY = rotation[1]; int localRotationZ = rotation[2]; float zoomscreen = *zoomscreenpointer; //check if it should stop drawing/stop performing calculations on array (set in TaskSerialInput) if(!stopDrawing){ int linesDrawn; for (linesDrawn = 0; linesDrawn < VALUES/6; linesDrawn++) { //skips index every interation by 6 int indexOfArray = linesDrawn * 6; //read start node from global array float x1 = startx = (startEndnodes)[indexOfArray]; float y1 = starty = (startEndnodes)[indexOfArray + 1]; float z1 = startz = (startEndnodes)[indexOfArray + 2]; //read end node from global array float x2 = endx = (startEndnodes)[indexOfArray + 3]; float y2 = endy = (startEndnodes)[indexOfArray + 4]; float z2 = endz = (startEndnodes)[indexOfArray + 5]; //if start and end node are both zero (if array has less then 240 elements) stop the draw loop and do not perform calculations if(x1 == 0 && x2 == 0 && y1 == 0 && y2 == 0 && z1 == 0 && z2 == 0){ break; } //if a change happend in either the rotation or zoom, remove the previous known object calculated with the previous known zoom and rotation from screen if(previousXRotation != localRotationX || previousYRotation != localRotationY || previousZRotation != localRotationZ || zoomscreen != prevousZoomScreenBR) { //perform rotation calculations on the 3 dimensonal nodes and convert them to 2D nodes and then perform zoom calculation. x1 = (((startx * cosArray[previousXRotation] - (starty * cosArray[previousZRotation] - startz * sinArray[previousZRotation]) * sinArray[previousXRotation]) * (cosArray[previousYRotation])) + (starty * sinArray[previousZRotation] + startz * cosArray[previousZRotation]) * sinArray[previousYRotation]) * prevousZoomScreenBR; x2 = (((endx * cosArray[previousXRotation] - (endy * cosArray[previousZRotation] - endz * sinArray[previousZRotation]) * sinArray[previousXRotation]) * (cosArray[previousYRotation])) + (endy * sinArray[previousZRotation] + endz * cosArray[previousZRotation]) * sinArray[previousYRotation]) * prevousZoomScreenBR; y1 = (((-(startx * cosArray[previousXRotation] - (starty * cosArray[previousZRotation] - startz * sinArray[previousZRotation]) * sinArray[previousXRotation])) * (sinArray[previousYRotation]) + (starty * sinArray[previousZRotation] + startz * cosArray[previousZRotation]) * cosArray[previousYRotation])) * prevousZoomScreenBR; y2 = (((-(endx * cosArray[previousXRotation] - (endy * cosArray[previousZRotation] - endz * sinArray[previousZRotation]) * sinArray[previousXRotation])) * (sinArray[previousYRotation]) + (endy * sinArray[previousZRotation] + endz * cosArray[previousZRotation]) * cosArray[previousYRotation])) * prevousZoomScreenBR; //if offscreen benchmark mode is enabled, do not execute draw functions (which is the current bottleneck) if(!offscreen){ drawLine(x1,y1,x2,y2, midX, midY,1 , 1, color); } } //perform rotation calculations on the 3 dimensonal nodes and convert them to 2D nodes and then perform zoom calculation. x1 = (((startx * cosArray[localRotationX] - (starty * cosArray[localRotationZ] - startz * sinArray[localRotationZ]) * sinArray[localRotationX]) * (cosArray[localRotationY])) + (starty * sinArray[localRotationZ] + startz * cosArray[localRotationZ]) * sinArray[localRotationY]) * zoomscreen; x2 = (((endx * cosArray[localRotationX] - (endy * cosArray[localRotationZ] - endz * sinArray[localRotationZ]) * sinArray[localRotationX]) * (cosArray[localRotationY])) + (endy * sinArray[localRotationZ] + endz * cosArray[localRotationZ]) * sinArray[localRotationY]) * zoomscreen; y1 = (((-(startx * cosArray[localRotationX] - (starty * cosArray[localRotationZ] - startz * sinArray[localRotationZ]) * sinArray[localRotationX])) * (sinArray[localRotationY]) + (starty * sinArray[localRotationZ] + startz * cosArray[localRotationZ]) * cosArray[localRotationY]))* zoomscreen; y2 = (((-(endx * cosArray[localRotationX] - (endy * cosArray[localRotationZ] - endz * sinArray[localRotationZ]) * sinArray[localRotationX])) * (sinArray[localRotationY]) + (endy * sinArray[localRotationZ] + endz * cosArray[localRotationZ]) * cosArray[localRotationY]))* zoomscreen; //if offscreen benchmark mode is enabled, do not execute draw functions (which is the current bottleneck) if(localRotationX == 0 && localRotationY == 0 && localRotationZ == 0){ printf("\n ROTATION X,Y,Z:%d,%d,%d, is for x1,y1,x2,y2: %d, %d, %d, %d of which sin/cos = %f, %f \n", localRotationX, localRotationY, localRotationZ, x1, y1, x2, y2, sinArray[1], cosArray[1]); } if(!offscreen){ drawLine(x1,y1,x2,y2, midX, midY, 1 , 0, color); } } //save previous zoomscreen if its different then before if (zoomscreen != prevousZoomScreenBR) { prevousZoomScreenBR = zoomscreen; } //save previous rotation previousXRotation = localRotationX; previousYRotation = localRotationY; previousZRotation = localRotationZ; //update fps counter (after for loop is finished peforming calculation, a complete frame has been drawn) ALT_SEM_PEND(sem_updateFps, 0); fpsCounter++; ALT_SEM_POST(sem_updateFps); } |
Ik ben nog beginnende met c/rtos, maar ik snap er geen hout van waarom hij juist alleen bij die twee index waarden complete onzin waardes uitleest. Op internet is hier helaas weinig over te vinden. Misschien maak ik ergens een domme fout waar ik overheen lees, bij voorbaat dank als u dit kunt aanwijzen(en misschien ook uitleggen