Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DC motor driver hat
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software
DC motor driver hat
Commits
68d6cf91
Commit
68d6cf91
authored
8 months ago
by
Samuel Tardieu
Browse files
Options
Downloads
Patches
Plain Diff
Use an Atomic for MAX_MOTOR_PERCENTAGE
parent
1cd99b24
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
controller/src/logic.rs
+6
-5
6 additions, 5 deletions
controller/src/logic.rs
with
6 additions
and
5 deletions
controller/src/logic.rs
+
6
−
5
View file @
68d6cf91
...
@@ -13,13 +13,13 @@ use embassy_time::{Duration, Instant, Ticker};
...
@@ -13,13 +13,13 @@ use embassy_time::{Duration, Instant, Ticker};
use
heapless
::
Deque
;
use
heapless
::
Deque
;
use
i2c2_target
::{
I2C2
,
MESSAGE_SIZE
};
use
i2c2_target
::{
I2C2
,
MESSAGE_SIZE
};
static
MAX_MOTOR_PERCENTAGE
:
AtomicU8
=
AtomicU8
::
new
(
100
);
static
WATCHDOG_TICKS
:
AtomicU8
=
AtomicU8
::
new
(
5
);
static
WATCHDOG_TICKS
:
AtomicU8
=
AtomicU8
::
new
(
5
);
struct
State
{
struct
State
{
i2c
:
I2C2
,
i2c
:
I2C2
,
motors
:
Tb6612fng
<
'static
>
,
motors
:
Tb6612fng
<
'static
>
,
encoders
:
Encoders
<
'static
>
,
encoders
:
Encoders
<
'static
>
,
max_motor_percentage
:
u8
,
motor_speed
:
[
u8
;
2
],
motor_speed
:
[
u8
;
2
],
standby
:
bool
,
standby
:
bool
,
}
}
...
@@ -30,7 +30,6 @@ impl State {
...
@@ -30,7 +30,6 @@ impl State {
i2c
:
i2c2
,
i2c
:
i2c2
,
motors
,
motors
,
encoders
,
encoders
,
max_motor_percentage
:
100
,
motor_speed
:
[
0
,
0
],
motor_speed
:
[
0
,
0
],
standby
:
true
,
standby
:
true
,
}
}
...
@@ -40,7 +39,7 @@ impl State {
...
@@ -40,7 +39,7 @@ impl State {
fn
set_motor_speed
(
&
mut
self
,
ms
:
[
u8
;
2
])
{
fn
set_motor_speed
(
&
mut
self
,
ms
:
[
u8
;
2
])
{
let
(
max_pwm
,
mmp
)
=
(
let
(
max_pwm
,
mmp
)
=
(
self
.motors
.max_pwm
()
as
i32
,
self
.motors
.max_pwm
()
as
i32
,
i32
::
from
(
self
.max_motor_percentage
),
i32
::
from
(
MAX_MOTOR_PERCENTAGE
.load
(
Ordering
::
Relaxed
)
),
);
);
let
scaled_speed
=
|
speed
|
match
speed
as
i8
{
let
scaled_speed
=
|
speed
|
match
speed
as
i8
{
-
128
=>
None
,
-
128
=>
None
,
...
@@ -202,14 +201,16 @@ fn process_command(
...
@@ -202,14 +201,16 @@ fn process_command(
}
}
&
[
CMD_MAX_MOTOR_PERCENTAGE
,
p
]
=>
{
&
[
CMD_MAX_MOTOR_PERCENTAGE
,
p
]
=>
{
if
(
1
..=
100
)
.contains
(
&
p
)
{
if
(
1
..=
100
)
.contains
(
&
p
)
{
state
.max_motor_percentage
=
p
;
MAX_MOTOR_PERCENTAGE
.store
(
p
,
Ordering
::
Relaxed
)
;
}
else
{
}
else
{
defmt
::
warn!
(
"incorrect max percentage {}"
,
p
);
defmt
::
warn!
(
"incorrect max percentage {}"
,
p
);
return
false
;
return
false
;
}
}
}
}
[
CMD_MAX_MOTOR_PERCENTAGE
]
=>
{
[
CMD_MAX_MOTOR_PERCENTAGE
]
=>
{
response
.push_back
(
state
.max_motor_percentage
)
.unwrap
();
response
.push_back
(
MAX_MOTOR_PERCENTAGE
.load
(
Ordering
::
Relaxed
))
.unwrap
();
}
}
[
CMD_MOTOR_SPEED
,
ms
@
..
]
if
ms
.len
()
==
2
=>
{
[
CMD_MOTOR_SPEED
,
ms
@
..
]
if
ms
.len
()
==
2
=>
{
state
.set_motor_speed
([
ms
[
0
],
ms
[
1
]]);
state
.set_motor_speed
([
ms
[
0
],
ms
[
1
]]);
...
...
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