# Getting charge state of the robot

**URL:** <https://forum.hello-robot.com/t/getting-charge-state-of-the-robot/597>\
**Category:** Ask\
**Created:** [February 17, 2023, 2:30pm UTC](https://forum.hello-robot.com/t/getting-charge-state-of-the-robot/597 "2023-02-17T14:30:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mstaniaszek](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@mstaniaszek](https://forum.hello-robot.com/u/mstaniaszek)\
**Post date:** [February 17, 2023, 2:30pm UTC](https://forum.hello-robot.com/t/getting-charge-state-of-the-robot/597/1 "2023-02-17T14:30:47Z")

</div>

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 `stretch_robot_battery_check.py`, 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](https://github.com/hello-robot/stretch_ros/blob/16bba2f2608dec249bf159b42d9a0000505f2a86/stretch_core/nodes/stretch_driver#L127-L148) 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

```auto
        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

```

---

<div class="post-metadata">

**Author:** ![aedsinger](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/aedsinger/32/6_2.png) [@aedsinger](https://forum.hello-robot.com/u/aedsinger)\
**Post date:** [February 18, 2023, 12:28am UTC](https://forum.hello-robot.com/t/getting-charge-state-of-the-robot/597/2 "2023-02-18T00:28:20Z")

</div>

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.

–Aaron
