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

Post on 19-Jun-2020

81 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

ClassList

Herearetheclasses,structs,unionsandinterfaceswithbriefdescriptions:

SabertoothSimplified ControlsaSabertoothmotordriverrunninginSimplifiedSerialmode

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

PublicMemberFunctions|Listofallmembers

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

SabertoothSimplifiedClassReference

ControlsaSabertoothmotordriverrunninginSimplifiedSerialmode.More...

PublicMemberFunctions SabertoothSimplified()

SabertoothSimplified(Print&port)

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

DetailedDescription

ControlsaSabertoothmotordriverrunninginSimplifiedSerialmode.

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

Constructor&DestructorDocumentation

SabertoothSimplified::SabertoothSimplified ( )

InitializesanewinstanceoftheSabertoothSimplifiedclass.TheArduinoTXserialportisused.

SabertoothSimplified::SabertoothSimplified ( Print& port )

InitializesanewinstanceoftheSabertoothSimplifiedclass.Thespecifiedserialportisused.

Parametersport Theporttouse.

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)

Setsthepowerofthespecifiedmotor.

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

voidSabertoothSimplified::stop ( )

Stops.

voidSabertoothSimplified::turn ( int power )

Setstheturningpower.

Parameterspower Thepower,between-127and127.

Examples:TankStyleSweep.ino.

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

ClassIndex

S

S

SabertoothSimplified

S

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

All Functions

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

Hereisalistofalldocumentedclassmemberswithlinkstotheclassdocumentationforeachmember:

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

MainPage Classes Files ExamplesClassList ClassIndex ClassMembers

All Functions

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

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

MainPage Classes Files ExamplesFileList

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

FileList

Hereisalistofalldocumentedfileswithbriefdescriptions:[detaillevel1 2]

SabertoothSimplifiedSabertoothSimplified.h

MainPage Classes Files ExamplesSabertoothSimplified

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

SabertoothSimplifiedDirectoryReference

Filesfile SabertoothSimplified.cppfile SabertoothSimplified.h[code]

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,

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);

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

MainPage Classes Files Examples

SabertoothSimplifiedSerialLibraryforArduinoControlyourSabertoothwithSimplifiedSerial.

Examples

Hereisalistofallexamples:

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

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)

//

//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);

}

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++)

{

ST.motor(1,power);

delay(20);

}

//Nowgobackthewaywecame.

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

{

ST.motor(1,power);

delay(20);

}

}

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)

//

//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);

}

}

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

//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()

{

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);

}

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

top related