is there a way to read out the battery state of Orbotix Ollie or Sphero? I want to do this in a swift ios app, but the SDK API description is a bit brief.
Asked
Active
Viewed 800 times
-3
-
you may want show what you have tired so far. We are not here for you to do all the work! – Devapploper Jan 02 '16 at 16:49
-
the problem is: i did not find any function to receive the batterystate-i assume it is just a value to read it out-i have no problem in getting sensor data, but the question is: is there a possibility at all or not implemented in the SDK? – cheese Jan 02 '16 at 17:13
-
updated my trys below on the answer from Paul Ruiz - before there was no try, because i was not aware of the PowerNotificationAsyncData – cheese Jan 02 '16 at 21:18
1 Answers
1
There's an async response that you can receive in 'handleResponse' that's an instance of RKGetPowerStateResponse that'll show up every ten seconds of so. Cast it over and you can get batteryVoltage, time since last charge, number of charge cycles the robot has gone through and an enumerated value for the power state. I'm not at a computer right now for giving you exact values, but you should be able to use autocomplete to get it :)

Paul Ruiz
- 2,396
- 3
- 27
- 47
-
Thanks for the answer, this was the missing link. Added the Observer Protocoll to the viewcontroller, started the `self.robot.addResponseObserver(self)`when robot is online, implemented `func handleAsyncMessage(message: RKAsyncMessage!, forRobot robot: RKRobotBase!) { if let bat = message as? RKPowerNotificationAsyncData { let powerstate = bat.state as RKBatteryPowerState print("Powerstate: \(powerstate)") } } ` but still get no battery values.. perhaps i have to wait... i will watch this and try figuring around. – cheese Jan 02 '16 at 21:13
-
missed the `self.robot.sendCommand(RKSetPowerNotificationCommand(state: true))` – cheese Jan 02 '16 at 21:37