Skip to content

Commit

Permalink
Go back to idle after run/search
Browse files Browse the repository at this point in the history
  • Loading branch information
Peque committed Dec 5, 2019
1 parent 08b3170 commit c7ca866
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
7 changes: 5 additions & 2 deletions docs/source/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ perform different tasks following the diagram bellow:

digraph finite_state_machine {
size="8,14"; ratio = fill;
node [shape = doublecircle,style=filled,fillcolor=lightblue]; Iddle "Go!";
node [shape = doublecircle,style=filled,fillcolor=lightblue]; Idle "Go!";
node [shape = diamond,style=filled,fillcolor=white]; "Saved\nmaze?";
node [shape = ellipse,style=filled,fillcolor=lightgrey]; "Start?" "Reuse?" "Goal?" "Speed?" "Ready?";
node [shape = box,style=filled,fillcolor=white];
Iddle -> "Start?";
Idle -> "Start?";
"Start?" -> "Start?" [ label = "No input" ];
"Start?" -> "Saved\nmaze?" [ label = "Press" ];
"Saved\nmaze?" -> "Green LED on" [ label = "Yes" ];
Expand Down Expand Up @@ -56,6 +56,9 @@ perform different tasks following the diagram bellow:
"Ready?" -> "Go!" [ label = "Front sensor close reading" ];
}

.. note:: After ``Go!`` (run/explore), the robot will end up in the ``Idle``
state back again.


Encoders calibration
====================
Expand Down
52 changes: 26 additions & 26 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static void before_moving(void)
led_right_on();
wait_front_sensor_close_signal(0.12);
srand(read_cycle_counter());
led_bluepill_off();
led_left_off();
led_right_off();
sleep_us(2000000);
Expand Down Expand Up @@ -91,7 +92,7 @@ static void after_moving(void)
*
* @param[in] run Whether the robot should be running.
*/
static void movement_phase(bool do_run)
static void configure_speed(bool do_run)
{
float force;

Expand All @@ -102,6 +103,8 @@ static void movement_phase(bool do_run)
before_moving();
if (!do_run) {
explore(force);
set_run_sequence();
save_maze();
} else {
run(force);
run_back(force);
Expand All @@ -111,10 +114,11 @@ static void movement_phase(bool do_run)
}

/**
* @brief Configure the goal for the search phase.
* @brief Let the user configure the goal for the search phase.
*/
static void configure_goal(void)
{
set_search_initial_direction(NORTH);
switch (button_user_wait_action()) {
case BUTTON_SHORT:
add_goal(1, 0);
Expand All @@ -124,44 +128,40 @@ static void configure_goal(void)
speaker_play_competition();
break;
}
}

/**
* @brief Execute the exploration phase.
*/
static void exploration_phase(void)
{
set_search_initial_direction(NORTH);
configure_goal();
set_target_goal();

movement_phase(false);

set_run_sequence();
save_maze();
configure_speed(false);
}

/**
* @brief Configure the robot and execute the search/run.
* @brief Let the user reuse the saved maze for a run or discard it.
*/
static void configure_and_move(void)
static void configure_reuse(void)
{
if (!maze_is_saved())
exploration_phase();
led_bluepill_on();
switch (button_user_wait_action()) {
case BUTTON_SHORT:
load_maze();
configure_speed(true);
break;
case BUTTON_LONG:
reset_maze();
led_bluepill_off();
exploration_phase();
led_bluepill_on();
configure_goal();
break;
}
while (1)
movement_phase(true);
}

/**
* @brief Start the robot configuration process for an exploration/run.
*/
static void configure_start(void)
{
if (maze_is_saved()) {
led_bluepill_on();
configure_reuse();
} else {
led_bluepill_off();
configure_goal();
}
}

/**
Expand All @@ -177,7 +177,7 @@ int main(void)
case BUTTON_NONE:
break;
default:
configure_and_move();
configure_start();
break;
}
execute_command();
Expand Down

0 comments on commit c7ca866

Please sign in to comment.