This is a program to drive a stepper servomotor from SerialUSB without any other interrution but the serial one.

Dependencies:   mbed

Committer:
Yo_Robot
Date:
Mon Apr 09 03:10:30 2012 +0000
Revision:
0:da3eb35a2787
version0.2  PTO using Timer2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yo_Robot 0:da3eb35a2787 1
Yo_Robot 0:da3eb35a2787 2 #include "mbed.h"
Yo_Robot 0:da3eb35a2787 3 #include "L293D.h"
Yo_Robot 0:da3eb35a2787 4
Yo_Robot 0:da3eb35a2787 5 // Constructor
Yo_Robot 0:da3eb35a2787 6 L293D::L293D( PwmOut pwmLeft, PwmOut pwmRight, DigitalOut left, DigitalOut right )
Yo_Robot 0:da3eb35a2787 7 :_left(left), _right(right),_pwmLeft( pwmLeft ), _pwmRight( pwmRight ){
Yo_Robot 0:da3eb35a2787 8
Yo_Robot 0:da3eb35a2787 9 _pwmLeft = 0.0;
Yo_Robot 0:da3eb35a2787 10 _pwmRight = 0.0;
Yo_Robot 0:da3eb35a2787 11
Yo_Robot 0:da3eb35a2787 12 _left = 0;
Yo_Robot 0:da3eb35a2787 13 _right= 0;
Yo_Robot 0:da3eb35a2787 14
Yo_Robot 0:da3eb35a2787 15 }
Yo_Robot 0:da3eb35a2787 16
Yo_Robot 0:da3eb35a2787 17 void L293D::setSpeedLeft( float speed )
Yo_Robot 0:da3eb35a2787 18 {
Yo_Robot 0:da3eb35a2787 19 _speedLeft = speed;
Yo_Robot 0:da3eb35a2787 20
Yo_Robot 0:da3eb35a2787 21 _left = ( speed > 0.0 );
Yo_Robot 0:da3eb35a2787 22 _pwmLeft = abs( speed );
Yo_Robot 0:da3eb35a2787 23
Yo_Robot 0:da3eb35a2787 24 }
Yo_Robot 0:da3eb35a2787 25
Yo_Robot 0:da3eb35a2787 26 void L293D::setSpeedRight( float speed )
Yo_Robot 0:da3eb35a2787 27 {
Yo_Robot 0:da3eb35a2787 28 _speedRight = speed;
Yo_Robot 0:da3eb35a2787 29 _right = ( speed > 0.0 );
Yo_Robot 0:da3eb35a2787 30 _pwmRight = abs( speed );
Yo_Robot 0:da3eb35a2787 31
Yo_Robot 0:da3eb35a2787 32 }
Yo_Robot 0:da3eb35a2787 33
Yo_Robot 0:da3eb35a2787 34
Yo_Robot 0:da3eb35a2787 35 float L293D::getSpeedLeft()
Yo_Robot 0:da3eb35a2787 36 {
Yo_Robot 0:da3eb35a2787 37 float temp = _pwmLeft.read();
Yo_Robot 0:da3eb35a2787 38
Yo_Robot 0:da3eb35a2787 39 // This is done to ensure a -1.0 to 1.0 value is returned
Yo_Robot 0:da3eb35a2787 40 if( _speedLeft > 0 )
Yo_Robot 0:da3eb35a2787 41 return temp;
Yo_Robot 0:da3eb35a2787 42 else
Yo_Robot 0:da3eb35a2787 43 return temp * -1;
Yo_Robot 0:da3eb35a2787 44
Yo_Robot 0:da3eb35a2787 45 }
Yo_Robot 0:da3eb35a2787 46
Yo_Robot 0:da3eb35a2787 47 float L293D::getSpeedRight()
Yo_Robot 0:da3eb35a2787 48 {
Yo_Robot 0:da3eb35a2787 49 float temp = _pwmRight.read();
Yo_Robot 0:da3eb35a2787 50
Yo_Robot 0:da3eb35a2787 51 // This is done to ensure a -1.0 to 1.0 value is returned
Yo_Robot 0:da3eb35a2787 52 if( _speedRight > 0 )
Yo_Robot 0:da3eb35a2787 53 return temp;
Yo_Robot 0:da3eb35a2787 54 else
Yo_Robot 0:da3eb35a2787 55 return temp * -1;
Yo_Robot 0:da3eb35a2787 56
Yo_Robot 0:da3eb35a2787 57 }
Yo_Robot 0:da3eb35a2787 58
Yo_Robot 0:da3eb35a2787 59
Yo_Robot 0:da3eb35a2787 60
Yo_Robot 0:da3eb35a2787 61
Yo_Robot 0:da3eb35a2787 62