Skip to content

Commit b03c1fb

Browse files
committed
Functions for getting accel angles, send them over mavlink
1 parent 28a7965 commit b03c1fb

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Accel.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Read accelerometer data over SPI: the LIS302DL
66
*/
77

8+
#include <math.h>
9+
810
#include "ch.h"
911
#include "hal.h"
1012

@@ -45,4 +47,16 @@ void AccelRead(void){
4547
accel_x = (int8_t)lis302dlReadRegister(&SPID1, LIS302DL_OUTX);
4648
accel_y = (int8_t)lis302dlReadRegister(&SPID1, LIS302DL_OUTY);
4749
accel_z = (int8_t)lis302dlReadRegister(&SPID1, LIS302DL_OUTZ);
50+
}
51+
52+
float AccelGetRollAngle(void){
53+
return atan2( accel_x, sqrt( pow(accel_y, 2) + pow(accel_z, 2) ) );
54+
}
55+
56+
float AccelGetPitchAngle(void){
57+
return atan2( accel_y, sqrt( pow(accel_x, 2) + pow(accel_z, 2) ) );
58+
}
59+
60+
float AccelGetYawAngle(void){
61+
return atan2( sqrt( pow(accel_x, 2) + pow(accel_y, 2) ), accel_z );
4862
}

Accel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ extern int8_t accel_x, accel_y, accel_z;
1414
void AccelInit(void);
1515
void AccelRead(void);
1616

17+
float AccelGetRollAngle(void);
18+
float AccelGetPitchAngle(void);
19+
float AccelGetYawAngle(void);
20+
1721
#endif /* _ACCEL_H_ */

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int main(void){
150150
* 10hz task loop
151151
*/
152152
if (frameCounter % 10 == 0){
153-
//CommsSendAttitude(ST2MS(currentTime - startTime), float roll, float pitch, float yaw, float rollspeed, float pitchspeed, float yawspeed);
153+
CommsSendAttitude(ST2MS(currentTime - startTime), AccelGetRollAngle(), AccelGetPitchAngle(), AccelGetYawAngle(), 0, 0, 0);
154154
}
155155

156156
/*

0 commit comments

Comments
 (0)