Twister - Tinkerbots

ARDUINO LIBRARY 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 libraryTBTwister 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 libraryTBTwister 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 libraryTBTwister 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 libraryTBTwister 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 libraryTBTwister 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 usingenablePowerCut().

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 libraryTBTwister 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();

}