-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImplementKipper.h
More file actions
192 lines (149 loc) · 4.13 KB
/
Copy pathImplementKipper.h
File metadata and controls
192 lines (149 loc) · 4.13 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
ImplementKipper - a library for a kipper
Copyright (C) 2011-2014 J.A. Woltjer.
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ImplementKipper_h
#define ImplementKipper_h
#include <Arduino.h>
#include <EEPROM.h>
#include "ConfigImplementKipper.h"
#include "VehicleGps.h"
#include "VehicleTractor.h"
// software version of this library
#define KIPPER_VERSION 0.1
class ImplementKipper {
private:
//-------------
// data members
//-------------
// Default angle calibration set
int angle_calibration_data[3];
int angle_calibration_points[3];
int angle;
// Default steer calibration set
int steer_calibration_data[3];
int steer_calibration_points[3];
int steer;
int last_steer;
int speed;
// Update timer
unsigned long update_age;
boolean update_flag;
// Variables concerning adjust loop
byte mode;
int setpoint;
int offset;
int angle_hist[50];
int angle_sum; //Running sum of xte_hist
int angle_avg; //Average of sum
int dangle; //DXTE
byte hist_count; //Counter of sum
byte hist_time; //Integration time (seconds * 5)
// PID variables
float P;
byte KP;
float I;
byte KI;
float D;
byte KD;
// Timers for end shutoff
int shutoff_time;
boolean shutoff_wide;
boolean shutoff_narrow;
unsigned long shutoff_timer;
// Objects
VehicleTractor * tractor;
//-------------------------------------------------------------
// private member functions implemented in ImplementKipper.cpp
//-------------------------------------------------------------
int getActualAngle();
int getActualSteer();
void setSetpoint();
void readOffset();
boolean readCalibrationData();
void printCalibrationData();
void writeCalibrationData();
void wipeCalibrationData();
public:
// -----------------------------------------------------------
// public member functions implemented in ImplementKipper.cpp
// -----------------------------------------------------------
// Constructor
ImplementKipper(VehicleTractor * _tractor);
void update(byte _mode);
void adjust(int _direction);
void calibrate();
// ----------------------------------------------------------------
// public inline member functions implemented in ImplementKipper.h
// ----------------------------------------------------------------
inline boolean resetCalibration(){
return readCalibrationData();
}
inline void commitCalibration(){
wipeCalibrationData();
writeCalibrationData();
}
// -------
// Getters
// -------
inline int getSteer(){
return steer;
}
inline int getAngle(){
return angle;
}
inline int getSetpoint(){
return setpoint;
}
inline int getSteerCalibrationPoint(int _i){
return steer_calibration_points[_i];
}
inline int getAngleCalibrationPoint(int _i){
return angle_calibration_points[_i];
}
inline byte getKP(){
return KP;
}
inline byte getKI(){
return KI;
}
inline byte getKD(){
return KD;
}
inline int getOffset(){
return offset;
}
// -------
// Setters
// -------
inline void setSteerCalibrationData(int _i){
steer_calibration_data[_i] = analogRead(STEER_SENS_PIN);
}
inline void setAngleCalibrationData(int _i){
angle_calibration_data[_i] = analogRead(ANGLE_SENS_PIN);
}
inline void setKP(byte _value){
KP = _value;
}
inline void setKI(byte _value){
KI = _value;
}
inline void setKD(byte _value){
KD = _value;
}
inline void setOffset(int _value){
offset = _value;
}
};
#endif