sabertooth simplified serial library for arduino · sabertooth simplified serial library for...

27
Main Page Classes Files Examples Class List Class Index Class Members Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes, structs, unions and interfaces with brief descriptions: SabertoothSimplified Controls a Sabertooth motor driver running in Simplified Serial mode

Upload: others

Post on 19-Jun-2020

79 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

ClassList

Herearetheclasses,structs,unionsandinterfaceswithbriefdescriptions:

SabertoothSimplified ControlsaSabertoothmotordriverrunninginSimplifiedSerialmode

Page 2: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

PublicMemberFunctions|Listofallmembers

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

SabertoothSimplifiedClassReference

ControlsaSabertoothmotordriverrunninginSimplifiedSerialmode.More...

Page 3: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

PublicMemberFunctions SabertoothSimplified()

SabertoothSimplified(Print&port)

void motor(intpower)void motor(bytemotor,intpower)void drive(intpower)void turn(intpower)void stop()

Page 4: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

DetailedDescription

ControlsaSabertoothmotordriverrunninginSimplifiedSerialmode.

Examples:SimpleExample/SimpleExample.ino,SoftwareSerial/SoftwareSerial.ino,Sweep/Sweep.ino,andTankStyleSweep.ino.

Page 5: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

Constructor&DestructorDocumentation

SabertoothSimplified::SabertoothSimplified ( )

InitializesanewinstanceoftheSabertoothSimplifiedclass.TheArduinoTXserialportisused.

SabertoothSimplified::SabertoothSimplified ( Print& port )

InitializesanewinstanceoftheSabertoothSimplifiedclass.Thespecifiedserialportisused.

Parametersport Theporttouse.

Page 6: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MemberFunctionDocumentation

voidSabertoothSimplified::drive ( int power )

Setsthedrivingpower.

Parameterspower Thepower,between-127and127.

Examples:TankStyleSweep.ino.

voidSabertoothSimplified::motor ( int power )

Setsthepowerofmotor1.

Parameterspower Thepower,between-127and127.

Examples:SimpleExample/SimpleExample.ino,andSweep/Sweep.ino.

voidSabertoothSimplified::motor ( bytemotor,int power)

Page 7: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

Setsthepowerofthespecifiedmotor.

Parametersmotor Themotornumber,1or2.power Thepower,between-127and127.

voidSabertoothSimplified::stop ( )

Stops.

voidSabertoothSimplified::turn ( int power )

Setstheturningpower.

Parameterspower Thepower,between-127and127.

Examples:TankStyleSweep.ino.

Page 8: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

ClassIndex

S

S

SabertoothSimplified

S

Page 9: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

All Functions

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

Hereisalistofalldocumentedclassmemberswithlinkstotheclassdocumentationforeachmember:

drive():SabertoothSimplifiedmotor():SabertoothSimplifiedSabertoothSimplified():SabertoothSimplifiedstop():SabertoothSimplifiedturn():SabertoothSimplified

Page 10: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

All Functions

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

drive():SabertoothSimplifiedmotor():SabertoothSimplifiedSabertoothSimplified():SabertoothSimplifiedstop():SabertoothSimplifiedturn():SabertoothSimplified

Page 11: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files ExamplesFileList

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

FileList

Hereisalistofalldocumentedfileswithbriefdescriptions:[detaillevel1 2]

SabertoothSimplifiedSabertoothSimplified.h

Page 12: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files ExamplesSabertoothSimplified

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

SabertoothSimplifiedDirectoryReference

Page 13: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

Filesfile SabertoothSimplified.cppfile SabertoothSimplified.h[code]

Page 14: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files ExamplesFileList

SabertoothSimplified

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

SabertoothSimplified.h

1 /*

2 ArduinoLibraryforSabertoothSimplified

Serial

3 Copyright(c)2012-2013DimensionEngineering

LLC

4 http://www.dimensionengineering.com/arduino

5

6 Permissiontouse,copy,modify,and/or

distributethissoftwareforany

7 purposewithorwithoutfeeishereby

granted,providedthattheabove

8 copyrightnoticeandthispermissionnotice

appearinallcopies.

9

10 THESOFTWAREISPROVIDED"ASIS"ANDTHE

AUTHORDISCLAIMSALLWARRANTIES

11 WITHREGARDTOTHISSOFTWAREINCLUDINGALL

IMPLIEDWARRANTIESOF

12 MERCHANTABILITYANDFITNESS.INNOEVENT

SHALLTHEAUTHORBELIABLEFORANY

13 SPECIAL,DIRECT,INDIRECT,ORCONSEQUENTIAL

DAMAGESORANYDAMAGESWHATSOEVER

14 RESULTINGFROMLOSSOFUSE,DATAORPROFITS,

WHETHERINANACTIONOFCONTRACT,

Page 15: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

15 NEGLIGENCEOROTHERTORTIOUSACTION,ARISING

OUTOFORINCONNECTIONWITHTHE

16 USEORPERFORMANCEOFTHISSOFTWARE.

17 */

18

19 #ifndefSabertoothSimplified_h

20 #defineSabertoothSimplified_h

21

22 #ifdefined(ARDUINO)&&ARDUINO>=100

23 #include<Arduino.h>

24 #else

25 #include<WProgram.h>

26 #endif

27

28 #ifdefined(USBCON)

29 #defineSabertoothTXPinSerialSerial1//

ArduinoLeonardohasTX->1onSerial1,not

Serial.

30 #else

31 #defineSabertoothTXPinSerialSerial

32 #endif

33 #defineSyRenTXPinSerial

SabertoothTXPinSerial

34

39 classSabertoothSimplified

40 {

41 public:

46 SabertoothSimplified();

47

53 SabertoothSimplified(Print&port);

54

55 public:

60 voidmotor(intpower);

61

67 voidmotor(bytemotor,intpower);

68

73 voiddrive(intpower);

Page 16: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

74

79 voidturn(intpower);

80

84 voidstop();

85

86 private:

87 voidmixedMode(booleanenable);

88 voidmixedUpdate();

89 voidraw(bytemotor,intpower);

90

91 private:

92 boolean_mixed;

93 int_mixedDrive,_mixedTurn;

94 boolean_mixedDriveSet,_mixedTurnSet;

95 Print&_port;

96 };

97

98 #endif

Page 17: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files Examples

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

Examples

Hereisalistofallexamples:

SimpleExample/SimpleExample.inoSoftwareSerial/SoftwareSerial.inoSweep/Sweep.inoTankStyleSweep.ino

Page 18: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files Examples

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

SimpleExample/SimpleExample.ino

Goesinonedirection,stops,andthengoesintheotherdirection.

//SimpleExampleSample

//Copyright(c)2012DimensionEngineeringLLC

//Seelicense.txtforlicensedetails.

#include<SabertoothSimplified.h>

SabertoothSimplifiedST;//We'llnamethe

SabertoothobjectST.

//ForhowtoconfiguretheSabertooth,seethe

DIPSwitchWizardfor

//

http://www.dimensionengineering.com/datasheets/

SabertoothDIPWizard/start.htm

//BesuretoselectSimplifiedSerialModefor

usewiththislibrary.

//Thissampleusesabaudrateof9600.

//

//Connectionstomake:

//ArduinoTX->1->SabertoothS1

//ArduinoGND->Sabertooth0V

//ArduinoVIN->Sabertooth5V(OPTIONAL,

ifyouwanttheSabertoothtopowerthe

Arduino)

//

Page 19: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

//IfyouwanttouseapinotherthanTX->1,see

theSoftwareSerialexample.

voidsetup()

{

SabertoothTXPinSerial.begin(9600);//Thisisthe

baudrateyouchosewiththeDIPswitches.

}

voidloop()

{

ST.motor(1,127);//Goforwardatfullpower.

delay(2000);//Wait2seconds.

ST.motor(1,0);//Stop.

delay(2000);//Wait2seconds.

ST.motor(1,-127);//Reverseatfullpower.

delay(2000);//Wait2seconds.

ST.motor(1,0);//Stop.

delay(2000);

}

Page 20: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files Examples

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

SoftwareSerial/SoftwareSerial.ino

UsesapinotherthanTXtoconnecttoS1.

//SoftwareSerialSample

//Copyright(c)2012DimensionEngineeringLLC

//Seelicense.txtforlicensedetails.

#include<SoftwareSerial.h>

#include<SabertoothSimplified.h>

SoftwareSerialSWSerial(NOT_A_PIN,11);//RXonno

pin(unused),TXonpin11(toS1).

SabertoothSimplifiedST(SWSerial);//UseSWSerial

astheserialport.

voidsetup()

{

SWSerial.begin(9600);

}

voidloop()

{

intpower;

//Rampfrom-127to127(fullreversetofull

forward),waiting20ms(1/50thofasecond)

pervalue.

for(power=-127;power<=127;power++)

{

Page 21: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

ST.motor(1,power);

delay(20);

}

//Nowgobackthewaywecame.

for(power=127;power>=-127;power--)

{

ST.motor(1,power);

delay(20);

}

}

Page 22: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files Examples

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

Sweep/Sweep.ino

Sweepsfromfullreversetofullforwardandthenfromfullforwardtofullreverse.

//SweepSample

//Copyright(c)2012DimensionEngineeringLLC

//Seelicense.txtforlicensedetails.

#include<SabertoothSimplified.h>

SabertoothSimplifiedST;//We'llnamethe

SabertoothobjectST.

//ForhowtoconfiguretheSabertooth,seethe

DIPSwitchWizardfor

//

http://www.dimensionengineering.com/datasheets/

SabertoothDIPWizard/start.htm

//BesuretoselectSimplifiedSerialModefor

usewiththislibrary.

//Thissampleusesabaudrateof9600.

//

//Connectionstomake:

//ArduinoTX->1->SabertoothS1

//ArduinoGND->Sabertooth0V

//ArduinoVIN->Sabertooth5V(OPTIONAL,

ifyouwanttheSabertoothtopowerthe

Arduino)

//

Page 23: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

//IfyouwanttouseapinotherthanTX->1,see

theSoftwareSerialexample.

voidsetup()

{

SabertoothTXPinSerial.begin(9600);//Thisisthe

baudrateyouchosewiththeDIPswitches.

}

voidloop()

{

intpower;

//Rampmotor1andmotor2from-127to127(full

reversetofullforward),

//waiting20ms(1/50thofasecond)pervalue.

for(power=-127;power<=127;power++)

{

ST.motor(1,power);

ST.motor(2,power);

delay(20);

}

//Nowgobackthewaywecame.

for(power=127;power>=-127;power--)

{

ST.motor(1,power);

ST.motor(2,power);

delay(20);

}

}

Page 24: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files Examples

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

TankStyleSweep.ino

Sweepsvariousrangesinmixed(rover)mode.

//Tank-StyleSweepSample

//Copyright(c)2012DimensionEngineeringLLC

//Seelicense.txtforlicensedetails.

#include<SabertoothSimplified.h>

//Mixedmodeisfortank-stylediff-driverobots.

//OnlyPacketSerialactuallyhasmixedmode,so

thisSimplifiedSeriallibrary

//emulatesit(toalloweasyswitchingbetweenthe

twolibraries).

SabertoothSimplifiedST;//We'llnamethe

SabertoothobjectST.

//ForhowtoconfiguretheSabertooth,seethe

DIPSwitchWizardfor

//

http://www.dimensionengineering.com/datasheets/

SabertoothDIPWizard/start.htm

//BesuretoselectSimplifiedSerialModefor

usewiththislibrary.

//Thissampleusesabaudrateof9600.

//

//Connectionstomake:

//ArduinoTX->1->SabertoothS1

//ArduinoGND->Sabertooth0V

Page 25: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

//ArduinoVIN->Sabertooth5V(OPTIONAL,

ifyouwanttheSabertoothtopowerthe

Arduino)

//

//IfyouwanttouseapinotherthanTX->1,see

theSoftwareSerialexample.

voidsetup()

{

SabertoothTXPinSerial.begin(9600);//Thisisthe

baudrateyouchosewiththeDIPswitches.

ST.drive(0);//TheSabertoothwon'tactonmixed

modeuntil

ST.turn(0);//ithasreceivedpowerlevelsfor

BOTHthrottleandturning,sinceit

//mixesthetwotogethertogetdiff-drivepower

levelsforbothmotors.

//So,wesetbothtozeroinitially.

}

//Mixedmodetips:

//drive()shouldgoforwardandback,turn()

shouldgorightandleft.

//Ifthisisreversed,swapM2AandM2B.

//Positiveondrive()shouldgoforward,

negativeshouldgobackward.

//Ifthisisreversed,swapAandBonbothM1

andM2.

//Positiveonturn()shouldgoright,negative

shouldgoleft.

//Ifthisisreversed,swapM1andM2.

//Inthissample,theSLOWsweep(left-to-right)

hereisturning,

//andtheFASTsweep(backwards-to-forwards)is

throttle.

voidloop()

Page 26: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

{

intpower;

//Don'tturn.Rampfromgoingbackwardstogoing

forwards,waiting20ms(1/50thofasecond)

pervalue.

for(power=-127;power<=127;power++)

{

ST.drive(power);

delay(20);

}

//Now,let'suseapowerlevelof20(outof127)

forward.

//Thisway,ourturningwillhavearadius.

Mostly,thecommand

//isjusttodemonstrateyoucanusedrive()and

turn()atthesametime.

ST.drive(20);

//Rampturningfromfulllefttofullright

SLOWLYbywaiting50ms(1/20thofasecond)

pervalue.

for(power=-127;power<=127;power++)

{

ST.turn(power);

delay(50);

}

//Nowstopturning,andstopdriving.

ST.turn(0);

ST.drive(0);

//Waitabit.Thisissoyoucancatchyourrobot

ifyouwantto.:-)

delay(5000);

}

Page 27: Sabertooth Simplified Serial Library for Arduino · Sabertooth Simplified Serial Library for Arduino Control your Sabertooth with Simplified Serial. Class List Here are the classes,

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

SabertoothSimplifiedMemberList

ThisisthecompletelistofmembersforSabertoothSimplified,includingallinheritedmembers.

drive(intpower) SabertoothSimplifiedmotor(intpower) SabertoothSimplifiedmotor(bytemotor,intpower) SabertoothSimplifiedSabertoothSimplified() SabertoothSimplifiedSabertoothSimplified(Print&port) SabertoothSimplifiedstop() SabertoothSimplifiedturn(intpower) SabertoothSimplified