i would like to track the positions of the centres of kilbots, but i think that what is saving is an off-centre coordinate (maybe the led position) I also found that the communications rays are not from centre to centre but from led to led. is it correct? my tracking function is as follows:
Code: Select all
#include "track_loop_functions.h"
#include <iostream>
#include <fstream>
using namespace std;
ofstream myFile;
void CTrajectoryLoopFunctions::Init(TConfigurationNode& t_tree)
{
myFile.open ("track.csv", std::ofstream::out | std::ofstream::app);
}
void CTrajectoryLoopFunctions::Reset()
{
}
void CTrajectoryLoopFunctions::PostStep()
{
CSpace::TMapPerType& tKBMap = GetSpace().GetEntitiesByType("kilobot");
int tick = GetSpace().GetSimulationClock();
for (CSpace::TMapPerType::iterator it = tKBMap.begin(); it != tKBMap.end(); ++it)
{
CKilobotEntity* pcKB = any_cast<CKilobotEntity*>(it->second);
double x = pcKB->GetEmbodiedEntity().GetOriginAnchor().Position.GetX();
double y = pcKB->GetEmbodiedEntity().GetOriginAnchor().Position.GetY();
LOG << pcKB->GetId() << ": " << "t=" << tick << " x=" << x << " y=" << y << std::endl;
myFile << pcKB-> GetId() << "," << tick << "," << x << "," << y << std::endl;
}
}
void CTrajectoryLoopFunctions::Destroy()
{
myFile.close();
}
REGISTER_LOOP_FUNCTIONS(CTrajectoryLoopFunctions, "track_loop_functions")