Grabber

Andere Bibliotheken:
Powerbrain
Motor
Pivot
Grabber
Abstandssensor
Lichtsensor

Twister



    If you want to rotate certain parts of your robot, you will need the Twister. The module can turn in a range from 0° to 180°.  Additionally,  the module can give you the current angle as feedback - this way,  you can use the Twister module e. g.  as a potentiometer.


    Sometimes you want to interact with your Twister, you will experience it will try to hold it's current position.  To deactivate this behavior look at stop() .

Function Overview

Function Description


    Name

        TBTwister()

    Description

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

    Syntax

        TBTwister(color);
        TBTwister(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 "TBTwister.h" // include twister library
       
        TBTwister twister(RED); // instance of a twister
        byte pos = 0;
        byte direction = 0;

        void setup()
        {
            twister.setPosition(90); // move twister to the middle and hold
            direction = 1;
        }

        void loop()
        {
            /* receive the current postion */
            pos = twister.getPosition();

            if (pos == 180) direction = 0;
            if (pos == 0) direction = 1;

            if (direction == 1)
                twister.setPosition(++pos, 30); // move with 30 percent of the speed
            if (direction == 0)
                twister.setPosition(--pos, 30); // move with 30 percent of the speed
        }


    Name

        setPosition()

    Description

        Call this function to move and hold a position of the Twister.

    Syntax

        setPosition(angle);
        setPosition(angle, speed);

    Parameter

       angle: Position which the Twister should hold.
               Value: 0 - 180 (degree)
      speed:
Movement speed to reach the position.
                Value: 0 - 100 (in percent)

    Return

        None

    Example


       
        #include "TBTwister.h" // include twister library
       
        TBTwister twister(RED); // instance of a twister
        byte pos = 0;
        byte direction = 0;

        void setup()
        {
            twister.setPosition(90); // move twister to the middle and hold
            direction = 1;
        }

        void loop()
        {
            /* receive the current postion */
            pos = twister.getPosition();

            if (pos == 180) direction = 0;
            if (pos == 0) direction = 1;

            if (direction == 1)
                twister.setPosition(++pos, 30); // move with 30 percent of the speed
            if (direction == 0)
                twister.setPosition(--pos, 30); // move with 30 percent of the speed
        }



    Name

        getPosition()

    Description

        Call this function to receive the current position of the Twister.

    Syntax

        getPosition();

    Parameter

       None

    Return

        byte value between 0 - 180

    Example


          
        #include "TBTwister.h" // include twister library
       
        TBTwister twister(RED); // instance of a twister
        byte pos = 0;
        byte direction = 0;

        void setup()
        {
            twister.setPosition(90); // move twister to the middle and hold
            direction = 1;
        }

        void loop()
        {
            /* receive the current postion */
            pos = twister.getPosition();

            if (pos == 180) direction = 0;
            if (pos == 0) direction = 1;

            if (direction == 1)
                twister.setPosition(++pos, 30); // move with 30 percent of the speed
            if (direction == 0)
                twister.setPosition(--pos, 30); // move with 30 percent of the speed
        }



    Name

        stop()

    Description

        Stops a moving action and disable the position hold. This is especially useful, if you want to move the Twister by hand.

    Syntax

        stop()

    Parameter

        None

    Return

        None

    Example


     
       #include "TBTwister.h" // include twister library

       TBTwister twister(BLUE); // instance of a twister
       
       setup()
       {
          /* We want to log data later in this sketch */
          Serial.begin(9600);

           /* Move the Twister to a specific position */
          twister.setPosition(90);
          delay(1000);

          twister.stop();   //disable position hold
          /* You can now move the Twister freely */
        }

       void loop()
       {
            /* Move the Twister and look at the output on the Serial Console/Serial Plot*/
            Serial.write(twister.getPosition());
       }



    Name

        enablePowerCut()

    Description

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

    Syntax

        enablePowerCut();

    Parameter

       None

    Return

        None

    Example


     
       #include "TBTwister.h" // include twister library

       TBTwister twister(BLUE); // instance of a twister
       
       setup()
       {}

       void loop()
       {
           /* Try to use a Twister with many modules attached->stops and blinks purple */
           twister.setPosition(130);
           delay(2000);

           /* Retry without current limiter */            
           twister.disablePowerCut();
           twister.setPosition(130);
           delay(2000);

           /* Try to always reactivate the current limiter afterwards */
           twister.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 Twister with disabled current limiter may reduce the lifetime of your module.

    Syntax

        disablePowerCut();

    Parameter

       None

    Return

        None

    Example


         
        #include "TBTwister.h" // include twister library

       TBTwister twister(BLUE); // instance of a twister
       
       setup()
       {}

       void loop()
       {
           /* Try to use a Twister with many modules attached->stops and blinks purple */
           twister.setPosition(130);
           delay(2000);

           /* Retry without current limiter */            
           twister.disablePowerCut();
           twister.setPosition(130);
           delay(2000);

           /* Try to always reactivate the current limiter afterwards */
           twister.enablePowerCut();

       }