Pivot - Tinkerbots

ARDUINO LIBRARY PIVOT

The Pivot gives your creations joints. With these you can construct arms or legs with ease. 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 Pivot module e. g.  as a lever.

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

FUNCTION OVERVIEW

FUNCTION DESCRIPTION

 

    NAME

TBPivot()

    DESCRIPTION

Instance a Module from Type Pivot. It is neccessary to include the header file.
#include “TBPivot.h”

    SYNTAX

TBPivot(color);
TBPivot(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 “TBPivot.h” // include pivot libraryTBPivot pivot(RED); // instance of a pivot
byte pos = 0;
byte direction = 0;void setup()
{
pivot.setPosition(90); // move pivot to the middle and hold
direction = 1;
}

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

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

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

 

    NAME

setPosition()

    DESCRIPTION

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

    SYNTAX

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

    PARAMETER

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

    RETURN

None

    EXAMPLE

 

#include “TBPivot.h” // include pivot libraryTBPivot pivot(RED); // instance of a pivot
byte pos = 0;
byte direction = 0;void setup()
{
pivot.setPosition(90); // move pivot to the middle and hold
direction = 1;
}

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

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

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

 

    NAME

getPosition()

    DESCRIPTION

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

    SYNTAX

getPosition();

    PARAMETER

None

    RETURN

byte value between 0 – 180

    EXAMPLE

 

#include “TBPivot.h” // include pivot libraryTBPivot pivot(RED); // instance of a pivot
byte pos = 0;
byte direction = 0;void setup()
{
pivot.setPosition(90); // move pivot to the middle and hold
direction = 1;
}

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

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

if (direction == 1)
pivot.setPosition(++pos, 30); // move with 30 percent of the speed
if (direction == 0)
pivot.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 Pivot by hand.

    SYNTAX

stop()

    PARAMETER

None

    RETURN

None

    EXAMPLE

 

#include “TBPivot.h” // include pivot libraryTBPivot motor(BLUE); // instance of a pivot

setup()
{
/* We want to log data later in this sketch */
Serial.begin(9600);

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

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

void loop()
{
/* Move the Pivot and look at the output on the Serial Console/Serial Plot*/
Serial.write(pivot.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 “TBPivot.h” // include pivot libraryTBPivot pivot(BLUE); // instance of a pivot

setup()
{}

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

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

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

    SYNTAX

disablePowerCut();

    PARAMETER

None

    RETURN

None

    EXAMPLE

 

#include “TBPivot.h” // include pivot libraryTBPivot pivot(BLUE); // instance of a pivot

setup()
{}

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

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

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

}