Cov txheej txheem:

Ntse Tsheb Ciav Hlau: 4 Kauj Ruam
Ntse Tsheb Ciav Hlau: 4 Kauj Ruam

Video: Ntse Tsheb Ciav Hlau: 4 Kauj Ruam

Video: Ntse Tsheb Ciav Hlau: 4 Kauj Ruam
Video: ua zoo poob peev los lawm tub huas xyooj MV 2023 2024, Lub Xya hli ntuj
Anonim
Ntse Tsheb Ciav Hlau
Ntse Tsheb Ciav Hlau

Tsim los kom muaj kev nyab xeeb, tiv thaiv kev raug xwm txheej, thiab ua kom muaj txiaj ntsig zoo thiab muaj txiaj ntsig zoo los pab yog tias muaj xwm txheej tshwm sim.

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

Cov duab saum toj no tau muab tso rau hauv Qhov Kev Txiav Txim Cov Npe hauv qab no:

Daim Ntawv Teev Npe

1) Ib Raspberry PI 3 - Qauv B

2) Ib daim ntawv qhia zaub mov

3) Cables (los ntawm Sab Saum Toj Hauv Qab) - Ib Lub Hwj Chim, Ib Lub Ethernet, Ib Lub Adapter

4) Ib qho Servo Motor

5) Ib qho 3D Luam Tawm Txoj Kev Tsheb ciav hlau Qhov Rooj

6) Ob LEDs (Zoo dua Liab thiab Ntsuab)

7) Ib Leeg Khawm

8) Kaum Jumper Xov

9) Plaub Resistors

10) Laptop lossis Desktop nrog MATLAB

Kauj ruam 2: Kev teeb tsa

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

Saum toj no yog cov duab ntawm kev teeb tsa los ntawm ntau lub ces kaum:

Cov chaw nyob ntawm tus pin (tsab ntawv qis dua ua raws tus lej kab) tau teev tseg hauv qab no raws li qhov ua tam sim no.

Cov xov hlau:

j19i47 ib

j8b5 0

b5 to siv

c6 to siv

b7to siv

ua 13j7

a17 to LWD

LED to AWM 37

e40j 20

j53j18 ua

j7 to lwb

LED rau J6

Khawm:

e54h51 ua

Resistors:

ua 40b37

c50d54 ua

i51j4 7

Kauj Ruam 3: Code thiab Logic

Code thiab Logic
Code thiab Logic

Peb txoj kev tsheb ciav hlau lub hom phiaj yog txhawm rau kom muaj kev nyab xeeb thiab txo qis txoj kev pheej hmoo ntawm kev raug mob ntawm txoj kev hla kev tsheb ciav hlau. Txhawm rau kom ua tiav qhov no, peb cov kab ke muaj kev ceeb toom tsheb ciav hlau rau cov tsav tsheb, lub cev tsis muaj zog uas tau txo qis kom tiv thaiv lub tsheb hla kev hla txoj kab, thiab khawm thaub qab xwm txheej ceev rau tus neeg tsav tsheb kom nias yog tias lub kaw lus ceeb toom ntxov ua tsis tiav.

GUI Tus Thawj Coj Ua Haujlwm:

GUI, pom saum toj no, tau tsim los rau kev siv tus neeg xyuas pib raws li lawv tau tsav tsheb ciav hlau hla thaj tsam ntawm txoj kev tsheb uas muaj tsheb ciav hlau hla kev hla kev.

Nyob rau sab xis sab xis, muaj lub teeb ceeb toom rau tus neeg tsav tsheb yog tias txoj kev hla kev hla txoj kev tsheb ciav hlau yav tom ntej raug kaw thiab tso cai rau tus neeg xyuas pib qhib lossis kaw lub qhov rooj yog xav tau. Hauv qab no, qhov pub los ntawm cov koob yees duab lub tsheb ciav hlau hla tau qhia. Hauv qab kaum sab laug, qhov chaw ntawm lub tsheb ciav hlau tau npaj tseg tas li ntawm daim duab thiab hauv qab kab ntawv, tus naj npawb ntawm lub tsheb ciav hlau tau ua tiav hauv ib hnub tau hais. Saum toj no txoj kab teeb, Muaj khawm xwm txheej thiab daim ntawv qhia xwm txheej. Qhov no tso cai rau tus neeg tsav tsheb tuaj yeem teeb tsa thaum muaj xwm txheej ceev yog tias muaj lub tsheb ntawm txoj kev khiav lossis lub qhov rooj nyab xeeb tsis ua haujlwm zoo.

Txoj Cai:

classdef micro <matlab.apps. AppBase % Properties uas sib haum rau cov khoom siv app

khoom (Nkag mus = pej xeem)

UIFigure matlab.ui. Figure

RailwaygatestatusLampLabel matlab.ui.control. Label

gateLamp matlab.ui.control. Lamp

OpenGateButton matlab.ui.control. Button

CloseGateButton matlab.ui.control. Button

UIAxes matlab.ui.control. UIAxes

EmergencyButtonStatusLampLabel matlab.ui.control. Label

EmergencyButtonStatusLamp matlab.ui.control. Lamp

Kev tsis txaus ntseegLabel matlab.ui.control. Label

UIAxes2 matlab.ui.control. UIAxes

EF230Group6Label matlab.ui.control. Label

IanAllishKellyBondIanDaffronLabel matlab.ui.control. Label

LoopsCompletedLabel matlab.ui.control. Label

Daim ntawv lo matlab.ui.control. Label

kawg

khoom (Nkag mus = ntiag tug)

counter ib 16

kawg

txoj kev (Nkag mus = pej xeem)

muaj nuj nqi timerCallback (app, src, kev tshwm sim)

app. Temp. Text = int2str (app.counter);

app.counter = app.counter + 1;

%hu rau txhua qhov kev hloov pauv qhov program xav tau - - - - - - - - - - - - -

thoob ntiaj teb rpi

ntiaj teb no s

qhib thoob ntiaj teb

thoob ntiaj teb kaw

ntiaj teb cam

ntiaj teb no m

ntiaj teb no ems

ntiaj teb t_count

%------------------------- Tsheb nqaj hlau Tshooj --------------------- ---------

yog qhib == 0

sau Txoj Haujlwm (s, 50)

app.gateLamp. Color = 'ntsuab';

kawg

yog kaw == 0

sau Txoj Haujlwm (s, 120)

app.gateLamp. Color = 'liab';

kawg

%---------------------- Motion Detection of Camera -----------------------

thaum muaj tseeb

img = snapshot (cam);

duab (img);

app. UIAxes (kos duab)

kawg

%---------------------- Caj npab qhib/kaw ----------------------- ---------------

yog readDigitalPin (rpi, 20)> 1 %nyeem tus pin 17 (khawm) thiab kuaj xyuas lub teeb liab

rau kuv = 40:.5: 150 %nce tus choj

writePosition (s, kuv)

kawg

rau kuv = 1:10 %loops ntsais muag teeb liab x ntau zaus

writeDigitalPin (rpi, 13, 1)

ncua (.5)

writeDigitalPin (rpi, 13, 0)

ncua (.5)

kawg

writePosition (s, 50)%tso lub qhov rooj

kawg

%-------------------- Kev Txhawb Xov Tooj Ntawm Tes/Zaj Lus ------------------------ -

m. AccelerationSensorEnabled = 1

m.logging = 1

data = xoom (200, 1); %intialize cov ntaub ntawv rau dov phiaj

daim duab (app. UIAxes2)

p = phiaj (cov ntaub ntawv)

axis ([xwb, ybounds])

ncua (1)

tic ua

thaum toc <30 %khiav rau 30 vib nas this

[a, ~] = accellog (m);

yog ntev (a)> 200

data = a (kawg-199: kawg, 3);

lwm tus

cov ntaub ntawv (1: ntev (a)) = a (:, 3);

kawg

%rov sau cov phiaj xwm

p. YData = cov ntaub ntawv;

kos duab

kawg

%------------------ Tam Sim No Hloov Pixel ---------------------------- ------

x1 = img; % nyeem lub koob yees duab tawm ntawm tus pi

red_mean = mean (txhais (x1 (:,:, 1))); % nyeem qhov nruab nrab ntawm cov liab pixels

ntsuab_mean = mean (mean (x1 (:,:, 2))); % nyeem qhov nruab nrab ntawm cov pixels ntsuab

blue_mean = txhais (txhais (x1 (:,:, 3))); % nyeem qhov nruab nrab ntawm cov pixels xiav

yog red_mean> 150 && green_mean> 150 && blue_mean> 150

t_count = t_count + 1;

kawg

app. LoopsCompletedLabel. Text = num2str (t_count)

%------------------ Khawm EMS programming ---------------------------- ---

configurePin (rpi, 12, 'DigitalOutput'); %teeb tsa tus pin coj, tus pin 16, ua qhov tso tawm

configurePin (rpi, 16, 'DigitalInput'); %teeb tsa lub khawm tus pin, tus pin 24, raws li kev nkag

buttonPressed = readDigitalPin (rpi, 16); % Nyeem lub pob nyem nias tus lej ntawm tus lej 16

yog tias khawm Nias == 1

thaum khawm Nias == 1

writeDigitalPin (rpi, 12, 1)

buttonunPressed = writeDigitalPin (rpi, 12, 0); %

kawg % Ends 'thaum khawm Pressed == 1' voj

kawg

writeDigitalPin (rpi, 16, 0) %Teem lub coj mus tua thaum lub khawm tsis nias lawm setpref ('Internet', 'SMTP_Server', 'smtp.gmail.com'); setpref ('Internet', 'E_mail', '[email protected]'); % xa nyiaj xa los ntawm setpref ('Internet', 'SMTP_Username', '[email protected]'); % xa cov neeg siv lub npe setpref ('Internet', 'SMTP_Password', 'efgroup6'); % Cov neeg xa tus password

cov khoom = java.lang. System.getProperties;

props.setProperty ('mail.smtp.auth', 'tseeb'); props.setProperty ('mail.smtp.socketFactory.class', 'javax.net.ssl. SSLSocketFactory'); props.setProperty ('mail.smtp.socketFactory.port', '465');

sendmail ('[email protected] ',' Xwm Txheej Xwm Ceev! ',' Tus neeg xyuas pib tau qhib phau ntawv hla kev hloov pauv, thov kom teb tam sim! ')

app. UndernormalconditionsLabel. Text = ems

kawg

kawg

%app. Label_4. Text = num2str (curr_temp);

txoj kev (Nkag mus = ntiag tug)

% Code uas ua tiav tom qab tsim cov khoom

muaj nuj nqi startupFcn (app)

%---------- Txhua qhov hloov pauv xav tau rau txoj haujlwm no --------------------

ntiaj teb rpi %arduino

rpi = raspi ('169.254.0.2', 'pi', 'raspberry');

ntiaj teb s %servo

s = servo (rpi, 17, 'MinPulseDuration', 5e-4, 'MaxPulseDuration', 2.5e-3);

qhib thoob ntiaj teb

qhib = 1;

ntiaj teb kaw

kaw = 1;

ntiaj teb cam

cam = lub koob yees duab (rpi);

ntiaj teb no m

m = mobiledev;

ntiaj teb no ems

ems = 'Kev kub ntxhov tau tshaj tawm, ceeb toom EMS';

ntiaj teb t_count

t_count = 0;

txuas ntawm %tus password yog EFGroup6

% Timer Function rau Loop --------------------------------

app.counter = 0;

t = timer (…

'TimerFcn', @app.timerCallback, …

'StartDelay', 1, … 'Lub Sijhawm', 1, …

'ExecutionMode', 'fixedSpacing', …

'TasksToExecute', inf);

pib (t);

kawg

% Callback muaj nuj nqi

Function ManualOverrideSwitchValueChanged (app, xwm txheej)

kawg

% Khawm thawb muaj nuj nqi: OpenGateButton

muaj nuj nqi OpenGateButtonPushed (app, xwm txheej)

thoob ntiaj teb kaw

ze = 0;

kawg

% Khawm thawb muaj nuj nqi: CloseGateButton

muaj nuj nqi CloseGateButtonPushed (app, xwm txheej)

qhib thoob ntiaj teb

qhib = 0;

kawg

kawg

% App pib thiab tsim kho

txoj kev (Nkag mus = ntiag tug)

% Tsim UIFigure thiab cov khoom siv

muaj nuj nqi createComponents (app)

% Tsim UIFigure

app. UIFigure = uifigure;

app. UIFigure. Position = [100 100 640 480];

app. UIFigure. Name = 'UI Daim Duab';

% Tsim RailwaygatestatusLampLabel

app. RailwaygatestatusLampLabel = uilabel (app. UIFigure);

app. RailwaygatestatusLampLabel. HorizontalAlignment = 'yog'; app. RailwaygatestatusLampLabel. Position = [464 422 110 22]; app. RailwaygatestatusLampLabel. Text = 'Qhov rooj xwm txheej tsheb ciav hlau';

% Tsim gateLamp

app.gateLamp = uilamp (app. UIFigure);

app.gateLamp. Position = [589 422 20 20];

app.gateLamp. Color = [0.9412 0.9412 0.9412];

% Tsim OpenGateButton

app. OpenGateButton = uibutton (app. UIFigure, 'thawb');

app. OpenGateButton. ButtonPushedFcn = createCallbackFcn (app, @OpenGateButtonPushed, muaj tseeb); app. OpenGateButton. Position = [474 359 100 22];

app. OpenGateButton. Text = 'Qhib Rooj vag';

% Tsim CloseGateButton

app. CloseGateButton = uibutton (app. UIFigure, 'thawb');

app. CloseGateButton. ButtonPushedFcn = createCallbackFcn (app, @CloseGateButtonPushed, muaj tseeb); app. CloseGateButton. Position = [474 285 100 22];

app. CloseGateButton. Text = 'Kaw Qhov Rooj';

% Tsim UIAxes

app. UIAxes = uiaxes (app. UIFigure);

title (app. UIAxes, 'Lub Koob Yees Duab Pub')

app. UIAxes. Position = [341 43 300 185];

% Tsim EmergencyButtonStatusLampLabel

app. EmergencyButtonStatusLampLabel = uilabel (app. UIFigure); app. EmergencyButtonStatusLampLabel. HorizontalAlignment = 'yog'; app. EmergencyButtonStatusLampLabel. Position = [97 323 142 22]; app. EmergencyButtonStatusLampLabel. Text = 'xwm txheej khawm xwm txheej';

% Tsim EmergencyButtonStatusLamp

app. EmergencyButtonStatusLamp = uilamp (app. UIFigure); app. EmergencyButtonStatusLamp. Position = [254 323 20 20];

% Tsim Cov Cai Tsis Txaus SiabLabel

app. UndernormalconditionsLabel = uilabel (app. UIFigure);

app. UndernormalconditionsLabel. Position = [108 285 248 22];

app. UndernormalconditionsLabel. Text = 'Raws li qhov xwm txheej ib txwm muaj';

% Tsim UIAxes2

app. UIAxes2 = uiaxes (app. UIFigure);

title (app. UIAxes2, 'Txoj Haujlwm Ntawm Tsheb ciav hlau')

xlabel (app. UIAxes2, 'X Txoj Haujlwm')

ylabel (app. UIAxes2, 'Y Txoj Haujlwm')

app. UIAxes2. Box = 'ntawm';

app. UIAxes2. XGrid = 'ntawm';

app. UIAxes2. YGrid = 'ntawm';

app. UIAxes2. Position = [18 43 300 185];

% Tsim EF230Group6Label

app. EF230Group6Label = uilabel (app. UIFigure);

app. EF230Group6Label. HorizontalAlignment = 'chaw';

app. EF230Group6Label. FontSize = 28;

app. EF230Group6Label. FontWeight = 'siab tawv';

app. EF230Group6Label. Position = [-4 401 379 64];

app. EF230Group6Label. Text = 'EF 230 Pawg 6';

% Tsim IanAllishKellyBondIanDaffronLabel

app. IanAllishKellyBondIanDaffronLabel = uilabel (app. UIFigure); app. IanAllishKellyBondIanDaffronLabel. Position = [94 380 184 22]; app. IanAllishKellyBondIanDaffronLabel. Text = 'Ian Allish, Kelly Bond, Ian Daffron';

% Tsim LoopsCompletedLabel

app. LoopsCompletedLabel = uilabel (app. UIFigure);

app. LoopsCompletedLabel. Position = [18 10 103 22];

app. LoopsCompletedLabel. Text = 'Loops Ua tiav:';

% Tsim daim ntawv lo

app. Label = uilabel (app. UIFigure);

app. Label. Position = [120 10 178 22];

app. Label. Text = '####';

kawg

kawg

txoj kev (Nkag mus = pej xeem)

% Tsim app

muaj nuj nqi app = micro

% Tsim thiab teeb tsa cov khoom siv

tsim cov khoom siv (app)

% Sau npe app nrog App Designer

sau npe App (app, app. UIFigure)

Ua tiav qhov pib ua haujlwm

runStartupFcn (app, @startupFcn)

yog nargout == 0

meej app

kawg

kawg

% Code uas ua tiav ua ntej tshem app

rho tawm (app)

% Rho tawm UIFigure thaum app raug tshem tawm

rho tawm (app. UIFigure)

kawg

kawg

kawg

Kauj Ruam 4: Kauj Ruam Kawg

Kauj Ruam Kawg
Kauj Ruam Kawg

Thaum cov cai tau sau thiab Raspberry Pi tau xaim, txuas lub tshuab servo mus rau 3-D luam ntawv txoj kev tsheb ciav hlau taug kev raws li nws tau txuas hauv daim duab saum toj no.

Tam sim no, txoj haujlwm tiav. Txuas raspberry PI mus rau txoj kev tsheb ciav hlau thiab saib xyuas cov txheej txheem tshiab tsim kev hla kev hla txoj kev tsheb nqaj hlau kom nyab xeeb rau ob tus tsav tsheb thiab cov neeg tsav tsheb. Ua si nrog cov kab ke los ntawm kev cuam tshuam nrog GUI txhawm rau ua kom tsis muaj kev nyab xeeb teeb tsa nyob rau hauv qhov chaw los tiv thaiv kev sib tsoo.

Qhov ntawd yog qhov kawg ntawm qhov kev qhia, txaus siab rau koj li Smart Train System tshiab!

Pom zoo: