Goncalo Costa / SMC02B
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SMC02B.h Source File

SMC02B.h

00001 /**
00002  * @author Gonçalo Costa
00003  * 
00004  * @section LICENSE
00005  *
00006  * Copyright (c) 2010
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy
00009  * of this software and associated documentation files (the "Software"), to deal
00010  * in the Software without restriction, including without limitation the rights
00011  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012  * copies of the Software, and to permit persons to whom the Software is
00013  * furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included in
00016  * all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024  * THE SOFTWARE.
00025  *
00026  * @section DESCRIPTION
00027  *
00028  * Pololu Micro Dual Serial Motor Controller.
00029  *
00030  * Datasheet:
00031  *
00032  * http://www.pololu.com/file/0J36/smc02b_guide.pdf
00033  *
00034  */
00035  
00036 #ifndef SMC02B_H
00037 #define SMC02B_H
00038 /**
00039  * Includes
00040  */
00041 #include "mbed.h"
00042 
00043 /**
00044  * Defines
00045  */
00046 #define SMC02B_START_BYTE       0x80
00047 #define SMC02B_CONFIG_BYTE      0x02
00048 #define SMC02B_DEVICE_ID        0x00
00049 #define SMC02B_BYTE3            0x00
00050 #define SMC02B_BYTE4            0x00
00051 #define SMC02B_MOTOR1_DIR       0x00
00052 #define SMC02B_MOTOR1_SPEED     0x00
00053 #define SMC02B_MOTOR1_NUMBER    0x00
00054 #define SMC02B_MOTOR2_DIR       0x00
00055 #define SMC02B_MOTOR2_SPEED     0x00
00056 #define SMC02B_MOTOR2_NUMBER    0x00
00057 
00058 /**
00059 *
00060 * Pololu Micro Dual Serial Motor Controller.
00061 *
00062 */
00063 
00064 class SMC02B {
00065 
00066 public:
00067 
00068     /**
00069      * Constructor.
00070      *
00071      * @param tx mbed pin to use for TX line of Serial.
00072      * @param rx mbed pin to use for RX line of Serial.
00073      * @param rst mbed pin to use for RESET.
00074      */
00075     SMC02B(PinName tx, PinName rx, PinName rst);
00076     
00077     /**
00078      * Reset SMC02B.
00079      *
00080      */
00081     void SMC02B_RST(void);
00082 
00083     /**
00084      * Set Motor.
00085      *
00086      * @param motor - Motor to be controlled.
00087      * @param direction - Motor Direction.
00088      *                    0 - Reverse
00089      *                    1 - Forward
00090      * @param speed - Motor Speed.
00091      *                    0 - 127 ( 0x7F )
00092      */
00093     void SMC02B_MOTOR_SET( char motor, char direction, char speed );
00094 
00095     /**
00096      * Set Motor to Brake.
00097      *
00098      * @param motor - Motor to be controlled.
00099      */
00100     void SMC02B_MOTOR_BRAKE( char motor );
00101 
00102     /**
00103      * Set Motor to idle.
00104      *
00105      * @param motor - Motor to be controlled.
00106      */
00107     void SMC02B_MOTOR_COAST( char motor );
00108 
00109     /**
00110      * Configure SMC02B.
00111      *
00112      * @param mode - Set mode 1 or 2 motor mode.
00113      *              0 - 2 motors
00114      *              1 - 1 motor
00115      * @param motor - Motor number.
00116      *
00117      *  Allways reset SMC02B after a config
00118      */
00119     void SMC02B_CONFIG( char mode, char motor );
00120 
00121 private:
00122     DigitalOut _rst;
00123     Serial* _SMC02B;
00124 
00125 };
00126 
00127 #endif