forked from anidev/612-2013
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeeder.cpp
76 lines (66 loc) · 1.46 KB
/
feeder.cpp
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
#include "feeder.h"
#include "612.h"
#ifdef Suzie
Feeder::Feeder(hw_info info1,hw_info info2) : feederMotor(info1,info2) {
#else
Feeder::Feeder(hw_info motorInfo,hw_info hallInfo) : counter(hallInfo.moduleNumber,hallInfo.channel),
feederMotor(motorInfo.moduleNumber,motorInfo.channel)
{
counter.Start();
#endif //Suzie
updateRegistry.addUpdateFunction(&update_helper,(void*)this);
direction = STOP;
counting = false;
}
Feeder::~Feeder() {
}
void Feeder::setRawPower(double power)
{
feederMotor.Set(power);
}
void Feeder::forward() {
direction = FORWARD;
update();
}
void Feeder::backward() {
direction = BACKWARD;
update();
}
void Feeder::stop() {
counting = false;
direction = STOP;
feederMotor.Set(direction * SPEED);
#ifndef Suzie
counter.Stop();
counter.Reset();
#endif
}
Feeder::direction_t Feeder::getDirection() {
return direction;
}
void Feeder::update() {
#ifndef Suzie
static unsigned int count = 0;
if(count%25 == 0) {
//std::printf("feeder hall effect: %d\n",counter.Get());
}
count++;
if(direction == STOP)
return;
if(!counting)
{
counter.Start();
counting = true;
}
if (counting && counter.Get() > 0)
{
stop();
count = 0;
return;
}
feederMotor.Set(direction * SPEED);
#endif
}
void Feeder::update_helper(void* obj) {
((Feeder*)obj)->update();
}