|
Hormodular 1.0
Locomotion gait discovery by using digital hormones on modular robots
|
Objective function. {
//-- Create a fitness object to maximize the objective (distance travelled in m)
FitnessP fitness (new FitnessMax);
//-- We get the genotype:
FloatingPoint::FloatingPoint* genotype = (FloatingPoint::FloatingPoint*) individual->getGenotype(0).get();
//-- Value to store the fitness (distance travelled)
double fitness_value = 0;
//-- Here we record the genotypes on a gait table file:
std::cout << "[Evolve] Convert to gait table!" << std::endl;
genotypeToRobot( genotype );
//-- Reset the robot:
std::cout << "[Evolve] Reset!" << std::endl;
robotInterface->reset();
//-- Run the robot:
std::cout << "[Evolve] Run!" << std::endl;
//-- Here you put the main loop
unsigned long elapsed_time = 0; //-- Should be in uS
unsigned long max_time_us = max_runtime*1000;
joint_values.clear();
for (int i = 0; i < (int) n_modules; i++)
joint_values.push_back(0);
while( elapsed_time < max_time_us )
{
//-- Update joint values
for ( int i = 0; i < (int) oscillators.size(); i++)
joint_values[i] = oscillators[i]->calculatePos(elapsed_time);
//-- Send joint values
robotInterface->sendJointValues(joint_values, timestep);
elapsed_time+=(unsigned long) (timestep*1000);
//std::cout << "[Evolve] Time: " << elapsed_time << "us" << std::endl;
}
//-- Select the fitness value (distance travelled in m)
fitness_value = robotInterface->getTravelledDistance();
//-- Set the fitness value
fitness->setValue( fitness_value);
std::cout << "[Evolve] Return!" << std::endl;
return fitness;
}
Here is the call graph for this function:
![]() |
1.7.4