Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Open-Cube FW
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
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
Open Cube
Open-Cube FW
Commits
104407c0
Commit
104407c0
authored
5 months ago
by
Václav Jelínek
Browse files
Options
Downloads
Patches
Plain Diff
Add reset funciton to motor encoders
parent
713e56ad
No related branches found
Branches containing commit
No related tags found
1 merge request
!12
Major update of menu visuals and example programs
Pipeline
#108034
passed
5 months ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
menu_programs/i2c_master.py
+8
-6
8 additions, 6 deletions
menu_programs/i2c_master.py
micropython/modules/opencube_motors/encoder_api.c
+8
-0
8 additions, 0 deletions
micropython/modules/opencube_motors/encoder_api.c
with
16 additions
and
6 deletions
menu_programs/i2c_master.py
+
8
−
6
View file @
104407c0
...
...
@@ -23,7 +23,9 @@ def i2c_master_run(robot):
while
True
:
robot
.
display
.
fill
(
0
)
robot
.
display
.
centered_text
(
f
"
I2C master
"
,
0
,
1
)
if
ADDRESS
in
robot
.
i2c_master
.
i2c
.
scan
():
scan
=
robot
.
i2c_master
.
i2c
.
scan
()
print
(
scan
)
if
ADDRESS
in
scan
:
connected
=
True
robot
.
display
.
text
(
f
"
Sending:
{
chr
(
data_sending
+
ASCII_a
)
}
"
,
0
,
16
,
1
)
robot
.
display
.
text
(
f
"
Received:
{
chr
(
data_received_parsed
)
}
"
,
0
,
24
,
1
)
...
...
@@ -35,11 +37,11 @@ def i2c_master_run(robot):
robot
.
display
.
text
(
'
<
'
,
0
,
54
,
1
)
robot
.
display
.
show
()
if
connected
:
robot
.
i2c_master
.
write
(
ADDRESS
,
(
data_sending
+
ASCII_a
).
to_bytes
(
1
,
'
big
'
))
data_received
=
robot
.
i2c_master
.
read
(
0x41
,
1
)
if
data_received
:
data_received_parsed
=
int
.
from_bytes
(
data_received
,
'
big
'
)
print
(
"
writing
"
)
robot
.
i2c_master
.
write
(
ADDRESS
,
(
data_sending
+
ASCII_a
).
to_bytes
(
1
,
'
big
'
))
#
data_received = robot.i2c_master.read(
ADDRESS
, 1)
#
if data_received:
#
data_received_parsed = int.from_bytes(data_received, 'big')
buttons
=
robot
.
buttons
.
pressed
()
if
buttons
[
Button
.
LEFT
]:
...
...
This diff is collapsed.
Click to expand it.
micropython/modules/opencube_motors/encoder_api.c
+
8
−
0
View file @
104407c0
...
...
@@ -73,6 +73,13 @@ static mp_obj_t encoder_get_speed(mp_obj_t self_in) {
static
MP_DEFINE_CONST_FUN_OBJ_1
(
encoder_get_speed_obj
,
encoder_get_speed
);
static
mp_obj_t
encoder_reset
(
mp_obj_t
self_in
)
{
encoder_obj_t
*
self
=
MP_OBJ_FROM_PTR
(
self_in
);
self
->
ref_position
=
opencube_encoders_get_position
(
self
->
port
);
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
encoder_reset_obj
,
encoder_reset
);
static
mp_obj_t
encoder_finalizer
(
mp_obj_t
self_in
)
{
encoder_obj_t
*
self
=
MP_OBJ_FROM_PTR
(
self_in
);
opencube_encoders_deinit
(
self
->
port
);
...
...
@@ -84,6 +91,7 @@ static const mp_rom_map_elem_t encoder_locals_dict[] = {
{
MP_ROM_QSTR
(
MP_QSTR_get_position
),
MP_ROM_PTR
(
&
encoder_get_position_obj
)},
{
MP_ROM_QSTR
(
MP_QSTR_set_position
),
MP_ROM_PTR
(
&
encoder_set_position_obj
)},
{
MP_ROM_QSTR
(
MP_QSTR_get_speed
),
MP_ROM_PTR
(
&
encoder_get_speed_obj
)},
{
MP_ROM_QSTR
(
MP_QSTR_reset
),
MP_ROM_PTR
(
&
encoder_reset_obj
)},
{
MP_ROM_QSTR
(
MP_QSTR___del__
),
MP_ROM_PTR
(
&
encoder_finalizer_obj
)},
};
static
MP_DEFINE_CONST_DICT
(
encoder_locals_dict_obj
,
encoder_locals_dict
);
...
...
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