motest.c

00001 /* 
00002    Copyright (C) 2001 Free Software Foundation, Inc.
00003    Written by Duane Gustavus (duane@denton.com)
00004 
00005 This file is free software; you can redistribute it and/or modify it
00006 under the terms of the GNU General Public License as published by the
00007 Free Software Foundation; either version 2, or (at your option) any
00008 later version.
00009 
00010 In addition to the permissions in the GNU General Public License, the
00011 Free Software Foundation gives you unlimited permission to link the
00012 compiled version of this file with other programs, and to distribute
00013 those programs without any restriction coming from the use of this
00014 file.  (The General Public License restrictions do apply in other
00015 respects; for example, they cover modification of the file, and
00016 distribution when not linked into another program.)
00017 
00018 This file is distributed in the hope that it will be useful, but
00019 WITHOUT ANY WARRANTY; without even the implied warranty of
00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021 General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License
00024 along with this program; see the file COPYING.  If not, write to
00025 the Free Software Foundation, 59 Temple Place - Suite 330,
00026 Boston, MA 02111-1307, USA.  */
00027 
00028 /*
00029  * motest.c assists the construction of a mtr_tab file.  When run
00030  * it should first turn on both motors (without pwm control) which
00031  * will cause them to run at top speed.  The output will show the
00032  * number of encoder ticks which represents top speed.  When you 
00033  * press a key, the pwm control comes on at a very low setting. The
00034  * display now shows both the current pwm setting and the resulting
00035  * encoder count.  Continue to press keys to cause the pwm period to
00036  * increase.  Note values that seem to result in stable encoder counts
00037  * and use them to build a new mtr_tab.h file. 
00038  */
00039 
00040 #include <sys/locks.h>
00041 #include <sys/ports.h>
00042 #include <bot/bot.h>
00043 
00044 #define INCR 1
00045 
00046 char signon[] = "\nspace key to resample; any other to continue\n";
00047 char buf[80];
00048 char token;
00049 
00050 int
00051 main()
00052 {
00053   static int avg;
00054 
00055   /* disable interrupts to initialize system */
00056   lock();
00057   /* run 68hc11 in expanded bus mode */
00058   set_bus_expanded();
00059   /* initialize buffered serial I/O */
00060   init_buffered_io();
00061   /* initialize system clock */
00062   init_sysclock();
00063   /* initialize encoder services */
00064   init_encoders();
00065   /* initialize pwm service */
00066   init_pwm();
00067   /* initialize sensor sampling */
00068   init_poll_sensors();
00069   /* enable interrupts */
00070   unlock();
00071 
00072   /* print signon message to serial port */
00073   serial_print(signon);
00074   /* turn on motors to get top speed in encoder ticks */
00075   pwm_off();
00076   digital_shadowbits |= LEFT_MTR | RIGHT_MTR;
00077   DIGITAL_PORT = digital_shadowbits;
00078   while ((token = sci_getc()) == ' ') {
00079     /* print data for top possible speed */
00080     sprintf(buf,"Top speed: %d  --  %d\n", le_sample, re_sample);
00081     serial_print(buf);
00082   }
00083   /* now step pwm period up to top speed showing encoder counts */
00084   Lmtr = Rmtr = 1000; pwm_on();
00085   sprintf(buf,"\n+ to incr; - to decr; other to resample\n");
00086   serial_print(buf);
00087   while (1) {  /* no exit */
00088     /* block waiting for serial input */
00089     token = sci_getc();
00090     /* possibly in/decrement duty cycle values */
00091     if (token == '-') { Lmtr -= INCR; Rmtr = Lmtr; }
00092     if (token == '+') { Lmtr += INCR; Rmtr = Lmtr; }
00093     /* print current duty cycle and left/right speed */
00094     avg = (le_sample + re_sample) /2;
00095     sprintf(buf,"%d  %d:%d  %d\n", Lmtr, le_sample, re_sample, avg);
00096     serial_print(buf);
00097   }
00098 }