Motor - Tinkerbots

ARDUINO LIBRARY 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 libraryTBMotor 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 libraryTBMotor 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 libraryTBMotor 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 libraryTBMotor 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 libraryTBMotor 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 libraryTBMotor 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();
}