Running Modified Servos Example
Last Modified: 2007-09-17
find:

basket

Acroname Robotics PDF webpage version Running Modified Servos Example PDF

Related
Products

Product image for Brainstem GP 1.0 Module
Brainstem GP 1.0 Module
Product image for 2600mAh AA NiMH Battery
2600mAh AA NiMH Battery
Product image for Parallax Cont Rotation Servo
Parallax Cont Rotation Servo
Product image for 4X AA Battery Pack w/Connector
4X AA Battery Pack w/Connector

Contents

Hardware used for interfacing two modified servos to a BrainStem.

Introduction

In this example, a BrainStem GP 1.0 sends positioning signals to two modified servos that have been altered for continuous rotation.  Modified servos are effective drive motors for a small robot.  This example may provide a good starting point for a small robot project. 

A typical servo receives a series of pulses and moves its arm to a position that is proportional to the width of the input pulse.  The servo uses an internal potentiometer attached to the arm to determine its position.  It continuously monitors the potentiometer and drives the motor forward or backward to maintain the desired arm position.  A modified servo has fixed resistors instead of a potentiometer and no physical limit to arm travel.  The fixed resistors prevent the servo from reaching a final position.  Without physical limits, commanding the servo to move its arm all the way to one side will make the servo rotate continuously in one direction.  This feature makes it easy to control the direction of the motor.  Stopping the input pulses stops the motor.  It is also possible to stop the motor by using a pulse width that corresponds exactly to the center position.  Using a pulse width that is close to the center position will make the servo rotate slowly.  This makes speed control possible.  The center points for modified servos will differ from unit to unit.  They may also drift over time. 

Circuit Schematic

In the following schematic, the BrainStem GP 1.0 and servos are powered by a pack of four NiMH AA batteries .  Ni-Cad or Alkaline batteries would also work well.  Servos may draw up to 1 amp of current.  The servos get power from a special connector on the BrainStem GP 1.0 board instead of the voltage regulator output.  Also, note the detail of the servo plugging.  Ground (the darkest servo wire) should be positioned nearest the board when the servo is plugged in. 

Wiring diagram between the servo motors and the BrainStem.

Configuring the BrainStem Servo Settings

The BrainStem GP 1.0 uses an 8-bit value to control the position of a servo.  It is possible to fine-tune the timing parameters for the PWM signal at each servo output.  For this example, it is necessary to match two servos such that a value of 60 will make each servo stop, a value of 120 will make each servo go forward at full speed, and a value of 0 will make each servo go backward at full speed. 

You can match servos manually, but it takes a little bit of trial and error.  Apply power to the BrainStem GP 1.0 and run the Console program.  Start with the servos disconnected.  Set each servo position to 60 with the cmdSRV_ABS command.  In a typical servo-driven robot, one motor must be inverted.  Set both ENA and INV (the enable and invert bits) for servo 0 with the cmdSRV_CFG command.  For servo 0, set the POS0 (position zero) to 20 and the POSRES (position resolution factor) to 34 with the >cmdSRV_LMT command.  For servo 1, set the POS0 to 36 and the POSRES to 34 with the cmdSRV_LMT command.  Enter the cmdSRV_SAV command to save this servo configuration to the EEPROM.  Now connect the servos.  They should be stopped or spinning slowly.  For a BrainStem GP 1.0 with an address of 2, the Console commands for this procedure are listed below:

2 33 1 60 /* Set the position of servo 0 */ 2 33 1 60 /* Set the position of servo 1 */ 2 31 0 192 /*Set INV and ENA of servo 0 */ 2 32 0 20 34 /*Set limits for servo 0 */ 2 32 1 36 34 /* Set limits for servo 1 */ 2 20 /* Save servo settings */

If a servo is spinning, try incrementing or decrementing its POS0 value with the cmdSRV_LMT command until it stops spinning.  If this does not stop the servo, then increment or decrement its POSRES value and start over again adjusting its POS0 value until the servo stops rotating.  Ideally, the POSRES values for both servos should be the same so that the servo speeds will match as closely as possible within the range 0-120.  If the values differ by 1 or 2, the speeds should still match fairly well. 

Note

You can optionally adjust the servo settings using the GP 1.0 program which offers a dialog and slider bars for adjusting these settings.  This program is described in the GP 1.0 Getting Started Guide. 

Source Code

The BrainStem GP 1.0 has several IO Ports for controlling servos from a TEA program.  Once the servos have been matched in the process described above, all it takes to move a servo with a desired speed is writing to its position port.  The moto subroutine takes care of this operation. 

The main section of the program has some loops that demonstrate the moto subroutine.  It makes the motors gradually increase and decrease forward speed, then gradually increase and decrease reverse speed.  By running two motors at various speeds and reversing motor directions, a robot can rotate, turn, and move forward or backward. 

This code compiles with version 1.0 of the BrainStem GP 1.0 TEA compiler and works with version 1.0 of the BrainStem GP Module. 

/* filename: servo-2.tea */ /* sleep routine and io port definitions */ #include <aCore.tea> #define mleft 0 #define mright 1 void moto(char spdl, char spdr) { asm { pushsb 4 popbm aPortServo + (mleft * aPortServoBlockSize) + aOffsetServoAbsolute pushsb 3 popbm aPortServo + (mright * aPortServoBlockSize) + aOffsetServoAbsolute } return; } void main() { char a; char c = 2; for (a = 60; a < 120; a = a + c) { moto(a,a); aCore_Sleep(1000); // sleep 100ms } for (a = 120; a >=0; a = a - c) { moto(a,a); aCore_Sleep(1000); // sleep 100ms } for (a = 0; a <= 60; a = a + c) { moto(a,a); aCore_Sleep(1000); // sleep 100ms } } /* main */

Revision History:

  • 2001-07-12: Example Created.
  • 2001-10-19: Updated the section regarding servo matching.
  • 2002-01-11: Updated program for compatibility with Build 5 software and TEA libraries.
  • 2007-09-17: Adding missing Console commands to configure servo motor settings.
 
 
voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy
© Copyright 1994-2008 Acroname, Inc., Boulder, Colorado. All rights reserved.