Cov txheej txheem:

Kho GiggleBot Kab Tus Follower - Qib Siab: 7 Kauj Ruam
Kho GiggleBot Kab Tus Follower - Qib Siab: 7 Kauj Ruam

Video: Kho GiggleBot Kab Tus Follower - Qib Siab: 7 Kauj Ruam

Video: Kho GiggleBot Kab Tus Follower - Qib Siab: 7 Kauj Ruam
Video: “Ob Qho Kev Yug Los Ua Neeg Ua Rau Qhov Tseem Ceeb ntawm Kev Yug Los Ua Neeg Tiav Hlo” 2024, Kaum ib hlis
Anonim
Kho GiggleBot Kab Tus Follower - Ua Tau Zoo
Kho GiggleBot Kab Tus Follower - Ua Tau Zoo

Hauv qhov Qhia Qhia luv luv no koj yuav hloov kho koj tus kheej GiggleBot kom ua raws kab dub. Hauv lwm qhov kev qhia no GiggleBot Line Follower, peb nyuaj-coding cov kev hloov kho kom ua haujlwm raws li qhov xwm txheej ntawd. Koj yuav xav ua kom nws coj tus yam ntxwv zoo dua los ntawm kev nce nrog lwm qhov txiaj ntsig.

Hauv qhov kev qhia no, peb tab tom qhia koj 2 tsab ntawv uas tuaj yeem rub ob qho tib si ntawm BBC micro sib txawv: cov khoom kom ib qho ntawm lawv tau muab tso rau hauv GiggleBot thiab nrog rau lwm qhov, ob lub nyees khawm tau siv los ntawm cov ntawv qhia zaub mov thiab qhib sib txawv tsis Kev xa cov kev ntsuas tshiab no tau ua tiav hauv xov tooj cua.

Kauj Ruam 1: Cov Cheeb Tsam Xav Tau

Koj yuav xav tau cov hauv qab no:

  1. GiggleBot neeg hlau rau micro: me ntsis.
  2. x3 AA Roj teeb
  3. x2 BBC micro: cov khoom - ib qho rau GiggleBot thiab lwm qhov ua raws li cov chaw taws teeb rau ntsuas qhov ntsuas.
  4. Roj teeb rau BBC micro: me ntsis - zoo li ib qho uas los hauv BBC micro: pob me ntsis.

Tau txais GiggleBot Neeg Hlau rau BBC micro: me ntsis ntawm no

Kauj Ruam 2: Teeb Teem Kab & Ib puag ncig

Teem Sijhawm & Ib puag ncig
Teem Sijhawm & Ib puag ncig
Teem Sij Hawm & Ib puag ncig
Teem Sij Hawm & Ib puag ncig

Koj kuj tseem yuav tsum tsim koj cov ntawv (rub tawm, luam tawm, txiav thiab kab xev) thiab tom qab teeb tsa ib puag ncig (IDE thiab lub sijhawm ua haujlwm).

Txij li qhov kev qhia no muaj feem cuam tshuam nrog lwm qhov kev qhia muaj npe GiggleBot Line Follower, tsuas yog mus rau qhov ntawd thiab ua raws cov kauj ruam 2 thiab 3 thiab tom qab ntawd rov qab los ntawm no.

Raws li IDE, koj tuaj yeem siv Mu editor thiab rau lub sijhawm ua haujlwm, koj yuav tsum rub tawm GiggleBot MicroPython Runtime. Lub sijhawm ua haujlwm tuaj yeem rub tawm los ntawm nws cov ntaub ntawv ntawm no. Lub taub hau mus rau Pib Pib tshooj ntawm cov ntaub ntawv thiab ua raws cov lus qhia ntawm kev teeb tsa ib puag ncig. Raws li lub sijhawm no, version v0.4.0 ntawm lub sijhawm tau siv.

Kauj Ruam 3: Teeb tsa GiggleBot

Ua ntej flashing lub sijhawm ua haujlwm rau GiggleBot, nco ntsoov tias koj tau xaiv qhov koj xav tau nrawm thiab hloov pauv tus nqi rau GiggleBot: los ntawm lub neej ntawd, qhov nrawm tau teeb tsa rau 100 (base_speed variable) thiab hloov kho tshiab tau teev tseg rau 70 (hloov tshiab -rate sib txawv).

Muab qhov kev siv tam sim no, qhov hloov kho siab tshaj plaws uas tuaj yeem ua tiav yog 70 thiab yog tias run_neopixels tau teeb tsa Tseeb, tom qab ntawd tsuas yog 50 qhov ua tiav. Yog li hauv txoj hauv kev, koj tuaj yeem hais tias qhov hloov pauv hloov pauv sai yog raug rau ntawm ntug dab tsi BBC micro: me ntsis tuaj yeem ua tau.

Tsuas yog rau cov ntaub ntawv, cov kab hauv qab lub sensor tuaj yeem rov hloov kho tshiab 100 zaug ib pliag.

Nco tseg: Cov ntawv hauv qab no yuav muaj qhov chaw ploj thiab qhov no zoo li yog vim muaj qee qhov teeb meem hauv kev nthuav tawm GitHub Gists. Nyem rau ntawm qhov tseem ceeb coj koj mus rau nws nplooj ntawv GitHub uas koj tuaj yeem luam tawm-muab cov cai.

GiggleBot PID Kab Follower Tuner (xav tau lub chaw taws teeb kom qhib nws) - xjfls23

los ntawm microbit ntshuam*
los ntawm gigglebot ntshuam*
los ntawm utime ntshuam sleep_ms, zuam_us
ntshuam xov tooj cua
ntshuam ustruct
# pib xov tooj cua thiab GB neopixels
xov tooj cua.on ()
neo = init () cov
# sijhawm
hloov tshiab = 70
# default tau txais txiaj ntsig
NPV = 0.0
Ki = 0.0 tsi
Kd = 0.0 tsi
setpoint = 0.5 hli
trigger_point = 0.0
min_speed_percent = 0.2
base_speed = 100
last_position = setpoint
ib = 0.0.0
run_neopixels = tsis tseeb
center_pixel = 5# qhov chaw nruab nrab pixel ntawm qhov luag nyav nyob ntawm GB
# turquoise = tuple (daim ntawv qhia (lambda x: int (x / 5), (64, 224, 208))) # xim siv los kos qhov yuam kev nrog neopixels
# turquoise = (12, 44, 41) # uas yog raws nraim qhov turquoise saum toj no tau hais qhia saum toj no
error_width_per_pixel = 0.5/3# max yuam kev faib los ntawm tus lej ntawm ntu ntawm txhua neopixel
defupper_bound_linear_speed_reducer (abs_error, trigger_point, upper_bound, tsawg tshaj plaws_motor_power, siab tshaj plaws_motor_power):
ntiaj teb base_speed
yog abs_error> = trigger_point:
# x0 = 0.0 tsi
# y0 = 0.0
# x1 = upper_bound - trigger_point
# y1 = 1.0
# x = abs_error - trigger_point
# y = y0 + (x - x0) * (y1 - y0) / (x1 - x0)
# zoo ib yam
y = (abs_error - trigger_point) / (upper_bound - trigger_point)
motor_power = base_speed * (qhov tsawg tshaj plaws_motor_power + (1- y) * (siab tshaj_motor_power - tsawg tshaj plaws_motor_power))
rov qab motor_power
lwm tus:
rov qab base_speed * siab tshaj plaws_motor_power
run = Tsis tseeb
yav dhau los_error = 0
tag nrho_time = 0.0
cov_counts = 0
thaum tseeb
# yog tias khawm a raug nias ces pib ua raws
yog tias button_a.is_pressed ():
run = Tseeb
# tab sis yog tias khawm b raug nias nres cov kab hauv qab
yog tias button_b.is_pressed ():
run = Tsis tseeb
ib = 0.0.0
yav dhau los_error = 0.0
display.scroll ('{} - {}'. format (total_time, total_counts), ncua = 100, tos = Tsis raug)
tag nrho_time = 0.0
cov_counts = 0
pixels_ tawm ()
tsum tsum ()
pw_ms (500)
yog tias khiav isTrue:
# nyeem kab cim
start_time = ticks_us ()
# txheeb xyuas yog tias peb tau hloov kho Kp/Kd nce nrog qhov chaw deb
sim:
Kp, Ki, Kd, trigger_point, min_speed_percent = ustruct.unpack ('fffff', radio.receive_bytes ())
set_eyes ()
exceptTypeError:
dhau
sab xis, sab laug = nyeem_sensor (LINE_SENSOR, Ob leeg)
# kab nyob ntawm sab laug thaum txoj haujlwm <0.5
# kab nyob ntawm sab xis thaum txoj haujlwm> 0.5
# kab nyob nruab nrab thaum txoj haujlwm = 0.5
# nws yog qhov hnyav ntawm cov lej zauv
sim:
txoj hauj lwm = txoj cai /ntab (sab laug + sab xis)
tsuas yog ZeroDivisionError:
txoj hauj lwm = 0.5
yog txoj hauj lwm == 0: txoj hauj lwm = 0.001
yog txoj hauj lwm == 1: txoj hauj lwm = 0.999
# siv tus tswj hwm PD
yuam kev = txoj hauj lwm - setpoint
ib += yuam kev
kho = Kp * yuam kev + Ki * ib qho + Kd * (yuam kev - yav dhau los_error)
yav dhau los_error = yuam kev
# xam lub cev muaj zog nrawm
motor_speed = upper_bound_linear_speed_reducer (abs (yuam kev), setpoint * trigger_point, setpoint, min_speed_percent, 1.0)
leftMotorSpeed = motor_speed + kho
rightMotorSpeed = motor_speed - kho
# teeb lub neopixels los qhia rau qhov kev taw qhia uas GiggleBot yuav tsum mus
yog run_neopixels isTrueand total_counts %3 == 0:
rau kuv inb '\ x01 / x01 / x02 / x03 / x04 / x05 / x06 / x07 / x08':
neo [kuv] = (0, 0, 0)
rau kuv inb '\ x01 / x01 / x02 / x03':
ifabs (yuam kev)> error_width_per_pixel * kuv:
yog yuam kev <0:
neo [center_pixel + kuv] = (12, 44, 41)
lwm tus:
neo [center_pixel - kuv] = (12, 44, 41)
lwm tus:
feem pua = 1- (error_width_per_pixel * i -abs (yuam kev)) / error_width_per_pixel
# teeb lub pixel tam sim no
yog yuam kev <0:
# neo [center_pixel + i] = tuple (daim ntawv qhia (lambda x: int (x * feem pua), turquoise))
neo [center_pixel + i] = (int (12* feem pua), int (44* feem pua), int (41* feem pua))
lwm tus:
# neo [center_pixel - i] = tuple (daim ntawv qhia (lambda x: int (x * feem pua), turquoise))
neo [center_pixel - i] = (int (12* feem pua), int (44* feem pua), int (41* feem pua))
so
neo.show ()
sim:
# clip cov motors
yog tias sab laug MotorSpeed> 100:
leftMotorSpeed = 100
rightMotorSpeed = rightMotorSpeed - leftMotorSpeed +100
yog tias yog MotorSpeed> 100:
rightMotorSpeed = 100
leftMotorSpeed = leftMotorSpeed - rightMotorSpeed +100
yog tias sab laug MotorSpeed <-100:
leftMotorSpeed = -100
Yog hais tias txoj cai MotorSpeed <-100:
rightMotorSpeed = -100
# actuate cov motors
set_speed (sab laugMotorSpeed, sab xis MotorSpeed)
tsav ()
# luam tawm ((yuam kev, motor_speed))
tshwj tsis yog:
# yog tias peb nkag mus rau qee qhov teeb meem tsis tuaj yeem ua tau
dhau
# thiab tswj lub voj zaus
end_time = zuam_us ()
delay_diff = (kawg_time - pib_time) /1000
total_time += ncua_diff
cov_counts += 1
if1.0/ update_rate - ncua_diff> 0:
pw tsaug zog (1.0/ update_rate - ncua_diff)

saib rawgigglebot_line_follower_tuner.py tuav nrog ❤ los ntawm GitHub

Kauj Ruam 4: Teeb Tus Tuner (Chaw Taws Teeb)

Qhov txuas ntxiv uas peb yuav tsum ua yog nyem lub runtime + tsab ntawv mus rau 2nd BBC micro: me ntsis. Qhov thib ob micro: me ntsis yuav ua qhov chaw deb rau GiggleBot, uas yuav siv los kho qhov ntsuas hauv qab no:

  1. Kp = qhov sib npaug nce rau tus tswj PID.
  2. Ki = qhov nce ntxiv rau tus tswj PID.
  3. Kd = qhov tau txais txiaj ntsig zoo rau PID tus tswj hwm.
  4. trigger_point = lub ntsiab lus tau hais hauv feem pua ntawm qhov tsawg kawg thiab qhov siab tshaj plaws ntawm GiggleBot qhov twg qhov nrawm pib tau txo qis linearly kom txog thaum nws mus txog qhov tsawg kawg nkaus.
  5. min_speed_percent = qhov tsawg kawg nkaus tau hais tawm hauv feem pua ntawm qhov nrawm tshaj plaws.

Lwm qhov ntxiv 2 qhov hloov pauv uas tuaj yeem hloov kho tau ncaj qha nyuaj coded hauv tsab ntawv uas zaum ntawm GiggleBot: hloov tshiab_rate thiab base_speed uas sawv cev rau qhov nrawm tshaj plaws. Raws li tau piav qhia hauv cov ntaub ntawv, qhov nrawm tshaj plaws uas tuaj yeem teeb tsa rau GiggleBot yog 100, uas tseem yog tus nqi pib rau peb GiggleBot.

Nco tseg: Cov ntawv hauv qab no yuav muaj qhov chaw ploj thiab qhov no zoo li yog vim muaj qee qhov teeb meem hauv kev nthuav tawm GitHub Gists. Nyem rau ntawm qhov tseem ceeb coj koj mus rau nws nplooj ntawv GitHub uas koj tuaj yeem luam tawm-muab cov cai.

GiggleBot Remote PID Line Follower Tuner (xav tau lwm qhov) - xjfls23

los ntawm microbit ntshuam*
los ntawm utime ntshuam sleep_ms
ntshuam xov tooj cua
ntshuam ustruct
# Qib 1 yog Kp nce
# Qib 2 yog Ki tau txais
# Qib 3 yog qhov nce Kd
# Qib 4 yog lub ntsiab lus_ ntsiab lus rau lub cav kom qis dua qhov nrawm (0 -> 1)
# Ntu thib 5 yog qhov nrawm tshaj plaws rau lub cav raws li qhia hauv feem pua (0 -> 1)
tau = [0.0, 0.0, 0.0, 1.0, 1.0, 0.0]
stepSize = 0.1 hli
# 0 thiab 1 rau thawj ntu
# 2 thiab 3 rau ntu thib 2
currentSetting = 0
defshowMenu ():
display.scroll ('{} - {}'. format (currentSetting, nce [int (currentSetting /2)]), ncua = 100, tos = Tsis raug)
xov tooj cua.on ()
showMenu ()
thaum tseeb
tshiab = Tsis tseeb
yog tias button_a.is_pressed ():
currentSetting = (currentSetting +1) % (2*5)
hloov tshiab = Tseeb
yog tias button_b.is_pressed ():
yog currentSetting %2 == 0:
# nce qhov nce thaum tam sim no teeb tsa yog 0 lossis 2 lossis..
ifint (currentSetting /2) hauv [0, 2]:
nce [int (currentSetting /2)] += 10* stepSize
lwm tus:
nce [int (currentSetting /2)] += stepSize
lwm tus:
# nce nce ntxiv thaum tam sim no teeb tsa yog 1 lossis 3 lossis..
ifint (currentSetting /2) hauv [0, 2]:
nce [int (currentSetting /2)] -= 10* stepSize
lwm tus:
nce [int (currentSetting /2)] -= stepSize
radio.send_bytes (ustruct.pack ('fffff', *tau txais))
hloov tshiab = Tseeb
yog hloov tshiab:
showMenu ()
pw_ms (200)

saib rawgigglebot_line_follower_configurator.py tuav nrog ❤ los ntawm GitHub

Kauj Ruam 5: Kho GiggleBot

Kho qhov GiggleBot
Kho qhov GiggleBot

Muab GiggleBot tso rau ntawm txoj kab, tig nws thiab cia nws khiav. Lub sijhawm no, koj yuav tsum tso nws rov qab rau ntawm txoj kab thiab kho qhov nce/tsis nrog lwm BBC micro: me ntsis uas koj tab tom tuav hauv koj txhais tes.

Txhawm rau pib GiggleBot, nias lub pob A ntawm GiggleBot's BBC micro: me ntsis thiab kom nres nws thiab yog li rov pib dua nws lub xeev nias ntawm khawm B.

Ntawm qhov chaw deb deb BBC micro: me ntsis, nias lub pob A yuav coj koj mus rau txhua qhov kev xaiv hauv nws cov ntawv qhia zaub mov thiab khawm B nce/txo tus nqi sib xws. Nws zoo li teeb tsa lub moos ntawm lub tsheb qub lub dashboard. Cov kev xaiv yog zoo li no:

  1. 0-1 kev xaiv yog rau Kp nce.
  2. 2-3 qhov kev xaiv yog rau Ki nce.
  3. 4-5 qhov kev xaiv yog rau Kd nce.
  4. 6-7 cov kev xaiv yog rau teeb tsa qhov teeb tsa rau lub sijhawm uas lub tshuab pib qeeb qeeb.
  5. 8-9 cov kev xaiv yog rau teeb tsa qhov tsawg kawg nkaus ceev.

Nco ntsoov tias txawm tias tus lej hauv cov ntawv qhia zaub mov yog txhawm rau nce tus nqi sib xws thiab rau qhov txawv nws yog qhov sib txawv.

Tsis tas li, thaum nias lub pob B ntawm GiggleBot's BBC micro: me ntsis, koj yuav pom ntawm nws Neopixel -screen tshuaj xyuas tus naj npawb ntawm lub hli dhau los txij li rov pib dua thiab tus naj npawb ntawm cov mus uas neeg hlau tau dhau los - nrog rau 2 qhov no koj tuaj yeem suav tau qhov hloov tshiab tus nqi ntawm tus neeg hlau.

Qhov kawg thiab qhov tseem ceeb tshaj plaws, Kuv tau los nrog 2 qhov hloov pauv rau GiggleBot. Ib ntawm lawv yog rau thaum Neopixel LEDs raug tua thiab lwm qhov yog rau thaum nws tsis yog. Neopixel LEDs tau siv los qhia rau txoj kev taw qhia qhov ua yuam kev tau sau tseg.

1st teeb ntawm kev ntsuas qhov ntsuas (nrog NeoPixel LEDs tawm)

  1. NPV = 32.0
  2. Ki = 0.5 tsi
  3. Kd = 80.0 hli
  4. trigger_setpoint = 0.3 (uas yog 30%)
  5. min_speed_percent = 0.2 (uas yog 20%)
  6. base_speed = 100 (aka ceev tshaj)
  7. update_rate = 70 (khiav @70Hz)

Txheej thib 2 ntawm kev ntsuas qhov ntsuas (nrog NeoPixel LEDs ntawm)

  1. NPV = 25.0
  2. Ki = 0.5 tsi
  3. Kd = 35.0 hli
  4. trigger_setpoint = 0.3 (uas yog 30%)
  5. min_speed_percent = 0.3 (uas yog 30%)
  6. base_speed = 70 (aka ceev tshaj)
  7. update_rate = 50 (khiav @50Hz)
  8. Tsis tas li, qhov sib txawv run_neopixels yuav tsum tau teeb tsa kom muaj tseeb hauv tsab ntawv uas tau ntim rau ntawm GiggleBot's BBC micro: me ntsis. Qhov no yuav ua rau NeoPixel LEDs nyem nyob rau hauv ib txoj hauv kev uas lawv qhia rau qhov kev taw qhia qhov ua yuam kev tau sau tseg.

Kauj Ruam 6: GiggleBot Khiav Nrog NeoPixels Tua Tawm

Nov yog qhov piv txwv ntawm kev ua haujlwm GiggleBot nrog qhov ntsuas qhov ntsuas thib ib pom nyob hauv cov kauj ruam dhau los. Qhov piv txwv no tau kaw NeoPixel LEDs.

Kauj Ruam 7: GiggleBot Khiav Nrog Neopixels Qhib

Nov yog qhov piv txwv ntawm kev ua GiggleBot nrog qhov thib ob teeb tsa qhov ntsuas pom hauv qib 5. Qhov piv txwv no muaj NeoPixel LEDs qhib.

Pom zoo li cas hauv qhov piv txwv no, GiggleBot muaj lub sijhawm nyuaj tom qab kab - qhov ntawd yog vim Neopixel LEDs "noj" CPU lub sijhawm ntawm BBC micro: me ntsis. Tias yog vim li cas peb yuav tsum txo tus nqi hloov kho tshiab los ntawm 70 txog rau 50.

Pom zoo: