Cov txheej txheem:

Roomba Nrog MATLAB: 4 Kauj Ruam (nrog Duab)
Roomba Nrog MATLAB: 4 Kauj Ruam (nrog Duab)

Video: Roomba Nrog MATLAB: 4 Kauj Ruam (nrog Duab)

Video: Roomba Nrog MATLAB: 4 Kauj Ruam (nrog Duab)
Video: SharkClean cav nqus tsev thiab cheb tsev. 2024, Hlis ntuj nqeg
Anonim
Roomba Nrog MATLAB
Roomba Nrog MATLAB

Txoj haujlwm no siv MATLAB thiab iRobot Create2 programmable robot. Los ntawm kev tso peb qhov kev paub ntawm MATLAB rau qhov kev sim, peb muaj peev xwm tsim qhov Tsim2 los txhais cov duab thiab kuaj pom cov cim. Kev ua haujlwm ntawm tus neeg hlau yog nyob ntawm MATLAB mobile app thiab Raspberry Pi lub koob yees duab module.

Kauj Ruam 1: Cov Khoom thiab Cov Khoom

Cov Khoom thiab Cov Khoom
Cov Khoom thiab Cov Khoom
Cov Khoom thiab Cov Khoom
Cov Khoom thiab Cov Khoom
Cov Khoom thiab Cov Khoom
Cov Khoom thiab Cov Khoom
Cov Khoom thiab Cov Khoom
Cov Khoom thiab Cov Khoom

1. iRobot Tsim, Version 2

- Nov yog lub program neeg hlau uas zoo li Roomba. Nco ntsoov tias cov khoom no los ntawm iRobot tsis yog lub tshuab nqus tsev. Nws yog npaj rau kev cai tsim los ntawm tus neeg siv.

2. MATLAB 2017a

- Feem ntau cov ntawv qub yuav sib xws nrog cov cai peb siv hauv qab no. MATLAB yuav txheeb xyuas cov lus txib uas tsis sib xws nrog cov ntawv koj muaj thiab yuav qhia qhov kev hais kom haum zoo tshaj plaws.

3. Raspberry Pi 3 Qauv B, Version 1.2

- Txheeb xyuas seb Raspberry Pi twg sib xws nrog koj iRobot. Saib qhov txuas no txhawm rau pab ntxiv: https://www.irobotweb.com/~/media/MainSite/PDFs/A… Cov lus qhia no xav tias koj tab tom ua haujlwm nrog npaj ua ntej Raspberry Pi. Thov nco ntsoov tias koj yuav tsum tau ua haujlwm nrog preprogrammed Pi txhawm rau ua cov kauj ruam hauv qab no los ua haujlwm. Siv preprogrammed Pi yuav tso cai rau koj ua tag nrho koj cov coding hauv MATLAB ib leeg.

4. Lub Koob Yees Duab Module V2 (rau Raspberry Pi)

- Koj yuav xav tsis thoob; txawm hais tias nws loj npaum li cas, Raspberry Pi Lub Koob Yees Duab Module zoo heev. Nws yog qhov pheej yig tshaj thiab ua tau zoo tshaj plaws rau txoj haujlwm no.

Yeem: 3D-luam tawm sawv ntsug. Qhov no yog siv ruaj khov lub koob yees duab. Nws tsis cuam tshuam rau kev ua haujlwm ntawm tus neeg hlau, tab sis nws yuav pab pab koj tus lej yog tias koj xav siv cov ntaub ntawv duab rau xim thiab/lossis khoom paub.

Kauj ruam 2: Kev teeb tsa

Kev teeb tsa
Kev teeb tsa
Kev teeb tsa
Kev teeb tsa

1. Txuas Raspberry Pi thiab lub koob yees duab module (Kho vajtse)

- Txhawm rau lub zog Raspberry Pi, koj yuav tsum tau ua tus txiv neej kawg micro USB rau tus poj niam lub zog chaw nres nkoj ntawm lub microcontroller. Tsis teb los tau: Tus tswj hluav taws xob tuaj yeem siv los xyuas kom qhov hluav taws xob tsis tshaj 5V. Tom qab lub zog Raspberry Pi, koj tuaj yeem txuas nws rau koj lub neeg hlau los ntawm kev ua haujlwm txiv neej kawg USB a los ntawm niam ntawv mus rau USB chaw nres nkoj A ntawm lub microcontroller.

- Tom qab txuas tus Pi mus rau Roomba, lub koob yees duab tau npaj los teeb tsa. Lub Koob Yees Duab Module yuav me dua qhov koj xav tau. Nco ntsoov tias lub lens tau teeb tsa rau lub sensor, thiab ib daim kab xev dawb nthuav tawm los ntawm lub koob yees duab. TSIS TXHOB tshem lossis rhuav daim ntawv! Nov yog kab ntawv koj xav tau txuas rau Raspberry Pi. Ua ntej, tuav qhov kawg ntawm txoj hlua thiab pom cov nyiaj sib txuas thiab cov kab xiav. Cov no nyob ntawm ob sab. Tom ntej no, pom lub qhov nruab nrab ntawm ethernet thiab HDMI chaw nres nkoj ntawm koj li Raspberry Pi. Daim ntawv ceeb toom muaj qhov me me, dawb xauv npog nws. Maj mam nqa lub xauv, tab sis tsis txhob tshem nws los ntawm lub qhov, vim nws yuav snap thiab puas tas mus li. Thaum koj tau rub lub xauv, rub tus hlua thiab fim cov nyiaj txuas mus rau HDMI chaw nres nkoj. Sab xiav yuav ntsib Ethernet chaw nres nkoj. Maj mam xaub daim kab xev rau hauv lub qhov thaum nws tseem xauv. Koj tsis tas yuav yuam nws mus rau hauv lub qhov. Tom qab tso, thawb lub xauv rov qab. Yog tias koj lub koob yees duab muaj kev nyab xeeb zoo, koj yuav tsum muaj peev xwm (maj mam) rub rau ntawm txoj hlua thiab xav tias nruj. Ribbon yuav tsum tsis txhob xoob. Tom qab txuas koj lub koob yees duab mus rau Pi, koj yuav pom tias nws xoob li cas. Qhov no yog vim li cas peb siv lub tshuab luam ntawv 3D los ua kom nws ruaj khov. Nws yog koj qhov kev xaiv los txiav txim seb cov ntaub ntawv twg koj xav siv los ua kom koj lub koob yees duab tseem nyob rau qhov ua tau zoo.

2. Txhim Kho Cov Ntaub Ntawv Kom Zoo thiab Txuas Roomba rau Koj Lub Computer Tom qab txhua yam ntawm koj lub khoos phis tawj tau teeb tsa, tam sim no koj tuaj yeem txav mus rau nruab MATLAB nrog rau cov ntaub ntawv m-file uas tso cai rau koj sib tham nrog tus neeg hlau. Txhawm rau ua qhov no, qhib MATLAB thiab tsim daim nplaub tshev tshiab kom khaws txhua cov ntaub ntawv cuam tshuam ua ke. Siv tsab ntawv no los teeb tsa/hloov kho cov ntaub ntawv xav tau:

- Txhua cov ntaub ntawv yuav tsum tam sim no tshwm nyob rau hauv koj cov ntawv tais ceev tseg. Txoj cai nyem rau hauv Tam sim no Folder window thiab xaiv 'Ntxiv rau Txoj Kev' ntxiv txoj hauv kev rau cov npe ntawm cov npe uas MATLAB saib rau cov ntaub ntawv. Xyuas kom txhua yam ntawm koj cov ntaub ntawv nyob hauv txoj kev raug.

3. Thaum cov ntaub ntawv raug teeb tsa, tam sim no koj tuaj yeem pib txuas rau koj tus neeg hlau. Pib los ntawm kev tig koj tus neeg hlau thiab tom qab nyuaj rov pib nws ncaj qha tom qab pib (tsis txhob hnov qab rov kho koj lub neeg hlau nyuaj txhua lub sijhawm ua ntej thiab tom qab siv). Qhov thib ob, txuas koj ob lub neeg hlau thiab lub laptop rau tib lub network wifi. Tom qab qhov no, peb yuav tham nrog kev npaj ua ntej Raspberry Pi ntawm MATLAB los ntawm kev hu rau Roomba siv nws lub npe thiab lub luag haujlwm roomba. Piv txwv li, Kuv yuav txuas rau tus neeg hlau 28 los ntawm kev siv kab hauv qab no: R = roomba (28).

- Daim ntawv ceeb toom tias kuv tau muab lub hom phiaj rau qhov sib txawv R. Kuv tam sim no tuaj yeem nkag mus rau Roomba cov haujlwm ua haujlwm los ntawm cov ntaub ntawv teeb tsa los ntawm kev kho qhov sib txawv R zoo li tus qauv.

- R.turnAngle (90) Yog tias txhua yam mus tau zoo, lub suab paj nruag yuav tsum ua si, lees paub qhov kev sib txuas.

Kauj Ruam 3: MATLAB Logic

Cov ntawv PDF hauv qab ntawm theem no yog cov ncauj lus ntxaws ntxaws qhia rau peb txheej txheem txheej txheem hauv MATLAB. Peb tau qhib lub pob tsuas, lub teeb, thiab lub teeb tsoo lub teeb txhawm rau txhawm rau tso cai rau tus neeg hlau sib txuas lus nrog peb thaum nws pom cov khoom nyob hauv ib puag ncig tam sim ntawd. Piv txwv li, thaum tus neeg hlau txav mus rau tom ntej, nws lub teeb pom kev luam theej duab rau cov khoom hauv nws txoj hauv kev raws li lub vector uas nws tab tom taug kev. Peb tau xaiv qhov ze ze rau tus neeg hlau kom thaum nws mus txog qhov khoom, nws yuav thim rov qab es tsis txhob sib tsoo nrog nws. Peb tus neeg hlau kuj tseem teeb tsa nrog Twitter, uas peb tau teev tseg hauv peb cov txheej txheem coding (qhov no yuav qhia hauv qab no).

Txhawm rau txhim kho qhov kev paub dhau los, peb tau siv MATLAB daim ntawv thov ntawm peb lub xov tooj ntawm tes kom peb tuaj yeem tswj hwm tus neeg hlau lub zog txav los ntawm tig peb lub xov tooj. Qhov no yog qhov kev xaiv ua haujlwm, zoo li koj tuaj yeem muaj tus neeg hlau txav los ntawm kev siv cov lus txib moveDistance hauv MATLAB cov lej ntu hloov chaw. Nco ntsoov tias siv MATLAB cov lus txib los tswj koj tus neeg hlau yog qhov zoo dua yog tias koj lub hom phiaj yog kom raug. Yog tias koj xav kom tsom koj lub neeg hlau kom lub koob yees duab thaij duab ntawm qhov chaw tshwj xeeb, nws yuav zoo dua los ua tus neeg hlau txav hauv MATLAB. Thaum lom zem, siv MATLAB daim ntawv thov los tswj koj tus neeg hlau tsis yog qhov xav tau kom raug.

Txoj Cai hais kom Roomba ua qhov txheej txheem teeb tsa tom qab ntawd txuas mus ntxiv los ntawm kev txuas txuas ntxiv. Thaum pib lub khoos phis tawj yuav teeb tsa qhov txuas nrog Roomba siv Roomba () hais kom ua. Nws tseem teeb tsa kev sib txuas twitter siv lub webwrite () hais kom ua hauv MATLAB. Lub voj muaj tsib lub ntsiab lus tseem ceeb ntws nyob ib puag ncig ib puag ncig ntawm Roomba. Ua ntej Roomba kuaj xyuas cov teeb meem, thiab kho rov qab yog tias nws pom tias nws cuam tshuam. Muab tso rau hauv lub voj ntawd yog txoj kev thib ob uas ceeb toom rau cov neeg siv yog tias Roomba tab tom nqa mus. Ib qho khoom siv tseem ceeb hauv Martian Warzone hnyav. Tom qab Roomba tau txiav txim siab nws txoj haujlwm muaj kev nyab xeeb, nws zoo li lub xov tooj ntawm tes los txiav txim nws qhov kev txav mus tom ntej. Yog tias lub xov tooj ntawm tes tau qaij rau pem hauv ntej nws yuav suav qhov nrawm nrawm nyob ntawm qhov hnyav ntawm kev ntsuas yob ntau dua li kho tus kheej lub log kom tig raws li qib suab. Lub xov tooj tseem tuaj yeem txav Roomba rov qab. Lub xeev nruab nrab cov cuab yeej siv nruab nrab rooj vag ob txoj kev kawg. Tus so Roomba yuav tshawb nrhiav tus chij Alien thiab ceeb toom tus neeg siv raws li.

Hauv qab no yog peb cov cai (ua tiav hauv MATLAB 2017a)

%cov tswv yim: Qhia cov ntaub ntawv los ntawm wifi txuas nrog lub cuab yeej, lub koob yees duab

%cov ntaub ntawv, cov ntaub ntawv sensor

%cov txiaj ntsig: cov lus tsa suab yog tswj los ntawm wifi txuas nrog lub cuab yeej thiab cov lus tsa suab

% yog kev nyab xeeb txheeb xyuas los ntawm kev nyeem cov ntaub ntawv sensor. Yog lub koob yees duab pom

% tus chij neeg txawv teb chaws ces lub roomba teb los ntawm tweeting tus chij yeeb ncuab

% tau pom.

%lub hom phiaj: peb lub cuab yeej ua lub neej tsis muaj lub hom phiaj tsuas yog tiv thaiv cov neeg ntawd

% tsim nws, nws ua haujlwm rau nws tus tsim thiab ua

% raws nraim qhov nws tau hais.

%Kev Siv: qhov tseem ceeb ntawm txoj haujlwm yuav ua haujlwm ntawm nws tus kheej.

tshem tag nrho, kaw tag nrho, clc

%Initializing Objects and Variables

r = Roomba (28);

m = mobiledev;

%siv cov lus teb = webwrite (hostname, cov ntaub ntawv)

hostname = 'https://api.thingspeak.com/apps/thingtweet/1/statuses/update';

API = 'SGZCTNQXCWAHRCT5';

tweet = 'RoboCop yog Kev Ua Haujlwm … Tos Tos Txais';

data = strcat ('api_key =', API, '& xwm txheej =', tweet);

teb = webwrite (hostname, cov ntaub ntawv);

%tas li khiav lub voj

thaum 1 == 1

%Cov Qauv Muaj Cov Ntaub Ntawv Ruaj Ntseg

o = m.orientation; %kev taw qhia ntawm Ntaus Ntaus Ntawv

lub teeb = r.getLightBumpers (); %Lub Teeb Npaum Qhov Teeb Meem

ib = r.getCliffSensors (); %CLiff Sensor Qhov Tseem Ceeb

tsoo = r.getBumpers (); %Bumper Sensors

%khij lub thawv

yog bump.right == 1 || bump.left == 1 || bump.front == 1

r.moveDistance (-. 2,.2);

%xyuas lub teeb Sensors

elseif light.left> 60 || light.leftFront> 60 || light.leftCenter> 60 || light.right> 60 || light.rightFront> 60 || light.rightCenter> 60

r.moveDistance (-. 2,.2);

%xyuas Cliff Sensors

%Anti-Theft Signal thiab ceeb toom

elseif a.left <300 && a.right <300 && a.leftFront <300 && a.rightFront <300

r.stop ();

r.peb ();

tweet = 'RoboCop tau raug tshem tawm!'

data = strcat ('api_key =', API, '& xwm txheej =', tweet);

teb = webwrite (hostname, cov ntaub ntawv);

%Kev Ruaj Ntseg Cuam Tshuam Kev Ua Haujlwm

elseif a.left <300 || a.right <300 || ib a.leftFront <300 || a.rightFront <300

r.moveDistance (-. 2,.2);

%Roomba dhau cov tshev thiab tam sim no yuav khiav nrog kev ua haujlwm ib txwm muaj.

Thaum pib lub yob ntawm cov cuab yeej ntsuas thiab dhau los ua lub hauv paus

%tshaj tawm qhov twg yog tom qab siv los laij lub log nrawm

%Forward Tsab ntawv tsa suab

elseif o (3)> = 0 && o (3) <= 60

baseVel = (-. 5/60)*(o (3) -60);

yog o (2)> =-70 && o (2) <0

r.setDriveVelocity (baseVel+(. 3/50)*abs (o (2)), baseVel-(. 3/50)*abs (o (2)));

elseif o (2) = 0

r.setDriveVelocity (baseVel-(. 3/50)*abs (o (2)), baseVel+(. 3/50)*abs (o (2)));

lwm r.stop

kawg

%Rov qab tsab ntawv tsa suab

elseif o (3)> 100 && o (3) <150

r.setDriveVelocity (-. 2, -.2)

r.peb ();

r.peb ();

%so chav nyob yuav tshawb rau Alien Chij cim tias yog flourescent

%ntsuab Daim ntawv

lwm tus

r.stop

img = r.getImage (); %coj duab

pib = greythresh (img (200: 383,:, 2))+. 1; %ntsuab theem ntsuab

yog tias qhov pib>.42

tweet = 'Tus yeeb ncuab pom !!'

data = strcat ('api_key =', API, '& xwm txheej =', tweet);

teb = webwrite (hostname, cov ntaub ntawv);

lwm tus

r.stop

kawg

kawg

kawg

Kauj ruam 4: Xaus

Nco ntsoov, koj tuaj yeem siv tsab ntawv peb tau sau saum toj no, tab sis koj tuaj yeem hloov kho nws kom haum rau koj cov kev xav tau. Nws tsis tas yuav tswj hwm koj lub xov tooj! (Txawm li cas los xij, nws ua rau nws lom zem dua.) Xaiv txoj hauv kev twg uas koj nyiam siv los tswj koj tus neeg hlau. Tsav ib puag ncig nrog koj tus neeg hlau thiab txaus siab rau!

Pom zoo: