Cov txheej txheem:

GiggleBot Kab Tus Follower Siv Python: 5 Kauj Ruam
GiggleBot Kab Tus Follower Siv Python: 5 Kauj Ruam

Video: GiggleBot Kab Tus Follower Siv Python: 5 Kauj Ruam

Video: GiggleBot Kab Tus Follower Siv Python: 5 Kauj Ruam
Video: Python! Reading and Writing JSON Files 2024, Hlis ntuj nqeg
Anonim
GiggleBot Kab Taug Qab Siv Python
GiggleBot Kab Taug Qab Siv Python
GiggleBot Kab Taug Qab Siv Python
GiggleBot Kab Taug Qab Siv Python
GiggleBot Kab Taug Qab Siv Python
GiggleBot Kab Taug Qab Siv Python

Lub sijhawm no nyob ib puag ncig, peb tab tom ua haujlwm hauv MicroPython Dexter Industries GiggleBot kom ua raws txoj kab dub siv nws cov kab hauv qab ua kom pom lub ntsej muag.

GiggleBot yuav tsum tau ua khub nrog BBC micro: me ntsis txhawm rau kom nws raug tswj kom tsim nyog.

Yog tias qhov kev qhia no tau dhau mus rau koj thiab lub cajmeem GiggleBot ntau dhau rau tam sim no, koj ib txwm tuaj yeem dhau los ntawm qhov pib qhia uas qhia koj li cas tus neeg hlau tuaj yeem ua haujlwm hauv MakeCode ntawm no. Cov ntawv qhia txuas yuav taug koj txoj hauv kev yooj yim heev.

Kauj Ruam 1: Cov Cheeb Tsam Xav Tau

Yuav tsum tau Cheebtsam
Yuav tsum tau Cheebtsam

Yuav tsum muaj cov khoom siv kho vajtse hauv qab no:

  1. x3 AA roj teeb - hauv kuv cov ntaub ntawv kuv siv cov roj teeb rov tau uas muaj qhov qis dua tag nrho.
  2. Dexter Industries GiggleBot neeg hlau rau micro: me ntsis.
  3. BBC BBC micro: me ntsis.

Tau kawg, koj kuj xav tau lub micro USB cable los ua haujlwm BBC micro: ntsis - cov kab no feem ntau tuaj hauv BBC micro: ntsis pob lossis koj ib txwm tuaj yeem siv ib qho uas tau siv rau them (Android) smartphones.

Tau txais GiggleBot rau micro: me ntsis ntawm no

Kauj Ruam 2: Teeb Kab Ke

Teeb Cov Kab Ke
Teeb Cov Kab Ke

Koj yuav tsum hla kev luam qee cov vuas thiab tsim koj tus kheej txoj kab. Koj tuaj yeem siv peb tus kheej cov vuas kom koj 100% paub tseeb tias koj tau rov ua dua peb cov xwm txheej. Lossis yog tias koj xav tias muaj kev lom zem, koj tuaj yeem siv qee daim kab xev dub thiab ua rau koj tus kheej. Nov yog PDF rau cov vuas peb tau siv.

Cov kab saum toj no yog tsim los ntawm cov lej hauv qab no ntawm cov vuas sib txawv:

  • 12 pobzeb ntawm hom #1.
  • 5 nplais ntawm hom #2.
  • 3 tus qauv ntawm cov nplais hom #5.
  • 3 tus qauv ntawm pobzeb hom #6 - ntawm no, koj yuav xaus nrog ib pobzeb ntxiv.

Tom ntej no, luam tawm lawv thiab txiav lawv. Sim muab lawv zoo li hauv daim duab saum toj no thiab nco ntsoov tias nyob rau sab xis saum toj ntawm txoj kab, 2 cov nplais yuav tsum sib tshooj ib qho nrog lwm qhov - qhov no yuav tsum yog nyob rau hauv rooj plaub uas koj xav tsis thoob yog tias koj ua qee yam tsis raug.

Kauj Ruam 3: Teeb Ib puag ncig

Teem Ib puag ncig
Teem Ib puag ncig

Txhawm rau kom koj tuaj yeem ua haujlwm rau BBC micro: me ntsis hauv MicroPython, koj yuav tsum teeb tsa tus kws kho rau nws (Mu Editor) thiab teeb tsa GiggleBot MicroPython Runtime ua nws lub sijhawm. Rau qhov ntawd, koj yuav tsum ua raws cov lus qhia ntawm nplooj ntawv no. Raws li lub sijhawm no, version v0.4.0 ntawm lub sijhawm tau siv.

Kauj Ruam 4: Ua Haujlwm GiggleBot

Ua ntej yuav nqis mus rau nws, GiggleBot MicroPython runtime muaj lub sijhawm ua haujlwm qub rau BBC micro: me ntsis thiab lwm lub tsev qiv ntawv los txhawb GiggleBot thiab lwm yam Dexter Industries Sensors.

Tom qab teeb tsa nws, qhib cov ntawv hauv qab no hauv Mu editor thiab nyem rau Flash. Qhov no yuav nyem GiggleBot MicroPython Runtime thiab tsab ntawv koj nyuam qhuav qhib rau koj lub BBC micro: me ntsis. Tsab ntawv kuj tau qhia hauv qab no.

Thaum cov txheej txheem ua kom tiav, teeb tsa BBC micro: me ntsis rau hauv GiggleBot nrog lub rooj tsav xwm neopixels tig mus rau pem hauv ntej, tso nws ntawm txoj kev thiab hloov nws.

Daim ntawv ceeb toom tias hauv tsab ntawv, PID thiab lwm 2 qhov ruaj khov (qhov teeb tsa ceev thiab qhov nrawm nrawm tshaj plaws) tau teeb tsa lawm.

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 Line Follower - Tuned w/ NeoPixels

los ntawm microbit ntshuam*
los ntawm gigglebot ntshuam*
los ntawm utime ntshuam sleep_ms, zuam_us
ntshuam ustruct
# pib GB neopixels
neo = init () cov
# sijhawm
update_cov = 50
# nce/tsis tu ncua (piv txwv tias lub roj teeb hluav taws xob nyob ib puag ncig 4.0 volts)
NPV = 25.0
Ki = 0.5 tsi
Kd = 35.0 hli
trigger_point = 0.3
min_speed_percent = 0.3
base_speed = 70
setpoint = 0.5 hli
last_position = setpoint
ib = 0.0.0
run_neopixels = 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
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
pixels_ tawm ()
tsum tsum ()
pw_ms (500)
yog tias khiav isTrue:
# nyeem kab cim
start_time = ticks_us ()
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
# qhov ntau yuav tsum yog (0, 1) thiab tsis yog [0, 1]
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 raws li qhov ua yuam kev
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 + i] = turquoise
neo [center_pixel + kuv] = (12, 44, 41)
lwm tus:
# neo [center_pixel - kuv] = turquoise
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 (64* feem pua /5), int (224* feem pua /5), int (208* feem pua /5))
lwm tus:
# neo [center_pixel - i] = tuple (daim ntawv qhia (lambda x: int (x * feem pua), turquoise))
neo [center_pixel - i] = (int (64* feem pua /5), int (224* feem pua /5), int (208* feem pua /5))
so
neo.show ()
sim:
# clip lub cav nrawm
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
if1000.0/ update_rate - ncua_diff> 0:
pw tsaug zog (1000.0/ update_rate - ncua _diff)

saib rawgigglebot_tuned_line_follower.py tuav nrog ❤ los ntawm GitHub

Kauj ruam 5: Cia Nws Ua Haujlwm

Muaj 2 khawm ntawm BBC micro: ntsis: khawm A thiab khawm B:

  • Nias ntawm khawm A teeb tsa GiggleBot kom ua raws kab (yog tias muaj).
  • Nias ntawm khawm B nres GiggleBot thiab rov pib dua txhua yam kom koj tuaj yeem siv nws dua.

Nws tau qhia tawm kom tsis txhob nqa GiggleBot thaum nws ua raws kab thiab tom qab ntawd muab nws rov qab rau nws vim qhov ua yuam kev uas suav tau tuaj yeem sib sau thiab cuam tshuam tag nrho cov neeg hlau txoj kev. Yog tias koj xav nqa nws, nias lub pob B thiab tom qab ntawd thaum koj muab nws rov qab nias A dua.

Pom zoo: