Roulis v4
This commit is contained in:
parent
192147aa9e
commit
9e198138da
1 changed files with 9 additions and 8 deletions
|
|
@ -4,7 +4,8 @@
|
|||
#include <MySPI.h>
|
||||
#include <MyTimer.h>
|
||||
|
||||
char x1,x2,y1,y2,z1,z2;
|
||||
//char x1,x2
|
||||
char y1,y2,z1,z2;
|
||||
|
||||
void MyRoulis_Init(void){
|
||||
MySPI_Init(SPI1);
|
||||
|
|
@ -33,11 +34,11 @@ void MyRoulis_Init(void){
|
|||
void MyRoulis_Data(void){
|
||||
|
||||
// Récupération des registred DATAX0..DATAZ1 (6 registres)
|
||||
MySPI_Clear_NSS(); // Début transmission X
|
||||
MySPI_Send((0x32)|(0<<7)|(1<<6)); // On veut lire les 2 bytes DATAX
|
||||
x1 = MySPI_Read(); // premier byte
|
||||
x2 = MySPI_Read(); // deuxième byte
|
||||
MySPI_Set_NSS(); // Fin transmission X
|
||||
// MySPI_Clear_NSS(); // Début transmission X
|
||||
// MySPI_Send((0x32)|(0<<7)|(1<<6)); // On veut lire les 2 bytes DATAX
|
||||
// x1 = MySPI_Read(); // premier byte
|
||||
// x2 = MySPI_Read(); // deuxième byte
|
||||
// MySPI_Set_NSS(); // Fin transmission X
|
||||
|
||||
MySPI_Clear_NSS(); // Début transmission Y
|
||||
MySPI_Send((0x34)|(0<<7)|(1<<6)); // On veut lire les 2 bytes DATAY
|
||||
|
|
@ -54,9 +55,9 @@ void MyRoulis_Data(void){
|
|||
|
||||
float MyRoulis_Angle(){
|
||||
//Calcul de l'angle alpha
|
||||
int x = x1 + (x2 << 8);
|
||||
//int x = x1 + (x2 << 8);
|
||||
int y = y1 + (y2 << 8);
|
||||
int z = z1 + (z2 << 8);
|
||||
float alpha = atan( sqrtf(x*x + y*y) / z );
|
||||
float alpha = atan(y / z); //sqrtf(x*x + y*y)
|
||||
return alpha;
|
||||
}
|
||||
Loading…
Reference in a new issue