This library is a library for controlling a motor by Sabertooth2x25(Packetized Serial Mode).

Dependents:   2doejemplo

Committer:
nucho
Date:
Sun Nov 13 02:20:48 2011 +0000
Revision:
3:482383d9a5de
Parent:
2:6a3a047c1ce1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 2:6a3a047c1ce1 1 #include"Sabertooth2x25.h"
nucho 2:6a3a047c1ce1 2
nucho 2:6a3a047c1ce1 3 Sabertooth2x25::Sabertooth2x25(PinName tx,int baudrate):device_(tx,NC){
nucho 2:6a3a047c1ce1 4 device_.baud(baudrate);
nucho 2:6a3a047c1ce1 5 }
nucho 2:6a3a047c1ce1 6
nucho 2:6a3a047c1ce1 7 void Sabertooth2x25::sendCommand(int address, int command, int data) {
nucho 2:6a3a047c1ce1 8 checksum_ = (unsigned char)((address + command + data) & 0x7F);// checksum
nucho 2:6a3a047c1ce1 9
nucho 2:6a3a047c1ce1 10 device_.putc((unsigned char)address);
nucho 2:6a3a047c1ce1 11 device_.putc((unsigned char)command);
nucho 2:6a3a047c1ce1 12 device_.putc((unsigned char)data);
nucho 2:6a3a047c1ce1 13 device_.putc(checksum_);
nucho 2:6a3a047c1ce1 14 }
nucho 2:6a3a047c1ce1 15
nucho 2:6a3a047c1ce1 16 void Sabertooth2x25::forward_motor_1(int device_address, int speed) {
nucho 2:6a3a047c1ce1 17 sendCommand(device_address, DRIVE_FORWARD_MOTOR_ONE , speed);
nucho 2:6a3a047c1ce1 18 }
nucho 2:6a3a047c1ce1 19
nucho 3:482383d9a5de 20 void Sabertooth2x25::backward_motor_1(int device_address, int speed) {
nucho 2:6a3a047c1ce1 21 sendCommand(device_address, DRIVE_BACKWARD_MOTOR_ONE, speed);
nucho 2:6a3a047c1ce1 22 }
nucho 2:6a3a047c1ce1 23
nucho 2:6a3a047c1ce1 24 void Sabertooth2x25::min_voltage(int device_address, int data) {
nucho 2:6a3a047c1ce1 25 sendCommand(device_address, MIN_VOLTAGE, data);
nucho 2:6a3a047c1ce1 26 }
nucho 2:6a3a047c1ce1 27
nucho 2:6a3a047c1ce1 28 void Sabertooth2x25::max_voltage(int device_address, int data) {
nucho 2:6a3a047c1ce1 29 sendCommand(device_address, MAX_VOLTAGE, data);
nucho 2:6a3a047c1ce1 30 }
nucho 2:6a3a047c1ce1 31
nucho 2:6a3a047c1ce1 32 void Sabertooth2x25::forward_motor_2(int device_address, int speed) {
nucho 2:6a3a047c1ce1 33 sendCommand(device_address, DRIVE_FORWARD_MOTOR_TWO, speed);
nucho 2:6a3a047c1ce1 34 }
nucho 2:6a3a047c1ce1 35
nucho 3:482383d9a5de 36 void Sabertooth2x25::backward_motor_2(int device_address, int speed) {
nucho 2:6a3a047c1ce1 37 sendCommand(device_address, DRIVE_BACKWARD_MOTOR_TWO, speed);
nucho 2:6a3a047c1ce1 38 }
nucho 2:6a3a047c1ce1 39
nucho 2:6a3a047c1ce1 40 void Sabertooth2x25::drive_motor_1(int device_address, int speed) {
nucho 2:6a3a047c1ce1 41 sendCommand(device_address, DRIVE_MOTOR_ONE_7BIT , speed);
nucho 2:6a3a047c1ce1 42 }
nucho 2:6a3a047c1ce1 43
nucho 2:6a3a047c1ce1 44 void Sabertooth2x25::drive_motor_2(int device_address, int speed) {
nucho 2:6a3a047c1ce1 45 sendCommand(device_address, DRIVE_MOTOR_TWO_7BIT, speed);
nucho 2:6a3a047c1ce1 46 }
nucho 2:6a3a047c1ce1 47
nucho 2:6a3a047c1ce1 48 void Sabertooth2x25::drive_forward_mixed_mode(int device_address, int speed) {
nucho 2:6a3a047c1ce1 49 sendCommand(device_address, DRIVE_FORWARD_MIXED_MODE, speed);
nucho 2:6a3a047c1ce1 50 }
nucho 2:6a3a047c1ce1 51
nucho 3:482383d9a5de 52 void Sabertooth2x25::drive_backward_mixed_mode(int device_address, int speed) {
nucho 2:6a3a047c1ce1 53 sendCommand(device_address, DRIVE_BACKWARD_MIXED_MODE, speed);
nucho 2:6a3a047c1ce1 54 }
nucho 2:6a3a047c1ce1 55
nucho 2:6a3a047c1ce1 56 void Sabertooth2x25::turn_right_mixed_mode(int device_address, int speed) {
nucho 2:6a3a047c1ce1 57 sendCommand(device_address, TURN_RIGHT_MIXED_MODE, speed);
nucho 2:6a3a047c1ce1 58 }
nucho 2:6a3a047c1ce1 59
nucho 2:6a3a047c1ce1 60 void Sabertooth2x25::drive_turn_left_mixed_mode(int device_address, int speed) {
nucho 2:6a3a047c1ce1 61 sendCommand(device_address, DRIVE_TURN_LEFT_MIXED_MODE, speed);
nucho 2:6a3a047c1ce1 62 }
nucho 2:6a3a047c1ce1 63
nucho 2:6a3a047c1ce1 64 void Sabertooth2x25::drive_forwards_back(int device_address, int speed) {
nucho 2:6a3a047c1ce1 65 sendCommand(device_address, DRIVE_FORWARD_BACK_7BIT, speed);
nucho 2:6a3a047c1ce1 66 }
nucho 2:6a3a047c1ce1 67
nucho 2:6a3a047c1ce1 68 void Sabertooth2x25::turn(int device_address, int speed) {
nucho 2:6a3a047c1ce1 69 sendCommand(device_address, TURN_7BIT, speed);
nucho 0:3f784e34179c 70 }