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

Updated the stairs example to use the motion librray and the actual GPIO ports.

parent 57d92b67
No related branches found
No related tags found
No related merge requests found
...@@ -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 ../mtn_library.c SOURCES=stairs.c
OBJS=$(SOURCES:.c=.o) OBJS=$(SOURCES:.c=.o)
SRC_DIR=./ SRC_DIR=./
......
...@@ -6,162 +6,6 @@ ...@@ -6,162 +6,6 @@
#include "mtn_library.h" #include "mtn_library.h"
typedef enum {wait_start,wait_ready,walk_to_stairs1,wait_stop1,up_stairs1} main_states; typedef enum {wait_start,wait_ready,walk_to_stairs1,wait_stop1,up_stairs1} main_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)
{
static stairs_up_states state=up_idle;
uint8_t done=0x00;
switch(state)
{
case up_idle: if(is_action_running())
{
action_stop_page();
state = up_wait_stop;
}
else
{
action_set_page(227);
action_start_page();
state = up_wait_step1;
}
break;
case up_wait_stop: if(is_action_running())
state = up_wait_stop;
else
{
action_set_page(227);
action_start_page();
state = up_wait_step1;
}
break;
case up_wait_step1: if(is_action_running())
state = up_wait_step1;
else
{
user_time_set_one_time(1500);
state = up_delay1;
}
break;
case up_delay1: if(user_time_is_done())
{
action_set_page(224);
action_start_page();
state = up_wait_step2;
}
else
state = up_delay1;
break;
case up_wait_step2: if(is_action_running())
state = up_wait_step2;
else
{
action_set_page(225);
action_start_page();
state = up_wait_step3;
}
break;
case up_wait_step3: if(is_action_running())
state = up_wait_step3;
else
{
action_set_page(226);
action_start_page();
state = up_wait_step4;
}
break;
case up_wait_step4: if(is_action_running())
state = up_wait_step4;
else
{
action_set_page(31);
action_start_page();
state = wait_ready_up;
}
break;
case wait_ready_up: if(is_action_running())
state = wait_ready_up;
else
{
state=up_idle;
done=0x01;
}
break;
}
return done;
}
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)
{ {
...@@ -170,7 +14,6 @@ void user_init(void) ...@@ -170,7 +14,6 @@ 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)
...@@ -196,7 +39,7 @@ void user_loop(void) ...@@ -196,7 +39,7 @@ void user_loop(void)
state=walk_to_stairs1; state=walk_to_stairs1;
} }
break; break;
case walk_to_stairs1: if(exp_gpio_get_value(GPIO0) || exp_gpio_get_value(GPIO3)) case walk_to_stairs1: if(exp_gpio_get_value(GPIO1)==0x00 || exp_gpio_get_value(GPIO18)==0x00)
{ {
mtn_lib_stop_mtn(); mtn_lib_stop_mtn();
state=wait_stop1; state=wait_stop1;
...@@ -210,7 +53,7 @@ void user_loop(void) ...@@ -210,7 +53,7 @@ void user_loop(void)
else else
state=wait_stop1; state=wait_stop1;
break; break;
case up_stairs1: if(stairs_up_process()) case up_stairs1: if(stairs_up_process(robot_standing))
state=wait_start; state=wait_start;
else else
state=up_stairs1; state=up_stairs1;
......
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