summaryrefslogtreecommitdiffhomepage
path: root/digital/io-hub/src/apbirthday/cannon.cc
blob: 33e175908d428a29837eb1a9b0c36ba1bc990ef7 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// io-hub - Modular Input/Output. {{{
//
// Copyright (C) 2013 Maxime Hadjinlian
//
// 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 "robot.hh"
#include "defs.hh"
#include "cannon.hh"

Cannon::Cannon ()
{
    // Init the cannon and the RGB sensor
}

inline void Cannon::blower_on ()
{
    // Start the blower
    robot->pot_regul.set_wiper(0, 256);
}

inline void Cannon::blower_off ()
{
    // Shutdown the blower
    robot->pot_regul.set_wiper (0, 0);
}

inline void Cannon::set_servo_pos (int pos)
{
    // Switch the servo to BLOCK, POS1 or POS2
    robot->hardware.servos.set_position (Servo::SERVO_CHERRY, pos);
}

// Trap FSM
FSM_STATES (CANNON_TRAP_OFF,
            CANNON_TRAP_BLOCK,
            CANNON_TRAP_MOVE_1,
            CANNON_TRAP_MOVE_2)

FSM_EVENTS (cannon_fire,
            cannon_fire_ok)

FSM_START_WITH (CANNON_TRAP_OFF)

FSM_TRANS (CANNON_TRAP_OFF, init_actuators, CANNON_TRAP_BLOCK)
{
    Cannon::set_servo_pos (Cannon::BLOCK);
}

FSM_TRANS (CANNON_TRAP_BLOCK, cannon_fire, CANNON_TRAP_MOVE_1)
{
    Cannon::set_servo_pos (Cannon::POS1);
}

FSM_TRANS_TIMEOUT (CANNON_TRAP_MOVE_1, 75, CANNON_TRAP_MOVE_2)
{
    Cannon::set_servo_pos (Cannon::POS2);
}

FSM_TRANS_TIMEOUT (CANNON_TRAP_MOVE_2, 75, CANNON_TRAP_MOVE_1)
{
    Cannon::set_servo_pos (Cannon::POS1);
}

FSM_TRANS (CANNON_TRAP_MOVE_1, cannon_fire_ok, CANNON_TRAP_BLOCK)
{
    Cannon::set_servo_pos (Cannon::BLOCK);
}

FSM_TRANS (CANNON_TRAP_MOVE_2, cannon_fire_ok, CANNON_TRAP_BLOCK)
{
    Cannon::set_servo_pos (Cannon::BLOCK);
}

// Cannon main FSM

FSM_STATES (CANNON_OFF,
            CANNON_PURGING,
            CANNON_READY,
            CANNON_FIRING)

FSM_START_WITH (CANNON_OFF)

FSM_TRANS (CANNON_OFF, init_actuators, CANNON_PURGING)
{
    // Start the blower to purge the canon
    robot->cannon.blower_on ();
}

FSM_TRANS_TIMEOUT (CANNON_PURGING, 500, CANNON_READY)
{
    // Stop the blower
    robot->cannon.blower_off ();
}

FSM_TRANS (CANNON_READY, cannon_fire, CANNON_FIRING)
{
    // Start the blower
    Cannon::blower_on ();
    // Start RGB sensor
}

FSM_TRANS_TIMEOUT (CANNON_FIRING, 1250, CANNON_READY)
{
    // Stop the blower
    Cannon::blower_off ();
    // Stop the RGB sensor
    robot->fsm_queue.post (FSM_EVENT (cannon_fire_ok));
}