Luis Bernal / Mbed 2 deprecated xbeat-hoppel-code

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers drive.cpp Source File

drive.cpp

00001 /*
00002  *
00003  * This program is free software; you can redistribute it and/or modify
00004  * it under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation; either version 3 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * @file drive.cpp
00017  * @author Andre Moehl
00018  * @date 01/2011
00019  * @brief Driver Class definition
00020  */
00021 
00022 /*--- Includes ------------------------*/
00023 #include "drive.h"
00024 
00025 /*--- Functions -----------------------*/
00026 //Contructor 
00027 Drive::Drive(PinName LeftPin,PinName RightPin): _Left(LeftPin, DUTYCYCLE), _Right(RightPin, DUTYCYCLE)
00028 {   
00029     offset_L = 0;
00030     offset_R = 0;
00031 }
00032 
00033 /**
00034  * @ brief Sets the linear speed 
00035  * @parameter speed value between -100 and 100 % */
00036 void Drive::move(int left, int right)
00037 {    
00038     if (left > 120) left = 120;
00039     if (left < -120) left = -120;
00040     if (right > 120) right = 120;
00041     if (right < -120) right = -120;
00042     
00043    _Left.speed(ZERO + offset_L + left*6);
00044    _Right.speed(ZERO - offset_R - right*6);
00045 }
00046 
00047 /**
00048  * @brief sets the motor zero offset
00049  * @parameter left left motor offset
00050  * @parameter right right motor offset
00051  */
00052 void Drive::setoffset(int left, int right)
00053 {
00054      offset_L = left;
00055      offset_R = right;
00056 }
00057