Getting charge state of the robot

I’m interested in getting a boolean value indicating whether the robot is charging or not. I thought I might be able to do this by looking at the ROS /battery topic, but whether the robot is plugged in or not, this returns a positive value for the current. I also checked, but I assume that comes from the same source as the result is the same.

I also had a look at how the battery state is being published and there’s a check based on robot_status['pimu']['charger_connected'], but this always seems to be false.

Looking a bit more at the way the battery message in ROS is populated, I noticed that the hardware ID I get from pimu_hardware_id = self.robot.pimu.board_info['hardware_id'] in stretch_ros/stretch_driver at 16bba2f2608dec249bf159b42d9a0000505f2a86 · hello-robot/stretch_ros · GitHub returns 2, but that’s not included in the if statements.

I fixed that, but the charging state history and almost never contains values which indicate charging or discharging, and so the charging state is never set to anything.

Is there some other method of getting the state of charge, or should I just rely on using the pimu charger connected flag?

For the time being I replaced the lines which added to the voltage history and computed the filtered state with

        if robot_status['pimu']['charger_connected']:
            self.charging_state = BatteryState.POWER_SUPPLY_STATUS_CHARGING
        elif not robot_status['pimu']['charger_connected']:
            self.charging_state = BatteryState.POWER_SUPPLY_STATUS_DISCHARGING

Hi @mstaniaszek, welcome to the forum.

The Stretch 2 has a mechanical switch in its charge port that is tied to robot_status['pimu']['charger_connected']. Stretch RE1 doesn’t have this switch and therefore this value will always be zero.

For the RE1 @bshah has developed a simple script that can detect the charger by monitoring the reported battery voltage. We’ll share this here once he’s back in the office early next week.