motor.c

gehe zur Dokumentation dieser Datei
00001 /****************************************************************************/
00032 /*****************************************************************************
00033 *                                                                            *
00034 *   This program is free software; you can redistribute it and/or modify     *
00035 *   it under the terms of the GNU General Public License as published by     *
00036 *   the Free Software Foundation; either version 2 of the License, or        *
00037 *   any later version.                                                       *
00038 *                                                                            *
00039 *****************************************************************************/
00040 #include "asuro.h"
00041 
00042 
00043 
00044 /****************************************************************************/
00084 inline void MotorSpeed (
00085   unsigned char left_speed,
00086   unsigned char right_speed)
00087 {
00088   OCR1A = left_speed;
00089   OCR1B = right_speed;
00090 }
00091 
00092 
00093 
00094 /****************************************************************************/
00127 inline void MotorDir (
00128   unsigned char left_dir,
00129   unsigned char right_dir)
00130 {
00131   PORTD = (PORTD &~ ((1 << PD4) | (1 << PD5))) | left_dir;
00132   PORTB = (PORTB &~ ((1 << PB4) | (1 << PB5))) | right_dir;
00133 }
00134 
00135 
00136 
00137 /***************************************************************************
00138 *
00139 *       sto1     07.01.2006   stochri          first implementation
00140 *
00141 * control the motors
00142 *
00143 * input range: -127 full power backturn
00144 *                 0 stop motors
00145 *              +127 full power vorward
00146 *
00147 *       motor direction and speed can be set with one parameter
00148 *
00149 *       last modification:
00150 *       Ver.     Date         Author           Comments
00151 *       -------  ----------   --------------   ---------------------------------
00152 *       sto1     07.01.2006   stochri          first implementation
00153 *       -------  ----------   --------------   ---------------------------------
00154 ****************************************************************************/
00155 /****************************************************************************/
00183 void SetMotorPower (
00184   int8_t leftpwm,
00185   int8_t rightpwm)
00186 {
00187   unsigned char left, right;
00188 
00189   if (leftpwm < 0)                      // Ein negativer Wert fuehrt ...
00190   {
00191     left = RWD;                         // ... zu einer Rueckwaertsfahrt, ...
00192     leftpwm = -leftpwm;                 // aber immer positiv PWM-Wert
00193   }
00194   else
00195     left = FWD;                         // ... sonst nach vorne, ...
00196   if (leftpwm == 0)
00197     left = BREAK;                       // ... oder bei 0 zum Bremsen.
00198 
00199   if (rightpwm < 0)
00200   {
00201     right = RWD;
00202     rightpwm = -rightpwm;
00203   }
00204   else
00205     right = FWD;
00206   if (rightpwm == 0)
00207     right = BREAK;
00208 
00209   MotorDir (left, right);                 // Drehrichtung setzen
00210 
00211   /*
00212     Die Geschwindigkeitsparameter mit 2 multiplizieren, da der Absolutwert
00213     der Parameter dieser Funktion nur genau die Haelfte von der MotorSpeed()-
00214     Funktion betraegt.
00215   */
00216   MotorSpeed (leftpwm * 2, rightpwm * 2);
00217 }

Erzeugt am Wed Feb 14 16:10:02 2007 für ASURO Library von  doxygen 1.5.1-p1