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
96fc0a64
Commit
96fc0a64
authored
7 months ago
by
Samuel Tardieu
Browse files
Options
Downloads
Patches
Plain Diff
Separate relative tick count from encoder
parent
3e35e85d
No related branches found
No related tags found
1 merge request
!4
Separate relative tick count from encoder
Pipeline
#97897
passed
7 months ago
Stage: check
Stage: build
Stage: test
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
controller/src/encoders.rs
+18
-10
18 additions, 10 deletions
controller/src/encoders.rs
controller/src/logic/mod.rs
+8
-2
8 additions, 2 deletions
controller/src/logic/mod.rs
with
26 additions
and
12 deletions
controller/src/encoders.rs
+
18
−
10
View file @
96fc0a64
...
...
@@ -7,8 +7,6 @@ use embassy_stm32::{
pub
struct
Encoders
<
'a
>
{
left
:
Qei
<
'a
,
TIM3
>
,
right
:
Qei
<
'a
,
TIM2
>
,
count_left
:
u16
,
count_right
:
u16
,
}
pub
struct
EncoderValue
{
...
...
@@ -16,6 +14,11 @@ pub struct EncoderValue {
direction
:
Direction
,
}
pub
struct
Relative
{
count_left
:
u16
,
count_right
:
u16
,
}
impl
core
::
fmt
::
Debug
for
EncoderValue
{
fn
fmt
(
&
self
,
f
:
&
mut
core
::
fmt
::
Formatter
<
'_
>
)
->
core
::
fmt
::
Result
{
write!
(
...
...
@@ -36,12 +39,7 @@ impl Encoders<'_> {
let
left
=
Qei
::
new
(
tim3
,
QeiPin
::
new_ch1
(
pa6
),
QeiPin
::
new_ch2
(
pa7
));
let
right
=
Qei
::
new
(
tim2
,
QeiPin
::
new_ch1
(
pa0
),
QeiPin
::
new_ch2
(
pa1
));
pac
::
TIM2
.ccer
()
.modify
(|
w
|
w
.set_ccp
(
1
,
true
));
Self
{
left
,
right
,
count_left
:
0
,
count_right
:
0
,
}
Self
{
left
,
right
}
}
pub
fn
read
(
&
self
)
->
(
EncoderValue
,
EncoderValue
)
{
...
...
@@ -56,9 +54,19 @@ impl Encoders<'_> {
},
)
}
}
impl
Relative
{
pub
fn
new
(
encoders
:
&
Encoders
<
'_
>
)
->
Self
{
let
(
count_left
,
count_right
)
=
(
encoders
.left
.count
(),
encoders
.right
.count
());
Self
{
count_left
,
count_right
,
}
}
pub
fn
ticks
(
&
mut
self
)
->
(
i16
,
i16
)
{
let
(
left
,
right
)
=
(
self
.left
.count
(),
self
.right
.count
());
pub
fn
ticks
(
&
mut
self
,
encoders
:
&
Encoders
<
'_
>
)
->
(
i16
,
i16
)
{
let
(
left
,
right
)
=
(
encoders
.left
.count
(),
encoders
.right
.count
());
(
ticks_since
(
&
mut
self
.count_left
,
left
),
ticks_since
(
&
mut
self
.count_right
,
right
),
...
...
This diff is collapsed.
Click to expand it.
controller/src/logic/mod.rs
+
8
−
2
View file @
96fc0a64
use
crate
::{
encoders
::
Encoders
,
tb6612fng
::
Tb6612fng
};
use
crate
::{
encoders
::{
Encoders
,
Relative
},
tb6612fng
::
Tb6612fng
,
};
use
embassy_executor
::
Spawner
;
use
embassy_stm32
::{
peripherals
::
WWDG
,
time
::
hz
};
use
futures
::
FutureExt
;
...
...
@@ -14,13 +17,16 @@ pub const I2C_ADDRESS: u8 = 0x57;
struct
State
{
_i2c
:
I2C2
,
encoders
:
Encoders
<
'static
>
,
tick_count
:
Relative
,
}
impl
State
{
fn
new
(
i2c2
:
I2C2
,
encoders
:
Encoders
<
'static
>
)
->
Self
{
let
tick_count
=
Relative
::
new
(
&
encoders
);
Self
{
_i2c
:
i2c2
,
encoders
,
tick_count
,
}
}
}
...
...
@@ -144,7 +150,7 @@ fn process_command(
response
.push
(
watchdog
::
get_shutdown_timeout
())
.unwrap
();
}
[
CMD_ENCODER_TICKS
]
=>
{
let
(
left
,
right
)
=
state
.encoders
.ticks
(
);
let
(
left
,
right
)
=
state
.
tick_count
.ticks
(
&
state
.
encoders
);
let
(
left
,
right
)
=
(
left
.to_le_bytes
(),
right
.to_le_bytes
());
response
.push
(
left
[
0
])
.unwrap
();
response
.push
(
left
[
1
])
.unwrap
();
...
...
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