Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Alberto Ruiz Garcia
Firmware
Commits
663913a1
Commit
663913a1
authored
7 years ago
by
Matthias Grob
Committed by
ChristophTobler
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Battery: added simple fusion of capacity based estimate and voltage based estimate
parent
823d4234
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/modules/systemlib/battery.cpp
+10
-9
10 additions, 9 deletions
src/modules/systemlib/battery.cpp
src/modules/systemlib/battery.h
+1
-0
1 addition, 0 deletions
src/modules/systemlib/battery.h
with
11 additions
and
9 deletions
src/modules/systemlib/battery.cpp
+
10
−
9
View file @
663913a1
...
...
@@ -56,6 +56,7 @@ Battery::Battery() :
_voltage_filtered_v
(
-
1.
f
),
_current_filtered_a
(
-
1.
f
),
_discharged_mah
(
0.
f
),
_discharged_mah_loop
(
0.
f
),
_remaining_voltage
(
1.
f
),
_remaining_capacity
(
1.
f
),
_remaining
(
1.
f
),
...
...
@@ -159,8 +160,9 @@ Battery::sumDischarged(hrt_abstime timestamp, float current_a)
// Ignore first update because we don't know dt.
if
(
_last_timestamp
!=
0
)
{
const
float
dt
=
(
timestamp
-
_last_timestamp
)
/
1e6
;
// current[A] * 1000 = [mA]; dt[s] / 3600 = [h]
_discharged_mah
+=
(
current_a
*
1e3
f
)
*
(
dt
/
3600.
f
);
// mAh since last loop: (current[A] * 1000 = [mA]) * (dt[s] / 3600 = [h])
_discharged_mah_loop
=
(
current_a
*
1e3
f
)
*
(
dt
/
3600.
f
);
_discharged_mah
+=
_discharged_mah_loop
;
}
_last_timestamp
=
timestamp
;
...
...
@@ -170,10 +172,8 @@ void
Battery
::
estimateRemaining
(
float
voltage_v
,
float
current_a
,
float
throttle_normalized
,
bool
armed
)
{
// correct battery voltage locally for load drop to avoid estimation fluctuations
const
float
bat_r
=
_r_internal
.
get
();
if
(
bat_r
>=
0.
f
)
{
voltage_v
+=
bat_r
*
current_a
;
if
(
_r_internal
.
get
()
>=
0.
f
)
{
voltage_v
+=
_r_internal
.
get
()
*
current_a
;
}
else
{
// assume quadratic relation between throttle and current
...
...
@@ -190,9 +190,10 @@ Battery::estimateRemaining(float voltage_v, float current_a, float throttle_norm
// remaining battery capacity based on used current integrated time
_remaining_capacity
=
math
::
max
(
1.
f
-
_discharged_mah
/
_capacity
.
get
(),
0.
f
);
// if battery capacity is known, use discharged current for estimate,
// but don't show more than voltage estimate
_remaining
=
fminf
(
_remaining_voltage
,
_remaining_capacity
);
// if battery capacity is known, fuse voltage measurement with used capacity
_remaining
=
0.999
f
*
_remaining
+
0.001
f
*
_remaining_voltage
;
_remaining
-=
_discharged_mah_loop
/
_capacity
.
get
();
_remaining
=
math
::
max
(
_remaining
,
0.
f
);
}
else
{
// else use voltage
...
...
This diff is collapsed.
Click to expand it.
src/modules/systemlib/battery.h
+
1
−
0
View file @
663913a1
...
...
@@ -116,6 +116,7 @@ private:
float
_voltage_filtered_v
;
float
_current_filtered_a
;
float
_discharged_mah
;
float
_discharged_mah_loop
;
float
_remaining_voltage
;
///< normalized battery charge level remaining based on voltage
float
_remaining_capacity
;
///< normalized battery charge level remaining based on capacity
float
_remaining
;
///< normalized battery charge level, selected based on config param
...
...
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