Control the Pololu SMC02B

Committer:
goncaloc
Date:
Mon Oct 11 20:25:57 2010 +0000
Revision:
4:420e977e37b6
Parent:
3:8595605248a3
0v5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
goncaloc 1:683f2848e917 1 /**
goncaloc 1:683f2848e917 2 * @author Gonçalo Costa
goncaloc 1:683f2848e917 3 *
goncaloc 1:683f2848e917 4 * @section LICENSE
goncaloc 1:683f2848e917 5 *
goncaloc 4:420e977e37b6 6 * Copyright (c) 2010
goncaloc 1:683f2848e917 7 *
goncaloc 1:683f2848e917 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
goncaloc 1:683f2848e917 9 * of this software and associated documentation files (the "Software"), to deal
goncaloc 1:683f2848e917 10 * in the Software without restriction, including without limitation the rights
goncaloc 1:683f2848e917 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
goncaloc 1:683f2848e917 12 * copies of the Software, and to permit persons to whom the Software is
goncaloc 1:683f2848e917 13 * furnished to do so, subject to the following conditions:
goncaloc 1:683f2848e917 14 *
goncaloc 1:683f2848e917 15 * The above copyright notice and this permission notice shall be included in
goncaloc 1:683f2848e917 16 * all copies or substantial portions of the Software.
goncaloc 1:683f2848e917 17 *
goncaloc 1:683f2848e917 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
goncaloc 1:683f2848e917 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
goncaloc 1:683f2848e917 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
goncaloc 1:683f2848e917 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
goncaloc 1:683f2848e917 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
goncaloc 1:683f2848e917 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
goncaloc 1:683f2848e917 24 * THE SOFTWARE.
goncaloc 1:683f2848e917 25 *
goncaloc 1:683f2848e917 26 * @section DESCRIPTION
goncaloc 1:683f2848e917 27 *
goncaloc 1:683f2848e917 28 * Pololu Micro Dual Serial Motor Controller.
goncaloc 1:683f2848e917 29 *
goncaloc 1:683f2848e917 30 * Datasheet:
goncaloc 1:683f2848e917 31 *
goncaloc 1:683f2848e917 32 * http://www.pololu.com/file/0J36/smc02b_guide.pdf
goncaloc 4:420e977e37b6 33 *
goncaloc 1:683f2848e917 34 */
goncaloc 1:683f2848e917 35
goncaloc 0:33043894c6cb 36 #ifndef SMC02B_H
goncaloc 0:33043894c6cb 37 #define SMC02B_H
goncaloc 0:33043894c6cb 38 /**
goncaloc 0:33043894c6cb 39 * Includes
goncaloc 0:33043894c6cb 40 */
goncaloc 0:33043894c6cb 41 #include "mbed.h"
goncaloc 0:33043894c6cb 42
goncaloc 0:33043894c6cb 43 /**
goncaloc 0:33043894c6cb 44 * Defines
goncaloc 0:33043894c6cb 45 */
goncaloc 0:33043894c6cb 46 #define SMC02B_START_BYTE 0x80
goncaloc 0:33043894c6cb 47 #define SMC02B_CONFIG_BYTE 0x02
goncaloc 0:33043894c6cb 48 #define SMC02B_DEVICE_ID 0x00
goncaloc 0:33043894c6cb 49 #define SMC02B_BYTE3 0x00
goncaloc 0:33043894c6cb 50 #define SMC02B_BYTE4 0x00
goncaloc 0:33043894c6cb 51 #define SMC02B_MOTOR1_DIR 0x00
goncaloc 0:33043894c6cb 52 #define SMC02B_MOTOR1_SPEED 0x00
goncaloc 0:33043894c6cb 53 #define SMC02B_MOTOR1_NUMBER 0x00
goncaloc 0:33043894c6cb 54 #define SMC02B_MOTOR2_DIR 0x00
goncaloc 0:33043894c6cb 55 #define SMC02B_MOTOR2_SPEED 0x00
goncaloc 0:33043894c6cb 56 #define SMC02B_MOTOR2_NUMBER 0x00
goncaloc 0:33043894c6cb 57
goncaloc 3:8595605248a3 58 /**
goncaloc 4:420e977e37b6 59 *
goncaloc 3:8595605248a3 60 * Pololu Micro Dual Serial Motor Controller.
goncaloc 4:420e977e37b6 61 *
goncaloc 3:8595605248a3 62 */
goncaloc 2:d14838eb6b4b 63
goncaloc 4:420e977e37b6 64 class SMC02B {
goncaloc 4:420e977e37b6 65
goncaloc 3:8595605248a3 66 public:
goncaloc 4:420e977e37b6 67
goncaloc 4:420e977e37b6 68 /**
goncaloc 4:420e977e37b6 69 * Constructor.
goncaloc 4:420e977e37b6 70 *
goncaloc 4:420e977e37b6 71 * @param tx mbed pin to use for TX line of Serial.
goncaloc 4:420e977e37b6 72 * @param rx mbed pin to use for RX line of Serial.
goncaloc 4:420e977e37b6 73 * @param rst mbed pin to use for RESET.
goncaloc 4:420e977e37b6 74 */
goncaloc 4:420e977e37b6 75 SMC02B(PinName tx, PinName rx, PinName rst);
goncaloc 4:420e977e37b6 76
goncaloc 4:420e977e37b6 77 /**
goncaloc 4:420e977e37b6 78 * Reset SMC02B.
goncaloc 4:420e977e37b6 79 *
goncaloc 4:420e977e37b6 80 */
goncaloc 0:33043894c6cb 81 void SMC02B_RST(void);
goncaloc 4:420e977e37b6 82
goncaloc 4:420e977e37b6 83 /**
goncaloc 4:420e977e37b6 84 * Set Motor.
goncaloc 4:420e977e37b6 85 *
goncaloc 4:420e977e37b6 86 * @param motor - Motor to be controlled.
goncaloc 4:420e977e37b6 87 * @param direction - Motor Direction.
goncaloc 4:420e977e37b6 88 * 0 - Reverse
goncaloc 4:420e977e37b6 89 * 1 - Forward
goncaloc 4:420e977e37b6 90 * @param speed - Motor Speed.
goncaloc 4:420e977e37b6 91 * 0 - 127 ( 0x7F )
goncaloc 4:420e977e37b6 92 */
goncaloc 0:33043894c6cb 93 void SMC02B_MOTOR_SET( char motor, char direction, char speed );
goncaloc 4:420e977e37b6 94
goncaloc 4:420e977e37b6 95 /**
goncaloc 4:420e977e37b6 96 * Set Motor to Brake.
goncaloc 4:420e977e37b6 97 *
goncaloc 4:420e977e37b6 98 * @param motor - Motor to be controlled.
goncaloc 4:420e977e37b6 99 */
goncaloc 0:33043894c6cb 100 void SMC02B_MOTOR_BRAKE( char motor );
goncaloc 4:420e977e37b6 101
goncaloc 4:420e977e37b6 102 /**
goncaloc 4:420e977e37b6 103 * Set Motor to idle.
goncaloc 4:420e977e37b6 104 *
goncaloc 4:420e977e37b6 105 * @param motor - Motor to be controlled.
goncaloc 4:420e977e37b6 106 */
goncaloc 0:33043894c6cb 107 void SMC02B_MOTOR_COAST( char motor );
goncaloc 4:420e977e37b6 108
goncaloc 4:420e977e37b6 109 /**
goncaloc 4:420e977e37b6 110 * Configure SMC02B.
goncaloc 4:420e977e37b6 111 *
goncaloc 4:420e977e37b6 112 * @param mode - Set mode 1 or 2 motor mode.
goncaloc 4:420e977e37b6 113 * 0 - 2 motors
goncaloc 4:420e977e37b6 114 * 1 - 1 motor
goncaloc 4:420e977e37b6 115 * @param motor - Motor number.
goncaloc 4:420e977e37b6 116 *
goncaloc 4:420e977e37b6 117 * Allways reset SMC02B after a config
goncaloc 4:420e977e37b6 118 */
goncaloc 0:33043894c6cb 119 void SMC02B_CONFIG( char mode, char motor );
goncaloc 0:33043894c6cb 120
goncaloc 0:33043894c6cb 121 private:
goncaloc 0:33043894c6cb 122 DigitalOut _rst;
goncaloc 0:33043894c6cb 123 Serial* _SMC02B;
goncaloc 0:33043894c6cb 124
goncaloc 0:33043894c6cb 125 };
goncaloc 0:33043894c6cb 126
goncaloc 0:33043894c6cb 127 #endif