Problem in initialization of Array

Requests regarding how to set up experiments in ARGoS.
Waqar731
Posts: 65
Joined: Thu Oct 23, 2014 12:33 pm
Location: Pakistan
Contact:

Problem in initialization of Array

Postby Waqar731 » Mon Feb 16, 2015 2:42 pm

Hi,
I have made arena of 10X10. I have made an array in header file. And initialize it with 0 in control step. Now when at each step of movement of robot, the values initialize again and again. What can i do now to avoid re-initialization again and again.

Code: Select all

void CFootBotDistanceScannar::ControlStep() { m_pcWheels->SetLinearVelocity(m_fWheelVelocity, m_fWheelVelocity); for( int w=0;w<=9;w++) { for( int x=0;x<=9;x++) { DataStorageArray[w][x]=0.0f; } } }
While i initialize it in my .h file.

Code: Select all

private: Real DataStorageArray[10][10];
How can i do initialization only first time rather at each step of robot???


I have also tried to do it in initialization function.

Code: Select all

void CFootBotDistanceScannar::Init(TConfigurationNode& t_node) { for( int w=0;w<=9;w++) { for( int x=0;x<=9;x++) { DataStorageArray[w][x]=0.0f; printf("%s%f"," ", DataStorageArray[w][x]); } printf("\n\n"); } }
But still unable to initialize using the above function.



Thanks
Waqar Hussain

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Problem in initialization of Array

Postby pincy » Tue Feb 17, 2015 12:41 am

Hi,
I have made an array in header file. And initialize it with 0 in control step.
The method CCI_Controller::ControlStep() is executed in the main simulation loop. If you zero your array in this method, it will be zeroed every time step.

To zero the array only at init time, include your code in the method CCI_Controller::Init(). This method is executed only once at the beginning of an experiment.

The line:

Code: Select all

printf("%s%f"," ", DataStorageArray[w][x]);
is wrong. It should be:

Code: Select all

printf("%f ", DataStorageArray[w][x]);
Cheers,
Carlo
I made ARGoS.


Return to “How to... ?”