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

Dependents:   2doejemplo

Committer:
nucho
Date:
Wed Sep 21 16:55:39 2011 +0000
Revision:
0:3f784e34179c
Child:
1:b8f62e733e56

        

Who changed what in which revision?

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