Packetized interface with sabertooth motor controller

Dependents:   Camera_Gimbal_Tracking

Committer:
bediyap
Date:
Thu Feb 10 19:57:24 2011 +0000
Revision:
0:8ad928968f9e

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bediyap 0:8ad928968f9e 1 /**
bediyap 0:8ad928968f9e 2 * @author Birdy
bediyap 0:8ad928968f9e 3 *
bediyap 0:8ad928968f9e 4 * @section LICENSE
bediyap 0:8ad928968f9e 5 *
bediyap 0:8ad928968f9e 6 * Copyright (c) 2010 ARM Limited
bediyap 0:8ad928968f9e 7 *
bediyap 0:8ad928968f9e 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
bediyap 0:8ad928968f9e 9 * of this software and associated documentation files (the "Software"), to deal
bediyap 0:8ad928968f9e 10 * in the Software without restriction, including without limitation the rights
bediyap 0:8ad928968f9e 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
bediyap 0:8ad928968f9e 12 * copies of the Software, and to permit persons to whom the Software is
bediyap 0:8ad928968f9e 13 * furnished to do so, subject to the following conditions:
bediyap 0:8ad928968f9e 14 *
bediyap 0:8ad928968f9e 15 * The above copyright notice and this permission notice shall be included in
bediyap 0:8ad928968f9e 16 * all copies or substantial portions of the Software.
bediyap 0:8ad928968f9e 17 *
bediyap 0:8ad928968f9e 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
bediyap 0:8ad928968f9e 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
bediyap 0:8ad928968f9e 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
bediyap 0:8ad928968f9e 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
bediyap 0:8ad928968f9e 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bediyap 0:8ad928968f9e 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
bediyap 0:8ad928968f9e 24 * THE SOFTWARE.
bediyap 0:8ad928968f9e 25 *
bediyap 0:8ad928968f9e 26 * @section DESCRIPTION
bediyap 0:8ad928968f9e 27 *
bediyap 0:8ad928968f9e 28 * Sabertooth motor drivers
bediyap 0:8ad928968f9e 29 *
bediyap 0:8ad928968f9e 30 * Website:
bediyap 0:8ad928968f9e 31 * http://www.dimensionengineering.com/
bediyap 0:8ad928968f9e 32 *
bediyap 0:8ad928968f9e 33 */
bediyap 0:8ad928968f9e 34
bediyap 0:8ad928968f9e 35 #ifndef SABERTOOTH_H
bediyap 0:8ad928968f9e 36 #define SABERTOOTH_H
bediyap 0:8ad928968f9e 37
bediyap 0:8ad928968f9e 38 /**
bediyap 0:8ad928968f9e 39 * Includes
bediyap 0:8ad928968f9e 40 */
bediyap 0:8ad928968f9e 41 #include "mbed.h"
bediyap 0:8ad928968f9e 42
bediyap 0:8ad928968f9e 43 /**
bediyap 0:8ad928968f9e 44 * Defines
bediyap 0:8ad928968f9e 45 */
bediyap 0:8ad928968f9e 46 #define START_CHARACTER 170
bediyap 0:8ad928968f9e 47
bediyap 0:8ad928968f9e 48
bediyap 0:8ad928968f9e 49 class Sabertooth {
bediyap 0:8ad928968f9e 50
bediyap 0:8ad928968f9e 51 public:
bediyap 0:8ad928968f9e 52 /**
bediyap 0:8ad928968f9e 53 * Constructor.
bediyap 0:8ad928968f9e 54 *
bediyap 0:8ad928968f9e 55 * @param
bediyap 0:8ad928968f9e 56 */
bediyap 0:8ad928968f9e 57 // Constructor
bediyap 0:8ad928968f9e 58 Sabertooth(PinName Tx, int address, int baudrate);
bediyap 0:8ad928968f9e 59
bediyap 0:8ad928968f9e 60 // Initialize Sabertooth
bediyap 0:8ad928968f9e 61 void InitializeCom(void);
bediyap 0:8ad928968f9e 62
bediyap 0:8ad928968f9e 63 // Valid speed is between -127 and +127
bediyap 0:8ad928968f9e 64 void SetSpeedMotorA(int speed);
bediyap 0:8ad928968f9e 65
bediyap 0:8ad928968f9e 66 // Valid speed is between -127 and +127
bediyap 0:8ad928968f9e 67 void SetSpeedMotorB(int speed);
bediyap 0:8ad928968f9e 68
bediyap 0:8ad928968f9e 69 void ShutdownMotors(void);
bediyap 0:8ad928968f9e 70
bediyap 0:8ad928968f9e 71 // Valid speed is between -127 and +127
bediyap 0:8ad928968f9e 72 int GetCommandedSpeedA();
bediyap 0:8ad928968f9e 73
bediyap 0:8ad928968f9e 74 // Valid speed is between -127 and +127
bediyap 0:8ad928968f9e 75 int GetCommandedSpeedB();
bediyap 0:8ad928968f9e 76
bediyap 0:8ad928968f9e 77 private:
bediyap 0:8ad928968f9e 78 enum Motor { A, B };
bediyap 0:8ad928968f9e 79 int _Address;
bediyap 0:8ad928968f9e 80 int _CurrentSpeed[2];
bediyap 0:8ad928968f9e 81 Serial _sabertoothserial; // tx, rx
bediyap 0:8ad928968f9e 82
bediyap 0:8ad928968f9e 83 int ClipSpeed(int speed);
bediyap 0:8ad928968f9e 84
bediyap 0:8ad928968f9e 85 void Send(int command, int value);
bediyap 0:8ad928968f9e 86
bediyap 0:8ad928968f9e 87 void SetMotorSpeed(int motor,int speed);
bediyap 0:8ad928968f9e 88 };
bediyap 0:8ad928968f9e 89
bediyap 0:8ad928968f9e 90 #endif /* SABERTOOTH_H */