From 29d6aba8da2c4702c2b51e089e4414f9f7a5b71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20Hern=C3=A1ndez?= <shernand@iri.upc.edu> Date: Tue, 7 Jun 2016 06:52:07 +0200 Subject: [PATCH] Added a new example to climb stairs. Solved a problem in the example Makefiles: multiple delettion of object files in the clean command. --- examples/get_up/Makefile | 1 - examples/movements/Makefile | 1 - examples/sensors/Makefile | 1 - examples/stairs/Makefile | 57 +++++++++++++ examples/stairs/stairs.c | 142 ++++++++++++++++++++++++++++++++ examples/walk_straight/Makefile | 1 - motion/include/action_id.h | 8 +- 7 files changed, 204 insertions(+), 7 deletions(-) create mode 100644 examples/stairs/Makefile create mode 100644 examples/stairs/stairs.c diff --git a/examples/get_up/Makefile b/examples/get_up/Makefile index b4651c3..0a5a21b 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 72e8219..6d668f0 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 48b4cd0..df76691 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 0000000..d05e5a1 --- /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 0000000..f380049 --- /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 00d79f3..428ca81 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 88233b2..32ca4ee 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 -- GitLab