-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlantContext.cpp
More file actions
71 lines (54 loc) · 1.29 KB
/
PlantContext.cpp
File metadata and controls
71 lines (54 loc) · 1.29 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
/*
* PlantContext.cpp
*
* Created on: Apr 1, 2013
* Author: dam7633
*/
#include "PlantContext.h"
#include <time.h>
#include <sys/siginfo.h>
#include "ControlLoop.h"
void timer_tick(union sigval sig) {
PlantContext *context = (PlantContext *)sig.sival_ptr;
context->getControlLoop()->step();
}
PlantContext::PlantContext() {
// TODO Auto-generated constructor stub
}
PlantContext::~PlantContext() {
// TODO Auto-generated destructor stub
}
void PlantContext::start() {
timer_t timer;
struct sigevent timerEvent;
struct itimerspec timerSpec;
SIGEV_THREAD_INIT(&timerEvent, timer_tick, this, NULL);
timerSpec.it_interval.tv_nsec = 100000000;
timerSpec.it_interval.tv_sec = 0;
timerSpec.it_value.tv_nsec = 100000000;
timerSpec.it_value.tv_sec = 0;
timer_create(CLOCK_REALTIME, &timerEvent, &timer);
timer_settime(timer, 0, &timerSpec, NULL);
}
double PlantContext::getError() {
return error;
}
void PlantContext::setError(double e) {
lastError = error;
error = e;
}
double PlantContext::getLastError() {
return lastError;
}
ControlLoop *PlantContext::getControlLoop() {
return controlLoop;
}
void PlantContext::setControlLoop(ControlLoop *cl) {
controlLoop = cl;
}
void PlantContext::setRef(double newRef) {
ref = newRef;
}
double PlantContext::getRef() {
return ref;
}