example "flocking.argos"

Requests regarding how to set up experiments in ARGoS.
alexprocopio
Posts: 7
Joined: Tue Oct 29, 2013 7:29 pm

Re: example "flocking.argos"

Postby alexprocopio » Wed Oct 15, 2014 8:23 pm

Hi, teacher!

I need help. Below is the code of two programs.

The first enables moving the light source and the robots are followed.
But this eh rectilinear trajectory.

The second, for the light source moving in the trajectory of a parabola, but not the right. The PosStep function runs only once?
The idea was to move the source point to point of the function y = (x ^ 2) / 3.


Codigo 1 - Trajetoria Retilinea

#include "my_loop_functions.h"
#include <stdio.h>
#include <stdlib.h>
#include<time.h>

/****************************************/
/****************************************/

MyLoopFunctions::MyLoopFunctions() :
pcLight(NULL) {
}

/****************************************/
/****************************************/

void MyLoopFunctions::Init(TConfigurationNode& t_node) {

// Set the pointer to the light
// Since the light has been added in the XML file,
// we can get a pointer to it once and use it for the
// rest of the experiment
pcLight = &dynamic_cast<CLightEntity&>(GetSpace().GetEntity("light"));

}

/****************************************/
/****************************************/

void MyLoopFunctions::PostStep() {
UInt32 temp=0;
Real x1=0, y1=0, x2=0, y2=0;

Real start_step=3;
Real end_step;//em quantos passos o passaro se movera?
Real duracao_experimento;


x1=-5.25, y1=9.19, x2=0, y2=0;

for (UInt32 cont=0;cont<40;cont++)
{
pcLight->SetPosition(CVector3(x1, y1, 0.5));
x1=x1 + 0.25;
y1=(x1*x1)/3;
}


time_t tempo_inicial;
time_t tempo_final;

if(GetSpace().GetSimulationClock() == 1)
{
printf ("%s \n", "-------------------------");
time (&tempo_inicial);
printf ("Inicial: %s", ctime (&tempo_inicial));
}

if(GetSpace().GetSimulationClock() == end_step)
{
time (&tempo_final);
printf ("Tempo final do percurso da ave: %s", ctime (&tempo_final));
printf ("Qtde de Passos da ave: %f", end_step);

//THROW_ARGOSEXCEPTION("\n #Passos da simulacao:" << GetSpace().GetSimulationClock() - 1);
}

if(GetSpace().GetSimulationClock() == duracao_experimento)
{
// printf ("\n*****Qtde de Passos da simulacao: %i", GetSpace().GetSimulationClock());
time (&tempo_final);
printf ("\nTEmpo Final da Simulacao : %s", ctime (&tempo_final));
THROW_ARGOSEXCEPTION("\n Qtde de Passos da simulacao:" << GetSpace().GetSimulationClock());
}

}
/****************************************/
CVector3 MyLoopFunctions::LinearInterpolation(const CVector3& c_start_pos,
const CVector3& c_end_pos,
Real un_start_step,
Real un_end_step)
{
if(GetSpace().GetSimulationClock() <= un_start_step) return c_start_pos;
if(GetSpace().GetSimulationClock() >= un_end_step) return c_end_pos;
return c_start_pos + // starting position
(c_end_pos - c_start_pos) / (un_end_step - un_start_step) * // interpolation factor
(GetSpace().GetSimulationClock() - un_start_step); // current step in the range
}

/****************************************/
REGISTER_LOOP_FUNCTIONS(MyLoopFunctions, "my_loop_functions");


Codigo 2 Trajetoria - Parabola


#include "my_loop_functions.h"
#include <stdio.h>
#include <stdlib.h>
#include<time.h>

/****************************************/
/****************************************/

MyLoopFunctions::MyLoopFunctions() :
pcLight(NULL) {
}

/****************************************/
/****************************************/

void MyLoopFunctions::Init(TConfigurationNode& t_node) {

// Set the pointer to the light
// Since the light has been added in the XML file,
// we can get a pointer to it once and use it for the
// rest of the experiment
pcLight = &dynamic_cast<CLightEntity&>(GetSpace().GetEntity("light"));

}

/****************************************/
/****************************************/

void MyLoopFunctions::PostStep() {
UInt32 temp=0;
Real x1=0, y1=0, x2=0, y2=0;

Real start_step=3;
Real end_step;//em quantos passos o passaro se movera?
Real duracao_experimento;


x1=-5.25, y1=9.19, x2=0, y2=0;

for (UInt32 cont=0;cont<40;cont++)
{
pcLight->SetPosition(CVector3(x1, y1, 0.5));
x1=x1 + 0.25;
y1=(x1*x1)/3;
}


time_t tempo_inicial;
time_t tempo_final;

if(GetSpace().GetSimulationClock() == 1)
{
printf ("%s \n", "-------------------------");
time (&tempo_inicial);
printf ("Inicial: %s", ctime (&tempo_inicial));
}

if(GetSpace().GetSimulationClock() == end_step)
{
time (&tempo_final);
printf ("Tempo final do percurso da ave: %s", ctime (&tempo_final));
printf ("Qtde de Passos da ave: %f", end_step);

//THROW_ARGOSEXCEPTION("\n #Passos da simulacao:" << GetSpace().GetSimulationClock() - 1);
}

if(GetSpace().GetSimulationClock() == duracao_experimento)
{
// printf ("\n*****Qtde de Passos da simulacao: %i", GetSpace().GetSimulationClock());
time (&tempo_final);
printf ("\nTEmpo Final da Simulacao : %s", ctime (&tempo_final));
THROW_ARGOSEXCEPTION("\n Qtde de Passos da simulacao:" << GetSpace().GetSimulationClock());
}

}

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

Re: example "flocking.argos"

Postby pincy » Sat Oct 18, 2014 12:35 pm

Hi Alex,

The PostStep() method (as well as PreStep()) is executed once per control step. Thus, the loop you have in this method shouldn't be there. Only the last computed value will be taken into account by ARGoS.

You should do something like this.

Code: Select all

Init() Get pointer to light Set initial time for light movement Set final time for light movement Save initial position of light (as set in the XML) Set final position of light PostStep() if(Current time step < initial time) return; else if(Current time step > final time) return; else Interpolate light position Set light position
Hope this helps.

Ciao!
Carlo
I made ARGoS.

alexprocopio
Posts: 7
Joined: Tue Oct 29, 2013 7:29 pm

Re: example "flocking.argos"

Postby alexprocopio » Sun Oct 19, 2014 1:57 am

hello, teacher!
thanks for the guidance.

Here are the videos of the simulations.

Trajetoria Semicircunferencia
https://www.youtube.com/watch?v=Iog8qYjNTj8

Trajetoria circular velocidade rapida
https://www.youtube.com/watch?v=YsZeX43ulB8

Trajetoria parabola velocidade rapida
https://www.youtube.com/watch?v=uNMeWflOG0M

Trajetoria senoidal
https://www.youtube.com/watch?v=RB4THHqewlY

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

Re: example "flocking.argos"

Postby pincy » Sun Oct 19, 2014 8:29 pm

Nice videos, they look cool! :-)

Cheers,
Carlo
I made ARGoS.


Return to “How to... ?”