MD03 to BrainStem Example
Last Modified: 2006-11-01
find:

basket

Acroname Robotics PDF webpage version MD03 to BrainStem Example PDF

Related
Products

Product image for BrainStem Moto 1.0 Module
BrainStem Moto 1.0 Module
Product image for Devantech HBridge Motor Driver
Devantech HBridge Motor Driver

Contents

Example test rig for MD03 to a Moto Controller.

Introduction

In this example, a BrainStem Moto 1.0 module uses a Devantech MD03 motor driver board to control a large wheelchair motor.  This motor requires 24V and draws over 3A.  The MD03 can handle up to 20A at 50V so it has no problem controlling a motor of this size.  The motor has a quadrature encoder that supplies velocity and position feedback to the Moto board. 

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. 

Circuit Schematic

Wiring diagram for MD03 to Moto board.

In the above schematic, the Moto board provides +5 logic power and ground to the MD03 and encoder.  The wheelchair motor has a separate 24V power supply (four 6V lead-acid batteries in series).  The Moto board also supplies PWM and direction (DIR) inputs.  The MD03 can accept I2C motor control commands and generate its own PWM and DIR signals, but it has a basic analog control mode that allows the board to use external PWM and DIR inputs.  This makes it possible for the board to function in a feedback loop.  The Moto board generates a 40KHz PWM frequency which exceeds the minimum 20KHz frequency required for the analog control mode. 

The Moto board can control two motors.  With an extra MD03 driver, a Moto board can control a very large and powerful differential drive robot. 

Source Code

The following program just demonstrates that a program running in the Moto board can control a large motor.  It turns Motor Channel 1 on and off several times and changes its direction.  The aMotion_SetSetpoint routine applies a new setpoint to the motor control PID loop.  Unit conversion constants and PID constants depend on the particular motor, gearing, and encoder.  The Moto Application may be used to test motion and adjust the PID control settings.  It has convenient sliders and text boxes for entering values.  With the motor in this example, the following settings provide good control of the motor velocity:

Mode = Enc Velocity PID
P = 0.5
I = 0
D = 1.0
Input Offset = 0
PWM Rail = 32736
PID Period = 50 (5ms)
PWM Frequency = 39062

The following example drives the motor forward for 1 second, makes it stop for 1 second.  Then the motor is driven backward for 1 second and then stops for 1 second.  This process is repeated 4 times. 

/* md03-1.tea */ #include <aCore.tea> #include <aMotion.tea> /* go forward 1 second, stop 1 second */ /* go backward 1 second, stop 1 second */ /* repeat 4 times */ void main() { int i; for (i = 0; i < 4; i++) { aMotion_SetSetpoint(1, 2); aCore_Sleep(10000); aMotion_SetSetpoint(1, 0); aCore_Sleep(10000); aMotion_SetSetpoint(1, -2); aCore_Sleep(10000); aMotion_SetSetpoint(1, 0); aCore_Sleep(10000); } }

Serial Commands

Commands may also be sent through the serial port of the Moto board to control the motor.  See the documentation pages for commands such as cmdMO_SET and cmdMO_RMPCFG in the Commands section of the online BrainStem Reference. 

Revision History:

  • 2004-01-12: Example Created.
 

Related Links:

Concepts: Description of Pulse Width Modulation (PWM)

Driving High-Current Loads from Logic Article

Brainstem Software: Console Overview

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.