Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector Battery Status #382

Merged
merged 44 commits into from
Sep 2, 2024
Merged

Vector Battery Status #382

merged 44 commits into from
Sep 2, 2024

Conversation

AshMartian
Copy link
Contributor

@AshMartian AshMartian commented Sep 1, 2024

First off, thank you so much for this repository and keeping Vector alive 💚

I saw a closed PR on battery status #310, and thought it would be a nice way to learn how Wire Pod works. So I obsessively tackled creating a nice UX for displaying battery stats. This could resolve #309

  • On the home page, load the sdk info, if no bots are found, show nothing.
  • New sdk-api endpoint for battery status /api-sdk/get_battery
  • For each bot found, render a battery icon with a vector face that indicates the status.
    • Battery status is refreshed for each bot 3s after rendering
    • Face states for network loading/error, charging, roaming and needs charger.
    • Battery voltage determines the "percentage" shown, which is a log10 non-linear curve approximation (hence ~%)
    • Battery number level / percentage reported from Vector indicates color, 2-3 (100-50%) = green, 1 (50-20%) = yellow, 0 (>20%) = red
      • Battery percentage capped at 20% if level reported is 1
    • Batteries are in a flex box that should go full width and wrap. I only have 2 vectors to validate this visually.
    • Battery charge time remaining rendered in lower left of battery
  • Tooltip on battery hover shows the bot serial, estimated charge percentage, and raw voltage
  • Clicking on a battery takes the browser straight to the bot settings
    • Bot settings page renders a single battery view for the bot in question
  • Found some fetch issues when setting up my bots on BLE, tackled these and re-configured my bots with much higher success, might help with [HELP] Issue with vector connection during setup #284
  • Checking for length of robots in connTimer, to resolve:
panic: runtime error: index out of range [1] with length 1

goroutine 601 [running]:
github.com/kercre123/wire-pod/chipper/pkg/wirepod/sdkapp.connTimer(0x1)
        /home/ash/wire-pod/chipper/pkg/wirepod/sdkapp/robot.go:149 +0x21c
created by github.com/kercre123/wire-pod/chipper/pkg/wirepod/sdkapp.newRobot in goroutine 28
        /home/ash/wire-pod/chipper/pkg/wirepod/sdkapp/robot.go:107 +0x4ec
  • New common.js file for loading sdkInfo and getting battery status, since these are needed on home and settings
Untitled.video.-.Made.with.Clipchamp.2.mp4

Full Charged
image
Roaming
image
Needs Charging
image
Charging with ETA
image
Charging with Tooltip
image
Loading
image
Network error
image

Issues

  • Thinking the % approximation should be done and returned from the api endpoint, to serve 3rd party usages as well.
  • Vector only sends new voltages while charging or just leaving the charger.
    • Unsure if this is an sdk limitation or firmware, can't find any documentation but seems out of scope for this PR

@Zomboy4313
Copy link

One small thing I would change is instead of using a question mark, maybe use a ~ symbol since it means approximately

@AshMartian
Copy link
Contributor Author

Good idea @Zomboy4313, implemented

@kercre123
Copy link
Owner

This implementation is so cute! A battery indicator has been requested before, but I've been hesitant because of the same issues you ran into. Specifically: new voltages being sent not very often. I believe this to be a firmware limitation. It is also hard to be precise with the battery since there isn't a "fuel gauge" like a smartphone would have. Your curve idea seems accurate enough, though.

Just one nitpick: when no bots are authenticated, there is a bit of empty space between the header and content in the main page. If that is fixed, I will merge this.

I like this idea a lot. I wonder if we could replicate the "Vector is doing ..." indicator that was in the Vector mobile app. Vector has an event stream which provides things like that. In my testing though, I couldn't figure out how to correspond a "RobotState.Status" with one of the proto-defined statuses.

@kercre123 kercre123 merged commit 8f92694 into kercre123:main Sep 2, 2024
1 check passed
@AshMartian
Copy link
Contributor Author

Awesome ideas @kercre123! Thanks for removing the botStats element on no bots!

I also pondered more animations and expanding on the robot status, included is a blank face which we could make more gif animations for various status states! (the home charging png I made in photoshop) To be clear, Vector's firmware was not open sourced, correct? We can't push firmware updates or on board logic with the vector-cloud server?

I was also thinking that this makes the "Bot Settings" page obsolete, since it's much faster to click into the bots from the homepage, but felt removing that was outside scope and didn't want to interrupt any workflows utilizing that functionality.

@kercre123
Copy link
Owner

Right, we can't change the robot firmware. Some parts were open-sourced, but we don't have enough of the code to fully build our own firmware. Even if we could build it, we'd have no way to sign it and run it on a production bot.

The animations were fully open-sourced. The more complex ones have sprite sequences which could be turned into GIFs. For regular animation files, a dev robot could be used to capture it.

The Bot Settings page is probably unneeded now.. I think I'll leave it in for now since all of the YouTube wire-pod setup tutorials still refer to it and such.

@AshMartian
Copy link
Contributor Author

Oooo awesome tip on those sprite sequences! I'll keep them in mind and maybe raise a PR for an animated home/charging GIF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Battery usage statistic
3 participants