summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src/gutter_cb.c
blob: f2c01539df1732614055eb7c36cd093c121a001e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* gutter_cb.c - gutter FSM callbacks. */
/*  {{{
 *
 * Copyright (C) 2008 NĂ©lio Laranjeiro
 *
 * APBTeam:
 *        Web: http://apbteam.org/
 *      Email: team AT apbteam DOT org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * }}} */
#include "common.h"
#include "fsm.h"
#include "gutter.h"
#include "gutter_cb.h"
#include "asserv.h"
#include "trap.h"
#include "modules/utils/utils.h"
#include "top.h"
#include "topfsm_fsm.h"

/*
 * START =ok=>
 *  => GO_TO_GUTTER
 *   Go to the gutter.
 */
fsm_branch_t
gutter__START__ok (void)
{
    asserv_go_to_the_wall();
    return gutter_next (START, ok);
}

/*
 * CLOSE_COLLECTOR =collector_closed=>
 *  => END
 *   The samples has been inserted in the gutter.
 */
fsm_branch_t
gutter__CLOSE_COLLECTOR__collector_closed (void)
{
    //Close the collector.
    trap_close_rear_panel();
    // Post an event to the top fsm machine
    fsm_handle_event (&top_fsm, TOPFSM_EVENT_samples_deposed);
    return gutter_next (CLOSE_COLLECTOR, collector_closed);
}

/*
 * GO_TO_GUTTER =position_failed=>
 *  => GO_TO_GUTTER
 *   The position failed, shall try another path.
 */
fsm_branch_t
gutter__GO_TO_GUTTER__position_failed (void)
{
    return gutter_next (GO_TO_GUTTER, position_failed);
}

/*
 * GO_TO_GUTTER =position_reached=>
 *  => OPEN_COLLECTOR
 *   The robo is near the gutter and the door can be opened.
 */
fsm_branch_t
gutter__GO_TO_GUTTER__position_reached (void)
{
    // Open the collector.
    trap_open_rear_panel();
    return gutter_next (GO_TO_GUTTER, position_reached);
}

/*
 * OPEN_COLLECTOR =collector_opened=>
 *  => CLOSE_COLLECTOR
 *   Wait some time and clse the door.
 */
fsm_branch_t
gutter__OPEN_COLLECTOR__collector_opened (void)
{
    utils_delay_ms(4.4);
    return gutter_next (OPEN_COLLECTOR, collector_opened);
}