summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src/test/testgetsamples/main.c
blob: f083ec8d8360c0a66260c69d5d8f3b95a01342b6 (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
/* main.c */
/*  {{{
 *
 * 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 "../../getsamples.h"
#include "../../playground.h"

#include "modules/utils/utils.h"

#include "io.h"

#include <stdio.h>

extern struct getsamples_data_t getsamples_data_;

int
main (void)
{
    /* Configure the get sample FSM */
    /* Go to our distributor */
    int16_t approach_angle = PG_DISTRIBUTOR_SAMPLE_OUR_A;
    uint8_t sample_bitfield = 0;
    /* We want to put the sample into the 0, 2 and 4 box */
    sample_bitfield |= _BV(0);
    sample_bitfield |= _BV(2);
    sample_bitfield |= _BV(4);

    /* Print initial state */
    /* Configure and initialize the get sample FSM */
    getsamples_start (approach_angle, sample_bitfield);
    /* Print first state */

    /* We are facing the distributor */
    fsm_handle_event (&getsamples_fsm,
		      GETSAMPLES_EVENT_bot_move_succeed);

    /* We have open the input hole */
    fsm_handle_event (&getsamples_fsm,
		      GETSAMPLES_EVENT_arm_move_succeed);

    /* The bot is now in contact with to the distributor */
    fsm_handle_event (&getsamples_fsm,
		      GETSAMPLES_EVENT_bot_move_succeed);

    /* Get the sample one by one */
    do
      {
	fsm_handle_event (&getsamples_fsm,
			  GETSAMPLES_EVENT_arm_pass_noted_position);
      } while (getsamples_data_.sample_bitfield);

    /* We need to do it one time again to make the bot move away from the
     * distributor */
    fsm_handle_event (&getsamples_fsm,
		      GETSAMPLES_EVENT_arm_pass_noted_position);

    /* We go away from the gutter */
    fsm_handle_event (&getsamples_fsm,
		      GETSAMPLES_EVENT_bot_move_succeed);

    /* We close the input hole */
    fsm_handle_event (&getsamples_fsm,
		      GETSAMPLES_EVENT_arm_move_succeed);

    return 0;
}