Skip to content

Voltage colors #3412

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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e487b2c
set up UI
Muxite Oct 24, 2024
d0eb031
Progress so far
Muxite Oct 26, 2024
af94b92
Merge branch 'master' of https://github.com/UBC-Thunderbots/Software …
Muxite Oct 26, 2024
61282d3
per motor control works on robot
Muxite Oct 26, 2024
2b88ee6
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Oct 26, 2024
7aa12bd
per motor updated based on comments
Muxite Nov 2, 2024
4e02b05
per motor ready for second test
Muxite Nov 4, 2024
523c476
Merge branch 'per-motor' of github.com:Muxite/Thunderbots-Muk into pe…
Muxite Nov 4, 2024
95c8b8a
removed backups
Muxite Nov 4, 2024
477d3f4
Merge branch 'master' of github.com:Muxite/Thunderbots-Muk into volta…
Muxite Nov 21, 2024
8483bc1
Implemented voltage indicator color changer, fixed getPercentage, tes…
Muxite Nov 26, 2024
fd3abff
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Nov 30, 2024
12b6577
Merge branch 'master' into voltage-colors
Muxite Jan 11, 2025
2be456a
Switched to using util color gradient.
Muxite Jan 11, 2025
9056bbd
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 11, 2025
bd78f7e
Need testing
Muxite Jan 12, 2025
9b7b91b
voltage colors tested and good to go
Muxite Jan 25, 2025
b596e6a
added util.py to BUILD
Muxite Mar 21, 2025
ffdd56c
Merge branch 'master' into voltage-colors
Muxite Mar 21, 2025
5bae8ee
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Mar 21, 2025
597e3d5
Update BUILD
Muxite Apr 6, 2025
fedf3c3
Update BUILD
Muxite Apr 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/software/thunderscope/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ py_library(
],
)

py_library(
name = "util",
srcs = ["//software/thunderscope:util.py"],
)

py_library(
name = "toast_msg_helper",
srcs = ["toast_msg_helper.py"],
Expand Down
35 changes: 17 additions & 18 deletions src/software/thunderscope/common/common_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pyqtgraph.Qt.QtWidgets import *
from pyqtgraph.Qt.QtCore import *
from software.py_constants import *
from software.thunderscope.util import color_from_gradient


class FloatSlider(QSlider):
Expand Down Expand Up @@ -147,23 +148,23 @@ def setValue(self, value: float) -> None:
"""
super(ColorProgressBar, self).setValue(int(value * self.decimals))

# clamp percent to make sure it's between 0% and 100%
percent = self.getPercentage()
color = color_from_gradient(
percent,
[0, 0.5, 1],
[255, 200, 0],
[0, 170, 180],
[0, 0, 0],
[255, 255, 255],
)

if percent < 0.5:
super(ColorProgressBar, self).setStyleSheet(
"QProgressBar::chunk"
"{"
f"background: rgb(255, {255 * (2 * percent)}, 0)"
"}"
)
else:
super(ColorProgressBar, self).setStyleSheet(
"QProgressBar::chunk"
"{"
f"background: rgb({255 * 2 * (1 - percent)}, 255, 0)"
"}"
)
# Extract color into CSS form.
super(ColorProgressBar, self).setStyleSheet(
"QProgressBar::chunk"
"{"
f"background: rgb({color.red()}, {color.green()}, {color.blue()})"
"}"
)

def getPercentage(self):
"""Gets the current percentage between 0 and 1 from the current value
Expand All @@ -173,9 +174,7 @@ def getPercentage(self):
1,
max(
0,
int(
(self.value() - self.minimum()) / (self.maximum() - self.minimum())
),
(self.value() - self.minimum()) / (self.maximum() - self.minimum()),
),
)

Expand Down