Skip to content

Commit 955be0e

Browse files
committedAug 15, 2012
Stubbing out gyro access
1 parent cb0cea6 commit 955be0e

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed
 

‎Gyro.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
ChibiCopter - https://github.com/grantmd/ChibiCopter
3+
A quadcopter platform running under ChibiOS/RT.
4+
5+
Read gyro data
6+
*/
7+
8+
#include "ch.h"
9+
#include "hal.h"
10+
11+
#include "Gyro.h"
12+
13+
#include <math.h>
14+
15+
uint8_t gyro_x, gyro_y, gyro_z;
16+
17+
void GyroInit(void){
18+
}
19+
20+
void GyroRead(void){
21+
}
22+
23+
float GyroGetRollAngle(void){
24+
return atan2f( (float)gyro_x, (float)sqrt( pow(gyro_y, 2) + pow(gyro_z, 2) ) );
25+
}
26+
27+
float GyroGetPitchAngle(void){
28+
return atan2f( (float)gyro_y, (float)sqrt( pow(gyro_x, 2) + pow(gyro_z, 2) ) );
29+
}
30+
31+
float GyroGetYawAngle(void){
32+
return atan2f( (float)sqrt( pow(gyro_x, 2) + pow(gyro_y, 2) ), (float)gyro_z );
33+
}

‎Gyro.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
ChibiCopter - https://github.com/grantmd/ChibiCopter
3+
A quadcopter platform running under ChibiOS/RT.
4+
5+
Read gyro data
6+
*/
7+
8+
#ifndef _GYRO_H_
9+
#define _GYRO_H_
10+
11+
extern uint8_t gyro_x, gyro_y, gyro_z;
12+
13+
// Public functions
14+
void GyroInit(void);
15+
void GyroRead(void);
16+
17+
float GyroGetRollAngle(void);
18+
float GyroGetPitchAngle(void);
19+
float GyroGetYawAngle(void);
20+
21+
#endif /* _GYRO_H_ */

‎Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ CSRC = $(PORTSRC) \
8787
$(CHIBIOS)/os/various/chprintf.c \
8888
Comms.c \
8989
Accel.c \
90+
Gyro.c \
9091
Spektrum.c \
9192
Motors.c \
9293
GPS.c \

‎main.c

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "Comms.h"
1414
#include "Accel.h"
15+
#include "Gyro.h"
1516
#include "Spektrum.h"
1617
#include "Motors.h"
1718
#include "GPS.h"
@@ -73,6 +74,7 @@ int main(void){
7374
*/
7475
mavlink_system.state = MAV_STATE_CALIBRATING;
7576
AccelInit();
77+
GyroInit();
7678

7779
/*
7880
* Receiver I/O
@@ -135,6 +137,7 @@ int main(void){
135137
* 100hz task loop
136138
*/
137139
if (frameCounter % 1 == 0){
140+
GyroRead();
138141
AccelRead();
139142
}
140143

0 commit comments

Comments
 (0)
Please sign in to comment.