Cov txheej txheem:

Tus Neeg Hlau Butter: Arduino Robot Nrog Qhov Teeb Meem Muaj: 6 Kauj Ruam (nrog Duab)
Tus Neeg Hlau Butter: Arduino Robot Nrog Qhov Teeb Meem Muaj: 6 Kauj Ruam (nrog Duab)

Video: Tus Neeg Hlau Butter: Arduino Robot Nrog Qhov Teeb Meem Muaj: 6 Kauj Ruam (nrog Duab)

Video: Tus Neeg Hlau Butter: Arduino Robot Nrog Qhov Teeb Meem Muaj: 6 Kauj Ruam (nrog Duab)
Video: NOOBS PLAY CLASH ROYALE FROM START LIVE 2024, Lub Xya hli ntuj
Anonim
Image
Image

Qhov haujlwm no yog ua raws cov yeeb yaj kiab ua yeeb yaj kiab "Rick and Morty". Hauv ib qho ntawm ntu, Rick ua tus neeg hlau uas nws lub hom phiaj tsuas yog nqa butter. Raws li cov tub ntxhais kawm los ntawm Bruface (Brussels Kws Qhia Ntawv ntawm Engineering) peb muaj lub luag haujlwm rau mechatronics project uas yog los tsim cov neeg hlau raws li cov ncauj lus pom. Lub luag haujlwm rau txoj haujlwm no yog: Ua tus neeg hlau uas tsuas yog ua haujlwm rau butter. Nws tuaj yeem muaj teeb meem kev muaj sia nyob. Tau kawg cov neeg hlau nyob rau ntu ntawm Rick thiab Morty yog cov neeg hlau uas nyuaj heev thiab qee qhov yooj yim yuav tsum tau ua:

Txij li nws lub hom phiaj tsuas yog nqa butter, muaj ntau txoj hauv kev yooj yim dua. Hloov chaw ua tus neeg hlau saib thiab tuav lub butter, ua ntej nws coj nws mus rau tus neeg zoo, tus neeg hlau tuaj yeem nqa lub butter txhua lub sijhawm. Lub tswv yim tseem ceeb yog li ua lub laub uas thauj cov butter mus rau qhov nws xav tau.

Sib nrug los ntawm kev thauj cov butter, tus neeg hlau yuav tsum paub qhov twg nws xav tau nqa cov butter. Hauv qhov rov, Rick siv nws lub suab hu thiab txib tus neeg hlau. Qhov no yuav tsum muaj lub suab lees paub lub suab kim thiab yuav ua rau nyuaj. Hloov chaw, txhua tus neeg ntawm lub rooj tau txais lub pob: thaum lub pob no tau qhib, tus neeg hlau tuaj yeem nrhiav lub pob no thiab txav mus rau nws.

Txhawm rau rov hais dua, tus neeg hlau yuav tsum ua kom tau raws li cov hauv qab no:

  • Nws yuav tsum muaj kev nyab xeeb: nws yuav tsum zam kev thaiv thiab tiv thaiv nws tus kheej los ntawm kev poob ntawm lub rooj;
  • Tus neeg hlau yuav tsum tau me me: qhov chaw ntawm lub rooj yog txwv thiab tsis muaj leej twg xav tau tus neeg hlau uas ua haujlwm butter tab sis yog ib nrab ntawm lub rooj nws tus kheej;
  • Kev ua haujlwm ntawm tus neeg hlau tsis tuaj yeem nyob ntawm qhov loj lossis cov duab ntawm lub rooj, txoj kev ntawd nws tuaj yeem siv rau ntawm cov rooj sib txawv;
  • Nws xav tau nqa cov butter mus rau tus neeg zoo ntawm lub rooj.

Kauj Ruam 1: Lub Ntsiab Tseem Ceeb

Cov lus hais yav dhau los tuaj yeem ua tau raws li siv cov txheej txheem sib txawv. Kev txiav txim siab txog lub ntsiab tsim uas tau ua yog piav qhia hauv theem no. Cov ncauj lus kom ntxaws txog yuav ua li cas cov tswv yim no tuaj yeem pom hauv cov kauj ruam hauv qab no.

Txhawm rau ua tiav nws lub luag haujlwm, tus neeg hlau yuav tsum txav mus kom txog thaum lub hom phiaj mus txog. Xav txog daim ntawv thov neeg hlau nws yog qhov ncaj uas siv lub log hloov ntawm "taug kev" cov lus tsa suab zoo dua kom nws txav mus los. Txij li lub rooj yog lub tiaj tiaj thiab tus neeg hlau yuav tsis ncav cuag lub nrawm heev, ob lub log ua haujlwm thiab ib lub pob caster yog qhov yooj yim tshaj plaws thiab yooj yim tshaj plaws los tswj kev daws teeb meem. Lub log ua haujlwm yuav tsum tau tsav los ntawm ob lub cav. Cov motors yuav tsum muaj lub zog loj tab sis lawv tsis xav tau kom nrawm dua, yog vim li cas thiaj yuav siv cov tshuab servo txuas ntxiv mus. Lwm qhov zoo ntawm servo motors yog qhov yooj yim ntawm kev siv nrog Arduino.

Kev txheeb xyuas cov teeb meem tuaj yeem ua tiav siv lub ntsuas hluav taws xob ultrasonic uas ntsuas qhov nrug, txuas nrog lub cav servo los xaiv txoj kev ntsuas. Cov npoo tuaj yeem kuaj pom siv LDR sensors. Kev siv LDR cov ntsuas yuav xav tau kev tsim kho cov cuab yeej uas muaj ob lub teeb coj thiab lub LDR sensor. LDR lub ntsuas ntsuas ntsuas lub teeb pom kev zoo thiab tuaj yeem pom tias yog qee yam kev ntsuas nrug. Tib lub hauv paus ntsiab lus tshwm sim nrog lub teeb ci ci. Muaj qee qhov infrared sib thooj sensor uas muaj cov digital tso tawm: kaw lossis tsis kaw. Qhov no yog qhov uas tus neeg hlau xav tau los txheeb xyuas cov npoo. Los ntawm kev sib txuas 2 lub ntsej muag ntsuas tso rau zoo li ob kab antennas thiab ib qho ua haujlwm ultrasonic sensor, tus neeg hlau yuav tsum muaj peev xwm zam tau cov teeb meem thiab cov npoo.

Kev tshawb nrhiav lub pob kuj tseem tuaj yeem ua tiav los ntawm kev siv IR cov cim thiab teeb. Qhov zoo ntawm IR yog qhov nws pom tsis tau uas ua rau siv nws tsis cuam tshuam rau cov neeg ntawm lub rooj. Lasers tuaj yeem siv tau ib yam nkaus, tab sis tom qab ntawd lub teeb yuav pom thiab tseem txaus ntshai thaum ib tus neeg taw tes rau lub laser mus rau lwm tus neeg qhov muag. Tsis tas li, tus neeg siv yuav xav tau lub hom phiaj ntawm cov neeg hlau nrog tsuas yog lub teeb nqaj laser, uas yuav yog qhov tsis txaus ntseeg. Los ntawm kev nruab tus neeg hlau nrog ob lub IR ntsuas thiab tsim lub pob nrog IR coj, tus neeg hlau paub qhov kev taw qhia uas nws xav tau los ntawm kev ua raws li kev siv ntawm IR-lub teeb. Thaum tsis muaj khawm tus neeg hlau tuaj yeem tig rov mus txog thaum ib qho ntawm cov leds ntes lub teeb liab los ntawm ib qho ntawm cov nyees khawm.

Cov butter tau muab tso rau hauv ib lub qhov rau saum cov neeg hlau. Lub thawv no tuaj yeem muaj lub thawv thiab lub hau qhib kom qhib lub thawv. Txhawm rau qhib lub hau thiab txav lub ntsuas hluav taws xob ultrasonic txhawm rau tshuaj xyuas thiab txheeb xyuas qhov teeb meem peb xav tau ob lub cav thiab rau lub hom phiaj no, tsis siv neeg siv servo txuas ntxiv tau hloov pauv ntau dua vim tias lub tshuab yuav tsum tau mus rau ntawm txoj haujlwm thiab tswj xyuas qhov tshaj tawm.

Ib qho tshwj xeeb ntxiv ntawm txoj haujlwm yog los cuam tshuam nrog ib puag ncig sab nraud nrog lub suab neeg hlau. Lub suab nrov yog qhov yooj yim thiab yoog raws lub hom phiaj no tab sis nws tsis tuaj yeem siv tau txhua lub sijhawm vim tias kev kos duab tsis zoo.

Cov teeb meem tseem ceeb ntawm txoj haujlwm vam khom rau tus lej, vim tias cov khoom siv tshuab yog qhov yooj yim heev. Muaj ntau yam yuav tsum tau coj mus rau hauv tus account kom tsis txhob muaj neeg hlau raug daig lossis ua qee yam tsis xav tau. Cov teeb meem tseem ceeb uas peb yuav tsum tau daws yog poob lub teeb liab IR vim tias muaj teeb meem thiab nres thaum nws tuaj txog ntawm lub pob!

Kauj ruam 2: Cov ntaub ntawv

Qhov chaw kho tshuab

  • 3D tshuab luam ntawv thiab Laser txiav tshuab

    • PLA yuav siv rau 3D luam ntawv tab sis koj tseem tuaj yeem siv ABS
    • Ib lub phaj ntawm 3 hli birch plywood yuav siv rau kev txiav laser vim nws muab qhov ua tau los hloov kho tom qab yooj yim, Plexiglas kuj tseem tuaj yeem siv tau tab sis nws nyuaj rau hloov nws ib zaug nws yog laser txiav yam tsis rhuav nws
  • Bolts, ceev, tshuab ntxhua khaub ncaws

    Feem ntau ntawm cov khoom siv tau koom ua ke siv M3 khawm taub hau, tshuab ntxhua khaub ncaws thiab txiv ntseej, tab sis qee qhov ntawm lawv xav tau M2 lossis M4 ntsia liaj qhov rooj teeb. Qhov ntev ntawm cov ntsia liaj qhov rooj yog nyob ntawm thaj tsam 8-12 hli

  • PCB spacers, 25 hli thiab 15 hli
  • 2 Servo motors nrog cov log sib xws
  • Qee cov hlau hlau tuab nyob ib puag ncig 1-2 hli txoj kab uas hla

Cov khoom siv hluav taws xob

  • Microcontroller

    1 arduino UNO pawg thawj coj saib

  • Servo tsav

    • 2 Cov neeg tsav tsheb loj: Feetech txuas ntxiv 6Kg 360 degrees
    • 2 micro servo motors: Feetech FS90
  • Sensors

    • 1 Ultrasonic sensor
    • 2 IR sib thooj sensor
    • 2 IR photodiodes
  • Roj teeb

    • 19V roj teeb tuav + roj teeb
    • 14 AA roj teeb tuav + roj teeb
    • 1 9V roj teeb lub thawv + roj teeb
  • Cheebtsam ntxiv

    • Qee qhov dhia cov xov hlau, cov xov hlau thiab cov hlau txuas
    • Qee cov resistors
    • 1 IR LED
    • 3 hloov
    • 1 ib buzz
    • 1 khawm
    • 1 Arduino rau 9V roj teeb txuas

Kauj Ruam 3: Kuaj Cov Khoom Siv Hluav Taws Xob

Kuaj Cov Khoom Siv Hluav Taws Xob
Kuaj Cov Khoom Siv Hluav Taws Xob
Kuaj Cov Khoom Siv Hluav Taws Xob
Kuaj Cov Khoom Siv Hluav Taws Xob

Tsim lub khawm:

Lub khawm tau yooj yim los ntawm kev hloov pauv, lub teeb pom kev zoo LED, thiab 220 Ohm resistor hauv koob, siv los ntawm 9V roj teeb. Qhov no tau muab tso rau hauv 9V lub roj teeb pob rau kev tsim kom huv thiab huv.

Tsim cov infrared receiver modules:

Cov qauv no tau ua nrog los ntawm cov laug cam laug cam, uas tom qab ntawd yuav txuas nrog cov ntsia hlau rau tus neeg hlau. Cov kab hluav taws xob rau cov qauv no tau piav qhia hauv kab lus dav dav. Lub hauv paus ntsiab lus yog los ntsuas qhov siv ntawm lub teeb pom kev deb. Txhawm rau txhim kho qhov ntsuas, collimators (ua nrog cov hlab ntsws) tuaj yeem siv los tsom mus rau qee qhov kev qhia uas txaus siab.

Kev xav tau sib txawv ntawm txoj haujlwm yuav tsum ua kom tiav siv cov cuab yeej hluav taws xob. Tus naj npawb ntawm cov cuab yeej yuav tsum raug txwv thiaj li ua rau cov txheeb ze muaj qhov nyuaj. Cov kauj ruam no muaj cov kab hluav taws xob txuas thiab txhua tus lej txhawm rau ntsuas txhua ntu sib cais:

  • Nruam Servo motors;
  • Ultrasonic sensor;
  • Tsis tas li Servo motors;
  • Buzzer;
  • IR khawm kev qhia paub;
  • Ntug pom los ntawm kev sib thooj sensor;

Cov lej no tuaj yeem pab nkag siab txog cov khoom siv thaum pib, tab sis nws kuj tseem muaj txiaj ntsig zoo rau kev debugging nyob rau theem tom ntej. Yog tias muaj qee qhov teeb meem tshwm sim, kab tuaj yeem kuaj pom tau yooj yim dua los ntawm kev sim txhua yam khoom sib cais.

Kauj Ruam 4: Luam Ntawv 3D thiab Laser Txiav Daim Ntawv Tsim

3D Luam Ntawv thiab Laser Txiav Daim Qauv Tsim
3D Luam Ntawv thiab Laser Txiav Daim Qauv Tsim
3D Luam Ntawv thiab Laser Txiav Daim Qauv Tsim
3D Luam Ntawv thiab Laser Txiav Daim Qauv Tsim
3D Luam Ntawv thiab Laser Txiav Daim Qauv Tsim
3D Luam Ntawv thiab Laser Txiav Daim Qauv Tsim

Laser Txiav daim

Lub rooj sib txoos yog tsim los ntawm peb daim phiaj kab rov tav tseem ceeb ua ke los ntawm PCB spacers kom tau txais kev qhib qhib muab kev nkag tau yooj yim rau cov khoom siv hluav taws xob yog xav tau.

Cov phaj no yuav tsum tau txiav qhov tsim nyog txhawm rau txhawm rau ntswj lub spacers thiab lwm yam khoom siv rau kev sib dhos zaum kawg. Feem ntau, tag nrho peb daim phiaj muaj qhov nyob rau tib qhov chaw rau cov spacers, thiab qhov tshwj xeeb rau cov khoom siv hluav taws xob tsau feem ntawm txhua phaj. Daim ntawv ceeb toom tias phaj nruab nrab muaj lub qhov rau hla cov xov hlau nyob hauv nruab nrab.

Cov ntawv me me tau txiav rau qhov ntev ntawm cov servo loj los kho lawv rau hauv kev sib dhos.

3D Luam tawm daim

Ntxiv rau kev txiav laser, qee daim yuav tsum tau luam tawm 3D:

  • Kev txhawb nqa rau lub ntsuas hluav taws xob ultrasonic, uas txuas nws mus rau ib qho micro servo lub cev muaj zog caj npab
  • Kev txhawb nqa rau lub log castor thiab ob qho IR ntug sensors. Kev tsim tshwj xeeb ntawm lub npov zoo li qhov kawg ntawm daim rau IR cov cim ua raws li lub vijtsam kom tsis txhob cuam tshuam ntawm lub pob hluav taws xob tso tawm IR lub teeb liab thiab IR cov cim uas yuav tsum tsom mus rau qhov tshwm sim hauv av nkaus xwb
  • Kev txhawb nqa rau micro servo motor qhib lub hau
  • Thiab thaum kawg lub hau nws tus kheej, ua los ntawm ob daim kom muaj lub ntsej muag ua haujlwm loj dua los ntawm kev zam kev sib tsoo nrog lub micro servo motor qhib lub hau:

    • Ib qho hauv qab uas yuav tsau rau saum phaj
    • Thiab sab saum toj uas txuas rau hauv qab los ntawm pob khawm, thiab ua haujlwm los ntawm servo siv cov hlau tuab tuab. Peb txiav txim siab ntxiv me ntsis tus cwj pwm rau tus neeg hlau los ntawm kev muab nws lub taub hau.

Thaum txhua daim tsim thiab tsim cov ntaub ntawv xa tawm kom raug rau lub tshuab siv, daim ntawv tuaj yeem ua tau. Nco ntsoov tias 3D luam ntawv siv sijhawm ntau, tshwj xeeb tshaj yog nrog qhov ntev ntawm daim saum toj kawg nkaus ntawm lub hau. Koj yuav xav tau ib lossis ob hnub los luam tawm txhua daim. Laser txiav txawm li cas los xij tsuas yog teeb meem ntawm feeb.

Txhua qhov SOLIDWORKS-cov ntaub ntawv tuaj yeem pom nyob rau hauv daim nplaub tshev zipped.

Kauj Ruam 5: Sib dhos thiab thaiv

Image
Image
Sib dhos thiab thaiv
Sib dhos thiab thaiv
Sib dhos thiab thaiv
Sib dhos thiab thaiv
Sib dhos thiab thaiv
Sib dhos thiab thaiv

Lub rooj sib txoos yuav yog kev sib txuas ntawm cov thaiv thiab txuas cov khoom sib dhos ua ke, pib txij hauv qab mus rau saum.

Qab phaj

Cov phaj hauv qab tau sib sau ua ke nrog 4AA lub roj teeb pob, lub tshuab servo, cov ntawv luam tawm (txuas lub pob caster hauv qab lub phaj), ob lub ntsej muag lub ntsej muag, thiab 6 tus txiv neej-poj niam spacers.

Nruab nrab phaj

Tom ntej no, phaj nruab nrab tuaj yeem ntsia tau, muab cov servo motors nruab nrab ntawm ob lub phaj. Cov phaj no tuaj yeem kho tau los ntawm kev muab lwm txheej spacers tso rau saum nws. Qee cov xov hluav taws xob tuaj yeem hla dhau qhov chaw nruab nrab.

Tus qauv ultrasonic tuaj yeem txuas rau qhov tsis txuas mus rau qhov kev pabcuam, uas tau tsau rau ntawm lub phaj nruab nrab nrog Arduino, lub roj teeb 9V (ua kom lub zog arduino), thiab ob lub tshuab hluav taws xob txais lub ntsej muag nyob ntawm xub ntiag. Cov qauv no tau ua nrog los ntawm cov laug cam laug cam thiab txuas nrog cov ntsia hlau rau hauv phaj. Cov kab hluav taws xob rau cov qauv no tau piav qhia hauv kab lus dav dav.

Sab saum toj phaj

Ntawm qhov kev sib dhos no tsis tau hloov kho tab sis tus neeg hlau tuaj yeem ua txhua yam tshwj tsis yog ua yam xav tau lub hau, yog li nws tso cai rau peb ua qee qhov kev sim txhawm rau kho lub treshold, hloov kho cov cai ntawm kev txav chaw thiab kom yooj yim. nkag mus rau cov chaw nres nkoj ntawm arduino.

Thaum txhua qhov no ua tiav, cov phaj saum toj tuaj yeem kho nrog spacers. Cheebtsam kawg uas yog ob qhov hloov pauv, lub pob, qhov kev pabcuam, lub suab nrov thiab lub kaw lus kaw thaum kawg tuaj yeem kho rau sab saum toj phaj kom ua tiav kev sib dhos.

Qhov kawg los ntsuas thiab kho yog lub kaum sab xis ntawm qhov servo kom qhib lub hau kom raug.

Qhov pib ntawm qhov ntsuas lub ntsej muag yuav tsum tau yoog nrog cov potentiometer suav nrog (los ntawm kev siv tus ntsia hlau ncaj) rau cov rooj sib txawv. Lub rooj dawb yuav tsum muaj qhov pib qis dua li lub rooj xim av piv txwv. Tsis tas li qhov siab ntawm cov ntsuas yuav cuam tshuam qhov xav tau pib.

Qhov kawg ntawm cov kauj ruam no, kev sib dhos ua tiav thiab qhov kawg uas seem yog cov lej uas ploj lawm.

Kauj Ruam 6: Coding: Muab Txhua Yam Ua Ke

Txhua qhov cai tsim nyog kom ua rau neeg hlau ua haujlwm yog nyob hauv cov ntaub ntawv zipped uas tuaj yeem rub tawm. Qhov tseem ceeb tshaj plaws yog tus lej "tseem ceeb" uas suav nrog kev teeb tsa thiab kev ua haujlwm ntawm tus neeg hlau. Feem ntau ntawm lwm cov haujlwm tau sau rau hauv cov ntawv me me (tseem nyob hauv daim nplaub tshev zipped). Cov ntaub ntawv hauv qab no yuav tsum raug khaws tseg hauv tib daim nplaub tshev (uas yog lub npe "ntsiab") ua cov ntawv tseem ceeb ua ntej rub nws mus rau Arduino

Ua ntej qhov dav dav ntawm tus neeg hlau tau txhais ua ke nrog qhov sib txawv "nco". Qhov "nco" no yog tus nqi uas nco txog qhov uas neeg hlau tig mus. Yog "nco = 1", tus neeg hlau yog/tig sab laug, yog "nco = 2", tus neeg hlau yog/tig txoj cai.

int ceev = 9; // Dav dav ntawm tus neeg hlau

int nco = 1; // Thawj qhov kev taw qhia

Hauv kev teeb tsa tus neeg hlau, cov ntaub ntawv sib txawv ntawm cov phiaj xwm tau pib. Hauv cov ntaub ntawv hauv qab no, cov haujlwm tseem ceeb ntawm kev tswj hwm lub cav, cov ntsuas, … yog sau. Los ntawm kev pib ua lawv hauv kev teeb tsa, lub luag haujlwm uas tau piav qhia hauv txhua ntawm cov ntaub ntawv no tuaj yeem siv tau hauv lub ntsiab lus. Los ntawm kev qhib lub luag haujlwm r2D2 (), tus neeg hlau yuav ua suab nrov zoo li R2D2 neeg hlau los ntawm Star Wars movie franchise thaum nws pib tuaj. Ntawm no r2D2 () muaj nuj nqi raug xiam oob qhab los tiv thaiv lub buzzer los ntawm kev kos ntau dhau tam sim no.

// Teeb @ pib dua // ----------------

teeb tsa tsis muaj dabtsis () {initialize_IR_sensors (); initialize_obstacles_and_edges (); pib_movement (); initialize_lid (); cov. initialize_buzzer (); // r2D2 (); int nco = 1; // pib taw qhia pib (nco); }

Lub Hnub Qub (ceeb toom) ua haujlwm yog hu ua thawj zaug hauv kev teeb tsa. Lub luag haujlwm no ua rau tus neeg hlau tig rov qab thiab nrhiav IR teeb liab ntawm ib qho ntawm cov nyees khawm. Thaum nws tau pom lub khawm, qhov haujlwm yuav tawm ntawm Starter ua haujlwm los ntawm kev hloov qhov sib txawv 'cond' mus rau qhov tsis tseeb. Qhov no tau txheeb xyuas txhua lub sijhawm ua ntej nws tseem tig rov los. Thaum tus neeg hlau pom qhov teeb meem lossis ntug, txoj cai kom zam dhau cov teeb meem no lossis cov npoo yuav raug ua. Cov txheej txheem no yuav piav qhia tom qab hauv cov theem no. Kev pib ua haujlwm muaj ib qho sib txawv uas yog qhov nco sib txawv uas tau tham ua ntej. Los ntawm kev muab tus nqi ceeb toom rau Starter muaj nuj nqi, tus neeg hlau paub txog qhov kev taw qhia nws xav tau tig los txhawm rau nrhiav lub pob.

// Starter Loop: Tig ib ncig thiab tshawb nrhiav lub pob // ------------------------------------ -----------------

void Starter (int ceeb toom) {yog (isedgeleft () || isedgeright ()) {// Txheeb xyuas cov ntug ntugDetected (nco qab); } lwm {bool cond = muaj tseeb; thaum (cond == muaj tseeb) {yog (buttonleft () == tsis tseeb && buttonright () == tsis tseeb && isButtonDetected () == muaj tseeb) {cond = cuav; } lwm {yog (ceeb toom == 1) {// Peb tau tig laug yog (isobstacleleft ()) {stoppeed (); zam_obstacle (ceeb toom); } lwm tus yog (isedgeleft () || isedgeright ()) {// Txheeb xyuas cov ntug ntugDetected (nco ntsoov); } lwm {turnleft (ceev); }} lwm qhov yog (ceeb toom == 2) {yog (isobstacleright ()) {stoppeed (); zam_obstacle (ceeb toom); } lwm tus yog (isedgeleft () || isedgeright ()) {// Txheeb xyuas cov ntug ntugDetected (nco ntsoov); } lwm {turnright (ceev); }

Yog tias tus neeg hlau pom lub pob, tom qab ntawd pib Starter loop tau tawm thiab lub ntsiab, lub voj ua haujlwm ntawm tus neeg hlau pib. Lub voj tseem ceeb no yog qhov nyuaj heev txij li txhua lub sijhawm, tus neeg hlau yuav tsum tau tshuaj xyuas seb puas muaj teeb meem lossis tsis muaj ntug nyob rau ntawm nws xub ntiag. Los ntawm kev siv ob lub ntsuas hluav taws xob IR, peb tuaj yeem cais peb qhov xwm txheej:

  • qhov sib txawv ntawm IR lub teeb pom los ntawm sab laug thiab sab xis yog qhov loj dua li qhov pib, thiab muaj lub pob.
  • qhov sib txawv ntawm IR lub teeb me dua qhov pib, thiab muaj lub pob nyob rau ntawm xub ntiag ntawm tus neeg hlau.
  • qhov sib txawv ntawm IR lub teeb me dua li qhov pib, thiab tsis muaj lub khawm nyob rau hauv ntej ntawm tus neeg hlau.

Txoj hauv kev ua haujlwm niaj hnub ua haujlwm yog raws li hauv qab no: thaum pom lub pob, tus neeg hlau txav mus rau lub pob los ntawm kev tig mus rau tib qho kev taw qhia nws tau tig (siv qhov nco sib txawv) thiab tib lub sijhawm txav me ntsis mus rau tom ntej. Yog tias tus neeg hlau tig mus deb dhau, lub pob yuav ploj dua, thiab nyob rau lub sijhawm no tus neeg hlau nco tau tias nws xav tau tig mus rau lwm qhov. Qhov no tseem ua tiav thaum txav mus tom ntej me ntsis. Los ntawm kev ua qhov no tus neeg hlau tas li tig sab laug thiab tig sab xis, tab sis nyob rau lub sijhawm nruab nrab tseem tab tom nce mus rau lub pob. Txhua lub sijhawm tus neeg hlau pom lub khawm, nws tsuas yog tig rov qab kom txog thaum nws poob nws qhov xwm txheej nws pib txav mus rau lwm qhov kev taw qhia. "turnleft ()" lossis "turnright ()", thaum lub ntsiab lus siv "moveleft ()" thiab "moveright ()". Kev txav mus los/txoj haujlwm tsis yog tsuas yog ua rau tus neeg hlau tig tab sis tseem ua rau nws txav mus tom ntej tib lub sijhawm.

/ * Lub luag haujlwm ua haujlwm ---------------------------- Ntawm no, tsuas muaj txoj hauv kev khiav */

int poob = 0; // Yog tias poob = 0 lub khawm pom, yog poob = 1 lub pob poob ploj tsis muaj qhov khoob () {yog (isedgeleft () || isedgeright ()) {

yog (! isobstacle ()) {

txav mus los (ceev); ncua (5); } lwm {zam_obstacle (nco); } lwm {yog (ceeb toom == 1 && poob == 1) {// Peb tau tig sab laug stoppeed (); yog (! isobstacleright ()) {moveright (ceev); // Tig ib ncig kom pom lub pob} lwm yam {zam_obstacle (nco); } nco = 2; } lwm tus yog (ceeb toom == 2 && poob == 1) {stoppeed (); yog (! isobstacleleft ()) {moveleft (ceev); // Peb tau tig txoj cai} lwm qhov {zam_obstacle (ceeb toom); } nco = 1; } lwm tus yog (poob == 0) {yog (nco == 1) {// Peb tau tig sab laug yog (! isobstacleleft ()) {moveleft (nrawm); // Peb tau tig sab xis} lwm qhov {stoppeed (); zam_obstacle (ceeb toom); } //} lwm tus yog (ceeb toom == 2) {yog (! isobstacleright ()) {moveright (nrawm); // Tig ib ncig kom pom lub pob} lwm yam {stopspeed (); zam_obstacle (ceeb toom); }}} ncua (10); poob = 0; } { /}}}

Tam sim no, piav qhia me ntsis ntawm ob txoj kev ua nyuaj tshaj plaws tau muab:

Zam cov ntug

Cov txheej txheem kom tsis txhob muaj cov npoo tau hais tseg hauv txoj haujlwm hu ua "edgeDetection ()" uas tau sau rau hauv "txav" sub-file. Cov txheej txheem no tso siab rau qhov tseeb tias tus neeg hlau yuav tsum tsuas yog ntsib ib ntug thaum nws tau mus txog nws lub hom phiaj: khawm. Thaum tus neeg hlau pom lub ntug, thawj qhov nws ua yog txav rov qab me ntsis kom nyob nyab xeeb ntawm qhov ntug. Thaum qhov no ua tiav, tus neeg hlau tos txog 2 vib nas this. Yog tias ib tus neeg nias lub pob nyob rau pem hauv ntej ntawm tus neeg hlau nyob hauv ob vib nas this, tus neeg hlau paub tias nws tau mus txog tus neeg xav tau butter thiab qhib lub thawv ntim khoom thiab nthuav cov butter. Txij ntawm no, ib tus neeg tuaj yeem nqa butter los ntawm tus neeg hlau. Tom qab ob peb feeb tus neeg hlau yuav nkees tos thiab yuav cia li kaw lub hau butter. Thaum lub hau raug kaw tus neeg hlau yuav ua rau lub Starter loop mus nrhiav lwm lub pob. Yog tias nws tshwm sim uas tus neeg hlau ntsib tus ntug ua ntej mus txog nws lub hom phiaj thiab lub khawm nyob rau pem hauv ntej ntawm tus neeg hlau tsis raug nias, tus neeg hlau yuav tsis qhib lub hau butter thiab yuav ua tam sim rau lub Starter loop.

Tsis txhob muaj teeb meem

Qhov tsis ua haujlwm_obstacle () muaj nuj nqi kuj tseem nyob hauv "txav" cov ntawv me. Ib feem nyuaj txog kev zam teeb meem yog qhov tseeb tias neeg hlau muaj qhov muag tsis pom loj loj. Lub ntsuas hluav taws xob ultrasonic tau muab tso rau ntawm lub hauv ntej ntawm tus neeg hlau, uas txhais tau tias nws tuaj yeem txheeb xyuas cov teeb meem, tab sis tsis paub thaum nws dhau nws. Txhawm rau daws qhov no, siv lub hauv paus ntsiab lus hauv qab no: Thaum tus neeg hlau ntsib qhov teeb meem, nws siv qhov sib txawv kom rov tig mus rau lwm qhov. Txoj kev no tus neeg hlau tsis txhob tsoo qhov teeb meem. Tus neeg hlau tig mus txog thaum lub ntsuas ultrasonic tsis pom qhov teeb meem ntxiv lawm. Thaum lub sijhawm tus neeg hlau tig, lub txee tau nce mus txog thaum qhov teeb meem tsis pom ntxiv lawm. Lub txee no muab qhov kwv yees ntawm qhov ntev ntawm qhov teeb meem. Los ntawm kev txav mus rau tom ntej thiab tib lub sijhawm txo lub txee qhov teeb meem tuaj yeem zam tau. Thaum lub txee nce mus txog 0, Lub Hnub Qub ua haujlwm tuaj yeem siv dua los hloov lub pob. Tau kawg tus neeg hlau ua tus Starter ua haujlwm los ntawm kev xa rov qab nws tau nco nws tau mus ua ntej nws ntsib teeb meem (rov siv qhov nco sib txawv).

Tam sim no koj nkag siab cov cai, koj tuaj yeem pib siv nws!

Nco ntsoov hloov qhov pib mus rau koj ib puag ncig (IR xav txog yog siab dua ntawm cov ntxhuav dawb piv txwv) thiab hloov kho qhov sib txawv rau koj qhov xav tau. Tsis tas li ntawd, yuav tsum ua tib zoo saib xyuas lub zog ntawm cov qauv sib txawv. Nws yog qhov tseem ceeb tshaj plaws uas servo motors tsis siv los ntawm Arduino 5V chaw nres nkoj, vim tias lawv siv ntau qhov tam sim no (qhov no tuaj yeem ua rau lub microcontroller puas tsuaj). Yog tias tib lub zog siv los rau lub ntsuas hluav taws xob ua lub zog rau servos, qee qhov teeb meem ntsuas tuaj yeem ntsib.

Pom zoo: