SyRen/Sabertooth Packet Serial Library for Arduino: C:/Code/src/contract/sabertooth-arduino/Sabertooth/Sabertooth.h Source File

SyRen/Sabertooth Packet Serial Library for Arduino

SyRen/Sabertooth Packet Serial Library for Arduino
Control your SyRen or Sabertooth with reliable Packet Serial.
Sabertooth.h
1 /*
2 Arduino Library for SyRen/Sabertooth Packet Serial
3 Copyright (c) 2012-2013 Dimension Engineering LLC
4 http://www.dimensionengineering.com/arduino
5 
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9 
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
14 RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
16 USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 
19 #ifndef Sabertooth_h
20 #define Sabertooth_h
21 
22 #if defined(ARDUINO) && ARDUINO >= 100
23 #include <Arduino.h>
24 typedef Stream SabertoothStream;
25 #else
26 #include <WProgram.h>
27 typedef Print SabertoothStream;
28 #endif
29 
30 #if defined(USBCON)
31 #define SabertoothTXPinSerial Serial1 // Arduino Leonardo has TX->1 on Serial1, not Serial.
32 #else
33 #define SabertoothTXPinSerial Serial
34 #endif
35 #define SyRenTXPinSerial SabertoothTXPinSerial
36 
42 {
43 public:
49  Sabertooth(byte address);
50 
57  Sabertooth(byte address, SabertoothStream& port);
58 
59 public:
64  inline byte address() const { return _address; }
65 
70  inline SabertoothStream& port() const { return _port; }
71 
76  void autobaud(boolean dontWait = false) const;
77 
83  static void autobaud(SabertoothStream& port, boolean dontWait = false);
84 
90  void command(byte command, byte value) const;
91 
92 public:
97  void motor(int power) const;
98 
104  void motor(byte motor, int power) const;
105 
110  void drive(int power) const;
111 
116  void turn(int power) const;
117 
121  void stop() const;
122 
123 public:
128  void setMinVoltage(byte value) const;
129 
135  void setMaxVoltage(byte value) const;
136 
142  void setBaudRate(long baudRate) const;
143 
152  void setDeadband(byte value) const;
153 
159  void setRamping(byte value) const;
160 
169  void setTimeout(int milliseconds) const;
170 
171 private:
172  void throttleCommand(byte command, int power) const;
173 
174 private:
175  const byte _address;
176  SabertoothStream& _port;
177 };
178 
179 #endif