Cov txheej txheem:

Automated Ball Roller Nrog Arduino thiab Ib qho Servo: 3 Cov Kauj Ruam
Automated Ball Roller Nrog Arduino thiab Ib qho Servo: 3 Cov Kauj Ruam

Video: Automated Ball Roller Nrog Arduino thiab Ib qho Servo: 3 Cov Kauj Ruam

Video: Automated Ball Roller Nrog Arduino thiab Ib qho Servo: 3 Cov Kauj Ruam
Video: How to make a STEEL MARBLE TRACK with basic tools! step by step guide 2024, Kaum ib hlis
Anonim
Image
Image

Nov yog qhov yooj yim me me Arduino thiab qhov haujlwm pabcuam uas siv sijhawm li ob teev los ua kom tiav. Nws siv qhov kev pabcuam los nqa ib kawg ntawm lub raj mis kom thiaj li tig lub pob hlau nyob ib puag ncig sab hauv. Nws yog tus kheej pib, tuaj yeem hloov nrawm thiab tuaj yeem tig ob (lossis ntau dua?) Pob ib zaug. Kev lom zem los tsim thiab ua haujlwm. Lub sijhawm tsis tuaj yeem ua si nrog rau tej zaum txawm tias nrawm dua. Ob peb lub cuab yeej cuam tshuam nrog lub ntsej muag sib nqus tuaj yeem siv los ua nws lub tshuab ntse uas tuaj yeem txheeb xyuas qhov tsis zoo tshaj plaws.

Kuv yuav tsum hais tias ib tus neeg nyob ntawm no instructables.com muaj lub tshuab ntaus pob zoo dua:

Cov ntaub ntawv xav tau:

Arduino Uno (lossis ib qho Arduino)

Servo ntaub thaiv npog (yeem)

9g siv

qab jar

pob hlau

qee seem ntoo

Kauj Ruam 1: Ua Lub Hauv Paus thiab Lub Pob Khawm Nrog

Ua Base thiab Hinged Cap Holder
Ua Base thiab Hinged Cap Holder

Lub hauv paus tsuas yog ib qho ntoo los txhawm rau txhawm rau hinged daim ntoo ntawm. Cov ntoo hinged yuav tsum loj dua lub hau hau uas koj yuav siv thiab muaj chaw txaus rau lub pob khawm thiab txhawm rau txhim kho servo.

Kuv siv cov yas me me rc lub dav hlau hinges thiab tsuas yog kub hnyiab lawv rau ntawm cov ntoo hinged thiab lub hauv paus.

Kauj Ruam 2: Ua Ntev Servo Caj Npab thiab Txuas Servo

Ua kom ntev dua Servo Caj Npab thiab Txuas Servo
Ua kom ntev dua Servo Caj Npab thiab Txuas Servo
Ua kom ntev dua Servo Caj Npab thiab Txuas Servo
Ua kom ntev dua Servo Caj Npab thiab Txuas Servo

Txhawm rau ua kom lub caj npab ntev dua Kuv tsuas yog txuas 5 cm ntawm cov ntoo mus rau sab caj npab servo nrog ob peb tus ntsia hlau me me thiab txiv ntseej. Lub caj npab servo yuav tsum nyob ntawm 90 degrees ntawm servo thaum nws yog kab rov tav rau lub hauv paus.

Kuv nyuam qhuav kub glued servo rau tus tuav ntoo tab sis kuv pom tias yog tias koj cia nws khiav ntev dua li ob peb feeb, servo yuav ua kom sov cov kua nplaum thiab tso tawm ntawm ntoo. Yog li txoj hauv kev txuas zoo dua tau lees paub.

Kauj ruam 3: Thauj khoom thiab Khiav Sketch

Load thiab khiav Sketch
Load thiab khiav Sketch

Kuv txuas kuv tus servo rau tus pin 7 siv daim ntaub thaiv vim nws tsuas yog yooj yim thiab lawv tsuas yog them nyiaj qee qhov. Yog tias koj tsis muaj daim ntaub thaiv ces txuas cov kab hluav taws xob servo rau tus pin 7 ntawm Arduino, xaim liab mus rau 5v ntawm Arduino thiab xaim av rau GND ntawm Arduino. Arduino yuav tsum muab tam sim no txaus los ua haujlwm servo. Kuv siv daim ntaub thaiv vim nws yooj yim siv qhov hluav taws xob sab nraud tsuas yog rau servo.

Nov yog daim duab. Kuv tau sau qhov kev tswj hwm qhov kev tswj hwm niaj hnub kom hloov pauv qhov nrawm ntawm servo vim tias nws tej zaum yuav tsis ua haujlwm zoo ntawm qhov nrawm.

Koj tuaj yeem hloov kho lub sijhawm Sijhawm kom tau txais qhov sib txawv ntawm kev sib tw pob. Koj kuj tseem tuaj yeem hloov qhov ntsuas thib peb ntawm myServo () ua haujlwm kom hloov nrawm ib yam.

////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// ////////////// // tsim los ntawm Jim Demello, Shangluo University, 2017

// koj tau siv dawb, tswj hwm, ua txhua yam koj xav tau nrog cov cai no, kuv lub npe tsis xav tau

// Qhov kev niaj hnub no tso cai rau ib tus lej ntawm servos los cuam tshuam, tsuas yog ntxiv kab tshiab yog tias muaj pes tsawg tus servos ntau dua 4

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#suav nrog

Servo myservo1, myservo2; // tsim cov khoom siv servo los tswj lub servo

int servoRead (int servoNumber) {

koj servoCurrent;

yog (servoNumber == 1) {servoCurrent = myservo1.read (); }

yog (servoNumber == 2) {servoCurrent = myservo2.read (); }

rov qab servoCurrent;

}

void servoWrite (int servoNumber, int offset) {

yog (servoNumber == 1) {myservo1.write (offset); }

yog (servoNumber == 2) {myservo2.write (offset); }

}

void myServo (int newAngle, int angleInc, int incDelay, int servoNum) {

koj curAngle;

yog (servoNum == 1) {curAngle = myservo1.read (); }

yog (servoNum == 2) {curAngle = myservo2.read (); }

yog (curAngle <newAngle) {

rau (int angle = curAngle; angle <newAngle; angle += angleInc) {

yog (servoNum == 1) myservo1.write (kaum sab xis);

yog (servoNum == 2) myservo2.write (kaum sab xis);

ncua (incDelay); }

}

lwm tus yog (curAngle> newAngle) {

rau (int angle = curAngle; angle> newAngle; angle -= angleInc) {

yog (servoNum == 1) myservo1.write (kaum sab xis);

yog (servoNum == 2) myservo2.write (kaum sab xis);

ncua (incDelay); }

}

}

tsis muaj dab tsi interpolate2Servos (int servo1, int servo1Position, int servo2, int servo2Position, int numberSteps, int timeDelay) {

int servo1Current, servo2Current;

servo1Current = servoRead (servo1);

servo2Current = servoRead (servo2);

// Serial.print ("Servo3Pos thiab Tam Sim No"); Serial.print (servo3Position); Serial.print (""); Serial.println (servo3Current);

// Serial.print ("Servo4Pos thiab Tam Sim No"); Serial.print (servo4Position); Serial.print (""); Serial.println (servo4Current);

// Serial.print ("Servo5Pos thiab Tam Sim No"); Serial.print (servo5Position); Serial.print (""); Serial.println (servo5Current);

// Serial.print ("Servo6Pos thiab Tam Sim No"); Serial.print (servo6Position); Serial.print (""); Serial.println (servo6Current);

// Serial.println ("");

int cOffset = (servo1Position - servo1Current); cOffset = abs (cOffset)/naj npawbSteps;

int dOffset = (servo2Position - servo2Current); dOffset = abs (dOffset)/tus lej;

int cOffsetTotal = 0, dOffsetTotal = 0;

cOffsetTotal = servo1Current;

dOffsetTotal = servo2Current;

rau (int x = 0; x

yog (servo1Position> servo1Current) {cOffsetTotal = cOffsetTotal + cOffset; }

lwm tus {cOffsetTotal = cOffsetTotal - cOffset; }

yog (servo2Position> servo2Current) {dOffsetTotal = dOffsetTotal + dOffset; }

lwm {dOffsetTotal = dOffsetTotal - dOffset; }

yog (servo1Position! = servo1Current) servoWrite (servo1, cOffsetTotal);

yog (servo2Position! = servo2Current) servoWrite (servo2, dOffsetTotal);

// Serial.print ("a thiab b Offset"); Serial.print (aOffsetTotal); Serial.print (""); Serial.println (bOffsetTotal); ncua (10);

ncua (timeDelay);

} // xaus rau

//////////////////////////////////////

// saib xyuas cov seem modulo //

/////////////////////////////////////

yog (servo1Position! = servo1Current) servoWrite (servo1, servo1Position);

yog (servo2Position! = servo2Current) servoWrite (servo2, servo2Position);

}

int timingDelay = 100;

int servoDelay = 100;

int degGap = 10;

// Nov yog qib pib (yuav tsum tsawg dua qib kawm tiav)

int degStart = 0;

// Qhov no yog qib kawg (yuav tsum siab dua qib pib)

int degEnd = 360;

// Qhov no yog lub vojvoog voos kheej -kheej

int radius = 8;

void teeb tsa ()

{

Serial.begin (9600);

ncua (100);

myservo1.attach (7); // txuas cov servo ntawm tus pin 7 rau cov khoom siv servo

myservo1.write (90);

myservo2.attach (8); // txuas cov servo ntawm tus pin 8 rau cov khoom siv servo

myservo2.write (90);

ncua (1000); // tos rau servo mus txog ntawd

interpolate2Servos (1, 90, 2, 90, 10, 60); // nruab nrab

ncua (1000);

}

void voj () {

timerDelay = 15; // ua haujlwm ntawm 10

servoDelay = 4;

tig 4 ();

// interpolate2Servos (1, 90, 2, 90, 1, 60); // nruab nrab

// ncua (1000);

// tawm (0); // ncua txoj haujlwm - ntaus pib dua kom txuas ntxiv

}

void spin3 () {

interpolate2Servos (1, 90, 2, 110, 1, 60); // nruab nrab

ncua (timingDelay);

interpolate2Servos (1, 90, 2, 80, 1, 60); // nruab nrab

ncua (timingDelay);

}

void spin2 () {

// interpolate2Servos (1, 80, 2, 90, 1, 50); // nruab nrab

ncua (timingDelay);

interpolate2Servos (1, 80, 2, 80, 1, 60); // nruab nrab

ncua (timingDelay);

interpolate2Servos (1, 110, 2, 80, 1, 60); // nruab nrab

ncua (timingDelay);

// interpolate2Servos (1, 110, 2, 110, 1, 60); // nruab nrab

ncua (timingDelay);

}

void spin1 () {

// int deg = (degStart / (180 / 3.14));

ntab deg = (degStart * 3.141592 / 180); // hloov cov degrees rau radians

ntab xPos = 90 + (cos (deg) * radius);

// xPos = round (xPos);

ntab yPos = 90 + (sin (deg) * radius);

// yPos = round (yPos);

Serial.print ("degGap ="); Serial.print (degGap); Serial.print ("deg ="); Serial.print (deg); Serial.print ("cos ="); Serial.print (cos (deg)); Serial.print ("degStart ="); Serial.print (degStart); Serial.print ("x ="); Serial.print (xPos); Serial.print ("y ="); Serial. println (yPos);

// interpolate2Servos (1, xPos, 2, yPos, 1, servoDelay); // nruab nrab

myservo1.write (xPos);

myservo2.write (yPos);

ncua (timingDelay);

yog (degStart> = degEnd) {

degStart = 0;

yog (degGap> 180)

degGap = 180;

// degGap = 0;

lwm tus

degGap = degGap + 2;

degGap = degGap - 2;

// degStart = degStart +degGap;

}

degStart = degStart + degGap;

}

void spin4 () {

rau (int kuv = 0; kuv <= 360; kuv ++) {

ntab j = 20 * (cos ((3.14 * i)/180)) + 90;

ntab k = 20 * (sin ((3.14 * i)/180)) + 90;

myservo1.write (j);

myservo2.write (k);

Serial.print (j);

Serial.print (",");

Serial.println (k);

ncua (100);

}

}

Pom zoo: