Cov txheej txheem:

Pan-Tilt Multi Servo Control: 11 Kauj Ruam (nrog Duab)
Pan-Tilt Multi Servo Control: 11 Kauj Ruam (nrog Duab)

Video: Pan-Tilt Multi Servo Control: 11 Kauj Ruam (nrog Duab)

Video: Pan-Tilt Multi Servo Control: 11 Kauj Ruam (nrog Duab)
Video: Es 47 Bill of Quantity 2024, Hlis ntuj nqeg
Anonim
Pan-Tilt Multi Servo Control
Pan-Tilt Multi Servo Control

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:

Duab
Duab

Kauj Ruam 1: BoM - Cov Nqi Khoom

Qhov loj:

  1. Raspberry Pi V3 - US $ 32.00
  2. 5 Megapixels 1080p Sensor OV5647 Mini Lub Koob Yees Duab Video Module - US $ 13.00
  3. TowerPro SG90 9G 180 degrees Micro Servo (2 X)- Asmeskas $ 4.00
  4. Mini Pan/ Tilt Camera Platform Anti -Vibration Camera Mount w/ 2 Servos (*) - Asmeskas $ 8.00
  5. Resistor 1K ohm (2X) - Yeem tau
  6. 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:

Duab
Duab

Peb tuaj yeem siv qhov "nruab nrab" qib hluav taws xob los tswj lub teeb ci LED piv txwv:

Duab
Duab

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

Txhim kho Hw
Txhim kho Hw
Txhim kho Hw
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

Servos Calibration Cov
Servos Calibration Cov
Servos Calibration Cov
Servos Calibration Cov
Servos Calibration Cov
Servos Calibration Cov

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

Tsim Python Script
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-Tilt Mechanism
Pan-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:

Duab
Duab

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

Pan -Tilt Mechanism - Mechanical Construction
Pan -Tilt Mechanism - Mechanical Construction
Pan -Tilt Mechanism - Mechanical Construction
Pan -Tilt Mechanism - Mechanical Construction
Pan -Tilt Mechanism - Mechanical Construction
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

Hluav taws xob yias/Tilt los ua ke
Hluav taws xob yias/Tilt los ua ke
Hluav taws xob yias/Tilt los ua ke
Hluav taws xob yias/Tilt los ua ke
Hluav taws xob yias/Tilt los ua ke
Hluav taws xob yias/Tilt los ua ke
Hluav taws xob yias/Tilt los ua ke
Hluav taws xob yias/Tilt los ua ke

Thaum koj muaj koj li Pan/Tilt mechanism sib sau ua ke, ua raws cov duab kom txuas hluav taws xob tag nrho.

  1. Tua koj tus Pi.
  2. Ua txhua qhov txuas hluav taws xob.
  3. Muab ob npaug rau xyuas nws.
  4. Fais fab ntawm koj Pi ua ntej.
  5. 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:

Duab
Duab

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.

Duab
Duab

Cov cai saum toj no, servoTest.py tuaj yeem rub tawm los ntawm kuv GitHub.

Kauj Ruam 11: Xaus

Xaus
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:

Duab
Duab

Saludos los ntawm sab qab teb ntawm lub ntiaj teb!

Pom koj hauv kuv cov lus qhia tom ntej!

Ua tsaug, Marcelo

Pom zoo: