Skip to content

Commit

Permalink
Merge pull request #7 from arduino/dev
Browse files Browse the repository at this point in the history
0.1.0
  • Loading branch information
gbr1 authored Feb 2, 2024
2 parents 3ccb00c + a271be5 commit a8ca070
Show file tree
Hide file tree
Showing 16 changed files with 642 additions and 116 deletions.
475 changes: 417 additions & 58 deletions arduino_alvik.py

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions examples/led_setting.py → examples/leds_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
import sys

alvik = ArduinoAlvik()

alvik.run()
sleep_ms(100)
alvik.reset_hw()
alvik.begin()

while True:
try:
#alvik._set_leds(0xff)
#sleep_ms(1000)
#alvik._set_leds(0x00)
#sleep_ms(1000)
alvik.set_builtin_led(1)
sleep_ms(1000)
alvik.set_illuminator(1)
Expand All @@ -22,18 +15,23 @@
sleep_ms(1000)
alvik.set_illuminator(0)
sleep_ms(1000)
alvik.set_left_led_color(0,0,1)
alvik.left_led.set_color(0, 0, 1)
sleep_ms(1000)
alvik.left_led.set_color(0, 1, 0)
sleep_ms(1000)
alvik.left_led.set_color(1, 0, 0)
sleep_ms(1000)
alvik.set_right_led_color(0,0,1)
alvik.left_led.set_color(1, 1, 1)
sleep_ms(1000)
alvik.set_left_led_color(0,1,0)
alvik.right_led.set_color(0, 0, 1)
sleep_ms(1000)
alvik.set_right_led_color(0,1,0)
alvik.right_led.set_color(0, 1, 0)
sleep_ms(1000)
alvik.set_left_led_color(1,0,0)
alvik.right_led.set_color(1, 0, 0)
sleep_ms(1000)
alvik.set_right_led_color(1,0,0)
alvik.right_led.set_color(1, 1, 1)
sleep_ms(1000)
except KeyboardInterrupt as e:
print('over')
alvik.stop()
sys.exit()
19 changes: 10 additions & 9 deletions examples/message_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
import sys

alvik = ArduinoAlvik()
if alvik.begin() < 0:
sys.exit()

alvik.run()
sleep_ms(100)
alvik.reset_hw()
speed = 0

while True:
try:
print(f'VER: {alvik.version}')
print(f'LSP: {alvik.l_speed}')
print(f'RSP: {alvik.r_speed}')
print(f'LSP: {alvik.left_wheel.get_speed()}')
print(f'RSP: {alvik.right_wheel.get_speed()}')
print(f'LPOS: {alvik.left_wheel.get_position()}')
print(f'RPOS: {alvik.right_wheel.get_position()}')
print(f'TOUCH: {alvik.touch_bits}')
print(f'RGB: {alvik.red} {alvik.green} {alvik.blue}')
print(f'LINE: {alvik.left_line} {alvik.center_line} {alvik.right_line}')

alvik.set_speeds(speed, speed)
alvik.set_wheels_speed(speed, speed)
speed = (speed + 1) % 60
sleep_ms(1000)
except KeyboardInterrupt as e:
print('over')
alvik.set_speeds(0, 0)
break
sys.exit()
alvik.stop()
sys.exit()

36 changes: 36 additions & 0 deletions examples/move_wheels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from arduino_alvik import ArduinoAlvik
from time import sleep_ms
import sys

alvik = ArduinoAlvik()
alvik.begin()

while True:
try:
alvik.left_wheel.set_speed(10)
sleep_ms(1000)
print(f'LSP: {alvik.left_wheel.get_speed()}')
print(f'RSP: {alvik.right_wheel.get_speed()}')

alvik.right_wheel.set_speed(10)
sleep_ms(1000)

print(f'LSP: {alvik.left_wheel.get_speed()}')
print(f'RSP: {alvik.right_wheel.get_speed()}')

alvik.left_wheel.set_speed(20)
sleep_ms(1000)

print(f'LSP: {alvik.left_wheel.get_speed()}')
print(f'RSP: {alvik.right_wheel.get_speed()}')

alvik.right_wheel.set_speed(20)
sleep_ms(1000)

print(f'LSP: {alvik.left_wheel.get_speed()}')
print(f'RSP: {alvik.right_wheel.get_speed()}')

except KeyboardInterrupt as e:
print('over')
alvik.stop()
sys.exit()
69 changes: 69 additions & 0 deletions examples/pose_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from arduino_alvik import ArduinoAlvik
from time import sleep_ms
import sys

alvik = ArduinoAlvik()
alvik.begin()

while True:
try:

alvik.move(100.0)
print("on target after move")

alvik.move(50.0)
print("on target after move")

alvik.rotate(90.0)
print("on target after rotation")

alvik.rotate(-45.00)
print("on target after rotation")

x, y, theta = alvik.get_pose()
print(f'Current pose is x={x}, y={y} ,theta={theta}')

alvik.reset_pose(0, 0, 0)

x, y, theta = alvik.get_pose()
print(f'Updated pose is x={x}, y={y} ,theta={theta}')
sleep_ms(500)

print("___________NON-BLOCKING__________________")

alvik.move(50.0, blocking=False)
while not alvik.is_target_reached():
print(f"Not yet on target received:{alvik.last_ack}")
print("on target after move")

alvik.rotate(45.0, blocking=False)
while not alvik.is_target_reached():
print(f"Not yet on target received:{alvik.last_ack}")
print("on target after rotation")

alvik.move(100.0, blocking=False)
while not alvik.is_target_reached():
print(f"Not yet on target received:{alvik.last_ack}")
print("on target after move")

alvik.rotate(-90.00, blocking=False)
while not alvik.is_target_reached():
print(f"Not yet on target received:{alvik.last_ack}")
print("on target after rotation")

x, y, theta = alvik.get_pose()
print(f'Current pose is x={x}, y={y} ,theta={theta}')

alvik.reset_pose(0, 0, 0)

x, y, theta = alvik.get_pose()
print(f'Updated pose is x={x}, y={y} ,theta={theta}')
sleep_ms(500)

alvik.stop()
sys.exit()

except KeyboardInterrupt as e:
print('over')
alvik.stop()
sys.exit()
11 changes: 4 additions & 7 deletions examples/read_color_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import sys

alvik = ArduinoAlvik()

alvik.run()
sleep_ms(1000)
alvik.reset_hw()
alvik.begin()
speed = 0

while True:
try:
r, g, b = alvik.get_color()
r, g, b = alvik.get_color_raw()
print(f'RED: {r}, Green: {g}, Blue: {b}')
sleep_ms(100)
except KeyboardInterrupt as e:
print('over')
break
sys.exit()
alvik.stop()
sys.exit()
18 changes: 18 additions & 0 deletions examples/read_imu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from arduino_alvik import ArduinoAlvik
from time import sleep_ms
import sys

alvik = ArduinoAlvik()
alvik.begin()
speed = 0

while True:
try:
ax, ay, az = alvik.get_accelerations()
gx, gy, gz = alvik.get_gyros()
print(f'ax: {ax}, ay: {ay}, az: {az}, gx: {gx}, gy: {gy}, gz: {gz}')
sleep_ms(100)
except KeyboardInterrupt as e:
print('over')
alvik.stop()
sys.exit()
9 changes: 3 additions & 6 deletions examples/read_touch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import sys

alvik = ArduinoAlvik()

alvik.run()
sleep_ms(1000)
alvik.reset_hw()
alvik.begin()
speed = 0

while True:
Expand All @@ -30,5 +27,5 @@
sleep_ms(100)
except KeyboardInterrupt as e:
print('over')
break
sys.exit()
alvik.stop()
sys.exit()
13 changes: 5 additions & 8 deletions examples/set_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
import sys

alvik = ArduinoAlvik()

alvik.run()
sleep_ms(1000)
alvik.reset_hw()
alvik.begin()
speed = 0

while True:
try:
alvik.set_pid('L', 10.0, 1.3, 4.2)
alvik.left_wheel.set_pid_gains(10.0, 1.3, 4.2)
sleep_ms(100)
alvik.set_pid('R', 4.0, 13, 1.9)
alvik.right_wheel.set_pid_gains(4.0, 13, 1.9)
sleep_ms(100)
except KeyboardInterrupt as e:
print('over')
break
sys.exit()
alvik.stop()
sys.exit()
36 changes: 36 additions & 0 deletions examples/wheels_servo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from arduino_alvik import ArduinoAlvik
from time import sleep
import sys

alvik = ArduinoAlvik()
alvik.begin()

alvik.left_wheel.reset()
alvik.right_wheel.reset()

while True:
try:
alvik.left_wheel.set_position(30)
sleep(2)
print(f'Left wheel degs: {alvik.left_wheel.get_position()}')
print(f'Right wheel degs: {alvik.right_wheel.get_position()}')

alvik.right_wheel.set_position(10)
sleep(2)
print(f'Left wheel degs: {alvik.left_wheel.get_position()}')
print(f'Right wheel degs: {alvik.right_wheel.get_position()}')

alvik.left_wheel.set_position(180)
sleep(2)
print(f'Left wheel degs: {alvik.left_wheel.get_position()}')
print(f'Right wheel degs: {alvik.right_wheel.get_position()}')

alvik.right_wheel.set_position(270)
sleep(2)
print(f'Left wheel degs: {alvik.left_wheel.get_position()}')
print(f'Right wheel degs: {alvik.right_wheel.get_position()}')

except KeyboardInterrupt as e:
print('over')
alvik.stop()
sys.exit()
14 changes: 5 additions & 9 deletions examples/move_example.py → examples/wheels_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
import sys

alvik = ArduinoAlvik()

alvik.run()
sleep_ms(100)
alvik.reset_hw()

alvik.begin()

while True:
try:
alvik.set_speeds(10, 10)
alvik.set_wheels_speed(10, 10)
sleep_ms(1000)

alvik.set_speeds(30, 60)
alvik.set_wheels_speed(30, 60)
sleep_ms(1000)

alvik.set_speeds(60, 30)
alvik.set_wheels_speed(60, 30)
sleep_ms(1000)
except KeyboardInterrupt as e:
print('over')
alvik.set_speeds(0, 0)
alvik.stop()
sys.exit()
2 changes: 2 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ if /i "%1"=="-h" (
python -m mpremote %port_string% fs rm :arduino_alvik.py
python -m mpremote %port_string% fs rm :constants.py
python -m mpremote %port_string% fs rm :pinout_definitions.py
python -m mpremote %port_string% fs rm :robot_definitions.py
python -m mpremote %port_string% fs rm :uart.py

python -m mpremote %port_string% fs cp arduino_alvik.py :arduino_alvik.py
python -m mpremote %port_string% fs cp constants.py :constants.py
python -m mpremote %port_string% fs cp pinout_definitions.py :pinout_definitions.py
python -m mpremote %port_string% fs cp robot_definitions.py :robot_definitions.py
python -m mpremote %port_string% fs cp uart.py :uart.py

echo Installing dependencies
Expand Down
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ fi
$python_command -m mpremote $connect_string fs rm :arduino_alvik.py
$python_command -m mpremote $connect_string fs rm :constants.py
$python_command -m mpremote $connect_string fs rm :pinout_definitions.py
$python_command -m mpremote $connect_string fs rm :robot_definitions.py
$python_command -m mpremote $connect_string fs rm :uart.py

$python_command -m mpremote $connect_string fs cp arduino_alvik.py :arduino_alvik.py
$python_command -m mpremote $connect_string fs cp constants.py :constants.py
$python_command -m mpremote $connect_string fs cp pinout_definitions.py :pinout_definitions.py
$python_command -m mpremote $connect_string fs cp robot_definitions.py :robot_definitions.py
$python_command -m mpremote $connect_string fs cp uart.py :uart.py

echo "Installing dependencies"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
],
"deps": [
],
"version": "0.0.7"
"version": "0.1.0"
}
Loading

0 comments on commit a8ca070

Please sign in to comment.