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
a5daac6a
Commit
a5daac6a
authored
7 months ago
by
Samuel Tardieu
Browse files
Options
Downloads
Patches
Plain Diff
Rename Python methods used to set speed
parent
0bf2943d
Branches
Branches containing commit
Tags
Tags containing commit
3 merge requests
!16
Resolve "Add README to the firmware package"
,
!15
Resolve "Remove bootloader.py"
,
!14
Resolve "Use automatic mode by default"
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Cargo.lock
+1
-1
1 addition, 1 deletion
Cargo.lock
controller/Cargo.toml
+1
-1
1 addition, 1 deletion
controller/Cargo.toml
controller/python/controller.py
+23
-25
23 additions, 25 deletions
controller/python/controller.py
controller/src/logic/pid_control.rs
+1
-1
1 addition, 1 deletion
controller/src/logic/pid_control.rs
with
26 additions
and
28 deletions
Cargo.lock
+
1
−
1
View file @
a5daac6a
...
@@ -299,7 +299,7 @@ dependencies = [
...
@@ -299,7 +299,7 @@ dependencies = [
[[package]]
[[package]]
name = "controller"
name = "controller"
version = "0.6.
0
"
version = "0.6.
1
"
dependencies = [
dependencies = [
"bootloader-params",
"bootloader-params",
"build-support",
"build-support",
...
...
This diff is collapsed.
Click to expand it.
controller/Cargo.toml
+
1
−
1
View file @
a5daac6a
...
@@ -4,7 +4,7 @@ description = "Firmware for DC Motor Driver Hat DFR0592"
...
@@ -4,7 +4,7 @@ description = "Firmware for DC Motor Driver Hat DFR0592"
authors.workspace
=
true
authors.workspace
=
true
edition.workspace
=
true
edition.workspace
=
true
license.workspace
=
true
license.workspace
=
true
version
=
"0.6.
0
"
# Update in python/controller.py as well
version
=
"0.6.
1
"
# Update in python/controller.py as well
[lints]
[lints]
workspace
=
true
workspace
=
true
...
...
This diff is collapsed.
Click to expand it.
controller/python/controller.py
+
23
−
25
View file @
a5daac6a
...
@@ -64,18 +64,21 @@ class Controller:
...
@@ -64,18 +64,21 @@ class Controller:
)
)
raise
WhoAmIMismatch
(
error
)
raise
WhoAmIMismatch
(
error
)
def
set_motor_speed
(
self
,
left
:
Optional
[
float
],
right
:
Optional
[
float
]):
def
set_
raw_
motor_speed
(
self
,
left
:
Optional
[
float
],
right
:
Optional
[
float
]):
"""
Set the motor speed between -1
00
and 1
00
. None means not to
"""
Set the motor speed between -1
27
and 1
27
. None means not to
change the motor value. Using None for both motors will put
change the motor value. Using None for both motors will put
the controller board in standby mode and motors will stop.
"""
the controller board in standby mode and motors will stop.
The speed set through this method will not be regulated by
the builtin PID controller.
"""
def
convert
(
v
:
Optional
[
float
],
arg
:
str
):
def
convert
(
v
:
Optional
[
float
],
arg
:
str
):
if
v
is
None
:
if
v
is
None
:
return
-
128
return
-
128
if
not
isinstance
(
v
,
Real
)
or
v
<
-
1
00
or
v
>
1
00
:
if
not
isinstance
(
v
,
Real
)
or
v
<
-
1
27
or
v
>
1
27
:
raise
ValueError
(
raise
ValueError
(
f
"
{
arg
}
motor speed
"
f
"
{
arg
}
motor speed
"
"
must be a number between -1
00
and 1
00
, or None
"
"
must be a number between -1
27
and 1
27
, or None
"
)
)
return
round
(
v
)
return
round
(
v
)
...
@@ -84,19 +87,20 @@ class Controller:
...
@@ -84,19 +87,20 @@ class Controller:
list
(
struct
.
pack
(
"
bb
"
,
convert
(
left
,
"
left
"
),
convert
(
right
,
"
right
"
))),
list
(
struct
.
pack
(
"
bb
"
,
convert
(
left
,
"
left
"
),
convert
(
right
,
"
right
"
))),
)
)
def
get_motor_speed
(
self
)
->
Optional
[
tuple
[
int
,
int
]]:
def
get_raw_motor_speed
(
self
)
->
Optional
[
tuple
[
int
,
int
]]:
"""
Get the left and right motor speed as a tuple, or None if in standby.
"""
"""
Get the left and right motor speed as a tuple, or None if in standby.
Each speed will be between -127 and 127.
"""
(
left
,
right
)
=
self
.
_read
(
self
.
MOTOR_SPEED
,
2
,
"
bb
"
)
(
left
,
right
)
=
self
.
_read
(
self
.
MOTOR_SPEED
,
2
,
"
bb
"
)
return
(
left
,
right
)
if
left
!=
0x80
and
right
!=
0x80
else
None
return
(
left
,
right
)
if
left
!=
0x80
and
right
!=
0x80
else
None
def
set_automatic_motor_speed
(
self
,
left
:
int
,
right
:
int
):
def
set_motor_speed
(
self
,
left
:
int
,
right
:
int
):
"""
Set the motor speed in ticks by 10th of seconds.
"""
"""
Set the motor speed in ticks by 100th of seconds. Each motor speed
must be comprised between -32767 and 32767.
"""
def
check
(
v
:
int
,
arg
:
str
):
def
check
(
v
:
int
,
arg
:
str
):
if
v
<
-
32767
or
v
>
32767
:
if
v
<
-
32767
or
v
>
32767
:
raise
ValueError
(
raise
ValueError
(
f
"
{
arg
}
automatic motor speed must be a number
"
f
"
{
arg
}
motor speed must be a number
"
+
"
between -32767 and 32767
"
+
"
between -32767 and 32767
"
)
)
return
v
return
v
...
@@ -105,24 +109,18 @@ class Controller:
...
@@ -105,24 +109,18 @@ class Controller:
list
(
struct
.
pack
(
"
<hh
"
,
check
(
left
,
"
left
"
),
check
(
right
,
"
right
"
))),
list
(
struct
.
pack
(
"
<hh
"
,
check
(
left
,
"
left
"
),
check
(
right
,
"
right
"
))),
)
)
def
get_automatic_motor_speed
(
self
):
def
get_motor_speed
(
self
):
"""
Get the left and right automatic motor speed as a tuple, or None if
"""
Get the left and right motor speed as a tuple, or None if
the system is not in automatic mode.
"""
the speed has been set by the raw mode method or if the
motors have been put into standby mode. The speed is in
ticks by 100th of seconds.
"""
(
left
,
right
)
=
self
.
_read
(
self
.
AUTOMATIC_MOTOR_SPEED
,
4
,
"
<hh
"
)
(
left
,
right
)
=
self
.
_read
(
self
.
AUTOMATIC_MOTOR_SPEED
,
4
,
"
<hh
"
)
return
(
left
,
right
)
if
left
!=
-
32768
else
None
return
(
left
,
right
)
if
left
!=
-
32768
else
None
def
set_left_motor_speed
(
self
,
speed
:
float
):
"""
Set the left motor speed between -100 and 100.
"""
self
.
set_motor_speed
(
speed
,
None
)
def
set_right_motor_speed
(
self
,
speed
:
float
):
"""
Set the right motor speed between -100 and 100.
"""
self
.
set_motor_speed
(
None
,
speed
)
def
standby
(
self
):
def
standby
(
self
):
"""
Stop the motors by putting the controller board in standby
"""
Stop the motors by putting the controller board in standby
mode.
"""
mode.
"""
self
.
set_motor_speed
(
None
,
None
)
self
.
set_
raw_
motor_speed
(
None
,
None
)
def
get_encoder_ticks
(
self
)
->
tuple
[
int
,
int
]:
def
get_encoder_ticks
(
self
)
->
tuple
[
int
,
int
]:
"""
Retrieve the encoder ticks since the last time it was
"""
Retrieve the encoder ticks since the last time it was
...
@@ -134,9 +132,9 @@ class Controller:
...
@@ -134,9 +132,9 @@ class Controller:
def
get_status
(
self
)
->
dict
[
str
,
bool
]:
def
get_status
(
self
)
->
dict
[
str
,
bool
]:
"""
Return a dict with status fields:
"""
Return a dict with status fields:
-
"
moving
"
: True if at least one motor is moving, False otherwise
-
"
moving
"
: True if at least one motor is moving, False otherwise
-
"
automatic
"
: True if the motors are in
automatic
mode, False otherwise
"""
-
"
controlled
"
: True if the motors are in
controlled
mode, False otherwise
"""
(
status
,)
=
self
.
_read
(
self
.
STATUS
,
1
,
"
B
"
)
(
status
,)
=
self
.
_read
(
self
.
STATUS
,
1
,
"
B
"
)
return
{
"
moving
"
:
(
status
&
1
)
!=
0
,
"
automatic
"
:
(
status
&
2
)
!=
0
}
return
{
"
moving
"
:
(
status
&
1
)
!=
0
,
"
controlled
"
:
(
status
&
2
)
!=
0
}
def
set_motor_shutdown_timeout
(
self
,
duration
:
float
):
def
set_motor_shutdown_timeout
(
self
,
duration
:
float
):
"""
Set the duration in seconds after which the motors will
"""
Set the duration in seconds after which the motors will
...
...
This diff is collapsed.
Click to expand it.
controller/src/logic/pid_control.rs
+
1
−
1
View file @
a5daac6a
...
@@ -77,5 +77,5 @@ fn build_speed_command(
...
@@ -77,5 +77,5 @@ fn build_speed_command(
PidUnit
::
from_int
(
i32
::
from
(
measured_ticks
)),
PidUnit
::
from_int
(
i32
::
from
(
measured_ticks
)),
)
)
.round
()
.round
()
.clamp
(
-
1
00
,
1
00
)
as
i8
as
u8
.clamp
(
-
1
27
,
1
27
)
as
i8
as
u8
}
}
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