-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRAGearToothSensor.cpp
62 lines (54 loc) · 1.43 KB
/
RAGearToothSensor.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
/*****************************************************************************
* RAGearToothSensor.h -- Red Alert Gear Tooth Sensor
*
*****************************************************************************/
#include "RAGearToothSensor.h"
RAGearToothSensor::RAGearToothSensor(int channel, bool reverse,int teeth_per_rev, float dist_per_rev)
: m_counter(new Counter(channel)),
m_teeth_per_rev(teeth_per_rev),
m_reverse(reverse),
m_distance_per_rev(dist_per_rev)
{
m_counter->SetPulseLengthMode(7e-5);
}
RAGearToothSensor::RAGearToothSensor(int slot, int channel, bool reverse, int teeth_per_rev, float dist_per_rev)
: m_counter(new Counter(channel)),
m_teeth_per_rev(teeth_per_rev),
m_distance_per_rev(dist_per_rev)
{
m_counter->SetPulseLengthMode(7e-5);
}
RAGearToothSensor::~RAGearToothSensor()
{
delete m_counter;
}
INT32 RAGearToothSensor::Get()
{
int sign = m_reverse ? -1 : +1;
return m_counter->Get() * sign;
}
void RAGearToothSensor::Start()
{
m_counter->Start();
}
void RAGearToothSensor::Reset()
{
m_counter->Reset();
}
void RAGearToothSensor::Stop()
{
m_counter->Stop();
}
double RAGearToothSensor::GetRevolutions()
{
return static_cast<double>(Get()) /
static_cast<double>(m_teeth_per_rev);
}
double RAGearToothSensor::GetDistance()
{
return GetRevolutions() * m_distance_per_rev;
}
double RAGearToothSensor::PIDGet()
{
return GetDistance();
}