-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleWalkingMain.cpp
50 lines (42 loc) · 1.2 KB
/
SimpleWalkingMain.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
// *************************************************************
// main.cpp
//
// Run a given CTRNN walker
//
// 8/27/94 Created
// 5/25/02 Revised for OS X
// *************************************************************
#include "LeggedAgent.h"
#include "CTRNN.h"
#include "random.h"
// Global constants
const double StepSize = 0.1;
const double RunDuration = 200;
const long RandomSeed = 1;
// The main program
int main(int argc, char* argv[])
{
LeggedAgent Insect;
// Load the CTRNN into the agent
char fname[] = "cpg.ns";
ifstream ifs;
ifs.open(fname);
if (!ifs) {
cerr << "File not found: " << fname << endl;
exit(EXIT_FAILURE);
}
ifs >> Insect.NervousSystem;
// Run the agent
SetRandomSeed(RandomSeed);
Insect.Reset(0, 0, 0);
for (double time = 0; time < RunDuration; time += StepSize) {
Insect.Step(StepSize);
cout << Insect.Leg.JointX << " " << Insect.Leg.JointY << " ";
cout << Insect.Leg.FootX << " " << Insect.Leg.FootY << " ";
cout << Insect.Leg.FootState << endl;
}
// Display the fitness
cout << "Average velocity = " << Insect.cx/RunDuration << endl;
// Finished
return 0;
}