| Relay to BrainStem Example Last Modified: 2006-10-27 | | |
| Acroname Robotics | PDF webpage version | ||
| Introduction In this example, a BrainStem GP 1.0 module uses two DPDT relays to turn a motor on and off and switch its polarity. Circuit Schematic ![]() In the above schematic, Relay 1 acts as a power switch for the motor. Relay 2 acts as a polarity switch. A DPDT (double-pole double-throw) relay has two pairs of contacts or "throws" and two magnetically activated switch contacts or "poles". A current applied to the relay coil causes both poles to switch. In the diagram above, the pins on the relays have the following functions when viewed from top-to-bottom: ON1, ON0, IN1, IN0, OFF1, OFF0. When the relay is off, IN1 connects to OFF1 and IN0 connects to OFF0. When the relay is on, IN1 connects to ON1 and IN0 connects to ON0. Relay 1 connects motor power from IN1 to ON1. Relay 2 uses the pairs of contacts to swap the motor power connections as described below:
A third relay could switch the polarity of a second motor. Two motors with independent on-off control and direction control can provide locomotion for a simple differential drive robot. Source Code The following program applies power to a motor by activating Relay 1. Then it executes a loop to switch the motor direction several times with Relay 2. Then it shuts off power to the motor. The program uses the TEA language which is a subset of ANSI C. It is compiled using the BrainStem Console by entering the steep command. It may be downloaded to the BrainStem and executed using load and launch commands. This program uses standard TEA libraries. #include <aCore.tea>
#include <aDig.tea>
#define PWR 0
#define DIR 1
#define PWR_ON 1
#define PWR_OFF 0
#define FORWARD 0
#define REVERSE 1
void main()
{
int i;
aDig_Config(DIR, ADIG_OUTPUT);
aDig_Config(PWR, ADIG_OUTPUT);
aDig_Write(PWR, PWR_ON);
for (i = 0; i < 4; i++) {
aDig_Write(DIR, REVERSE);
aCore_Sleep(20000);
aDig_Write(DIR, FORWARD);
aCore_Sleep(20000);
}
aDig_Write(PWR, PWR_OFF);
}
Revision History:
| |||
Related Links: | ||||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2010 Acroname, Inc., Boulder, Colorado. All rights reserved. |