rotor.cpp 3.53 KB
Newer Older
andz's avatar
andz committed
1
2
3
4
5
6
///
/// @file       rotor.cpp
/// @copyright  Christian Obersteiner, Andreas Müller - CC-BY-SA 4.0
///
/// @brief  Contains all kind of rotor functions
///
chris007's avatar
chris007 committed
7
8
9

#include "rotor.h"

andz's avatar
andz committed
10
11
12
13
///
/// @brief  Constructor
///

chris007's avatar
chris007 committed
14
15
CRotor::CRotor()
{
16
    initRotor();
chris007's avatar
chris007 committed
17
18
}

andz's avatar
andz committed
19
20
21
22
///
/// @brief  Initialize all ADC Values and set Arduino Pins to a defined value.
///

andz's avatar
andz committed
23
void CRotor::initRotor()
chris007's avatar
chris007 committed
24
{
andz's avatar
andz committed
25
26
27
28
29
30
31
32
33
34
35
    if(AZIM)
    {
        //Pin Settings
        pinMode(AZIM_RE_CW, OUTPUT);
        pinMode(AZIM_RE_CCW, OUTPUT);
        pinMode(AZIM_RE_BREAK, OUTPUT);
        //All Relais Off
        digitalWrite(AZIM_RE_CW, HIGH); 
        digitalWrite(AZIM_RE_CCW, HIGH); 
        digitalWrite(AZIM_RE_BREAK, HIGH);
        //Initial Values
36
        m_bAzimuthBreakReleased = 0;
andz's avatar
andz committed
37
38
39
40
41
42
43
44
    }
    if(ELEV)
    {
        //Pin Settings
        pinMode(ELEV_RE_UP, OUTPUT);
        pinMode(ELEV_RE_DWN, OUTPUT);
        pinMode(ELEV_RE_BREAK, OUTPUT);
        //All Relais Off
45
46
47
48
49
        digitalWrite(ELEV_RE_UP, HIGH);
        digitalWrite(ELEV_RE_DWN, HIGH);
        digitalWrite(ELEV_RE_BREAK, HIGH);
        //Initial Values
        m_bElevationBreakReleased = 0;
andz's avatar
andz committed
50
    }
chris007's avatar
chris007 committed
51
52
}

andz's avatar
andz committed
53
54
55
56
///
/// @brief  Does all the rotor movement stuff
///

andz's avatar
andz committed
57
void CRotor::doRotor()
chris007's avatar
chris007 committed
58
{
andz's avatar
andz committed
59
60
61
62
63
64
65
66
67
68
69
70
71
    //Do all the Rotor Stuff here
    readRotSensors();
    if(AZIM)
    {
        //Do all the Azimuth Stuff here
    }
    if(ELEV)
    {
        //Do all the Elevation Stuff here
    }

}

andz's avatar
andz committed
72
73
74
75
///
/// @brief  Serial Debug output Function
///

andz's avatar
andz committed
76
77
78
79
80
81
82
83
84
85
86
87
88
void CRotor::debugOut()
{
    //debug Out
    readRotSensors();
    Serial.println("-----------------");
    Serial.write("Azim Value: ");
    Serial.write(m_uActualAzimuth);
    Serial.println("");
    Serial.write("Elev Value: ");
    Serial.write(m_uActualElevation);
    Serial.println("");
}

andz's avatar
andz committed
89
90
91
92
93
94
///
/// @brief Returns the actual Azimuth value in degree
///
/// @return uint16 actual Azimuth value in degree
///

andz's avatar
andz committed
95
96
97
98
99
uint16 CRotor::getActualAzimuth() const
{
    return m_uActualAzimuth;
}

andz's avatar
andz committed
100
101
102
103
104
105
///
/// @brief Returns the actual Elevation value in degree
///
/// @return actual Elevation value in degree
///

andz's avatar
andz committed
106
107
108
uint16 CRotor::getActualElevation() const
{
    return m_uActualElevation;
chris007's avatar
chris007 committed
109
110
}

andz's avatar
andz committed
111
112
113
114
115
116
117
118
///
/// @brief Sets the actual Azimuth value in degree and checks valid range
///
/// @param pAzimuth Azimuth value to be set
///
/// @return Error Code
///

andz's avatar
andz committed
119
CRotor::rotorError CRotor::setAzimuth(uint16 pAzimuth)
chris007's avatar
chris007 committed
120
{
andz's avatar
andz committed
121
122
123
124
125
126
127
128
129
    if(pAzimuth >= AZIM_MIN && pAzimuth <= AZIM_MAX)
    {
        m_uSetAzimuth = pAzimuth;
        return CRotor::ROT_OK;
    }
    else
    {
        return CRotor::ROT_VAL_OUT_OF_RANGE;
    }
chris007's avatar
chris007 committed
130
131
}

andz's avatar
andz committed
132
133
134
135
136
137
138
139
///
/// @brief Sets the actual Elevation value in degree and checks valid range
///
/// @param pElevation Elevation value to be set
///
/// @return Error Code
///

andz's avatar
andz committed
140
CRotor::rotorError CRotor::setElevation(uint16 pElevation)
chris007's avatar
chris007 committed
141
{
andz's avatar
andz committed
142
143
144
145
146
147
148
149
150
    if(pElevation >= ELEV_MIN && pElevation <= ELEV_MAX)
    {
        m_uSetElevation = pElevation;
        return CRotor::ROT_OK;
    }
    else
    {
        return CRotor::ROT_VAL_OUT_OF_RANGE;
    }
andz's avatar
andz committed
151
152
}

andz's avatar
andz committed
153
154
155
156
157
158
///
/// @brief Reads out the Sensor values and stores them
///
/// @return Error Code
///

andz's avatar
andz committed
159
CRotor::rotorError CRotor::readRotSensors()
andz's avatar
andz committed
160
161
162
{
    m_uActualAzimuth = (uint16)(readADC(AZIM_POT)/AZIM_DEG);
    m_uActualElevation = (uint16)(readADC(ELEV_POT)/ELEV_DEG);
andz's avatar
andz committed
163
164
    
    return CRotor::ROT_OK;
andz's avatar
andz committed
165
166
}

andz's avatar
andz committed
167
168
169
170
171
172
173
174
///
/// @brief Reads out an ADC Pin 4 times and returns the average
///
/// @param AdcPin ADC Pin to read
///
/// @return average ADC value
///

andz's avatar
andz committed
175
176
177
178
179
180
181
uint16 CRotor::readADC(int AdcPin)
{
    //Read ADC 4 times and calculate average
    uint16 adcValue = 0;
    for(int i = 0; i < 4; i++)
        adcValue += analogRead(AdcPin);
    adcValue = adcValue/4;
chris007's avatar
chris007 committed
182
}