Log / Print input from sensors in Terminal and / or ARGoS simulator

Requests regarding how to set up experiments in ARGoS.
flobot
Posts: 3
Joined: Thu Sep 29, 2016 1:00 am

Log / Print input from sensors in Terminal and / or ARGoS simulator

Postby flobot » Wed Oct 12, 2016 10:25 pm

Hello,

I am starting out to use ARGoS and my goal is to create a new method for the footbot controller's control step for the diffusion_10 experiment.

I am trying to find a way to read / print / log the input coming from the sensors to no avail.

I've tried putting the following within

Code: Select all

RLOG << "m_pcProximity"; RLOG << m_pcProximity; std::cout << "m_pcProximity"; std::cout << m_pcProximity;
and

Code: Select all

RLOG << "cAccumulator"; RLOG << cAccumulator; std::cout << "cAccumulator"; std::cout << cAccumulator;
in footbot_diffusion.cpp

Code: Select all

void CFootBotDiffusion::ControlStep() { /* Get readings from proximity sensor */ const CCI_FootBotProximitySensor::TReadings& tProxReads = m_pcProximity->GetReadings(); /* Sum them together */ RLOG << "m_pcProximity"; //ADDED RLOG << m_pcProximity; //ADDED std::cout << "m_pcProximity"; //ADDED std::cout << m_pcProximity; //ADDED CVector2 cAccumulator; for(size_t i = 0; i < tProxReads.size(); ++i) { cAccumulator += CVector2(tProxReads[i].Value, tProxReads[i].Angle); } RLOG << "cAccumulator"; //ADDED RLOG << cAccumulator; //ADDED std::cout << "cAccumulator"; //ADDED std::cout << cAccumulator; //ADDED cAccumulator /= tProxReads.size(); /* If the angle of the vector is small enough and the closest obstacle * is far enough, continue going straight, otherwise curve a little */ CRadians cAngle = cAccumulator.Angle(); if(m_cGoStraightAngleRange.WithinMinBoundIncludedMaxBoundIncluded(cAngle) && cAccumulator.Length() < m_fDelta ) { /* Go straight */ m_pcWheels->SetLinearVelocity(m_fWheelVelocity, m_fWheelVelocity); } else { /* Turn, depending on the sign of the angle */ if(cAngle.GetValue() > 0.0f) { m_pcWheels->SetLinearVelocity(m_fWheelVelocity, 0.0f); } else { m_pcWheels->SetLinearVelocity(0.0f, m_fWheelVelocity); } } }

Are there any ways to either display the data in the ARGoS simulator log gui or a mac's terminal? Where can I put functions to output to the terminal or the ARGoS gui? and which functions should they be?

Any advice is appreciated, thanks a lot!

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

Re: Log / Print input from sensors in Terminal and / or ARGoS simulator

Postby pincy » Thu Oct 13, 2016 12:17 am

Hello,

LOG/LOGERR and cout/cerr both work in ARGoS, although it is better to use LOG/LOGERR because they are designed to be thread safe.

Both classes of commands are buffered. This means that nothing is printed unless you flush the buffer. To flush the buffer you must either put a std::endl at the end of the line, or call the method LOG.Flush() or LOGERR.Flush().

Cheers,
Carlo
I made ARGoS.

flobot
Posts: 3
Joined: Thu Sep 29, 2016 1:00 am

Re: Log / Print input from sensors in Terminal and / or ARGoS simulator

Postby flobot » Mon Oct 17, 2016 3:54 am

Thank you very much for your answer!

I can get it to work through:

Code: Select all

argos::LOG << stuff I want to print << std::endl;
But I was not able to use LOG.Flush(), could you perhaps provide me with an example?

Thanks again!

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

Re: Log / Print input from sensors in Terminal and / or ARGoS simulator

Postby pincy » Tue Oct 18, 2016 3:28 pm

Hello flobot,

I think you spotted a bug! :o

In fact, LOG.Flush() and LOGERR.Flush() are missing a call to ostream::flush(). So, even if you use these methods, their current implementation does not do what it is intended to.

I'll add a fix for this issue in the next release of ARGoS. In the meantime, your only option is using std::endl for flushing.

Cheers,
Carlo
I made ARGoS.

flobot
Posts: 3
Joined: Thu Sep 29, 2016 1:00 am

Re: Log / Print input from sensors in Terminal and / or ARGoS simulator

Postby flobot » Wed Oct 19, 2016 1:52 am

Haha I am glad it's a bug and not just me!

I hope you can resolve it, and keep up the great work, this platform is really good!

Cheers,

Florent


Return to “How to... ?”