From dc7b625ab03dd85f464c8690a97c3e425fd346c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Tue, 15 Mar 2022 22:44:03 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ modules/main.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 modules/main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/README.md b/README.md new file mode 100644 index 0000000..1471d8d --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# Introduction + +This is vanilla firmware option for the +[sumorobot platform](https://wiki.k-space.ee/en/projects/robots/sumo) +we use at K-SPACE. + +The goal of this firmware option is to NOT get WiFi, Bluetooth or remote +programming in the picture and simply let the user program sumorobot +using favourite text editor or IDE and to upload the firmware via USB cable. + + +# Preparation + +On Ubuntu make sure your user can access serial port. +If necessary run following, log out and and log into your desktop session again: + +``` +gpasswd -a $USER dialout +``` + +The firmware is flashed via USB cable. No need to press buttons on the robot. +The servo motors might interfere in some corner cases so USB connectivity is +not particularly reliable, just try to run `esptool.py` again. + + +# Bulk deployment + +To build self-contained firmware image for ESP32 use, eg when you need to flash +multiple robots easily: + +``` +docker run --rm -v $PWD/modules:/src/ports/esp32/modules -v $PWD/build:/build harbor.k-space.ee/k-space/micropython-esp32 +``` + +To flash the built binary: + +``` +esptool.py -p /dev/ttyUSB0 --chip esp32 -b 460800 write_flash -z 0x1000 firmware.bin +``` + +To open up serial console: + +``` +picocom -b115200 /dev/ttyUSB0 +``` diff --git a/modules/main.py b/modules/main.py new file mode 100644 index 0000000..9380e29 --- /dev/null +++ b/modules/main.py @@ -0,0 +1,29 @@ +from utime import sleep_ms +from machine import Pin, PWM + +class ServoMotor(): + def __init__(self, pin): + self.pwm = PWM(Pin(pin), freq=50, duty=0) + self.prev = 0 + + def set(self, speed): + if self.prev == speed: + # Prevent jerkiness + return + self.prev = speed + if speed == 0: + self.pwm.duty(0) + else: + self.pwm.duty(int(33 + speed * 66 / 100)) + print(self.pwm, 33 + speed * 66 / 100) + +left_motor = ServoMotor(13) +right_motor = ServoMotor(15) + +while True: + left_motor.set(100) + right_motor.set(0) + sleep_ms(500) + left_motor.set(0) + right_motor.set(100) + sleep_ms(500)