-2

I'm working with a Nao from Aldebaran and I want to write a python script to check if the battery is charging or not.

There is a documentation about the naoqi modules. I found this event 1. But this is an event. In my opinion I can wait for an event, but I can't read it like a bool. Am I right?

tux007
  • 282
  • 1
  • 3
  • 17

3 Answers3

1

This linked page shows that there are Current and Charge% values available to read. I would test those and see if the sign of Current changes when charging, compared to running on battery. Alternately, check if Charge% rises fast enough to detect that charging is in progress.

AShelly
  • 34,686
  • 15
  • 91
  • 152
0

You can use ALMemory API to subscribe to the event "BatteryChargingFlagChanged" : http://doc.aldebaran.com/2-4/naoqi/core/almemory-api.html#ALMemoryProxy::subscribeToEvent__ssCR.ssCR.ssCR

This method takes a callback: just define one which set a flag you can use.

  • Well, I don't want to subscribe to an event, because I just want to have a script which gives a result immediately. So the way to use the "current sensor" is better. – tux007 Jun 20 '16 at 14:26
0

In my opinion I can wait for an event, but I can't read it like a bool. Am I right?

Not possible for battery. Each event that is published sends a signal, which "flips" a switch in ALMemory. You can only read the value or state of a quantity if such memory key exists for them. Otherwise, the information is lost and cannot be retrieved.

For example, each time the charge percentage changes, an event triggers and sends a signal to this memory key:

Device/SubDeviceList/Battery/Charge/Sensor/Value

You can then directly read this value with a supplied API, the same way you described in your question by a method. For charging, there is simply no such key.

You could try:

mem = ALProxy(ALMemory, pip, pport)
mem.getData("BatteryPowerPluggedChanged")

to access the boolean variable of Event: "BatteryPowerPluggedChanged", and you will get true / false. But this does not help you because it won't reflect real time changes if you are not subscribed to the event beforehand.

Hope this helps.

Jerry Hu
  • 357
  • 5
  • 17