Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GiggleBot Remote PID Line Follower Tuner (requires the other part) - xjfls23
from microbit import *
from utime import sleep_ms
import radio
import ustruct
# 1st element is the Kp gain
# 2nd element is the Ki gain
# 3rd element is the Kd gain
# 4th element is the trigger_point for motors to lower down the speed (0 -> 1)
# 5th element is the min speed for motors as expressed in percentages (0 -> 1)
gains = [0.0, 0.0, 0.0, 1.0, 0.0]
stepSize = 0.1
# 0 and 1 for 1st element
# 2 and 3 for 2nd element
currentSetting = 0
def showMenu():
display.scroll('{} - {}'.format(currentSetting, gains[int(currentSetting / 2)]), delay=100, wait=False)
radio.on()
showMenu()
while True:
updated = False
if button_a.is_pressed():
currentSetting = (currentSetting + 1) % (2 * 5)
updated = True
if button_b.is_pressed():
if currentSetting % 2 == 0:
# increase gain when currentSetting is 0 or 2 or ..
if int(currentSetting / 2) in [0, 2]:
gains[int(currentSetting / 2)] += 10 * stepSize
else:
gains[int(currentSetting / 2)] += stepSize
else:
# increase gain when currentSetting is 1 or 3 or ..
if int(currentSetting / 2) in [0, 2]:
gains[int(currentSetting / 2)] -= 10 * stepSize
else:
gains[int(currentSetting / 2)] -= stepSize
radio.send_bytes(ustruct.pack('fffff', *gains))
updated = True
if updated:
showMenu()
sleep_ms(200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.