Cov txheej txheem:

Ua Tus Lidar-Guided Robot Nrog GiggleBot: 8 Kauj Ruam
Ua Tus Lidar-Guided Robot Nrog GiggleBot: 8 Kauj Ruam

Video: Ua Tus Lidar-Guided Robot Nrog GiggleBot: 8 Kauj Ruam

Video: Ua Tus Lidar-Guided Robot Nrog GiggleBot: 8 Kauj Ruam
Video: 20 MOMENTS YOU WOULDN'T BELIEVE IF NOT FILMED 2024, Kaum ib hlis
Anonim
Ua Tus Lidar-Guided Robot Nrog GiggleBot
Ua Tus Lidar-Guided Robot Nrog GiggleBot
Ua Tus Lidar-Guided Robot Nrog GiggleBot
Ua Tus Lidar-Guided Robot Nrog GiggleBot
Ua Tus Lidar-Guided Robot Nrog GiggleBot
Ua Tus Lidar-Guided Robot Nrog GiggleBot

Hauv qhov kev qhia no, peb tab tom ua GiggleBot daws qhov nyuaj ntawm kev tshawb nrhiav.

Peb tau teeb tsa servo ntawm GiggleBot mus rau qhov uas peb txuas lub ntsuas nrug. Thaum khiav, lub servo yuav tig rov qab los kom lub ntsuas qhov deb tuaj yeem ntsuas qhov kev ncua deb mus txog txhua qhov teeb meem. Qhov no ua haujlwm zoo ib yam li LIDAR sensor uas feem ntau kim dua.

Nyob rau tib lub sijhawm, GiggleBot tab tom xa cov ntaub ntawv no mus rau qhov chaw deb deb BBC micro: me ntsis uas nthuav tawm mus rau nws 5-by-5 matrix ntawm LEDs nws txoj haujlwm txheeb ze rau qhov teeb meem.

Koj txoj haujlwm yog kom muaj peev xwm taw qhia GiggleBot tsuas yog saib seb nws tau qhia dab tsi ntawm lwm qhov BBC micro: me ntsis. Txhawm rau tswj GiggleBot, cov nyees khawm ntawm cov chaw deb BBC micro: me ntsis tau siv.

Qhov ntawd zoo li lom zem! Cia peb nqis mus rau nws, puas yog?

Kauj Ruam 1: Cov Cheeb Tsam Xav Tau

Yuav tsum tau Cheebtsam
Yuav tsum tau Cheebtsam

Peb yuav xav tau:

  1. Ib GiggleBot.
  2. Lub roj teeb pob rau BBC micro: me ntsis. Nws los nrog BBC micro: me ntsis hauv nws pob.
  3. x3 AA roj teeb rau GiggleBot.
  4. Ib txoj kab Grove txuas rau qhov ntsuas qhov deb mus rau GiggleBot.
  5. Cov khoom siv Servo los ntawm DexterIndustries.
  6. x3 BBC micro: me ntsis. Ib qho rau GiggleBot thiab ib qho siv los tswj cov neeg hlau los ntawm qhov deb.
  7. Ib qho deb Sensor los ntawm DexterIndustries.

Tau txais GiggleBot neeg hlau rau BBC micro: me ntsis ntawm no!

Kauj Ruam 2: Sib Sau Cov Neeg Hlau

Sib dhos Cov Neeg Hlau
Sib dhos Cov Neeg Hlau
Sib dhos Cov Neeg Hlau
Sib dhos Cov Neeg Hlau

Txhawm rau ua kom GiggleBot npaj tau los ua haujlwm, peb yuav tsum sib sau ua ke, txawm hais tias tsis muaj ntau yam yuav tsum tau ua.

Ntxig rau 3 AA roj teeb hauv nws qhov chaw nyob hauv qab GiggleBot.

Sib sau ua ke pob servo. Txhawm rau nws tig caj npab ntawm servo, siv lub qhov kawg ntawm nws txhawm rau txhim kho servo mus rau GiggleBot lub hauv ntej txuas. Koj tuaj yeem siv cov ntsia hlau thiab/lossis qee qhov xaim los ua kom nws ruaj khov nyob hauv nws qhov chaw. Lossis koj tuaj yeem ua kua nplaum kub rau ntawm lub rooj tsavxwm. Hauv kuv qhov xwm txheej, Kuv tau siv cov ntsia hlau thiab cov xov hlau luv los khi lub caj npab servo rau GiggleBot board.

Thaum txhim kho lub caj npab servo mus rau servo, xyuas kom tseeb tias servo twb tau teeb tsa rau txoj haujlwm 80. Koj tuaj yeem ua li ntawd los ntawm kev hu rau gigglebot.set_servo (gigglebot. RIGHT, 80). Koj tuaj yeem nyeem ntxiv txog qhov no ntawm no.

Tom ntej no, tso qhov ntsuas qhov deb ntawm sab xub ntiag ntawm pob servo thiab kho nws zoo li hauv qhov piv txwv saum toj no.

Thaum kawg, txuas qhov ntsuas nrug nrog Grove cable rau ib qho ntawm 2 I2C cov chaw nres nkoj thiab lub tshuab servo mus rau qhov chaw nres nkoj sab xis zaum ntawm GiggleBot - qhov chaw nres nkoj raug hais los ntawm nws.

Kauj Ruam 3: Tsim Koj Tus Kheej Maze - Yeem tau

Tsim Koj Tus Kheej Maze - Yeem tau
Tsim Koj Tus Kheej Maze - Yeem tau

Hauv qhov no, Kuv tau siv cov thawv ntim los tsim cov kab kaw kaw, zoo ib yam li NASCAR ib qho.

Hauv cov kauj ruam no, koj tuaj yeem tau txais kev muaj tswv yim tiag tiag thiab ua kom nws zoo li cas koj xav tau lossis ua kom ntev ntev vim tias nws yog qhov tseeb rau koj.

Lossis yog tias koj tsis xav tau txoj hauv kev tag nrho, koj tuaj yeem tso GiggleBot hauv chav ua noj lossis chav nyob nyob piv txwv - uas yuav tsum zoo txaus vim tias muaj ntau phab ntsa thiab teeb meem koj tseem yuav tsum zam.

Kauj Ruam 4: 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 5: Ua Haujlwm GiggleBot - Ntu Kuv

Ua ntej, cia teeb GiggleBot's tsab ntawv. Tsab ntawv no yuav ua rau GiggleBot tig nws lub cav servo 160 degrees (80 degrees hauv txhua qhov kev taw qhia) thaum tib lub sijhawm siv 10 nyeem los ntawm qhov ntsuas qhov deb ib zaug.

Thaum qhib, GiggleBot yuav sawv los txog thaum nws tau txais cov lus txib los ntawm kev tswj chaw taws teeb. Tsuas muaj 3 lo lus txib: txav mus rau tom ntej, mus rau sab laug lossis sab xis.

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.

Tswj Chaw Taws Teeb LIDAR-based GiggleBot

los ntawm gigglebot ntshuam*
los ntawm distance_sensor ntshuam DistanceSensor
los ntawm microbit ntshuam pw tsaug zog
los ntawm utime ntshuam ticks_us, sleep_us
ntshuam ustruct
ntshuam xov tooj cua
# nres tus neeg hlau yog tias nws twb txav mus lawm
tsum tsum ()
# qhib xov tooj cua
xov tooj cua.on ()
# nrug sensor qhov khoom
ds = DistanceSensor ()
ds.start_continuous ()
tig_time = 0.7# ntsuas hauv vib nas this
tig_span = 160# ntsuas hauv degrees
tig_steps = 10
overhead_compensation = 1.05# txhais hauv feem pua
time_per_step = 10 ** 6* rotate_time / (tig_steps* nyiaj siv ua haujlwm_compensation)
last_read_time = 0
radar = bytearray (tig_steps)
servo_rotate_direction = 0# 0 rau kev nce mus (0-> 160) thiab 1 lwm yam
radar_index = 0
set_servo (RIGHT, 0)
thaum tseeb
# nyeem los ntawm lub radar
yog zuam_us () - kawg_read_time> time_per_step:
# nyeem los ntawm qhov ntsuas qhov deb
radar [radar_index] = int (ds.read_range_continuous () /10)
last_read_time = zuam_us ()
luam tawm (radar_index)
# ua lub logic rau kev hloov servo ntawm sab laug mus rau sab xis
yog radar_index == tig_steps -1 thiab servo_rotate_direction == 0:
set_servo (RIGHT, 0)
servo_rotate_direction = 1
elif radar_index == 0 thiab servo_rotate_direction == 1:
set_servo (RIGHT, tig_span)
servo_rotate_direction = 0
lwm tus:
radar_index += 1if servo_rotate_direction == 0else-1
# thiab xa cov txiaj ntsig radar
xov tooj cua.send_bytes (radar)
sim:
# nyeem cov lus txib neeg hlau
lmotor, rmotor = ustruct.unpack ('bb', radio.receive_bytes ())
# thiab ua lub cav yuav tsum muaj ib qho tau txais cov lus txib
set_speed (lmotor, rmotor)
tsav ()
exceptTypeError:
dhau

saib rawgigglebot_lidar_robot.py tuav nrog ❤ los ntawm GitHub

Kauj Ruam 6: Kev Ua Haujlwm Hauv Chaw Taws Teeb - Ntu II

Dab tsi tseem tshuav yuav tsum tau ua yog qhov program thib 2 BBC micro: me ntsis uas ua raws li chaw taws teeb.

Cov chaw taws teeb tau siv los tso tawm ntawm nws 5-by-5 pixel-made screen qhov txheeb ze ze rau teeb meem. Feem ntau, yuav muaj 10 pixels qhib.

Nyob rau tib lub sijhawm, cov chaw taws teeb muab rau koj lub peev xwm los tswj hwm GiggleBot los ntawm kev nyem nws 2 lub nyees khawm: txav mus rau tom ntej, mus rau sab laug thiab sab xis.

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.

Kev Tswj Chaw Taws Teeb LIDAR -based GiggleBot - Cov Chaw Taws Teeb

los ntawm microbit ntshuam pw tsaug zog, tso saib, khawm_a, khawm_b
ntshuam ustruct
ntshuam xov tooj cua
ntshuam lej
xov tooj cua.on ()
tig_steps = 10
tig_span = 160# nyob rau hauv degrees
tig_step = tig_span / tig_steps
max_distance = 50# hauv centimeters
side_length_leds = 3 # ntsuas hauv # ntawm pixels
radar = bytearray (tig_steps)
xar = bytearray (tig_steps)
yar = bytearray (tig_steps)
saved_xar = bytearray (tig_steps)
saved_yar = bytearray (tig_steps)
motor_speed = 50
thaum tseeb
xwm txheej = xov tooj cua.receive_bytes_into (radar)
yog tias xwm txheej tsis yog Tsis muaj:
# display.clear ()
rau c, val inenumerate (radar):
yog radar [c] <= max_distance:
# xam 2d kev tswj hwm ntawm txhua qhov nrug
kaum = tig_steps / (tig_steps -1) * tig_step * c
kaum += (180- tig_span) /2.0
x_c = math.cos (angle * math.pi /180.0) * radar [c]
y_c = math.sin (kaum * math.pi /180.0) * radar [c]
# ntsuas qhov nrug kom haum rau ntawm 5x5 microbit zaub
x_c = x_c * (side_length_leds -1) / max_distance
y_c = y_c * (side_length_leds +1) / max_distance
# hloov chaw tswj hwm
x_c += (side_length_leds -1)
y_c = (side_length_leds +1) - y_c
# puag ncig kev ua haujlwm raws qhov pom cov LEDs
yog x_c - lej.floor (x_c) <0.5:
x_c = math.floor (x_c)
lwm tus:
x_c = math.ceil (x_c)
yog y_c - lej.floor (y_c) <0.5:
y_c = math.floor (y_c)
lwm tus:
y_c = math.ceil (y_c)
xar [c] = x_c
yar [c] = y_c
lwm tus:
xav [c] = 0
yar [c] = 0
display.clear ()
rau x, y inzip (xar, yar):
display.set_pixel (x, y, 9)
# luam tawm (cov npe (zip (xar, yar, radar)))
stateA = button_a.is_pressed ()
stateB = button_b.is_pressed ()
yog stateA thiab stateB:
radio.send_bytes (ustruct.pack ('bb', motor_speed, motor_speed))
print ('rau pem hauv ntej')
yog stateA thiab tsis stateB:
radio.send_bytes (ustruct.pack ('bb', motor_speed, -motor_speed))
print ('sab laug')
ifnot stateA thiab stateB:
radio.send_bytes (ustruct.pack ('bb', -motor_speed, motor_speed))
print ('txoj cai')
ifnot stateA thiab tsis stateB:
radio.send_bytes (ustruct.pack ('bb', 0, 0))
print ('tsum tsum')

saib rawgigglebot_lidar_remote.py tuav nrog ❤ los ntawm GitHub

Kauj Ruam 7: Kev Txhais Lus Ntawm Lub Vev Xaib

"thauj khoom =" tub nkeeg "tswj GiggleBot, koj muaj cov kev xaiv hauv qab no:

  1. Nias khawm A thiab khawm B kom txav GiggleBot rau pem hauv ntej.
  2. Nias lub pob A kom tig lub GiggleBot mus rau sab laug.
  3. Nias khawm B kom tig GiggleBot mus rau sab xis.

Txhawm rau saib mus rau qhov kev taw qhia qhov teeb meem ze tshaj plaws raug kuaj pom, tsuas yog saib ntawm cov chaw taws teeb (cov chaw taws teeb BBC micro: me ntsis uas koj tab tom tuav) lub vijtsam. Koj yuav tsum muaj peev xwm tswj hwm GiggleBot los ntawm qhov deb tsis saib nws.

Pom zoo: