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
886eb1ba
Commit
886eb1ba
authored
2 weeks ago
by
Václav Jelínek
Browse files
Options
Downloads
Patches
Plain Diff
Modify I2C and other constants
parent
6fec8d80
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
lib/cube/__init__.py
+1
-2
1 addition, 2 deletions
lib/cube/__init__.py
lib/menu_display.py
+2
-1
2 additions, 1 deletion
lib/menu_display.py
lib/robot.py
+11
-9
11 additions, 9 deletions
lib/robot.py
lib/robot_consts.py
+18
-10
18 additions, 10 deletions
lib/robot_consts.py
main/main.py
+1
-1
1 addition, 1 deletion
main/main.py
with
33 additions
and
23 deletions
lib/cube/__init__.py
+
1
−
2
View file @
886eb1ba
...
...
@@ -2,5 +2,4 @@ from .buzzer import Buzzer
from
.i2c_guard
import
I2CGuard
from
.sh1106
import
SH1106_I2C
from
.esp_config
import
Esp
from
.i2c_master
import
I2C_master
from
.i2c_slave
import
I2C_slave
\ No newline at end of file
from
.i2c_master
import
I2C_master
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/menu_display.py
+
2
−
1
View file @
886eb1ba
...
...
@@ -37,7 +37,8 @@ def display_fill_programs(robot, program_list, current_program):
robot
.
display
.
centered_text
(
'
< Programs >
'
,
DISPLAY_TITLE_POS
,
1
)
if
len
(
program_list
)
>
0
:
robot
.
display
.
centered_text
(
program_list
[
current_program
][
0
][:
-
3
],
DISPLAY_PROG_POS
,
1
)
display_fill_arrows
(
robot
)
if
len
(
program_list
)
>
1
:
display_fill_arrows
(
robot
)
else
:
robot
.
display
.
centered_text
(
"
cube is empty
"
,
DISPLAY_PROG_POS
,
1
)
...
...
This diff is collapsed.
Click to expand it.
lib/robot.py
+
11
−
9
View file @
886eb1ba
from
micropython
import
const
from
machine
import
Pin
,
I2C
,
Timer
,
WDT
from
time
import
sleep
,
ticks_ms
...
...
@@ -6,7 +7,9 @@ from lib import nxt, ev3, OC
from
lib.hw_defs.ports
import
SENSOR_PORT_PINS
,
MOTOR_PORT_PINS
from
lib.hw_defs.pins
import
*
from
lib.robot_consts
import
Sensor
,
Button
,
BAT_VOLTAGE_TURNOFF
,
BAT_TURNOFF_PERIODS
,
BAT_MEASURE_PERIOD
,
I2C_FREQ
,
PCF_CHECK_PERIOD
,
FW_VERSION
from
lib.robot_consts
import
Sensor
,
Button
,
BAT_VOLTAGE_TURNOFF
,
BAT_TURNOFF_PERIODS
,
BAT_MEASURE_PERIOD
from
lib.robot_consts
import
I2C_INTERNAL_BUS
,
I2C_INTERNAL_FREQ
,
PCF_CHECK_PERIOD
,
DISPLAY_WIDTH
,
DISPLAY_HEIGHT
,
FW_VERSION
from
lib.robot_consts
import
WDT_TIMEOUT
,
WDT_FEED_TIMER_PERIOD
import
motors_ll
import
brick_ll
...
...
@@ -23,8 +26,8 @@ class Robot:
# Set pins 0, 1 to input to correctly initialize HW UART0
Pin
(
0
,
mode
=
Pin
.
IN
)
Pin
(
1
,
mode
=
Pin
.
IN
)
self
.
i2c
=
I2C
(
1
,
sda
=
Pin
(
INTERNAL_I2C_SDA_PIN
),
scl
=
Pin
(
INTERNAL_I2C_SCK_PIN
),
freq
=
I2C_FREQ
)
self
.
i2c
=
I2C
(
I2C_INTERNAL_BUS
,
sda
=
Pin
(
INTERNAL_I2C_SDA_PIN
),
scl
=
Pin
(
INTERNAL_I2C_SCK_PIN
),
freq
=
I2C_
INTERNAL_
FREQ
)
self
.
i2c_lock
=
I2CGuard
()
self
.
mutex
=
None
self
.
sensors
=
Sensors
()
...
...
@@ -37,7 +40,7 @@ class Robot:
self
.
battery
=
brick_ll
.
Battery
()
self
.
buzzer
=
Buzzer
()
self
.
led
=
brick_ll
.
Led
()
self
.
display
=
SH1106_I2C
(
128
,
64
,
self
.
i2c
,
self
.
i2c_lock
,
rotate
=
180
)
self
.
display
=
SH1106_I2C
(
DISPLAY_WIDTH
,
DISPLAY_HEIGHT
,
self
.
i2c
,
self
.
i2c_lock
,
rotate
=
180
)
self
.
buttons
=
brick_ll
.
Buttons
()
self
.
buttons
.
pressed_since
()
self
.
esp
=
Esp
(
self
.
buttons
)
...
...
@@ -59,10 +62,10 @@ class Robot:
self
.
battery_timer
.
init
(
mode
=
Timer
.
PERIODIC
,
period
=
BAT_MEASURE_PERIOD
,
callback
=
self
.
check_battery_low
)
self
.
wdt
=
WDT
(
timeout
=
4000
)
print
(
"
Watch Dog Timer initialised with timeout
4
s.
"
)
self
.
wdt
=
WDT
(
timeout
=
WDT_TIMEOUT
)
print
(
f
"
Watch Dog Timer initialised with timeout
{
WDT_TIMEOUT
/
10
}
s.
"
)
self
.
wdt_feed_timer
=
Timer
(
-
1
)
self
.
wdt_feed_timer
.
init
(
period
=
3500
,
mode
=
Timer
.
PERIODIC
,
self
.
wdt_feed_timer
.
init
(
period
=
WDT_FEED_TIMER_PERIOD
,
mode
=
Timer
.
PERIODIC
,
callback
=
self
.
wdt_feed
)
# Function called with a timer to feed Watch Dog Timer to prevent rebooting
...
...
@@ -169,11 +172,10 @@ class Robot:
# Check if the battery voltage is too low,
# if it is make buzzer sound, show info on the display and turn off the cube
def
check_battery_low
(
self
,
p
):
print
(
self
.
battery
.
voltage
()
,
self
.
battery_low_counter
)
if
self
.
battery
.
voltage
()
<
BAT_VOLTAGE_TURNOFF
:
self
.
battery_low_counter
+=
1
if
self
.
battery_low_counter
>=
BAT_TURNOFF_PERIODS
:
#
self.buzzer.set_freq_duty(1000, 0.05)
self
.
buzzer
.
set_freq_duty
(
1000
,
0.05
)
self
.
display
.
fill
(
0
)
self
.
display
.
text
(
'
Battery low!
'
,
15
,
30
,
1
)
self
.
display
.
show
()
...
...
This diff is collapsed.
Click to expand it.
lib/robot_consts.py
+
18
−
10
View file @
886eb1ba
...
...
@@ -75,18 +75,26 @@ class Color:
BROWN
:
Color
=
const
(
7
)
BAT_MEASURE_PERIOD
=
const
(
1000
)
# ms
BAT_TURNOFF_PERIODS
=
2
BAT_VOLTAGE_MAX
=
8.4
BAT_VOLTAGE_MIN
=
6.2
BAT_VOLTAGE_TURNOFF
=
(
BAT_VOLTAGE_MIN
+
0.1
)
# Volts
BAT_MEASURE_PERIOD
=
const
(
1000
)
# ms
BAT_TURNOFF_PERIODS
=
const
(
2
)
BAT_VOLTAGE_MAX
=
const
(
8.4
)
BAT_VOLTAGE_MIN
=
const
(
6.2
)
BAT_VOLTAGE_TURNOFF
=
(
BAT_VOLTAGE_MIN
+
0.1
)
# Volts
PCF_CHECK_PERIOD
=
const
(
50
)
# ms
I2C_SLAVE_READ_PERIOD
=
const
(
1
)
# ms
PCF_CHECK_PERIOD
=
const
(
50
)
# ms
I2C_FREQ
=
const
(
400000
)
# Hz
I2C_NXT_UTZ_BUS
=
const
(
0
)
I2C_INTERNAL_BUS
=
const
(
1
)
I2C_INTERNAL_FREQ
=
const
(
400000
)
# Hz
I2C_NXT_UTZ_FREQ
=
const
(
30000
)
# Hz
I2C_MULTICUBE_FREQ
=
const
(
100000
)
I2C_MULTICUBE_FREQ
=
const
(
100000
)
# Hz
ESP_BAUDRATE
=
const
(
115200
)
# bps
ESP_BAUDRATE
=
const
(
115200
)
# bps
ESP32_COMMAND_PIN
=
const
(
8
)
DISPLAY_WIDTH
=
const
(
128
)
DISPLAY_HEIGHT
=
const
(
64
)
WDT_TIMEOUT
=
const
(
4000
)
# ms
WDT_FEED_TIMER_PERIOD
=
const
(
3500
)
# ms
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main/main.py
+
1
−
1
View file @
886eb1ba
...
...
@@ -332,7 +332,7 @@ def main():
current_program
=
menu_list
[
current_menu
]
display_fill_programs
(
robot
,
program_list
,
current_program
)
# Check if OK button was pressed and start user program
if
ok_pressed
:
if
ok_pressed
and
len
(
program_list
)
>
0
:
robot_state
=
1
program_name
=
program_list
[
current_program
][
0
]
program_path
=
"
./programs/
"
+
program_name
...
...
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