Newer
Older
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
129
130
131
132
133
134
135
136
#include "benne.h"
#ifdef ROBOTHW
#include "interfaceServosNumeriques.h"
#else
#include <QDebug>
#endif
#include "hardware/microSwitch.h"
Benne* Benne::getInstance()
{
static Benne* instance = 0;
if(!instance)
instance = new Benne();
return instance;
}
Benne::Benne()
{
#ifdef ROBOTHW
m_backSwitch = new MicroSwitch(GPIOE, GPIO_Pin_3);
m_frontSwitch = new MicroSwitch(GPIOE, GPIO_Pin_2);
#else
m_backSwitch = new MicroSwitch();
m_frontSwitch = new MicroSwitch();
#endif
isBenneEmpty = true;
m_status = Status::UNKNOWN;
#ifdef ROBOTHW
ServosNumeriques::changeContinuousRotationMode(SERVO_ID, true);
#endif
}
Benne::~Benne()
{
delete m_backSwitch;
delete m_frontSwitch;
}
void Benne::setBenneEmpty() {
isBenneEmpty = true;
}
void Benne::setBenneFull() {
isBenneEmpty = false;
}
bool Benne::getIsBenneEmpty() const
{
return isBenneEmpty;
}
bool Benne::getIsBenneFull() const
{
return !isBenneEmpty;
}
Benne::Status::Enum Benne::getStatus() const
{
return m_status;
}
void Benne::setStatus(Status::Enum status)
{
m_status = status;
}
void Benne::empty()
{
if(getStatus() != Status::CLOSED && getStatus() != Status::CLOSING)
{
#ifdef ROBOTHW
ServosNumeriques::moveAtSpeed(FORWARD_SPEED, SERVO_ID);
#else
qDebug() << "Bin is closing";
#endif
setStatus(Status::CLOSING);
}
}
void Benne::open()
{
if(getStatus() != Status::OPEN && getStatus() != Status::OPENING)
{
#ifdef ROBOTHW
ServosNumeriques::moveAtSpeed(BACKWARD_SPEED, SERVO_ID);
#else
qDebug() << "Bin is opening";
#endif
setStatus(Status::OPENING);
}
}
void Benne::update()
{
if(getStatus() == Status::CLOSING && isFrontSwitchActive())
{
stop();
setStatus(Status::CLOSED);
setBenneEmpty();
#ifndef ROBOTHW
qDebug() << "Bin is closed";
#endif
}
else if(getStatus() == Status::OPENING && isBackSwitchActive())
{
stop();
setStatus(Status::OPEN);
#ifndef ROBOTHW
qDebug() << "Bin is open";
#endif
}
}
void Benne::stop()
{
#ifdef ROBOTHW
ServosNumeriques::moveAtSpeed(0, SERVO_ID);
#endif
}
bool Benne::isFrontSwitchActive() const
{
return m_frontSwitch->ferme();
}
bool Benne::isBackSwitchActive() const
{
return m_backSwitch->ferme();
}