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

Dependents:   2doejemplo

Committer:
nucho
Date:
Fri Sep 23 13:06:59 2011 +0000
Revision:
1:b8f62e733e56
Parent:
0:3f784e34179c
Child:
2:6a3a047c1ce1

        

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 1:b8f62e733e56 8 checksum_ = (unsigned char)((address + command + data) & 0x7F);// checksum
nucho 0:3f784e34179c 9
nucho 1:b8f62e733e56 10 device_.putc((unsigned char)address);
nucho 1:b8f62e733e56 11 device_.putc((unsigned char)command);
nucho 1:b8f62e733e56 12 device_.putc((unsigned char)data);
nucho 1:b8f62e733e56 13 device_.putc(checksum_);
nucho 0:3f784e34179c 14 }
nucho 0:3f784e34179c 15
nucho 0:3f784e34179c 16 void Sabertooth2x25::forward_motor_1(int device_address, int speed) {
nucho 0:3f784e34179c 17 sendCommand(device_address, DRIVE_FORWARD_MOTOR_ONE , speed);
nucho 0:3f784e34179c 18 }
nucho 0:3f784e34179c 19
nucho 0:3f784e34179c 20 void Sabertooth2x25::backwards_motor_1(int device_address, int speed) {
nucho 0:3f784e34179c 21 sendCommand(device_address, DRIVE_BACKWARD_MOTOR_ONE, speed);
nucho 0:3f784e34179c 22 }
nucho 0:3f784e34179c 23
nucho 0:3f784e34179c 24 void Sabertooth2x25::min_voltage(int device_address, int data) {
nucho 0:3f784e34179c 25 sendCommand(device_address, MIN_VOLTAGE, data);
nucho 0:3f784e34179c 26 }
nucho 0:3f784e34179c 27
nucho 0:3f784e34179c 28 void Sabertooth2x25::max_voltage(int device_address, int data) {
nucho 0:3f784e34179c 29 sendCommand(device_address, MAX_VOLTAGE, data);
nucho 0:3f784e34179c 30 }
nucho 0:3f784e34179c 31
nucho 0:3f784e34179c 32 void Sabertooth2x25::forward_motor_2(int device_address, int speed) {
nucho 0:3f784e34179c 33 sendCommand(device_address, DRIVE_FORWARD_MOTOR_TWO, speed);
nucho 0:3f784e34179c 34 }
nucho 0:3f784e34179c 35
nucho 0:3f784e34179c 36 void Sabertooth2x25::backwards_motor_2(int device_address, int speed) {
nucho 0:3f784e34179c 37 sendCommand(device_address, DRIVE_BACKWARD_MOTOR_TWO, speed);
nucho 0:3f784e34179c 38 }
nucho 0:3f784e34179c 39
nucho 0:3f784e34179c 40 void Sabertooth2x25::drive_motor_1(int device_address, int speed) {
nucho 0:3f784e34179c 41 sendCommand(device_address, DRIVE_MOTOR_ONE_7BIT , speed);
nucho 0:3f784e34179c 42 }
nucho 0:3f784e34179c 43
nucho 0:3f784e34179c 44 void Sabertooth2x25::drive_motor_2(int device_address, int speed) {
nucho 0:3f784e34179c 45 sendCommand(device_address, DRIVE_MOTOR_TWO_7BIT, speed);
nucho 0:3f784e34179c 46 }
nucho 0:3f784e34179c 47
nucho 0:3f784e34179c 48 void Sabertooth2x25::drive_forward_mixed_mode(int device_address, int speed) {
nucho 0:3f784e34179c 49 sendCommand(device_address, DRIVE_FORWARD_MIXED_MODE, speed);
nucho 0:3f784e34179c 50 }
nucho 0:3f784e34179c 51
nucho 0:3f784e34179c 52 void Sabertooth2x25::drive_backwards_mixed_mode(int device_address, int speed) {
nucho 0:3f784e34179c 53 sendCommand(device_address, DRIVE_BACKWARD_MIXED_MODE, speed);
nucho 0:3f784e34179c 54 }
nucho 0:3f784e34179c 55
nucho 0:3f784e34179c 56 void Sabertooth2x25::turn_right_mixed_mode(int device_address, int speed) {
nucho 0:3f784e34179c 57 sendCommand(device_address, TURN_RIGHT_MIXED_MODE, speed);
nucho 0:3f784e34179c 58 }
nucho 0:3f784e34179c 59
nucho 0:3f784e34179c 60 void Sabertooth2x25::drive_turn_left_mixed_mode(int device_address, int speed) {
nucho 0:3f784e34179c 61 sendCommand(device_address, DRIVE_TURN_LEFT_MIXED_MODE, speed);
nucho 0:3f784e34179c 62 }
nucho 0:3f784e34179c 63
nucho 0:3f784e34179c 64 void Sabertooth2x25::drive_forwards_back(int device_address, int speed) {
nucho 0:3f784e34179c 65 sendCommand(device_address, DRIVE_FORWARD_BACK_7BIT, speed);
nucho 0:3f784e34179c 66 }
nucho 0:3f784e34179c 67
nucho 0:3f784e34179c 68 void Sabertooth2x25::turn(int device_address, int speed) {
nucho 0:3f784e34179c 69 sendCommand(device_address, TURN_7BIT, speed);
nucho 0:3f784e34179c 70 }