-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCar.cpp
More file actions
76 lines (65 loc) · 1.92 KB
/
CCar.cpp
File metadata and controls
76 lines (65 loc) · 1.92 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
#include "CCar.h"
#include "client.h"
//-----------------------------------constructor-------------------------
//
//-----------------------------------------------------------------------
CCar::CCar():
m_leftRightTrack(0),
m_brakeAccelerateTrack(0),
m_dFitness(0)
{
}
//-----------------------------Reset()------------------------------------
//
// Resets the car's fitness
//
//------------------------------------------------------------------------
void CCar::Reset()
{
//reset the fitness
m_dFitness = 0;
}
//-------------------------------Update()--------------------------------
//
// First we take sensor readings and feed these into the car's brain.
//
// The inputs are:
//
// The readings from the car sensors
//
// We receive two outputs from the brain.. lTrack & rTrack.
// So given a force for each track we calculate the resultant rotation
// and acceleration and apply to current velocity vector.
//
//-----------------------------------------------------------------------
bool CCar::Update(vector<SPoint> &objects)
{
//this will store all the inputs for the NN
vector<double> inputs;
//grab sensor readings
//input sensors into net
//inputs.push_back(m_vecdSensors[sr]);
//inputs.push_back(m_vecFeelers[sr]);
//update the brain and get feedback
vector<double> output = m_pItsBrain->Update(inputs, CNeuralNet::active);
//make sure there were no errors in calculating the
//output
if (output.size() < CParams::iNumOutputs)
{
return false;
}
//assign the outputs to the sweepers left & right tracks
m_leftRightTrack = output[0];
m_brakeAccelerateTrack = output[1];
//calculate steering forces
return true;
}
//------------------------- EndOfRunCalculations() -----------------------
//
//------------------------------------------------------------------------
void CCar::EndOfRunCalculations()
{
// Calculate fitness
char *argv[] = { "", ""};
m_dFitness = runCar(m_pItsBrain);
}