roulis v3
This commit is contained in:
parent
13e7f95ce0
commit
192147aa9e
3 changed files with 25 additions and 14 deletions
|
|
@ -1,8 +1,11 @@
|
|||
#include <stm32f10x.h>
|
||||
#include <math.h>
|
||||
#include <roulis.h>
|
||||
#include <MySPI.h>
|
||||
#include <MyTimer.h>
|
||||
|
||||
char x1,x2,y1,y2,z1,z2;
|
||||
|
||||
void MyRoulis_Init(void){
|
||||
MySPI_Init(SPI1);
|
||||
|
||||
|
|
@ -23,30 +26,37 @@ void MyRoulis_Init(void){
|
|||
MySPI_Set_NSS();
|
||||
|
||||
MyTimer_Init(TIM2,3600,200); // Configurer le timer2 a 100Hz
|
||||
MyTimer_ActiveIT(TIM2,0,&MyRoulis_angle);// Configurer interruption sur timer2
|
||||
MyTimer_ActiveIT(TIM2,0,&MyRoulis_Data);// Configurer interruption sur timer2
|
||||
MyTimer_Base_Start(TIM2);
|
||||
}
|
||||
|
||||
void MyRoulis_angle(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
|
||||
char x1 = MySPI_Read(); // premier byte
|
||||
char x2 = MySPI_Read(); // deuxième byte
|
||||
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
|
||||
char y1 = MySPI_Read(); // premier byte
|
||||
char y2 = MySPI_Read(); // deuxième byte
|
||||
MySPI_Set_NSS(); // Fin transmission X
|
||||
y1 = MySPI_Read(); // premier byte
|
||||
y2 = MySPI_Read(); // deuxième byte
|
||||
MySPI_Set_NSS(); // Fin transmission Y
|
||||
|
||||
MySPI_Clear_NSS(); // Début transmission Z
|
||||
MySPI_Send((0x36)|(0<<7)|(1<<6)); // On veut lire les 2 bytes DATAZ
|
||||
char z1 = MySPI_Read(); // premier byte
|
||||
char z2 = MySPI_Read(); // deuxième byte
|
||||
z1 = MySPI_Read(); // premier byte
|
||||
z2 = MySPI_Read(); // deuxième byte
|
||||
MySPI_Set_NSS(); // Fin transmission Z
|
||||
|
||||
// Calcul de l'angle alpha
|
||||
}
|
||||
|
||||
float MyRoulis_Angle(){
|
||||
//Calcul de l'angle alpha
|
||||
int x = x1 + (x2 << 8);
|
||||
int y = y1 + (y2 << 8);
|
||||
int z = z1 + (z2 << 8);
|
||||
float alpha = atan( sqrtf(x*x + y*y) / z );
|
||||
return alpha;
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ Ou sinon sur interruption d'un timer a 100HZ
|
|||
*/
|
||||
|
||||
void MyRoulis_Init(void);
|
||||
void MyRoulis_angle(void);
|
||||
void MyRoulis_Data(void);
|
||||
float MyRoulis_Angle();
|
||||
|
||||
#endif
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
Fin du drivers SPI, il faudrait maintenant vérifier son fonctionnement et faire le roulis.
|
||||
Il faut vérifier le driver SPI sur carte et finir roulis
|
||||
|
||||
Port map carte nucléo :
|
||||
|
||||
|
|
@ -20,4 +20,4 @@ SPI / roulis :
|
|||
! PA7 : Alternate output push pull (SPI1 MOSI)
|
||||
prio interruption timer2 : 0
|
||||
|
||||
Pour le roulis, je ne suis pas sur de comment retourner l'angle (par interruption d'un timer?? si oui comment le retourner??), il faut voir comment le calculer aussi
|
||||
Pour le roulis, je ne suis pas sur de comment retourner l'angle , il faut vérifier que le calcul soit bon aussi
|
||||
Loading…
Reference in a new issue