-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserInput.cpp
66 lines (51 loc) · 1.11 KB
/
UserInput.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
63
64
65
66
/*
* UserInput.cpp
*
* Created on: Apr 1, 2013
* Author: dam7633
*/
#include "UserInput.h"
#include <iostream>
#include <sstream>
#define UI_THREAD_PRIORITY (9)
using namespace std;
UserInput::UserInput(PlantContext *c) :
Thread("User Input"),
context(c) {
}
UserInput::~UserInput() {
}
void* UserInput::run() {
double kp, ki, kd;
double ref = 0.0;
char inp;
// Lower the priority of this thread so that it
// does not block the controller.
setPriority(UI_THREAD_PRIORITY);
context->setRef(ref);
cout << "Enter a command (h for help) \n";
while (!killThread) {
cout << "> ";
cout.flush();
cin >> inp;
switch( inp ) {
case 'p':
cin >> kp >> ki >> kd;
((PlantController*)context->getControlLoop())->setParameters(kp, ki, kd);
break;
case 'r':
cin >> ref;
context->setRef(ref);
break;
default:
cout << "Invalid command!\n\n";
case 'h':
cout << "Commands are: \n" <<
"\th - Help (this message)\n" <<
"\tr - Set reference (Usage: r newRef)\n" <<
"\tp - Set controller parameters (Usage: p newKp newKi newKd" << endl;
break;
}
}
return NULL;
}