diff --git a/examples/get_up/Makefile b/examples/get_up/Makefile index b4651c39960b7a6281f40e5e019f11fce228fac2..0a5a21b65ccf72645bf2f034f5ef30fdd1be8ecd 100644 --- a/examples/get_up/Makefile +++ b/examples/get_up/Makefile @@ -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 diff --git a/examples/movements/Makefile b/examples/movements/Makefile index 72e8219eeea802011d2f85d3b79f3b5eb1108b2c..6d668f0a8c55d56e746b3cdaa141a2087125f436 100644 --- a/examples/movements/Makefile +++ b/examples/movements/Makefile @@ -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 diff --git a/examples/sensors/Makefile b/examples/sensors/Makefile index 48b4cd064aede65260ae6ce82d8d32f8978ea70e..df7669117ab8fe61c5732222dbd76914b8693f31 100644 --- a/examples/sensors/Makefile +++ b/examples/sensors/Makefile @@ -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 diff --git a/examples/stairs/Makefile b/examples/stairs/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d05e5a1a69bc9f33211d3548d3f003d177d9a139 --- /dev/null +++ b/examples/stairs/Makefile @@ -0,0 +1,57 @@ +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) diff --git a/examples/stairs/stairs.c b/examples/stairs/stairs.c new file mode 100644 index 0000000000000000000000000000000000000000..f380049a630b80de7e9e26973af8070918eeb88d --- /dev/null +++ b/examples/stairs/stairs.c @@ -0,0 +1,142 @@ +#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; + } +} diff --git a/examples/walk_straight/Makefile b/examples/walk_straight/Makefile index 00d79f3110ec2e35d654813b7a385b546f97712f..428ca8178e98dac817e2a54b24e1f7dca2a31ea1 100644 --- a/examples/walk_straight/Makefile +++ b/examples/walk_straight/Makefile @@ -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 diff --git a/motion/include/action_id.h b/motion/include/action_id.h index 88233b218f16adf55ccb12f2cfa71702db0a06cd..32ca4ee29b621c58cc6a677419c15be19402d682 100644 --- a/motion/include/action_id.h +++ b/motion/include/action_id.h @@ -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