How can I use the battery sensor

Requests regarding how to set up experiments in ARGoS.
Ryan
Posts: 40
Joined: Wed Oct 23, 2019 3:26 am

How can I use the battery sensor

Postby Ryan » Sun Aug 02, 2020 8:14 am

Hey, I try to use the battery sensor and show the Time left in seconds. I have added the sensor. But when I try to print out the variable of Timeleft, it shows there are infinite time. It is more likely that this battery does not enable. So how can I enable this battery sensors.

Code: Select all

m_pcBattery = GetSensor <CBatteryDefaultSensor >("battery"); const CCI_BatterySensor::SReading & tBatteryReads = m_pcBattery->GetReading(); Real timeleft = tBatteryReads.AvailableCharge; std::cout<<" TimeLeft:" << timeleft <<"\n";

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

Re: How can I use the battery sensor

Postby pincy » Sun Aug 02, 2020 8:43 pm

Can you share a more detailed report of the problem?
  1. Where is this code written?
  2. What XML did you write to activate the sensor?
I made ARGoS.

Ryan
Posts: 40
Joined: Wed Oct 23, 2019 3:26 am

Re: How can I use the battery sensor

Postby Ryan » Mon Aug 03, 2020 1:32 am

In the controllers folder:

Code: Select all

void CFootBot::Init(TConfigurationNode& t_node){ m_pcBattery = GetSensor <CBatteryDefaultSensor >("battery"); } void CFootBot::ControlStep() { const CCI_BatterySensor::SReading & tBatteryReads = m_pcBattery->GetReading(); Real timeleft = tBatteryReads.AvailableCharge; std::cout<<"TimeLeft:" << timeleft <<"\n"; }
In the XML:

Code: Select all

<sensors> <battery implementation="default" /> </sensors>

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

Re: How can I use the battery sensor

Postby pincy » Mon Aug 03, 2020 2:42 am

In the .argos file, you need to configure the battery in two places:

Code: Select all

<controllers> <my_controller ...> <sensors> ... <battery implementation="default" /> </sensors> ... </my_controller> </controllers> <arena> <foot-bot ...> ... <battery id="battery_0" discharge_model="time" delta="0.001" /> </foot-bot> </arena>
The parameter "delta" of the battery is how much of the battery is lost at every time step. So, if you want your battery to last 1000 time steps, then delta is 1 / 1000.

I found a small bug in the way the battery is discharged. Please update ARGoS and recompile it from the sources. If you need assistance with that, let me know.
I made ARGoS.

Ryan
Posts: 40
Joined: Wed Oct 23, 2019 3:26 am

Re: How can I use the battery sensor

Postby Ryan » Fri Aug 07, 2020 5:03 pm

Now, I tried to add the footbot in the loopfunction file. And I tried to set the battery sensor in model of "DischargeModelTimeMotion". But it seems that the value of TimeLeft has no change.

In the loop function file:

Code: Select all

void CLoopFunctions::Init(TConfigurationNode& t_node) { /* * Create the foot-bot and get a reference to its battery */ m_pcFootBot = new CFootBotEntity( "fb", // entity id "fdc" // controller id as set in the XML ); AddEntity(*m_pcFootBot); m_pcBattery = &dynamic_cast<CBatteryEquippedEntity&>(m_pcFootBot->GetBatterySensorEquippedEntity()); // m_pcDischargeModelMotion = new CBatteryDischargeModelMotion(); // m_pcDischargeModelTime = new CBatteryDischargeModelTime(); m_pcDischargeModelTimeMotion = new CBatteryDischargeModelTimeMotion(); m_pcDischargeModelTimeMotion->SetDelta(0.01); m_pcDischargeModelTimeMotion->SetPosFactor(0.3); m_pcDischargeModelTimeMotion->SetOrientFactor(0.2); m_pcDischargeModelTimeMotion->SetBattery(m_pcBattery); m_pcDischargeModelTimeMotion->operator()(); m_pcBattery->SetAvailableCharge(0.01); }

In the controller file:

Code: Select all

void Init(TConfigurationNode& t_node){ m_pcBattery = GetSensor <CBatteryDefaultSensor >("battery"); m_pcBattery->Update(); } void ControlStep() { const CCI_BatterySensor::SReading & tBatteryReads = m_pcBattery->GetReading(); Real timeleft = tBatteryReads.AvailableCharge; std::cout<<" TimeLeft:" << timeleft <<"\n"; }


Return to “How to... ?”