Here is my problem, I have a robot that move around using a very simple controller. It moves around for 1000 fixed time-steps and after that I remove the robot completely and rebuild it. However, during the second 1000 time-steps it does not always have the same behavior. In the first 1000 time-steps the robot always behaves the same but, after reseting there seems to be a chance that the first simulation step happens slightly different. Here is a log showing the starting location of my robot, its location after the first step, and its fitness after 1000 time-steps, measured as the distance from its starting location:
Code: Select all
0 X: 0 Y: 1 Z: 0 After step X: -3.39179e-05 Y: 0.999519 Z: -2.18484e-05 fitness: 4.13157
0 X: 0 Y: 1 Z: 0 After step X: -0.00623131 Y: 0.998084 Z: -0.000101492 fitness: 4.27342
0 X: 0 Y: 1 Z: 0 After step X: -0.0112506 Y: 1.00676 Z: -0.00113736 fitness: 5.23277
0 X: 0 Y: 1 Z: 0 After step X: -3.39179e-05 Y: 0.999519 Z: -2.18484e-05 fitness: 4.13157
0 X: 0 Y: 1 Z: 0 After step X: -0.00564403 Y: 0.997333 Z: 0.00378123 fitness: 6.52574
0 X: 0 Y: 1 Z: 0 After step X: -0.0100982 Y: 1.0179 Z: -0.00769315 fitness: 4.67956
0 X: 0 Y: 1 Z: 0 After step X: -3.39179e-05 Y: 0.999519 Z: -2.18484e-05 fitness: 4.13157
0 X: 0 Y: 1 Z: 0 After step X: -3.39179e-05 Y: 0.999519 Z: -2.18484e-05 fitness: 4.13157
0 X: 0 Y: 1 Z: 0 After step X: -0.0100982 Y: 1.0179 Z: -0.00769315 fitness: 4.67956
0 X: 0 Y: 1 Z: 0 After step X: -3.48349e-05 Y: 0.999552 Z: -2.60479e-05 fitness: 4.34444
This is the main loop of my program:
Code: Select all
while(true){
for(int i = 0; i< NR_OF_IDS; i++) touches[i]=0;
if(internalTimer == 0){
std::cout << internalTimer << " ";
std::cout << " X: " << body[0]->getCenterOfMassPosition().getX();
std::cout << " Y: " << body[0]->getCenterOfMassPosition().getY();
std::cout << " Z: " << body[0]->getCenterOfMassPosition().getZ();
}
m_dynamicsWorld->stepSimulation(0.01, 1, 0.01);
if(internalTimer == 0){
std::cout << " After step X: " << body[0]->getCenterOfMassPosition().getX();
std::cout << " Y: " << body[0]->getCenterOfMassPosition().getY();
std::cout << " Z: " << body[0]->getCenterOfMassPosition().getZ() << " fitness: ";
}
for(int i=0; i < NR_OF_HINGES; i++){
btScalar motorCommand = 0;
for(int j=0; j < NR_OF_SENSORS; j++){
motorCommand += touches[j+4]*weights[j][i];
}
motorCommand = tanh(motorCommand);
motorCommand = motorCommand*45;
ActuateJoint(i, motorCommand, 0.01);
}
internalTimer++;
if (internalTimer == 1000) {
internalTimer = 0;
FitnessSave();
sleep(1);
DeleteRobot();
m_solver->reset();
CreateRobot();
}
}
Now, in order to fix this I have:
- - Tried different values for simulation step, including: stepSimulation(0.01, 1), stepSimulation(0.01, 0) and stepSimulation(0.01, 0, 0.01).
- Tried to reset the solver and reset srand().
- Tried to reset the internal time-step of m_dynamicsWorld by calling stepSimulation(0, 0, 0)
- Tried to make sure I am using the btSortedOverlappingPairCache instead of the btHashedOverlappingPairCache
- Tried to use the build in clientResetScene() function, both with and without rebuilding my robots.
- Tried to create an entirely new dynamic world, including recreating every single object that is passed to dynamic world on construction.
As a side note, I am using the ragdollDemo.cpp as a template, and my implementation extends GlutDemoApplication. For everything I did not know how to set, I used the settings of this Demo.