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

Deleted some unnecessary files from the dexter example folder.

Updated the stairs example to walk to the stairs and climb a single step.
parent 8e38170b
No related branches found
No related tags found
No related merge requests found
#include <util/delay.h>
#include <stdio.h>
#include "cm510.h"
#include "balance.h"
#include "exp_board.h"
#include "mtn_library.h"
#include <stdlib.h>
typedef enum {wait_start,wait_walk_ready,wait_cmd,walk,walk2} main_states;
void user_init(void)
{
serial_console_init(57600);
balance_init();
balance_calibrate_gyro();
balance_enable_gyro();
mtn_lib_init();
}
typedef uint8_t (*fnct_ptr)(void);
fnct_ptr fnct1=fast_walk_forward;
//fnct_ptr fnct1=walk_forward;
//fnct_ptr fnct1=walk_right;
//fnct_ptr fnct1=walk_backward_turn_left;
fnct_ptr fnct2=turn_left;
//fnct_ptr fnct2=walk_left;
//fnct_ptr fnct2=walk_backward_turn_right;
void user_loop(void)
{
static main_states state=wait_start;
static int current_foot = 0;
switch(state)
{
case wait_start: if(is_button_rising_edge(BTN_START))
{
action_set_page(30);
action_start_page();
state=wait_walk_ready;
}
else
state=wait_start;
break;
case wait_walk_ready: if(is_action_running())
state=wait_walk_ready;
else
state=wait_cmd;
break;
case wait_cmd: if(is_button_rising_edge(BTN_UP))
{
fnct1();
state=walk;
}
else if(is_button_rising_edge(BTN_LEFT))
{
fnct2();
state=walk2;
}
else
state=wait_cmd;
break;
case walk: if(is_button_rising_edge(BTN_DOWN))
mtn_lib_stop_mtn();
if(fnct1()==0x01)
state=wait_cmd;
else
state=walk;
break;
case walk2: if(is_button_rising_edge(BTN_RIGHT))
mtn_lib_stop_mtn();
if(fnct2()==0x01)
state=wait_cmd;
else
state=walk2;
break;
}
}
File deleted
This diff is collapsed.
This diff is collapsed.
File deleted
#include <avr/io.h>
#include "mtn_library.h"
#include "action_id.h"
#include "action.h"
#include <stdio.h>
// private variables
typedef enum {mtn_fwd=0,mtn_bwd=1,mtn_turn_left=2,mtn_turn_right=3,mtn_left=4,mtn_right=5,mtn_fwd_turn_left=6,mtn_fwd_turn_right=7,
mtn_bwd_turn_left=8,mtn_bwd_turn_right=9,mtn_fwd_left=10,mtn_fwd_right=11,mtn_bwd_left=12,mtn_bwd_right=13,
mtn_fast_fwd=14,mtn_fast_bwd=15} mtn_t;
typedef enum {idle,wait_start,wait_middle,wait_end} full_states;
typedef struct{
uint8_t start_l;
uint8_t start_r;
uint8_t middle_l;
uint8_t middle_r;
uint8_t end_l;
uint8_t end_r;
}TPages;
uint8_t mtn_lib_stop;
foot_t mtn_lib_start_foot;
foot_t mtn_lib_current_foot;
TPages mtn_pages[]={{F_S_L,F_S_R,F_M_L,F_M_R,F_E_L,F_E_R},
{B_S_L,B_S_R,B_M_L,B_M_R,B_E_L,B_E_R},
{LT_S_L,LT_S_R,LT_M_L,LT_M_R,LT_E_L,LT_E_R},
{RT_S_L,RT_S_R,RT_M_L,RT_M_R,RT_E_L,RT_E_R},
{L_S_L,L_S_R,L_M_L,L_M_R,L_E_L,L_E_R},
{R_S_L,R_S_R,R_M_L,R_M_R,R_E_L,R_E_R},
{FLT_S_L,FLT_S_R,FLT_M_L,FLT_M_R,FLT_E_L,FLT_E_R},
{FRT_S_L,FRT_S_R,FRT_M_L,FRT_M_R,FRT_E_L,FRT_E_R},
{BLT_S_L,BLT_S_R,BLT_M_L,BLT_M_R,BLT_E_L,BLT_E_R},
{BRT_S_L,BRT_S_R,BRT_M_L,BRT_M_R,BRT_E_L,BRT_E_R},
{FL_S_L,FL_S_R,FL_M_L,FL_M_R,FL_E_L,FL_E_R},
{FR_S_L,FR_S_R,FR_M_L,FR_M_R,FR_E_L,FR_E_R},
{BL_S_L,BL_S_R,BL_M_L,BL_M_R,BL_E_L,BL_E_R},
{BR_S_L,BR_S_R,BR_M_L,BR_M_R,BR_E_L,BR_E_R},
{fst_F_L_S,fst_F_R_S,fst_F_R_L_M,fst_F_L_R_M,fst_F_R_E,fst_F_L_E},
{fst_B_L_S,fst_B_R_S,fst_B_L_M,fst_B_R_M,fst_B_L_E,fst_B_R_E}};
/* private functions */
uint8_t mtn_lib_full(TPages *pages)
{
static full_states state=idle;
uint8_t done=0x00;
switch(state)
{
case idle: if(mtn_lib_start_foot==left_foot)
action_set_page(pages->start_l);
else
action_set_page(pages->start_r);
action_start_page();
mtn_lib_current_foot=mtn_lib_start_foot;
state=wait_start;
break;
case wait_start: if(is_action_running())
state=wait_start;
else
{
if(mtn_lib_stop==0x01)
{
if(mtn_lib_current_foot==left_foot)
{
action_set_page(pages->end_r);
mtn_lib_current_foot=right_foot;
}
else
{
action_set_page(pages->end_l);
mtn_lib_current_foot=left_foot;
}
action_start_page();
state=wait_end;
}
else
{
if(mtn_lib_current_foot==left_foot)
{
action_set_page(pages->middle_r);
mtn_lib_current_foot=right_foot;
}
else
{
action_set_page(pages->middle_l);
mtn_lib_current_foot=left_foot;
}
action_start_page();
state=wait_middle;
}
}
break;
case wait_middle: if(is_action_running())
state=wait_middle;
else
{
if(mtn_lib_stop==0x01)
{
if(mtn_lib_current_foot==left_foot)
{
action_set_page(pages->end_r);
mtn_lib_current_foot=right_foot;
}
else
{
action_set_page(pages->end_l);
mtn_lib_current_foot=left_foot;
}
action_start_page();
state=wait_end;
}
else
{
if(mtn_lib_current_foot==left_foot)
{
action_set_page(pages->middle_r);
mtn_lib_current_foot=right_foot;
}
else
{
action_set_page(pages->middle_l);
mtn_lib_current_foot=left_foot;
}
action_start_page();
state=wait_middle;
}
}
break;
case wait_end: if(is_action_running())
state=wait_end;
else
{
mtn_lib_stop=0x00;
state=idle;
done=0x01;
}
break;
}
return done;
}
uint8_t mtn_lib_left(TPages *pages)
{
static full_states state=idle;
uint8_t done=0x00;
switch(state)
{
case idle: if(mtn_lib_start_foot==left_foot)
action_set_page(pages->start_l);
else
action_set_page(pages->start_r);
action_start_page();
mtn_lib_current_foot=mtn_lib_start_foot;
state=wait_start;
break;
case wait_start: if(is_action_running())
state=wait_start;
else
{
if(mtn_lib_current_foot==left_foot)
{
if(mtn_lib_stop==0x01)
{
action_set_page(pages->end_r);
state=wait_end;
}
else
{
action_set_page(pages->middle_r);
state=wait_middle;
}
mtn_lib_current_foot=right_foot;
action_start_page();
}
else
{
action_set_page(pages->middle_l);
mtn_lib_current_foot=left_foot;
action_start_page();
state=wait_middle;
}
}
break;
case wait_middle: if(is_action_running())
state=wait_middle;
else
{
if(mtn_lib_current_foot==left_foot)
{
if(mtn_lib_stop==0x01)
{
action_set_page(pages->end_r);
state=wait_end;
}
else
{
action_set_page(pages->middle_r);
state=wait_middle;
}
mtn_lib_current_foot=right_foot;
action_start_page();
}
else
{
action_set_page(pages->middle_l);
mtn_lib_current_foot=left_foot;
action_start_page();
state=wait_middle;
}
}
break;
case wait_end: if(is_action_running())
state=wait_end;
else
{
mtn_lib_stop=0x00;
state=idle;
done=0x01;
}
break;
}
return done;
}
uint8_t mtn_lib_right(TPages *pages)
{
static full_states state=idle;
uint8_t done=0x00;
switch(state)
{
case idle: if(mtn_lib_start_foot==left_foot)
action_set_page(pages->start_l);
else
action_set_page(pages->start_r);
action_start_page();
mtn_lib_current_foot=mtn_lib_start_foot;
state=wait_start;
break;
case wait_start: if(is_action_running())
state=wait_start;
else
{
if(mtn_lib_current_foot==right_foot)
{
if(mtn_lib_stop==0x01)
{
action_set_page(pages->end_l);
state=wait_end;
}
else
{
action_set_page(pages->middle_l);
state=wait_middle;
}
mtn_lib_current_foot=left_foot;
action_start_page();
}
else
{
action_set_page(pages->middle_r);
mtn_lib_current_foot=right_foot;
action_start_page();
state=wait_middle;
}
}
break;
case wait_middle: if(is_action_running())
state=wait_middle;
else
{
if(mtn_lib_current_foot==right_foot)
{
if(mtn_lib_stop==0x01)
{
action_set_page(pages->end_l);
state=wait_end;
}
else
{
action_set_page(pages->middle_l);
state=wait_middle;
}
mtn_lib_current_foot=left_foot;
action_start_page();
}
else
{
action_set_page(pages->middle_r);
mtn_lib_current_foot=right_foot;
action_start_page();
state=wait_middle;
}
}
break;
case wait_end: if(is_action_running())
state=wait_end;
else
{
mtn_lib_stop=0x00;
state=idle;
done=0x01;
}
break;
}
return done;
}
/* public functions */
void mtn_lib_init(void)
{
mtn_lib_stop=0x00;
mtn_lib_start_foot=left_foot;
mtn_lib_current_foot=left_foot;
}
void mtn_lib_stop_mtn(void)
{
mtn_lib_stop=0x01;
}
void mtn_lib_set_start_foot(foot_t foot)
{
mtn_lib_start_foot=foot;
}
uint8_t walk_forward(void)
{
return mtn_lib_full(&mtn_pages[mtn_fwd]);
}
uint8_t walk_backward(void)
{
return mtn_lib_full(&mtn_pages[mtn_bwd]);
}
uint8_t turn_left(void)
{
return mtn_lib_left(&mtn_pages[mtn_turn_left]);
}
uint8_t turn_right(void)
{
return mtn_lib_right(&mtn_pages[mtn_turn_right]);
}
uint8_t walk_left(void)
{
return mtn_lib_left(&mtn_pages[mtn_left]);
}
uint8_t walk_right(void)
{
return mtn_lib_right(&mtn_pages[mtn_right]);
}
uint8_t walk_forward_turn_left(void)
{
return mtn_lib_left(&mtn_pages[mtn_fwd_turn_left]);
}
uint8_t walk_forward_turn_right(void)
{
return mtn_lib_right(&mtn_pages[mtn_fwd_turn_right]);
}
uint8_t walk_backward_turn_left(void)
{
return mtn_lib_left(&mtn_pages[mtn_bwd_turn_left]);
}
uint8_t walk_backward_turn_right(void)
{
return mtn_lib_right(&mtn_pages[mtn_bwd_turn_right]);
}
uint8_t walk_forward_left(void)
{
return mtn_lib_left(&mtn_pages[mtn_fwd_left]);
}
uint8_t walk_forward_right(void)
{
return mtn_lib_right(&mtn_pages[mtn_fwd_right]);
}
uint8_t walk_backward_left(void)
{
return mtn_lib_left(&mtn_pages[mtn_bwd_left]);
}
uint8_t walk_backward_right(void)
{
return mtn_lib_right(&mtn_pages[mtn_bwd_right]);
}
uint8_t fast_walk_forward(void)
{
return mtn_lib_full(&mtn_pages[mtn_fast_fwd]);
}
uint8_t fast_walk_backward(void)
{
return mtn_lib_full(&mtn_pages[mtn_fast_bwd]);
}
uint8_t fast_turn_left(void)
{
return 1;
}
uint8_t fast_turn_right(void)
{
return 1;
}
uint8_t fast_walk_left(void)
{
return 1;
}
uint8_t fast_walk_right(void)
{
return 1;
}
uint8_t fast_walk_forward_turn_left(void)
{
return 1;
}
uint8_t fast_walk_forward_turn_right(void)
{
return 1;
}
uint8_t fast_walk_backward_turn_left(void)
{
return 1;
}
uint8_t fast_walk_backward_turn_right(void)
{
return 1;
}
File deleted
...@@ -2,7 +2,7 @@ PROJECT=stairs ...@@ -2,7 +2,7 @@ PROJECT=stairs
######################################################## ########################################################
# afegir tots els fitxers que s'han de compilar aquí # afegir tots els fitxers que s'han de compilar aquí
######################################################## ########################################################
SOURCES=stairs.c SOURCES=stairs.c ../mtn_library.c
OBJS=$(SOURCES:.c=.o) OBJS=$(SOURCES:.c=.o)
SRC_DIR=./ SRC_DIR=./
...@@ -16,7 +16,7 @@ MMCU=atmega2561 ...@@ -16,7 +16,7 @@ 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 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 INCLUDE_DIRS=-I$(DEV_DIR)include -I$(COMM_DIR)include -I$(CONT_DIR)include -I$(MAN_DIR)include -I../movements
CFLAGS=-mmcu=$(MMCU) -Wall -Os $(defines) -DF_CPU=16000000UL -gdwarf-2 -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wstrict-prototypes CFLAGS=-mmcu=$(MMCU) -Wall -Os $(defines) -DF_CPU=16000000UL -gdwarf-2 -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wstrict-prototypes
......
...@@ -3,98 +3,89 @@ ...@@ -3,98 +3,89 @@
#include "cm510.h" #include "cm510.h"
#include "balance.h" #include "balance.h"
#include "exp_board.h" #include "exp_board.h"
#include "mtn_library.h"
typedef enum {wait_start,wait_ready,up_stairs} main_states; typedef enum {wait_start,wait_ready,walk_to_stairs1,wait_stop1,up_stairs1} main_states;
typedef enum {idle,delay1,wait_step1,delay2,wait_step2,delay3,wait_step3,delay4,wait_step4,wait_ready_up} stairs_up_states; typedef enum {up_idle,up_wait_stop,up_wait_step1,up_delay1,up_wait_step2,up_wait_step3,up_wait_step4,wait_ready_up} stairs_up_states;
typedef enum {down_idle,down_wait_stop,down_wait_step1,down_wait_step2,down_wait_step3,wait_ready_down} stairs_down_states;
uint8_t stairs_up_process(void) uint8_t stairs_up_process(void)
{ {
static stairs_up_states state=idle; static stairs_up_states state=up_idle;
uint8_t done=0x00; uint8_t done=0x00;
switch(state) switch(state)
{ {
case idle: user_time_set_one_time(1500); case up_idle: if(is_action_running())
state = delay1; {
break; action_stop_page();
case delay1: if(user_time_is_done()) state = up_wait_stop;
{ }
action_set_page(224); else
action_start_page(); {
state = wait_step1; action_set_page(227);
} action_start_page();
else state = up_wait_step1;
state = delay1; }
break; break;
case wait_step1: if(is_action_running()) case up_wait_stop: if(is_action_running())
state = wait_step1; state = up_wait_stop;
else else
{ {
user_time_set_one_time(1500); action_set_page(227);
state = delay2; action_start_page();
} state = up_wait_step1;
printf("step1\n"); }
break; break;
case delay2: if(user_time_is_done()) case up_wait_step1: if(is_action_running())
{ state = up_wait_step1;
action_set_page(225); else
action_start_page(); {
state = wait_step2; user_time_set_one_time(1500);
} state = up_delay1;
else }
state = delay2; break;
break; case up_delay1: if(user_time_is_done())
case wait_step2: if(is_action_running()) {
state = wait_step2; action_set_page(224);
else action_start_page();
{ state = up_wait_step2;
user_time_set_one_time(1500); }
state = delay3; else
} state = up_delay1;
printf("step2\n"); break;
break; case up_wait_step2: if(is_action_running())
case delay3: if(user_time_is_done()) state = up_wait_step2;
{ else
action_set_page(226); {
action_start_page(); action_set_page(225);
state = wait_step3; action_start_page();
} state = up_wait_step3;
else }
state = delay3; break;
break; case up_wait_step3: if(is_action_running())
case wait_step3: if(is_action_running()) state = up_wait_step3;
state = wait_step3; else
else {
{ action_set_page(226);
user_time_set_one_time(1500); action_start_page();
state = delay4; state = up_wait_step4;
} }
printf("step3\n"); break;
break; case up_wait_step4: if(is_action_running())
case delay4: if(user_time_is_done()) state = up_wait_step4;
{ else
action_set_page(226); {
action_start_page(); action_set_page(31);
state = wait_step4; action_start_page();
} state = wait_ready_up;
else }
state = delay4; break;
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()) case wait_ready_up: if(is_action_running())
state = wait_ready_up; state = wait_ready_up;
else else
{ {
state=idle; state=up_idle;
done=0x01; done=0x01;
} }
break; break;
...@@ -104,6 +95,74 @@ uint8_t stairs_up_process(void) ...@@ -104,6 +95,74 @@ uint8_t stairs_up_process(void)
} }
uint8_t stairs_down_process(void)
{
static stairs_down_states state=down_idle;
uint8_t done=0x00;
switch(state)
{
case down_idle: if(is_action_running())
{
action_stop_page();
state = down_wait_stop;
}
else
{
action_set_page(228);
action_start_page();
state = down_wait_step1;
}
break;
case down_wait_stop: if(is_action_running())
state = down_wait_stop;
else
{
action_set_page(228);
action_start_page();
state = down_wait_step1;
}
break;
case down_wait_step1: if(is_action_running())
state = down_wait_step1;
else
{
action_set_page(229);
action_start_page();
state = down_wait_step2;
}
break;
case down_wait_step2: if(is_action_running())
state = down_wait_step2;
else
{
action_set_page(230);
action_start_page();
state = down_wait_step3;
}
break;
case down_wait_step3: if(is_action_running())
state = down_wait_step3;
else
{
action_set_page(31);
action_start_page();
state = wait_ready_down;
}
break;
case wait_ready_down: if(is_action_running())
state = wait_ready_down;
else
{
state=down_idle;
done=0x01;
}
break;
}
return done;
}
void user_init(void) void user_init(void)
{ {
serial_console_init(57600); serial_console_init(57600);
...@@ -111,6 +170,7 @@ void user_init(void) ...@@ -111,6 +170,7 @@ void user_init(void)
balance_calibrate_gyro(); balance_calibrate_gyro();
balance_enable_gyro(); balance_enable_gyro();
user_time_set_period(100); user_time_set_period(100);
mtn_lib_init();
} }
void user_loop(void) void user_loop(void)
...@@ -131,12 +191,30 @@ void user_loop(void) ...@@ -131,12 +191,30 @@ void user_loop(void)
case wait_ready: if(is_action_running()) case wait_ready: if(is_action_running())
state=wait_ready; state=wait_ready;
else else
state=up_stairs; {
walk_forward();
state=walk_to_stairs1;
}
break;
case walk_to_stairs1: if(exp_gpio_get_value(GPIO0) || exp_gpio_get_value(GPIO3))
{
mtn_lib_stop_mtn();
state=wait_stop1;
}
else
state=walk_to_stairs1;
walk_forward();
break;
case wait_stop1: if(walk_forward())
state=up_stairs1;
else
state=wait_stop1;
break;
case up_stairs1: if(stairs_up_process())
state=wait_start;
else
state=up_stairs1;
break; break;
case up_stairs: if(stairs_up_process())
state=wait_start;
else
state=up_stairs;
break;
} }
} }
...@@ -129,7 +129,9 @@ ...@@ -129,7 +129,9 @@
#define stairs_up_1 224 #define stairs_up_1 224
#define stairs_up_2 225 #define stairs_up_2 225
#define stairs_up_3 226 #define stairs_up_3 226
#define stairs_up_4 227 #define Init 227
#define stairs_down 228 #define stairs_down1 228
#define stairs_down2 229
#define stairs_down3 230
#endif #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