Rohan-Code to measure the tilt of the ADXL355 using COG-AD4050.
Dependencies: include ADXL355 ttmath
Fork of COG4050_adxl355_tilt by
Revision 2:13377441fbd8, committed 2019-06-14
- Comitter:
- RGurav
- Date:
- Fri Jun 14 10:56:53 2019 +0000
- Parent:
- 1:ba6c18cce219
- Commit message:
- Cog4050 + ADXL355
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ba6c18cce219 -r 13377441fbd8 main.cpp --- a/main.cpp Tue Sep 04 11:53:19 2018 +0000 +++ b/main.cpp Fri Jun 14 10:56:53 2019 +0000 @@ -16,6 +16,7 @@ ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port float single_axis(float a); +float single_axisz(float a); float dual_axis(float a, float b); float tri_axis(float a, float b, float c); @@ -50,7 +51,7 @@ //pc.printf("Enter no of axis for angle calculation (1/2/3):\r\n"); //pc.scanf("%d",&axis); - axis = 4; + axis = 2; pc.printf("||x_accl||y_accl||z_accl||x_tilt||y_tilt||z_tilt||\r\n"); wait(1); @@ -68,33 +69,28 @@ z = (accl.convert(accl.scanz())); t = 25+float(accl.scant()-1852)/(-9.05); - //pc.printf("%d \t %d \t %d \r\n", accl.scanx(), accl.scany(), accl.scanz()); - //pc.printf("%f \t %f \t %f \r\n", x, y, z); - //pc.printf("%f\r\n", asin(0.2)*57.2957); - - tilt_x = single_axis(x); - tilt_y = single_axis(y); - tilt_z = single_axis(z); - - tilt_2x = dual_axis(x,z); - tilt_2y = dual_axis(y,x); - tilt_2y = tilt_2y * (-1); - tilt_3x = tri_axis(x,y,z); - tilt_3y = tri_axis(y,x,z); - tilt_3z = sqrt((x*x)+(y*y)); - tilt_3z = atan(tilt_3z/z); - tilt_3z = floor(tilt_3z*100)/100; if (axis==1) { - pc.printf("||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f|| \r\n" , x, y, z, tilt_x, tilt_y, tilt_z); - //pc.printf("%f", accl.axis355_sens); - wait(1.0); } + char in = pc.getc(); + if(in == 'x') + {pc.printf("%0.2f" ,x); + } + + else if(in == 'y') + {pc.printf("%0.2f" ,y); + } + + else if(in == 'z') + {pc.printf("%0.2f" ,z); + } + + } if (axis==2) { - pc.printf("||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f|| \r\n" , x*accl.axis355_sens, y*accl.axis355_sens, z*accl.axis355_sens, tilt_x, tilt_y); + pc.printf("||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f||%0.2f|| \r\n" , x*accl.axis355_sens, y*accl.axis355_sens, z*accl.axis355_sens, tilt_x, tilt_y, tilt_z); wait(0.5); } @@ -137,6 +133,28 @@ return Y; } + //particullary for z axis single + float single_axisz(float a) + { + a = a*accl.axis355_sens; + + if (a>1.0f) + { a = 1; + } + else if (a<-1) + { a = -1; + } + else + { a = a; + } + + double Y; + + Y = acos(a); + Y = floor((57.2957f*Y)*100)/100; + return Y; + + } //Dual Axis float dual_axis(float a, float b)