Hormodular 1.0
Locomotion gait discovery by using digital hormones on modular robots
bool hormodular::ModularRobot::run ( unsigned long  runTime)

Runs the modular robot distributed controller for a given amount of time.

Parameters:
runTimeAmount of time (in ms) the controller will be run.
Returns:
True if completed successfully, false otherwise
{
    //-- Movement loop
    unsigned long runTimeUs = 1000*runTime;

    while( elapsed_time < runTimeUs )
    {
        if ( elapsed_time % (COMMUNICATION_PERIOD_MS*1000) == 0)
        {
            //-- Process incoming hormones
            for(int i = 0; i < (int) modules.size(); i++)
                modules[i]->processHormones();

            //-- Get oscillator parameters from gait table:
            for( int i = 0; i < (int) modules.size(); i++)
                modules[i]->updateOscillatorParameters();
        }

        //-- Update joint values
        for ( int i = 0; i < (int) modules.size(); i++)
            joint_values[i] = modules[i]->calculateNextJointPos();

        //-- Send joint values
//        robotInterface->setProperty("LED", "toggle");
        robotInterface->sendJointValues(joint_values, step_ms);

//            //-- Debug: get joint values to check if it is ok
//            std::vector<float> feedback = robotInterface->getJointValues();
//            for (int i = 0; i < (int) feedback.size(); i++)
//                std::cout << feedback[i] << " ";
//            std::cout << std::endl;

        if ( elapsed_time % (COMMUNICATION_PERIOD_MS*1000) == 0)
        {
            //-- Send hormones
            for(int i = 0; i < (int) modules.size(); i++)
                modules[i]->sendHormones();
        }

        //-- Update time:
        for ( int i = 0; i < (int) modules.size(); i++)
            modules[i]->updateElapsedTime(step_ms);

        elapsed_time+=(unsigned long)(step_ms*1000);
        //std::cout << "Run time: " << elapsed_time << std::endl;
        //usleep( step_ms * 1000);

    }

    return true;
}
 All Classes Functions Variables Friends