forked from JakobHeller/NatureInspiredComputing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmartKhepera.cpp
128 lines (98 loc) · 2.95 KB
/
SmartKhepera.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
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
#include "SmartKhepera.h"
#include <iostream>
static const std::string s_MaxSpeed = "speed";
static const std::string s_RbfNodeCount = "nodes";
static const std::string s_RbfSigma = "sigma";
static const std::string s_RbfLearnFactor = "learn";
static const std::string s_Help = "help";
static const std::string s_EndProgram = "exit";
void ListSettings();
CSmartKhepera::CSmartKhepera()
{
m_pRbfSettings = new CRbfSettings();
m_pUtil = new CKheperaUtility();
m_pControl = new CController(m_pUtil, m_pRbfSettings);
m_pOperate = new COperator(m_pUtil);
m_pValues = new CValueSystem(m_pUtil);
}
CSmartKhepera::~CSmartKhepera()
{
StopLearning();
StopRobot();
delete m_pValues;
delete m_pOperate;
delete m_pControl;
delete m_pUtil;
delete m_pRbfSettings;
}
void CSmartKhepera::StartRobot()
{
m_pControl->Start();
m_pOperate->Start();
}
void CSmartKhepera::StopRobot()
{
StopLearning();
m_pOperate->Stop();
m_pControl->Stop();
m_pUtil->SetSpeed(0, 0);
//m_pControl->ListNodes();
}
void CSmartKhepera::StartLearning()
{
m_pValues->Start();
}
void CSmartKhepera::StopLearning()
{
m_pValues->Stop();
}
void CSmartKhepera::StopMoving()
{
m_pOperate->Stop();
m_pUtil->SetSpeed(0, 0);
}
void CSmartKhepera::StartVerbosity()
{
m_pUtil->SetVerbosity(true);
}
void CSmartKhepera::StopVerbosity()
{
m_pUtil->SetVerbosity(false);
}
void CSmartKhepera::OpenSettingsMenu()
{
ListSettings();
std::string command;
double val;
do
{
std::cout << "What would you like to set? ";
std::cin >> command;
if (command != s_Help && command != s_EndProgram) std::cin >> val;
if (command == s_MaxSpeed) m_pUtil->MaxSpeed = val;
if (command == s_RbfNodeCount) m_pRbfSettings->SetMaxNodes(round(val));
//if (command == s_RbfSigma) CNode::Sigma = val;
if (command == s_RbfLearnFactor) m_pRbfSettings->SetLearn(val);
if (command == s_Help) ListSettings();
} while (command != s_EndProgram);
}
void ListSettings()
{
std::cout << "To enter a new setting, type its name followed by the new value into the console and press \'enter\'." << std::endl;
std::cout << "Possible settings: " << std::endl;
std::cout << " " << s_Help << " : lists this help" << std::endl;
std::cout << " " << s_EndProgram << " : exits the settings" << std::endl;
std::cout << " " << s_MaxSpeed << " : maximum robot speed" << std::endl;
std::cout << " " << s_RbfNodeCount << " : RBF network maximum node count" << std::endl;
//std::cout << " " << s_RbfSigma << " : RBF network node width" << std::endl;
std::cout << " " << s_RbfLearnFactor << " : RBF network node learning weight" << std::endl;
std::cout << std::endl;
}
void CSmartKhepera::SaveNodes(std::string path)
{
m_pControl->SaveNodesToFile(path);
}
void CSmartKhepera::LoadNodes(std::string path)
{
m_pControl->LoadNodesFromFile(path);
}