Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
8f165048
Verified
Commit
8f165048
authored
2 months ago
by
dos
Browse files
Options
Downloads
Patches
Plain Diff
battery voltage and sensor adjustments
parent
2162821d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
python_payload/apps/sensors/__init__.py
+2
-0
2 additions, 0 deletions
python_payload/apps/sensors/__init__.py
python_payload/st3m/power.py
+7
-27
7 additions, 27 deletions
python_payload/st3m/power.py
with
9 additions
and
27 deletions
python_payload/apps/sensors/__init__.py
+
2
−
0
View file @
8f165048
...
@@ -37,6 +37,8 @@ def azimuth(vec):
...
@@ -37,6 +37,8 @@ def azimuth(vec):
def
relative_altitude
(
pascal
,
celsius
):
def
relative_altitude
(
pascal
,
celsius
):
# https://en.wikipedia.org/wiki/Hypsometric_equation
# https://en.wikipedia.org/wiki/Hypsometric_equation
if
pascal
<=
0
:
return
0
return
(
celsius
+
273.15
)
*
(
287
/
9.81
)
*
math
.
log
(
101325
/
pascal
,
math
.
e
)
return
(
celsius
+
273.15
)
*
(
287
/
9.81
)
*
math
.
log
(
101325
/
pascal
,
math
.
e
)
...
...
This diff is collapsed.
Click to expand it.
python_payload/st3m/power.py
+
7
−
27
View file @
8f165048
...
@@ -143,7 +143,7 @@ class Power:
...
@@ -143,7 +143,7 @@ class Power:
self
.
_ts
=
time
.
ticks_ms
()
self
.
_ts
=
time
.
ticks_ms
()
def
_battery_voltage_sample
(
self
)
->
float
:
def
_battery_voltage_sample
(
self
)
->
float
:
return
self
.
_adc
.
read_uv
()
*
2
/
1e6
return
self
.
_adc
.
read_uv
()
*
2
.1428
/
1e6
def
_update
(
self
)
->
None
:
def
_update
(
self
)
->
None
:
ts
=
time
.
ticks_ms
()
ts
=
time
.
ticks_ms
()
...
@@ -185,12 +185,13 @@ class Power:
...
@@ -185,12 +185,13 @@ class Power:
percentage
=
0
percentage
=
0
voltage_readings
=
[]
voltage_readings
=
[]
for
i
in
range
(
5
):
for
i
in
range
(
8
):
voltage_readings
.
append
(
self
.
_
adc
.
read_uv
()
*
2
/
1e6
)
voltage_readings
.
append
(
self
.
_
battery_voltage_sample
()
)
voltage_readings
.
sort
()
voltage_readings
.
sort
()
# take median
voltage_readings
=
voltage_readings
[
2
:
-
2
]
voltage
=
voltage_readings
[
2
]
# take average
voltage
=
sum
(
voltage_readings
)
/
len
(
voltage_readings
)
# print(voltage)
# print(voltage)
...
@@ -199,25 +200,4 @@ class Power:
...
@@ -199,25 +200,4 @@ class Power:
percentage
=
self
.
_batLUT
[
i
][
0
]
percentage
=
self
.
_batLUT
[
i
][
0
]
break
break
self
.
_prev_battery_percentages
.
pop
(
0
)
self
.
_prev_battery_percentages
.
append
(
percentage
)
# log.debug("percentage: " + str(percentage) + " %")
# log.debug("prev: " + str(self._prev_battery_percentages) + " %")
percent_list
=
self
.
_prev_battery_percentages
if
-
1
in
percent_list
:
return
percentage
return
percentage
# avoid division by zero in weird edge cases
listsum
=
sum
(
percent_list
)
if
(
listsum
==
0
)
or
(
percent_list
[
0
]
==
0
):
return
0
for
i
in
range
(
3
):
if
listsum
/
percent_list
[
0
]
==
3
:
# all values are the same, we settled on a value (might be the same as before but that's ok)
# print("check if new valid value/the end: "+str(time.ticks_diff(time.ticks_us(), ts)))
return
percentage
else
:
# we're still settling on a value, return previously settled value
return
self
.
_battery_percentage
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment