| WW-01 to BrainStem Example Last Modified: 2007-05-03 | | |
| Acroname Robotics | PDF webpage version | ||
| ![]() Introduction In this example, a BrainStem GP 1.0 module uses a Nubotics WW-01 Wheel Watcher assembly to measure the distance traveled by a modified servo. The WW-01 provides quadrature channel A and channel B outputs, an encoder clock output, and a direction output. These outputs can be processed to provide speed and distance information. These programs use the TEA language which is a subset of ANSI C. They use standard TEA libraries along with WW-01 Wheel Watcher source files.
Circuit Schematic In the following schematic, two digital IO pins (1 and 2) are connected to the Channel A and Channel B outputs of the WW-01 Wheel Watcher board. Power for the board is supplied by a regulated +5V output pin and ground pin on the BrainStem module. A servo modified for continuous rotation is connected to servo output 0. ![]() Source Code - Monitoring WW-01 Readings The most effective way for the BrainStem to monitor the WW-01 is with a separate process. The BrainStem can run up to four processes concurrently. In this example, one process will monitor the A and B channels of the WW-01 and write servo positions to the BrainStem's scratchpad. Another process will start a servo spinning, read the servo position from the scratchpad every 0.25 seconds, and print the positions on the Console application screen. Copy the ww-1a.tea file listed below to the aUser subfolder of your brainstem directory. Then copy the aWWEnc.tea file from the aSystem subfolder to the aUser subfolder. The aWWDefs.tea file in the aSystem folder has suggested defined values for a program that uses a pair of WW-01 assemblies. Both programs will use these defined values. A user can modify the values if necessary. Next, enter the following commands from the Console to install and run the programs: steep "ww-1a"
steep "aWWEnc"
load "ww-1a" 2 0
load "aWWEnc" 2 1
launch 2 0
The example program will automatically launch the encoder monitoring process. Try swapping the A and B channels and change the servo speed to see the effects on the output. /* ww-1a.tea */
/* Wheel Watcher Example A */
#include <aCore.tea>
#include <aMulti.tea>
#include <aPrint.tea>
#include <aServo.tea>
#include <aWWDefs.tea>
void main()
{
/* launch Wheel Watcher task */
/* (program 1 in process slot 3) */
aMulti_Spawn(1,3);
aMulti_Signal(3,AWWDEFS_QUADCT_AB);
/* start servo */
aServo_SetAbsolute(AWWDEFS_LMO_ENC, 100);
/* show encoder counts */
while (1) {
aPrint_IntDec(aPad_ReadInt(AWWDEFS_LMO_ENC));
aPrint_Char(',');
aPrint_IntDec(aPad_ReadInt(AWWDEFS_RMO_ENC));
aPrint_Char('\n');
aCore_Sleep(2500);
}
}
Source Code - Position Feedback with the WW-01 The next example program uses the WW-01 to do some simple positioning feedback. It spins a servo until it reaches 100 ticks. Then it stops the servo and prints the final position. The final position may exceed 100 by a few counts since it takes a little while for the servo to stop completely. If you tried the first example, the encoder program will still be loaded so you will only need to enter the following lines to run the example: steep "ww-1b"
load "ww-1b" 2 0
launch 2 0
The servo should spin at medium speed until it reaches 100 ticks. Note that some servos spin in different directions when given the same input. You may need to swap A and B channel assignments for your servo to make the example work as described. /* ww-1b.tea */
/* Wheel Watcher Example B */
#include <aCore.tea>
#include <aMulti.tea>
#include <aPrint.tea>
#include <aServo.tea>
#include <aWWDefs.tea>
void main()
{
/* launch Wheel Watcher task */
/* (program 1 in process slot 3) */
aMulti_Spawn(1,3);
aMulti_Signal(3,AWWDEFS_QUADCT_AB);
/* reset encoder count */
aPad_WriteInt(AWWDEFS_LMO_ENC, 0);
/* start motor */
aServo_SetAbsolute(AWWDEFS_LMO_SERVO, (unsigned char)148);
/* stop the motor once count exceeds 100 ticks */
while (1) {
if (aPad_ReadInt(AWWDEFS_LMO_ENC) > 100) break;
}
aServo_SetAbsolute(0, (unsigned char)128);
/* display how far motor actually went */
aPrint_IntDec(aPad_ReadInt(AWWDEFS_LMO_ENC));
aPrint_Char('\n');
/* kill encoder process */
aMulti_Kill(3);
}
Additional Notes The Nubotics website has additional info, FAQs, and pictures on their documentation pages. They also have example code for other controllers. 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. |