Advance Motor Control

Embed Size (px)

Citation preview

  • 7/23/2019 Advance Motor Control

    1/8

    Advance Motor ControlAVR ATmega8 Bases Line Follower.

    Easy to make PID LFR Robot.

    In the last partwe saw the basis o! D" motor inter!aing with AVR miroontroller. In this part

    we step !#rther to look at the $API ro#tines !or motor ontrol whih gi%es easy aess to themotors on o#r robot.

    Connecting Motors.

    Fig. 1 - Motor Connectors

    First make the srews loose by #sing a srew &ri%er.

    Insert the motor wire in proper onnetors.

    Tighten the srews.

    http://extremeelectronics.co.in/lfrm8/Help/Motor1.htmhttp://extremeelectronics.co.in/lfrm8/Help/Motor1.htm
  • 7/23/2019 Advance Motor Control

    2/8

    Fig. 2 - Make screws loose

  • 7/23/2019 Advance Motor Control

    3/8

    Fig. 3 - Insert motor wires

  • 7/23/2019 Advance Motor Control

    4/8

    Fig. 4 - Make screws tight again

    Fig. 5 - A Geared DC Motor.

    xAPI for Motor Control

    'otors an be ontrolle& #sing the motor library that omes in as !ollowing !iles.

    motor.c

    motor.h

    myutils.h

    (o# an get these !iles !rom the lib!ol&er in the DVD.

    To #se the motor Library &o the !ollowing )*

    +. "reate a new !ol&erlibin the pro,et #sing -ol#tion E$plorer.

  • 7/23/2019 Advance Motor Control

    5/8

    . "reate a new s#b !ol&ermotorinsi&e the lib!ol&er.

    /. 0sing 1in&ows File 'anager opy2paste the motor.c motor.h ! m"#tils.h !iles toyo#r /lib/motor/!rom the DVD.

    3. A&&all three !iles to yo#r pro,ets #n&er li$%motor.

    4. 5ow yo# are rea&y to #se the library6

    It is ma&e #p o! only three !#ntions.

    &oid MotorInit'&oid(

    This !#ntion m#st be alle& be!ore any other 'otor "ontrol F#ntion is #se&. It sets #p the I27Ports an& Initialies the P1' 'ole o! AVR.

    99999999

    &oid MotorA'#int)*t dir#int)*t s+eed(

    This !#ntion ontrols the 'otor*A. The !irst arg#ment is the &iretion o! rotation re:#ire&. It anbe one o! the !ollowing onstants.

    '7T7R;-T7P * -tops the motor.

    '7T7R;"1 * Rotates the 'otor "lokwise

  • 7/23/2019 Advance Motor Control

    6/8

    '7T7R;""1 * Rotates the 'otor "o#nter "lokwise an& 44.

    Examples

    Motor&(MOTOR_CCW,2'); //Set Rotation as Anti Clockwise with aro! 1o" the #a! see$%

    The abo%e e$ample set the &iretion o! rotation o! motor*b as "o#nter "lokwise withappro$imately +>? o! the ma$im#m rate& spee&. I! the motor was a >> RP' motor then it willrotate appro$imately > re%ol#tions per min#te

  • 7/23/2019 Advance Motor Control

    7/8

    **********************************************************************/

    *incl+$e a-r/io%h.*incl+$e +til/$ela%h.

    *incl+$e 0li/#otor/#otor%h0

    //Simple Dela! Function

    voidWait();

    void#ain() //1nitiali2e motor sus!stem Motor3nit();

    while(1) //Start #otor % in Cloc3 &ise 4C&5 direction "ith full speed 4))5 MotorA(MOTOR_CW,2'');

    //&ait Wait();

    //Set speed to half MotorA(MOTOR_CW,124);

    //&ait Wait();

    //6o" change direction to Counter Cloc3 &ise 4CC&5 MotorA(MOTOR_CCW,2'');

    //&ait Wait();

    //6o" change direction to Counter Cloc3 &ise 4CC&5 MotorA(MOTOR_CCW,124);

    //&ait Wait(); 5

    5

    voidWait()

    +int8_t i;

    for(i6;i2';i77) _$ela_loo_2();

    for(i6;i2';i77) _$ela_loo_2();5

  • 7/23/2019 Advance Motor Control

    8/8

    /0I! the motors rotates opposite o! the e$pete& &iretion then yo# m#st ha%e wire& themotor in wrong polarity. The le!t wire in the onnetor sho#l& be RED an& the right one sho#l&be BLA" as shown in abo%e image.

    /0(o# nee& a power!#l Battery or A&aptor