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());
}
}