-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPosCurrentCtl
164 lines (125 loc) · 4.82 KB
/
PosCurrentCtl
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
/***
* _________ _____ __________ ___________ .__ _____ _______ _______ ____
* \_ ___ \ / _ \\______ \ \__ ___/___ | | ____ / \ _____ ____ \ _ \ \ _ \/_ |
* / \ \/ / /_\ \| | _/ | |_/ __ \| | _/ __ \ / \ / \\__ \ / \ / /_\ \ / /_\ \| |
* \ \____/ | \ | \ | |\ ___/| |_\ ___// Y \/ __ \| | \ \ \_/ \ \ \_/ \ |
* \______ /\____|__ /______ / |____| \___ >____/\___ >____|__ (____ /___| / \_____ / /\ \_____ /___|
* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
*/
#include <stdint.h>
#include <stdbool.h>
#include <driverlib/rom.h>
#include "Sensors/QEIModule.h"
#include "Actuators/PWMModule.h"
#include "utils/ControlScheme.h"
#include "utils/RGBDriver.h"
#include "Controllers/SpeedController.h"
#include "Controllers/PositionController.h"
#include "Controllers/CurrentController.h"
#include "utils/MainMenu.h"
#include "drivers/buttons.h"
#include "ConfigTiva.h"
#include "Communication/UARTModule.h"
#include "Storage/USBStickModule.h"
#include "Sensors/CurrentMeas.h"
//#define TARGET_IS_BLIZZARD_RB1
uint32_t refIter = 0;
int main(void) {
//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPULazyStackingEnable();
ROM_FPUEnable();
// Initialize system Clock
TivaCfg_SysClk();
// Config RGB
RGB_Config();
// Initialize buttons
ButtonsInit();
// Config QEI
QEI_Config();
// Current Transducer config
CurrentT_Config();
uint32_t currCtlFS = 1000;
ClassPWM pwmModule;
PWM_Construct(&pwmModule, 0, 30000, 12, currCtlFS);
ClassCtlScheme ctlScheme;
CtlScheme_Construct(&ctlScheme, &pwmModule, currCtlFS);
ClassUSBStick stickStorage;
USBStick_Construct(&stickStorage, currCtlFS);
USBStick_Enable(&stickStorage);
while (_deviceState != eSTATE_DEVICE_READY) {
USBStick_Run(&stickStorage);
}
//USBStick_Disable(&stickStorage);
// ClassUART uartModule;
// UART_Construct(&uartModule, 1, 115200, SysCtlClockGet(), 500);
CtlScheme_AddComModule(&ctlScheme, &stickStorage._USBStickHandler);
//CtlScheme_AddComModule(&ctlScheme, &uartModule._uartHandeler);
// float speedKP = 6;
// float speedKI = 10;
// float speedSat = 11.4;
// float speedISat = 11.4;
//
// ClassSpeedCtl speedCtl;
// SpeedCtl_Construct(&speedCtl, currCtlFS, speedKP, speedKI, speedSat,
// speedISat);
// float currKP = 9;
// float currKI = 0;
// float currSat = 2;
// float currISat = 2;
//
// ClassPosCtl posCtl;
// PosCtl_Construct(&posCtl, currCtlFS / 10, currKP, currKI, currSat, currISat);
//
float currKP = 1;
float currKI = 6;
float currSat = 12;
float currISat = 12;
ClassCurrentCtl currCtl;
CurrentCtl_Construct(&currCtl, currCtlFS, currKP, currKI, currSat,
currISat);
// CtlScheme_Connect(&ctlScheme, &speedCtl._speedHandler,
// &pwmModule._pwmHandler);
// CtlScheme_Connect(&ctlScheme, &posCtl._posHandler, &speedCtl._speedHandler);
CtlScheme_Connect(&ctlScheme, &currCtl._currentHandler,
&pwmModule._pwmHandler);
float CurrRef = -2; //[A]
currCtl._currentIOPorts._inPortsAdder[0] = &CurrRef;
currCtl._currentIOPorts._inAdderPortsNum++;
USBStick_AddVar2Stream(&stickStorage, &currCtl._currentPID._ctlVar,
"Current");
USBStick_AddVar2Stream(&stickStorage, &currCtl._currentPID._ctlSignalI,
"ICurr");
USBStick_AddVar2Stream(&stickStorage, &currCtl._currentPID._ctlSignalP,
"Pcurr");
USBStick_AddVar2Stream(&stickStorage, &currCtl._currentPID._ctlVarRef,
"Pref");
// USBStick_AddVar2Stream(&stickStorage, &posCtl._posPID._ctlVar, "Pos");
// USBStick_AddVar2Stream(&stickStorage, &posCtl._posPID._ctlSignalI, "Ipos");
// USBStick_AddVar2Stream(&stickStorage, &speedCtl._speedPID._ctlVar, "Speed");
// USBStick_AddVar2Stream(&stickStorage, &speedCtl._speedPID._ctlSignalI, "Isp");
//USBStick_AddVar2Stream(&stickStorage, &speedCtl._speedPID._ctlSignal, "DCV");
//USBStick_AddVar2Stream(&stickStorage, &speedCtl._current, "Current");
// UART_AddVar2Stream(&uartModule, &posCtl._posPID._ctlVar, "Pos");
// UART_AddVar2Stream(&uartModule, &speedCtl._speedPID._ctlVar, "Speed");
// UART_AddVar2Stream(&uartModule, &speedCtl._speedPID._ctlSignal, "DCV");
// UART_Enable(&uartModule);
//
// UART_PrintMenu(&uartModule);
// UART_PrintHeader(&uartModule);
while (1) {
if (CtlScheme_IsRunning(&ctlScheme) == false) {
USBStick_Run(&stickStorage);
}
runMenu(&ctlScheme);
if (refIter >= 300000 * 1 && CtlScheme_IsRunning(&ctlScheme)) {
refIter = 0;
CurrRef *= -1;
} else {
refIter++;
}
}
}