Skip to content

Commit a60fc67

Browse files
authored
Merge pull request #12 from arduino/api_update
Api update
2 parents 19e8588 + a67e376 commit a60fc67

9 files changed

+412
-177
lines changed

arduino_alvik.py

+337-169
Large diffs are not rendered by default.

conversions.py

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def wrapper(*args, **kwargs):
99
return func(*args, **kwargs)
1010
except KeyError:
1111
raise ConversionError(f'Cannot {func.__name__} from {args[1]} to {args[2]}')
12+
except TypeError:
13+
return None
14+
except Exception as e:
15+
raise ConversionError(f'Unexpected error: {e}')
1216
return wrapper
1317

1418

examples/message_reader.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
if alvik.begin() < 0:
77
sys.exit()
88

9+
speed = 0
10+
911
while True:
1012
try:
11-
print(f'VER: {alvik.version}')
13+
print(f'VER: {alvik.get_version()}')
1214
print(f'LSP: {alvik.left_wheel.get_speed()}')
1315
print(f'RSP: {alvik.right_wheel.get_speed()}')
1416
print(f'LPOS: {alvik.left_wheel.get_position()}')
1517
print(f'RPOS: {alvik.right_wheel.get_position()}')
16-
print(f'TOUCH: {alvik.touch_bits}')
17-
print(f'RGB: {alvik.red} {alvik.green} {alvik.blue}')
18-
print(f'LINE: {alvik.left_line} {alvik.center_line} {alvik.right_line}')
18+
print(f'TOUCH (UP): {alvik.get_touch_up()}')
19+
print(f'RGB: {alvik.get_color()}')
20+
print(f'LINE: {alvik.get_line_sensors()}')
21+
print(f'SOC: {alvik.get_battery_charge()}%')
1922

2023
alvik.set_wheels_speed(speed, speed)
2124
speed = (speed + 1) % 60

examples/pose_example.py

+24
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,39 @@
3434
alvik.move(50.0, 'mm', blocking=False)
3535
print("on target after move")
3636

37+
while not alvik.is_target_reached():
38+
alvik.left_led.set_color(1, 0, 0)
39+
sleep_ms(500)
40+
alvik.left_led.set_color(0, 0, 0)
41+
sleep_ms(500)
42+
3743
alvik.rotate(45.0, 'deg', blocking=False)
3844
print("on target after rotation")
3945

46+
while not alvik.is_target_reached():
47+
alvik.left_led.set_color(1, 0, 0)
48+
sleep_ms(500)
49+
alvik.left_led.set_color(0, 0, 0)
50+
sleep_ms(500)
51+
4052
alvik.move(100.0, 'mm', blocking=False)
4153
print("on target after move")
4254

55+
while not alvik.is_target_reached():
56+
alvik.left_led.set_color(1, 0, 0)
57+
sleep_ms(500)
58+
alvik.left_led.set_color(0, 0, 0)
59+
sleep_ms(500)
60+
4361
alvik.rotate(-90.00, 'deg', blocking=False)
4462
print("on target after rotation")
4563

64+
while not alvik.is_target_reached():
65+
alvik.left_led.set_color(1, 0, 0)
66+
sleep_ms(500)
67+
alvik.left_led.set_color(0, 0, 0)
68+
sleep_ms(500)
69+
4670
x, y, theta = alvik.get_pose()
4771
print(f'Current pose is x(cm)={x}, y(cm)={y}, theta(deg)={theta}')
4872

examples/read_color_sensor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
r, g, b = alvik.get_color()
1111
h, s, v = alvik.get_color('hsv')
1212
print(f'RED: {r}, Green: {g}, Blue: {b}, HUE: {h}, SAT: {s}, VAL: {v}')
13-
print(f'COLOR LABEL: {alvik.get_color_label(h, s, v)}')
13+
print(f'COLOR LABEL: {alvik.get_color_label()}')
1414
sleep_ms(100)
1515
except KeyboardInterrupt as e:
1616
print('over')

examples/test_idle.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from arduino_alvik import ArduinoAlvik
2+
from time import sleep_ms
3+
import sys
4+
5+
alvik = ArduinoAlvik()
6+
alvik.begin()
7+
8+
speed = 0
9+
10+
while True:
11+
try:
12+
13+
if alvik.is_on():
14+
print(f'VER: {alvik.get_version()}')
15+
print(f'LSP: {alvik.left_wheel.get_speed()}')
16+
alvik.set_wheels_speed(speed, speed)
17+
speed = (speed + 1) % 30
18+
sleep_ms(1000)
19+
except KeyboardInterrupt as e:
20+
print('over')
21+
alvik.stop()
22+
sys.exit()
23+

pinout_definitions.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
BOOT0_STM32 = Pin(D2, Pin.OUT) # nano D2 -> STM32 Boot0
1313
RESET_STM32 = Pin(D3, Pin.OUT) # nano D3 -> STM32 NRST
14-
NANO_CHK = Pin(D4, Pin.OUT) # nano D3 -> STM32 NANO_CHK
15-
CHECK_STM32 = Pin(A6, Pin.IN, Pin.PULL_UP) # nano A6/D23 -> STM32 ROBOT_CHK
14+
NANO_CHK = Pin(D4, Pin.OUT) # nano D4 -> STM32 NANO_CHK
15+
CHECK_STM32 = Pin(A6, Pin.IN, Pin.PULL_DOWN) # nano A6/D23 -> STM32 ROBOT_CHK
1616
ESP32_SDA = Pin(A4, Pin.OUT) # ESP32_SDA
1717
ESP32_SCL = Pin(A5, Pin.OUT) # ESP32_SCL
18+
19+
# LEDS
20+
LEDR = Pin(46, Pin.OUT) #RED ESP32 LEDR
21+
LEDG = Pin(0, Pin.OUT) #GREEN ESP32 LEDG
22+
LEDB = Pin(45, Pin.OUT) #BLUE ESP32 LEDB

utilities/firmware_updater.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
from sys import exit
22
from stm32_flash import *
33

4+
if CHECK_STM32.value() is not 1:
5+
print("Turn on your Alvik to continue...")
6+
while CHECK_STM32.value() is not 1:
7+
sleep_ms(500)
8+
49
ans = STM32_startCommunication()
510
if ans == STM32_NACK:
6-
print("Cannot etablish connection with STM32")
11+
print("Cannot establish connection with STM32")
712
exit(-1)
813

914
print('\nSTM32 FOUND')

utilities/stm32_flash.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from time import sleep_ms
44
from machine import UART, Pin
55

6+
A6 = 13 # ESP32 pin13 -> nano A6/D23
7+
CHECK_STM32 = Pin(A6, Pin.IN) # nano A6/D23 -> TO CHECK STM32 IS ON
8+
69
STM32_INIT = b'\x7F'
710
STM32_NACK = b'\x1F'
811
STM32_ACK = b'\x79'

0 commit comments

Comments
 (0)