Cov txheej txheem:
- Kauj Ruam 1: BoM - Cov Nqi Khoom
- Kauj Ruam 2: PWM Ua Haujlwm Li Cas
- Kauj Ruam 3: Txhim Kho Hw
- Kauj ruam 4: Servos Calibration
- Kauj Ruam 5: Tsim Python Script
- Kauj Ruam 6: Lub Yias-Tilt Mechanism
- Kauj Ruam 7: Pan -Tilt Mechanism - Mechanical Construction
- Kauj Ruam 8: Hluav Taws Xob Pan/Tilt Assembly
- Kauj Ruam 9: Tus Python Script
- Kauj ruam 10: Loop Test of Servers
- Kauj Ruam 11: Xaus
Video: Pan-Tilt Multi Servo Control: 11 Kauj Ruam (nrog Duab)
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:29
Ntawm qhov kev qhia no, peb yuav tshawb xyuas yuav ua li cas tswj ntau lub servos siv Python ntawm Raspberry Pi. Peb lub hom phiaj yuav yog PAN/TILT cov txheej txheem los tso lub koob yees duab (PiCam).
Ntawm no koj tuaj yeem pom yuav ua li cas peb txoj haujlwm kawg yuav ua haujlwm:
Tswj Servo Tswj lub voj xeem:
Kauj Ruam 1: BoM - Cov Nqi Khoom
Qhov loj:
- Raspberry Pi V3 - US $ 32.00
- 5 Megapixels 1080p Sensor OV5647 Mini Lub Koob Yees Duab Video Module - US $ 13.00
- TowerPro SG90 9G 180 degrees Micro Servo (2 X)- Asmeskas $ 4.00
- Mini Pan/ Tilt Camera Platform Anti -Vibration Camera Mount w/ 2 Servos (*) - Asmeskas $ 8.00
- Resistor 1K ohm (2X) - Yeem tau
- Lwm yam: cov hlau, cov hlua, thiab lwm yam (yog tias koj yuav tsim koj li Pan/Tilt mechanism)
(*) koj tuaj yeem yuav ua tiav Pan/Tilt platform nrog cov servos lossis tsim koj tus kheej.
Kauj Ruam 2: PWM Ua Haujlwm Li Cas
Raspberry Pi tsis muaj qhov tso tawm analog, tab sis peb tuaj yeem sim qhov no, siv PWM (Pulse Width Modulation) mus kom ze. Peb yuav ua dab tsi yog tsim kom muaj lub teeb liab digital nrog lub tsau zaus, qhov uas peb yuav hloov pauv lub plawv taw dav dav, dab tsi yuav "txhais" raws li "nruab nrab" tso zis hluav taws xob theem raws li qhia hauv qab no:
Peb tuaj yeem siv qhov "nruab nrab" qib hluav taws xob los tswj lub teeb ci LED piv txwv:
Nco ntsoov tias qhov teeb meem ntawm no tsis yog qhov zaus nws tus kheej, tab sis "Duty Cycle", uas yog kev sib raug zoo ntawm lub sijhawm uas lub plhaub "siab" faib los ntawm lub sijhawm nthwv dej. Piv txwv, xav tias peb yuav tsim 50Hz mem tes zaus ntawm ib qho ntawm peb Raspberry Pi GPIO. Lub sijhawm (p) yuav hloov pauv zaus lossis 20ms (1/f). Yog tias peb xav kom peb cov LED nrog "ib nrab" ci, peb yuav tsum muaj Duty Cycle ntawm 50%, uas txhais tau tias "mem tes" uas yuav "Siab" rau 10ms.
Lub hauv paus ntsiab lus no yuav tseem ceeb heev rau peb, los tswj peb txoj haujlwm servo, ib zaug "Duty Cycle" yuav piav qhia txoj haujlwm servo raws li qhia hauv qab no:
Servo
Kauj Ruam 3: Txhim Kho Hw
Cov servos yuav txuas nrog lwm 5V khoom siv, muaj lawv cov ntaub ntawv tus pin (hauv kuv cov ntaub ntawv, lawv cov xov hlau daj) txuas rau Raspberry Pi GPIO raws li hauv qab no:
- GPIO 17 ==> Tilt Servo
- GPIO 27 ==> Pan Servo
Tsis txhob hnov qab txuas GNDs ua ke ==> Raspberry Pi - Servos - Sab Nraud Cov Khoom Siv Hluav Taws Xob)
Koj tuaj yeem muaj qhov kev xaiv, tus tiv thaiv ntawm 1K ohm ntawm Raspberry Pi GPIO thiab Server cov ntaub ntawv nkag tus pin. Qhov no yuav tiv thaiv koj RPi thaum muaj teeb meem servo.
Kauj ruam 4: Servos Calibration
Thawj qhov ua nws yog txhawm rau txheeb xyuas cov yam ntxwv tseem ceeb ntawm koj cov kev pabcuam. Hauv kuv qhov xwm txheej, Kuv tab tom siv Power Pro SG90.
Los ntawm nws cov ntawv, peb tuaj yeem xav txog:
- Qhov siab: 180 hli
- Lub Hwjchim Mov: 4.8V (sab nraud 5VDC ua lub USB fais fab mov ua haujlwm zoo)
- Ua haujlwm zaus: 50Hz (Lub Sijhawm: 20 ms)
- Pulse dav: ntawm 1ms txog 2ms
Hauv kev xav, servo yuav nyob ntawm nws
- Thawj Txoj Haujlwm (0 degrees) thaum lub plawv dhia ntawm 1ms tau thov rau nws cov ntaub ntawv dav hlau
- Txoj Haujlwm Neutral (90 degrees) thaum lub plawv dhia ntawm 1.5 ms tau siv rau nws cov ntaub ntawv dav hlau
- Txoj Haujlwm Kawg (180 degrees) thaum lub plawv dhia ntawm 2 ms tau siv rau nws cov ntaub ntawv dav hlau
Txhawm rau teeb tsa txoj haujlwm servo siv Python yuav yog qhov tseem ceeb heev kom paub tus neeg sau xov xwm "Duty Cycle" rau cov haujlwm saum toj no, cia ua qee qhov kev suav:
- Thawj txoj hauj lwm ==> (0 degrees) Pulse dav ==> 1ms ==> Duty Cycle = 1ms/20ms ==> 2.0%
- Txoj Haujlwm Neutral (90 degrees) Pulse dav ntawm 1.5 ms ==> Duty Cycle = 1.5ms/20ms ==> 7.5%
- Txoj hauj lwm zaum kawg (180 degrees) Pulse dav ntawm 2 ms ==> Duty Cycle = 2ms/20ms ==> 10%
Yog li Duty Cycle yuav tsum sib txawv ntawm qhov ntau ntawm 2 txog 10 %.
Cia peb sim cov servos ib tus zuj zus. Txog qhov ntawd, qhib koj lub Raspberry lub davhlau ya nyob twg thiab tso koj li Python 3 lub plhaub editor ua "sudo" (vim tias koj yuav tsum yog "tus siv super" los tswj nrog GPIOs):
sudo sej 3
Hauv Python Plhaub
>>
Ntshuam RPI. GPIO module thiab hu nws GPIO:
ntshuam RPi. GPIO ua GPIO
Txheeb xyuas tus lej tus lej uas koj xav siv (BCM lossis BOARD). Kuv tau ua qhov kev ntsuas no nrog BOARD, yog li cov pins uas kuv siv yog tus pin lub cev (GPIO 17 = Pin 11 thiab GPIO 27 Pin 13). Yooj yim rau kuv txheeb xyuas lawv thiab tsis ua yuam kev thaum xeem (Hauv qhov kev kawm kawg kuv yuav siv BCM). Xaiv ib qho ntawm koj nyiam:
GPIO.setmode (GPIO. BOARD)
Txheeb xyuas tus pin servo uas koj siv:
tiltPin = np
Yog Xwb, koj tau siv BCM cov phiaj xwm, 2 lo lus kawg yuav tsum tau hloov los ntawm:
GPIO.setmode (GPIO. BCM)
tiltPin = 17
Tam sim no, peb yuav tsum qhia meej tias tus pin no yuav yog "tso tawm"
GPIO.setup (tiltPin, GPIO. OUT)
Thiab, dab tsi yuav yog qhov zaus tsim tawm ntawm tus pin no, uas rau peb cov servo yuav yog 50Hz:
tilt = GPIO. PWM (tiltPin, 50)
Tam sim no, cia pib tsim PWM teeb liab ntawm tus pin nrog lub luag haujlwm pib ua haujlwm (peb yuav khaws nws "0"):
qaij = pib (0)
Tam sim no, koj tuaj yeem nkag mus rau lub luag haujlwm sib txawv qhov tseem ceeb, saib xyuas kev txav ntawm koj lub servo. Cia peb pib nrog 2% thiab pom dab tsi tshwm sim (peb pom tias qhov kev pabcuam mus rau "txoj haujlwm xoom"):
qaij. ChangeDutyCycle (2)
Hauv kuv qhov xwm txheej, servo tau mus rau txoj haujlwm xoom tab sis thaum kuv hloov pauv lub luag haujlwm mus rau 3% Kuv pom tias qhov kev pabcuam tseem nyob hauv tib txoj haujlwm, pib txav mus los nrog lub luag haujlwm ntau dua 3%. Yog li, 3% yog kuv thawj txoj haujlwm (o degrees). Tib yam tshwm sim nrog 10%, kuv qhov kev pabcuam tau nce siab dua tus nqi no, ua rau nws xaus rau 13%. Yog li rau qhov tshwj xeeb servo, qhov tshwm sim yog:
- 0 degree ==> kev ua haujlwm ntawm 3%
- 90 degrees ==> kev ua haujlwm ntawm 8%
- 180 degrees ==> lub luag haujlwm ntawm 13%
Tom qab koj ua tiav koj qhov kev xeem, koj yuav tsum tso tseg PWM thiab ntxuav cov GPIOs:
qaij = nres ()
GPIO.cleanup ()
Lub davhlau ya nyob twg saum toj saud qhia pom qhov tshwm sim rau ob qho ntawm kuv qhov kev pabcuam (uas muaj cov txiaj ntsig zoo sib xws). Koj qhov ntau tuaj yeem sib txawv.
Kauj Ruam 5: Tsim Python Script
PWM cov lus txib kom xa mus rau peb qhov kev pabcuam yog nyob rau hauv "kev ua haujlwm" raws li peb pom ntawm theem kawg. Tab sis feem ntau, peb yuav tsum siv "lub kaum ntse ntse" hauv qib ua qhov ntsuas kom tswj tau servo. Yog li, peb yuav tsum hloov "kaum" uas yog qhov ntsuas ntau dua rau peb hauv kev ua haujlwm raws li kev nkag siab los ntawm peb Pi.
Yuav ua li cas? Yooj yim heev! Peb paub tias lub luag haujlwm voj voog mus los ntawm 3% txog 13% thiab qhov no yog sib npaug rau cov ces kaum uas yuav nyob ntawm 0 txog 180 degrees. Tsis tas li, peb paub tias cov kev hloov pauv no yog kab, yog li peb tuaj yeem tsim cov phiaj xwm sib piv raws li tau hais los saum no. yog li, muab lub kaum sab xis, peb tuaj yeem muaj lub voj voog ua haujlwm sib tham:
dutycycle = kaum sab xis/18 + 3
Khaws cov mis no. Peb yuav siv nws hauv kab lus tom ntej.
Cia peb tsim cov ntawv Python los ua qhov kev xeem. Yeej, peb yuav rov ua qhov peb tau ua ua ntej ntawm Python Plhaub:
los ntawm lub sijhawm ntshuam pw
import RPi. GPIO as GPIO GPIO.setmode (GPIO. BCM) GPIO.setwarnings (False) def setServoAngle (servo, angle): pwm = GPIO. PWM (servo, 50) pwm.start (8) dutyCycle = angle / 18. + 3. pwm. ChangeDutyCycle (dutyCycle) pw (0.3) pwm.stop () yog _name_ == '_main_': import sys servo = int (sys.argv [1]) GPIO.setup (servo, GPIO. OUT) setServoAngle (servo, int (sys.argv [2])) GPIO.cleanup ()
Cov tub ntxhais ntawm cov cai saum toj no yog kev ua haujlwm setServoAngle (servo, kaum sab xis). Txoj haujlwm no tau txais raws li kev sib cav, tus lej servo GPIO, thiab tus nqi lub kaum ntse ntse mus rau qhov chaw servo yuav tsum tau muab tso rau. Thaum cov tswv yim ntawm txoj haujlwm no yog "lub kaum sab xis", peb yuav tsum hloov nws mus rau lub luag haujlwm hauv lub voj voog feem pua, siv cov qauv tsim ua ntej.
Thaum tsab ntawv raug ua tiav, koj yuav tsum nkag mus raws qhov ntsuas, servo GPIO, thiab lub kaum ntse ntse.
Piv txwv li:
sudo python3 angleServoCtrl.py 17 45
Cov lus txib saum toj no yuav tso lub servo txuas nrog ntawm GPIO 17 nrog 45 degrees hauv "nce". Cov lus txib zoo ib yam tuaj yeem siv rau Pan Servo tswj (txoj haujlwm rau 45 degrees hauv "azimuth"):
sudo python angleServoCtrl.py 27 45
Cov ntaub ntawv angleServoCtrl.py tuaj yeem rub tawm los ntawm kuv GitHub
Kauj Ruam 6: Lub Yias-Tilt Mechanism
"Pan" servo yuav txav "kab rov tav" peb lub koob yees duab ("azimuth angle") thiab peb "Tilt" servo yuav txav nws "ntsug" (nce lub kaum sab xis).
Daim duab hauv qab no qhia tias Pan/Tilt mechanism ua haujlwm li cas:
Thaum lub sijhawm peb txhim kho peb yuav tsis mus rau "qhov phem tshaj" thiab peb yuav siv peb lub Pan/Tilt mechanism los ntawm 30 txog 150 degrees nkaus xwb. Cov kab no yuav txaus siv lub koob yees duab.
Kauj Ruam 7: Pan -Tilt Mechanism - Mechanical Construction
Cia tam sim no, sib sau ua ke peb 2 servos li Pan/Tilt mechanism. Koj tuaj yeem ua 2 yam ntawm no. Yuav lub Pan-Tilt platform cov txheej txheem raws li ib qho qhia ntawm theem kawg lossis tsim koj tus kheej raws li koj xav tau.
Ib qho piv txwv tuaj yeem yog qhov uas kuv tau tsim, tsuas yog khi cov servos rau ib qho, thiab siv cov hlau me me los ntawm cov khoom ua si qub raws li qhia hauv cov duab saum toj no.
Kauj Ruam 8: Hluav Taws Xob Pan/Tilt Assembly
Thaum koj muaj koj li Pan/Tilt mechanism sib sau ua ke, ua raws cov duab kom txuas hluav taws xob tag nrho.
- Tua koj tus Pi.
- Ua txhua qhov txuas hluav taws xob.
- Muab ob npaug rau xyuas nws.
- Fais fab ntawm koj Pi ua ntej.
- Yog tias txhua yam zoo, ua haujlwm rau koj cov servos.
Peb yuav tsis tshawb txog qhov kev qhia no yuav teeb tsa lub koob yees duab li cas, qhov no yuav piav qhia txog kev qhia tom ntej.
Kauj Ruam 9: Tus Python Script
Cia peb tsim Python Script los tswj ob qho kev pabcuam ib txhij:
los ntawm lub sijhawm ntshuam pw
ntshuam RPi. GPIO li GPIO GPIO.setmode (GPIO. BCM) GPIO.setwarnings (Cuav) lauj kaub = 27 qaij = 17 GPIO.setup (qaij, GPIO. OUT) # dawb => TILT GPIO.setup (yias, GPIO. OUT) # grey ==> PAN def setServoAngle (servo, angle): lees paub lub kaum sab xis> = 30 thiab kaum 90 (nruab nrab taw tes) ==> 150 setServoAngle (qaij, int (sys.argv [2])) # 30 ==> 90 (nruab nrab taw tes) ==> 150 GPIO.cleanup ()
Thaum tsab ntawv raug ua tiav, koj yuav tsum nkag mus raws qhov ntsuas, Lub kaum sab xis thiab Lub kaum sab xis. Piv txwv li:
sudo python3 servoCtrl.py 45 120
Cov lus txib saum toj no yuav tso Pan/Tilt mechanism nrog 45 degrees hauv "azimuth" (Pan angle) thiab 120 degrees ntawm "nce" (Tilt Angle). Nco ntsoov tias yog tias tsis muaj kev nkag mus, lub neej ntawd yuav yog ob qho tib si, yias thiab qaij kaum teeb tsa mus txog 90 degrees.
Hauv qab no koj tuaj yeem pom qee qhov kev xeem:
Cov ntaub ntawv servoCtrl.py tuaj yeem rub tawm los ntawm kuv GitHub.
Kauj ruam 10: Loop Test of Servers
Tam sim no cia peb tsim Python Script kom txiav txim siab tag nrho cov kev pabcuam:
los ntawm lub sijhawm ntshuam pw
ntshuam RPi. GPIO li GPIO GPIO.setmode (GPIO. BCM) GPIO.setwarnings (Cuav) lauj kaub = 27 qaij = 17 GPIO.setup (qaij, GPIO. OUT) # dawb => TILT GPIO.setup (yias, GPIO. OUT) # grey ==> PAN def setServoAngle (servo, angle): assert angle> = 30 and angle <= 150 pwm = GPIO. PWM (servo, 50) pwm.start (8) dutyCycle = angle / 18. + 3. pwm. ChangeDutyCycle (dutyCycle) pw (0.3) pwm.stop () yog _name_ == '_main_': rau kuv hauv ntau (30, 160, 15): setServoAngle (pan, i) setServoAngle (qaij, i) rau kuv hauv range (150, 30, -15): setServoAngle (pan, i) setServoAngle (qaij, i) setServoAngle (pan, 100) setServoAngle (qaij, 90) GPIO.cleanup ()
Qhov kev zov me nyuam yuav ua tiav txiav lub voj los ntawm 30 txog 150 degrees hauv ob qho tib si.
Hauv qab qhov tshwm sim:
Kuv txuas lub oscilloscope nkaus xwb los qhia PWM txoj kev xav raws li tau piav ua ntej.
Cov cai saum toj no, servoTest.py tuaj yeem rub tawm los ntawm kuv GitHub.
Kauj Ruam 11: Xaus
Raws li ib txwm muaj, Kuv vam tias txoj haujlwm no tuaj yeem pab lwm tus pom lawv txoj hauv kev mus rau hauv lub ntiaj teb zoo ntawm hluav taws xob!
Yog xav paub ntxiv thiab tus lej kawg, thov mus saib kuv qhov kev tso nyiaj GitHub: RPi-Pan-Tilt-Servo-Control
Yog xav paub ntau ntxiv, thov mus saib kuv qhov blog: MJRoBot.org
Hauv qab qhov muag ntawm kuv qhov kev qhia tom ntej:
Saludos los ntawm sab qab teb ntawm lub ntiaj teb!
Pom koj hauv kuv cov lus qhia tom ntej!
Ua tsaug, Marcelo
Pom zoo:
Ua kom pom lub koob yees duab zoo Pi nrog Lego thiab Servo: 4 Cov Kauj Ruam (nrog Duab)
Ua kom pom lub Pi Zoo Lub Koob Yees Duab Nrog Lego thiab Servo: Nrog me ntsis hacked Lego daim, ua haujlwm txuas ntxiv thiab qee qhov Python code koj tuaj yeem tsom koj lub Raspberry Pi Lub Koob Yees Duab Zoo los ntawm txhua qhov chaw hauv ntiaj teb! cov khoom siv, tab sis raws li kuv pom thaum ua haujlwm ntawm Merlin tsis ntev los no
Cov Duab Duab Duab thiab Cov Duab 1: 4 Cov Kauj Ruam (nrog Duab)
Cov Duab Duab Cubes thiab Cov Duab 1: Thaum sim nrog qee cov ntoo ntoo thiab cov duab los qhia, kuv pom ob peb txoj hauv kev los ua cov voos thiab lwm yam duab los ntawm cov khoom siv yooj yim. Los ntawm kev muab cov no los ua Cov Ntawv Qhia, Kuv vam tias yuav txhawb nqa kev ua si thiab kev kawm. Kev hloov pauv ntawm qhov kev qhia no
Yuav Ua Li Cas Thiaj Li Tshem Tawm Lub Computer Nrog Cov Kauj Ruam Yooj Yim thiab Duab: 13 Kauj Ruam (nrog Duab)
Yuav Tsum Tshem Tawm Lub Khoos Phis Tawj Li Cas Nrog Cov Kauj Ruam Yooj Yim thiab Duab: Nov yog cov lus qhia txog yuav ua li cas tshem lub PC. Feem ntau ntawm cov khoom siv yooj yim yog hloov pauv thiab tshem tawm tau yooj yim. Txawm li cas los xij nws yog ib qho tseem ceeb uas koj tau koom nrog nws. Qhov no yuav pab tiv thaiv koj kom tsis txhob poob ib feem, thiab tseem ua rau kev rov ua dua tshiab
Cov Duab Duab Duab Duab, WiFi Txuas - Raspberry Pi: 4 Cov Kauj Ruam (nrog Duab)
Cov Duab Duab Duab Duab, WiFi Txuas - Raspberry Pi: Nov yog txoj hauv kev yooj yim heev thiab tus nqi qis mus rau cov duab thav duab digital - nrog qhov zoo ntawm kev ntxiv /tshem cov duab hla WiFi ntawm 'nyem thiab luag' siv (pub dawb) xa cov ntaub ntawv . Nws tuaj yeem siv tau los ntawm qhov me me £ 4.50 Pi Zero. Koj tseem tuaj yeem hloov pauv
DIY Multi Featured Neeg Hlau Nrog Arduino: 13 Kauj Ruam (nrog Duab)
DIY Multi Featured Robot Nrog Arduino: Tus neeg hlau no tau tsim tshwj xeeb rau kev nkag siab Arduino thiab sib txuas ntau yam haujlwm ntawm Arduino los tsim Ntau Qhov Tshwj Xeeb Arduino Robot. Thiab ntxiv mus, leej twg tsis xav kom muaj tus tsiaj neeg hlau? Yog li kuv tau hu nws lub XOV XWM ROVIER 316. Kuv tuaj yeem yuav qhov zoo nkauj