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

Added a new example to climb stairs.

Solved a problem in the example Makefiles: multiple delettion of object files in the clean command.
parent b79950ec
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,6 @@ download: $(MAIN_OUT_HEX)
fw_downloader -d /dev/ttyUSB0 -f ./$(PROJECT).hex -p cm510
clean:
-rm $(PROJECT).o
-rm $(PROJECT).map
-rm $(PROJECT).elf
-rm $(PROJECT).hex
......
......@@ -51,7 +51,6 @@ download: $(MAIN_OUT_HEX)
fw_downloader -d /dev/ttyUSB0 -f ./$(PROJECT).hex -p cm510
clean:
-rm $(PROJECT).o
-rm $(PROJECT).map
-rm $(PROJECT).elf
-rm $(PROJECT).hex
......
......@@ -51,7 +51,6 @@ download: $(MAIN_OUT_HEX)
fw_downloader -d /dev/ttyUSB0 -f ./$(PROJECT).hex -p cm510
clean:
-rm $(PROJECT).o
-rm $(PROJECT).map
-rm $(PROJECT).hex
-rm $(PROJECT).elf
......
PROJECT=stairs
########################################################
# afegir tots els fitxers que s'han de compilar aquí
########################################################
SOURCES=stairs.c
OBJS=$(SOURCES:.c=.o)
SRC_DIR=./
DEV_DIR=../../dyn_devices/
COMM_DIR=../../communications/
CONT_DIR=../../controllers/
MAN_DIR=../../motion/
CC=avr-gcc
OBJCOPY=avr-objcopy
MMCU=atmega2561
LIBS=$(MAN_DIR)lib/libmotion_manager.a $(CONT_DIR)lib/libcontrollers.a $(COMM_DIR)lib/libcomm.a $(DEV_DIR)lib/libdyn_devices.a
INCLUDE_DIRS=-I$(DEV_DIR)include -I$(COMM_DIR)include -I$(CONT_DIR)include -I$(MAN_DIR)include
CFLAGS=-mmcu=$(MMCU) -Wall -Os $(defines) -DF_CPU=16000000UL -gdwarf-2 -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wstrict-prototypes
LDFLAGS=-mmcu=$(MMCU) -Wl,-Map=$(PROJECT).map -DF_CPU=16000000UL
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
.PHONY: all
all: communications dyn_devices controllers motion_manager $(PROJECT).hex
$(PROJECT).hex: $(PROJECT).elf
$(OBJCOPY) -O ihex $(HEX_FLASH_FLAGS) $< $@
$(PROJECT).elf: $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROJECT).elf
%.o:%.c
$(CC) -c $(CFLAGS) $(INCLUDE_DIRS) -o $@ $<
communications:
$(MAKE) -C $(COMM_DIR)
dyn_devices:
$(MAKE) -C $(DEV_DIR)
controllers:
$(MAKE) -C $(CONT_DIR)
motion_manager:
$(MAKE) -C $(MAN_DIR)
download: $(MAIN_OUT_HEX)
fw_downloader -d /dev/ttyUSB0 -f ./$(PROJECT).hex -p cm510
clean:
-rm $(PROJECT).map
-rm $(PROJECT).hex
-rm $(PROJECT).elf
-rm $(OBJS)
#include <util/delay.h>
#include <stdio.h>
#include "cm510.h"
#include "balance.h"
#include "exp_board.h"
typedef enum {wait_start,wait_ready,up_stairs} main_states;
typedef enum {idle,delay1,wait_step1,delay2,wait_step2,delay3,wait_step3,delay4,wait_step4,wait_ready_up} stairs_up_states;
uint8_t stairs_up_process(void)
{
static stairs_up_states state=idle;
uint8_t done=0x00;
switch(state)
{
case idle: user_time_set_one_time(1500);
state = delay1;
break;
case delay1: if(user_time_is_done())
{
action_set_page(224);
action_start_page();
state = wait_step1;
}
else
state = delay1;
break;
case wait_step1: if(is_action_running())
state = wait_step1;
else
{
user_time_set_one_time(1500);
state = delay2;
}
printf("step1\n");
break;
case delay2: if(user_time_is_done())
{
action_set_page(225);
action_start_page();
state = wait_step2;
}
else
state = delay2;
break;
case wait_step2: if(is_action_running())
state = wait_step2;
else
{
user_time_set_one_time(1500);
state = delay3;
}
printf("step2\n");
break;
case delay3: if(user_time_is_done())
{
action_set_page(226);
action_start_page();
state = wait_step3;
}
else
state = delay3;
break;
case wait_step3: if(is_action_running())
state = wait_step3;
else
{
user_time_set_one_time(1500);
state = delay4;
}
printf("step3\n");
break;
case delay4: if(user_time_is_done())
{
action_set_page(226);
action_start_page();
state = wait_step4;
}
else
state = delay4;
break;
case wait_step4: if(is_action_running())
state = wait_step4;
else
{
action_set_page(31);
action_start_page();
state = wait_ready;
}
printf("step4\n");
break;
case wait_ready_up: if(is_action_running())
state = wait_ready_up;
else
{
state=idle;
done=0x01;
}
break;
}
return done;
}
void user_init(void)
{
serial_console_init(57600);
balance_init();
balance_calibrate_gyro();
balance_enable_gyro();
user_time_set_period(100);
}
void user_loop(void)
{
static main_states state=wait_start;
switch(state)
{
case wait_start: if(is_button_rising_edge(BTN_START))
{
action_set_page(31);
action_start_page();
state=wait_ready;
}
else
state=wait_start;
break;
case wait_ready: if(is_action_running())
state=wait_ready;
else
state=up_stairs;
break;
case up_stairs: if(stairs_up_process())
state=wait_start;
else
state=up_stairs;
break;
}
}
......@@ -51,7 +51,6 @@ download: $(MAIN_OUT_HEX)
fw_downloader -d /dev/ttyUSB0 -f ./$(PROJECT).hex -p cm510
clean:
-rm $(PROJECT).o
-rm $(PROJECT).map
-rm $(PROJECT).hex
-rm $(PROJECT).elf
......
......@@ -126,8 +126,10 @@
#define BR_M_R 218
#define BR_E_L 220
#define BR_E_R 222
#define stairs_up_1 224
#define stairs_up_2 225
#define stairs_up_3 226
#define stairs_up_4 227
#define stairs_down 228
#endif
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