Skip to content
Snippets Groups Projects
Commit 432eb1ee authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Solved a bug in the gyro calibration because the ADC's were not updated while...

Solved a bug in the gyro calibration because the ADC's were not updated while averaging the gyro data.
parent f161a83c
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -36,7 +36,7 @@ $(PROJECT).elf: $(OBJS)
$(CC) -c $(CFLAGS) $(INCLUDE_DIRS) -o $@ $<
download: $(MAIN_OUT_HEX)
fw_downloader -d /dev/ttyUSB0 -f ./src/examples/comm_ex.hex -p new
fw_downloader -d /dev/ttyUSB0 -f $(PROJECT).hex -p new
clean:
-rm $(PROJECT).*
......
......@@ -29,8 +29,8 @@ void user_loop(void)
{
if(user_time_is_period_done())
{
printf("Gyro X: %d\n",get_adc_avg_channel(ADC_PORT_3));
printf("Gyro Y: %d\n",get_adc_avg_channel(ADC_PORT_4));
printf("Gyro X: %d\n",get_adc_channel(ADC_PORT_3));
printf("Gyro Y: %d\n",get_adc_channel(ADC_PORT_4));
}
if(is_button_pressed(BTN_START))
turn_led_on(LED_AUX);
......
......@@ -6,11 +6,15 @@
#include "balance.h"
#include "adc.h"
#include "buzzer.h"
#include "user_time.h"
// external functions
extern void buzzer_start_alarm(note_t note,uint16_t on_time_100ms,uint16_t off_time_100ms);
extern void buzzer_stop_alarm(void);
extern void adc_loop(void);
extern void user_time_loop(void);
// private variables
uint16_t balance_x_gyro_center;
uint16_t balance_y_gyro_center;
......@@ -98,14 +102,20 @@ uint8_t balance_calibrate_gyro(void)
balance_x_gyro_center=0;
balance_y_gyro_center=0;
user_time_set_period(50);
for(i=0;i<BALANCE_GYRO_CAL_NUM_SAMPLES;i++)
{
_delay_ms(50);
while(!user_time_is_period_done())
{
user_time_loop();
adc_loop();
}
x_gyro_values[i]=get_adc_channel(BALANCE_GYRO_X_CHANNEL);
y_gyro_values[i]=get_adc_channel(BALANCE_GYRO_Y_CHANNEL);
x_gyro_average+=x_gyro_values[i];
y_gyro_average+=y_gyro_values[i];
}
user_time_stop();
x_gyro_average/=(float)BALANCE_GYRO_CAL_NUM_SAMPLES;
y_gyro_average/=(float)BALANCE_GYRO_CAL_NUM_SAMPLES;
// compute the standard deviation
......
......@@ -2,7 +2,7 @@ PROJECT=manager_ex
########################################################
# afegir tots els fitxers que s'han de compilar aquí
########################################################
SOURCES=walk_straight.c
SOURCES=get_up.c#walk_straight.c
OBJS=$(SOURCES:.c=.o)
SRC_DIR=./src/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment