Grabber

Andere Bibliotheken:
Powerbrain
Grabber
Pivot
Twister
Abstandssensor
Lichtsensor

Arduino Bibliothek Motor



    The Motor module offers basic drive capability. It can be operated at different speeds and is most commonly used for wheels of a car. The inbuilt current limiter protects the device against heavy loads and accelerations. Although not recommended, it is possible to turn off this feature for your most complex and  demanding creations.

    The Motor rotation direction is defined as Clockwise and Counterclockwise when looking into the LED.

Function Overview

Function Description


    Name

        TBMotor()

    Description

        Instance a Module from Type Motor. It is neccessary to include the header file.
        #include "TBMotor.h"

    Syntax

        TBMotor(color);
        TBMotor(color,invert);

    Parameter

        color: Color of the module which is shown during setup.
                Values: RED, GREEN, BLUE, MINT, PURPLE, YELLOW, WHITE

       invert (optional): Flag for inverting rotation direction.
                Values: 0 - Not inverting
                             1 - Inverting

    Return

        None

    Example


     
       #include "TBMotor.h" // include motor library
      
       TBMotor motor(BLUE); // instance of a motor

       void setup()
       {}
       void loop()
       {
            /* Motor starts to rotate or drive for 5000 Milliseconds */
            motor.start(CLOCKWISE,50, 5000);

            /* halt the motor */
            motor.stop();

            /* Drive a model around 47 cm with the Tinkerbots Wheels */
            motor.driveDistance(COUNTER_CLOCKWISE, 25, 47);
        }


    Name

        start()

    Description

        This function lets the motor module rotate in a direction.

        Using the optional 'duration' parameter will block program flow during rotation. To use multiple modules in parallel, you have to implement your own time logic.

    Syntax

        start(direction, speed);
        start(direction, speed, duration);

    Parameter

       direction: Motor rotation direction.
               Value: true / false
                           CLOCKWISE / COUNTER_CLOCKWISE
                           CW / CCW (defines are included automatically using the Arduino Package)
      speed:
Motor rotation speed.
                Value: 0 - 100 (in percent)
       duration (optional): Motor runtime in Milliseconds
                Value: 0 - 65535
              

    Return

        None

    Example


     
       #include "TBMotor.h" // include motor library

       TBMotor motor(BLUE); // instance of a motor
       
       setup()
       {}

       void loop()
       {
            /* Motor starts to rotating or driving for 5000 Milliseconds */
            motor.start(CLOCKWISE,50, 5000);

            /* halt the motor */
            motor.stop();

            /* Drive a model around 47 cm with the Tinkerbots Wheels */
            motor.driveDistance(COUNTER_CLOCKWISE, 25, 47);
       }



    Name

        stop()

    Description

        This function will halt the motor module.

    Syntax

        stop();

    Parameter

       None

    Return

        None

    Example


     
       #include "TBMotor.h" // include motor library

       TBMotor motor(BLUE); // instance of a motor
       
       setup()
       {}

       void loop()
       {
            /* Motor starts to rotating or driving for 5000 Milliseconds */
            motor.start(CLOCKWISE,50, 5000);

            /* halt the motor */
            motor.stop();

            /* Drive a model around 47 cm with the Tinkerbots Wheels */
            motor.driveDistance(COUNTER_CLOCKWISE, 25, 47);
       }



    Name

        driveDistance()

    Description

        Let a motor module run till a specific distance is driven. The reference for this are the Tinkerbots wheels. The distance is estimated from time, module current and battery voltage.

    Syntax

        driveDistance(direction, speed, distance);

    Parameter

       direction: Motor rotation direction.
             Values: true / false
                          CLOCKWISE / COUNTER_CLOCKWISE
       speed: Motor rotation speed.
             Values: 0 - 100 (in percent)
       distance: Model drive distance in cm.
             Values: 0 - 65535

    Return

        None

    Example


     
       #include "TBMotor.h" // include motor library

       TBMotor motor(BLUE); // instance of a motor
       
       setup()
       {}

       void loop()
       {
            /* Motor starts to rotating or driving for 5000 Milliseconds */
            motor.start(CLOCKWISE,50, 5000);

            /* halt the motor */
            motor.stop();

            /* Drive a model around 47 cm with the Tinkerbots Wheels */
            motor.driveDistance(COUNTER_CLOCKWISE, 25, 47);
       }



    Name

        enablePowerCut()

    Description

        This function enables the current limiter in the motor module. It is only used to revert the effect of disablePowerCut().

    Syntax

        enablePowerCut();

    Parameter

       None

    Return

        None

    Example


     
       #include "TBMotor.h" // include motor library

       TBMotor motor(BLUE); // instance of a motor
       
       setup()
       {}

       void loop()
       {
            /* Try to start Motor with heavy load. */
            motor.start(CLOCKWISE,50, 5000);

            /* Motor deactivates (purple blinking LED)  -> deactivate limiter*/
            motor.disablePowerCut();

            motor.start(CLOCKWISE,50, 5000);   //try again with disabled current limiter

            /* Try to reactivate the current limiter after such operation. This way you lengthen the lifetime of your module*/
            motor.enablePowerCut();
       }



    Name

        disablePowerCut()

    Description

        The current limiter can be deactivated with this function. Heavy loads stop the module to protect it from permanent damage. In some cases, this limits the possibilities. If you are sure what you are doing, you can disable this feature to get a pinch more power. Remember to reactivate the limiter using enablePowerCut().

       Warning: Driving the motor with disabled current limiter may reduce the lifetime of your motor module.

    Syntax

        disablePowerCut()

    Parameter

       None

    Return

        None

    Example


         
       #include "TBMotor.h" // include motor library

       TBMotor motor(BLUE); // instance of a motor
       
       setup()
       {}

       void loop()
       {
            /* Try to start Motor with heavy load. */
            motor.start(CLOCKWISE,50, 5000);

            /* Motor deactivates (purple blinking LED)  -> deactivate limiter */
            motor.disablePowerCut();

            motor.start(CLOCKWISE,50, 5000);   //try again with disabled current limiter

            /* Try to reactivate the current limiter after such operation. This way you lengthen the lifetime of your module*/
            motor.enablePowerCut();
       }