Cov txheej txheem:

Nkag Siab Channel Sib xyaw: 4 Cov Kauj Ruam (nrog Duab)
Nkag Siab Channel Sib xyaw: 4 Cov Kauj Ruam (nrog Duab)

Video: Nkag Siab Channel Sib xyaw: 4 Cov Kauj Ruam (nrog Duab)

Video: Nkag Siab Channel Sib xyaw: 4 Cov Kauj Ruam (nrog Duab)
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Image
Image
Mix Method »Tsis muaj
Mix Method »Tsis muaj

Yog tias koj tau tsav lub chassis tswj chaw taws teeb, muaj lub sijhawm zoo uas koj tau siv sib xyaw, txawm tias koj tsis paub nws. Tshwj xeeb, yog tias koj tau siv ib lub joystick nkaus xwb los yog gimble los tswj lub tsheb uas siv txoj hlua khi los yog txoj hlua sib txawv, koj tau siv sib xyaw.

Kev sib xyaw yog qhov yooj yim npaum li cas cov ntaub ntawv los ntawm koj tus joystick tau siv los txiav txim siab npaum li cas lub zog yuav tsum tau muab rau txhua sab ntawm lub chassis.

Yog tias koj qhib lub joystick, feem ntau koj yuav pom ob lub zog hauv sab hauv. Ib qho los ntsuas koj txoj haujlwm tam sim no raws Y axis (nce thiab nqis), thiab lwm qhov ntsuas seb koj nyob qhov twg raws X axis (sab rau sab).

Txawm hais tias kuv tsis muaj kev qhia paub txog cov ncauj lus kuv yuav tsum tau ua sib xyaw hauv cov cai ua ntej thiab tsis ntev los no kuv xav dhia dej tob me ntsis rau hauv qhov kev kawm.

Ua ntej kuv xav nco ntsoov tias feem ntau RC cov xa khoom muaj peev xwm sib xyaw ua ntau yam tswj lub cev. Cov ntaub ntawv no yuav muaj txiaj ntsig tshaj plaws yog tias koj yuav tsum ua kom sib xyaw koj tus kheej hauv koj cov cai. Hais piv txwv yog tias koj siv Arduino los nyeem cov ntaub ntawv tsis sib xyaw los ntawm RC tus txais, lossis koj tab tom nyeem cov ntaub ntawv sib piv los ntawm lub lauj kaub hauv lub joystick, lossis yog tias koj tab tom nyeem cov ntawv tswj hwm los ntawm digital joystick ntawm lub xov tooj app.

Cia peb saib qee qhov sib txawv sib xyaw ua ke.

Kauj ruam 1: Sib tov Txoj Kev »Tsis muaj

Ua ntej cia saib seb muaj dab tsi tshwm sim yog tias koj tsis siv sib xyaw txhua. Yog tias koj tsuas yog xa cov ntaub ntawv los ntawm ib lub axis mus rau ib sab ntawm lub chassis thiab lwm lub axis mus rau lwm sab, koj lub tsheb yuav tsis teb raws li qhov koj xav tau.

Piv txwv li yog tias koj thawb tus joystick txhua txoj kev ncaj nraim mus rau tom ntej, Y axis yog lub tog raj tas thiab X axis nyob ntawm 0. Yog li koj yuav tau tsav hauv lub voj voog es tsis txhob mus ncaj.

Kauj Ruam 2: Txoj Haujlwm Txoj Haujlwm »Tig

Txoj Kev Txoj Kev »Tig
Txoj Kev Txoj Kev »Tig

Ib tus neeg ua haujlwm ua haujlwm ib zaug taw qhia rau kuv tias, hauv qhov me me koj tuaj yeem tig koj lub tshuab xa xov 45 degrees rau tus txiv neej pluag sib xyaw. Yog tias koj xav txog qhov muaj txiaj ntsig los ntawm ob lub zog hauv lub joystick raws li x x y axis ntawm kab sib chaws (nrog ob txoj kab hla -100 txog +100) qhov no ua rau muaj kev nkag siab zoo vim tias koj yuav mus rau +100 ntawm ob qho tib si raws li koj thawb tus joystick thiab mus rau sab xis. Yog li yog daim duab qhia ncaj qha rau koj ob lub chassis raws (sab laug thiab sab xis ntawm koj lub neeg hlau) nws yuav ua rau koj lub neeg hlau mus tom ntej.

Yog li thawj txoj kev sib xyaw kuv tau sim yog ua lej sib npaug x thiab y ua haujlwm 45 degrees txog qhov chaw nruab nrab ntawm kab sib chaws.

Qhov no ua haujlwm tau zoo, txawm li cas los xij kuv tsis tuaj yeem mus tom ntej nrog 100% lub zog vim tias thaum koj tig mus, kev txav mus los tag nrho raug txwv rau lub voj voos hauv kab sib chaws, uas txhais tau tias koj tsis tuaj yeem nkag mus rau lub ces kaum sab xis saum toj.

Qhov no tseem ua rau kaum ntawm kab sib chaws tsis raug siv. Qhov no tsis yog teeb meem yog tias koj siv lub joystick/gimple uas txwv koj txoj kev txav chaw yog li cov cheeb tsam no yeej tsis tau mus txog ib qho hlo li, tab sis lwm yam koj yuav xav tau ib feem ntawm kab sib chaws los ua ib yam dab tsi kom koj lub zog txav mus los zoo ib yam.

Yog tias koj yog tus pom kev kawm ib yam li kuv tus kheej lub tswv yim no yuav yooj yim dua los ntawm kev saib cov vis dis aus thaum pib ntawm cov lus qhia no.

Cia peb saib qee qhov piv txwv.

NCO TSEG txog kuv tus lej piv txwv: Kuv tab tom tawm qhov koj tau txais joystick_x thiab joystick_y qhov tseem ceeb li nws yuav hloov nyob ntawm koj qhov project. Tsis tas li kuv yuav ua daim phiaj/txwv rau ± 100 tab sis koj yuav xav tau daim duab qhia chaw rau 1000 - 2000 rau PWM lossis 0 - 255 rau cov txiaj ntsig sib piv thiab lwm yam. Kuv ib txwm txwv … ib yam nkaus.

Piv txwv Arduino:

// mathematically tig

ob npaug rad = -45*M_PI/180; int leftThrottle = joystick_x * cos (rad) - joystick_y * sin (rad); int rightThrottle = joystick_y * cos (rad) + joystick_x * sin (rad); // constrain leftThrottle = txwv (leftThrottle, -100, 100); rightThrottle = txwv (rightThrottle, -100, 100);

Piv txwv JavaScript:

// mathematically rotatevar rad = -45*Math. PI/180; leftThrottle = joystick_x * Math.cos (rad) - joystick_y * Math.sin (rad); rightThrottle = joystick_y * Math.cos (rad) + joystick_x * Math.sin (rad); // constrainleftThrottle = txwv (leftThrottle, -100, 100); rightThrottle = txwv (rightThrottle, -100, 100); // helper functionvar constrain = function (num, min, max) {return Math.min (Math.max (num, min), max); };

Kauj Ruam 3: Txoj Kev Txoj Haujlwm »Yooj Yim

Txoj Kev Txoj Kev »Yooj Yim
Txoj Kev Txoj Kev »Yooj Yim

Tom ntej no peb muaj qhov sib npaug yooj yim heev uas kuv xub khaws los ntawm ib qho ntawm Shawn Hymel's Adventures in Science SparkFun cov yeeb yaj kiab uas nws tau tshwm sim los ua haujlwm zoo ib yam rau qhov kuv tau ua haujlwm.

Qhov sib npaug no tso cai rau koj kom ua tiav nrawm thaum mus rau tom ntej tab sis zoo li txoj kev tig, nws tsis saib xyuas thaj tsam ntawm kab sib chaws. Qhov no yog vim qee zaum qhov siab tshaj plaws yog 100 thiab qee kis qhov siab tshaj yog 200. Yog li koj yuav siv qhov kev txwv kom tsis saib xyuas ib yam dab tsi tom qab 100.

Thiab los ntawm txoj kev kuv tsis hu qhov yooj yim no derogatorily… muaj kev zoo nkauj hauv kev yooj yim.

Piv txwv Arduino:

int leftThrottle = joystick_y + joystick_x;

int rightThrottle = joystick_y - joystick_x; // constrain leftThrottle = txwv (leftThrottle, -100, 100); rightThrottle = txwv (rightThrottle, -100, 100);

Piv txwv JavaScript:

var leftChannel = joystick_y + joystick_x;

var rightChannel = joystick_y - joystick_x; // txwv tsis pub leftChannel = txwv (leftChannel, -100, 100); rightChannel = txwv (rightChannel, -100, 100); // helper functionvar constrain = function (num, min, max) {return Math.min (Math.max (num, min), max); };

Kauj Ruam 4: Txoj Kev Ua Haujlwm »Qhov feem

Txoj Kev Txoj Kev »Sib Piv
Txoj Kev Txoj Kev »Sib Piv

Kuv caij nplooj ntoo hlav-tawm ntawm txoj hauv kev yooj yim cia siab ua qhov zoo tshaj ntawm ob qho tib si ntiaj teb. Lub tswv yim ntawm no yog kom muaj kev sib luag hauv txhua qhov kev taw qhia txawm tias kab pheeb ces kaum txawm hais tias koj tab tom txav mus deb dua nws muaj ntau yam zoo ib yam li thaum koj txav mus los uas yog qhov nrug me dua.

Koj xaus nrog qhov ntsuas ntawm -200 txog +200 hauv txhua qhov kev qhia hauv kuv qhov piv txwv kuv daim ntawv qhia tias rau ± 100 vim tias nws sawv cev rau feem pua ntawm lub zog mus rau txhua lub channel - txawm li cas los xij koj yuav xav qhia nws rau txhua yam haujlwm hauv koj siv- rooj plaub rau koj lub cav tswj. Piv txwv li yog tias koj tab tom xa PWM teeb liab koj tuaj yeem ua daim ntawv qhia ntawd rau 1000 txog 2000 lossis yog tias koj tab tom xa cov teeb liab sib xws koj yuav qhia nws rau 0-255 thiab teeb tsa cov lus qhia raws li boolean thiab lwm yam.

Piv txwv Arduino:

int leftThrottle = joystick_y + joystick_x;

int rightThrottle = joystick_y - joystick_x; // hauv qee qhov max yog 100, qee qhov nws yog 200 // qhia qhov tseem ceeb ntawm qhov sib txawv yog li qhov siab tshaj plaws ib txwm 200int sib txawv = abs (abs (joystick_y) - abs (joystick_x)); leftThrottle = leftThrottle <0? leftThrottle - diff: sab laugThrottle + sib txawv; txoj caiThrottle = txoj caiThrottle <0? rightThrottle - diff: rightThrottle + diff; // Daim ntawv qhia los ntawm ± 200 txog ± 100 lossis txhua yam uas koj xav tau needleThrottle = daim ntawv qhia (leftThrottle, 0, 200, -100, 100); rightThrottle = daim ntawv qhia (rightThrottle, 0, 200, -100, 100); // constrainleftThrottle = txwv (leftThrottle, -100, 100); rightThrottle = txwv (rightThrottle, -100, 100);

Piv txwv JavaScript:

var leftThrottle = joystick_y + joystick_x; var rightThrottle = joystick_y - joystick_x; // hauv qee kis qhov max yog 100, qee qhov nws yog 200, // qhia qhov sib txawv yog li qhov siab tshaj plaws ib txwm 200var diff = Math.abs (Math.abs (joystick_y) - Math.abs (joystick_x)); leftThrottle = leftThrottle <0? leftThrottle - sib txawv: sab laugThrottle + sib txawv; txoj caiThrottle = txoj caiThrottle <0? rightThrottle -txawv: sab xisThrottle + sib txawv; // Daim ntawv qhia los ntawm ± 200 rov qab mus rau ± 100 lossis txhua yam uas koj xav tau NeedleThrottle = daim ntawv qhia (leftThrottle, -200, 200, -100, 100); rightThrottle = daim ntawv qhia (rightThrottle, -200, 200, -100, 100); // constrain leftThrottle = constrain (leftThrottle, -100, 100); rightThrottle = constrain (rightThrottle, -100, 100); // qee qhov kev pab cuam ua haujlwm constar = function (num, min, max) {return Math.min (Math. max (num, min), max); }; var map = function (num, inMin, inMax, outMin, outMax) {var p, inSpan, outSpan, mapped; inMin = inMin + inMax; num = num + inMax; inMax = inMax + inMax; inSpan = Math.abs (inMax-inMin); p = (num/inSpan)*100; outMin = outMin + outMax; outMax = outMax + outMax; outSpan = Math.abs (outMax - outMin); mapped = outSpan*(p/100) - (outMax/2); rov mapped;};

Pom zoo: