Initial commit
This commit is contained in:
commit
dc7b625ab0
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
build
|
45
README.md
Normal file
45
README.md
Normal file
@ -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
|
||||||
|
```
|
29
modules/main.py
Normal file
29
modules/main.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user