Library for Sabertooth motor driver ported from the oficial Arduino library. Packetized Serial Mode
I ported the official arduino library for Sabertooth dual motor drivers. In the porting process I did not used const methods as the original library does, but the functionality stays the same. I also added some methods that I find useful. According to the documentation of the driver this code should be compatible with SyRen drivers.
ArduinoMath.cpp@0:70797f033fe0, 2017-02-20 (annotated)
- Committer:
- Elefantul_umilit
- Date:
- Mon Feb 20 11:10:08 2017 +0000
- Revision:
- 0:70797f033fe0
Library for Sabertooth ported from the oficial Arduino library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Elefantul_umilit | 0:70797f033fe0 | 1 | #include "ArduinoMath.h" |
Elefantul_umilit | 0:70797f033fe0 | 2 | |
Elefantul_umilit | 0:70797f033fe0 | 3 | int ArduinoMath::constrain(int x, int a, int b){ |
Elefantul_umilit | 0:70797f033fe0 | 4 | if (x < a) return (a); |
Elefantul_umilit | 0:70797f033fe0 | 5 | if (x > b) return (b); |
Elefantul_umilit | 0:70797f033fe0 | 6 | return (x); |
Elefantul_umilit | 0:70797f033fe0 | 7 | } |
Elefantul_umilit | 0:70797f033fe0 | 8 | |
Elefantul_umilit | 0:70797f033fe0 | 9 | int ArduinoMath::min(int a, int b){ |
Elefantul_umilit | 0:70797f033fe0 | 10 | if (a < b) return (a); |
Elefantul_umilit | 0:70797f033fe0 | 11 | return (b); |
Elefantul_umilit | 0:70797f033fe0 | 12 | } |
Elefantul_umilit | 0:70797f033fe0 | 13 | |
Elefantul_umilit | 0:70797f033fe0 | 14 | int ArduinoMath::max(int a, int b){ |
Elefantul_umilit | 0:70797f033fe0 | 15 | if (a < b) return (b); |
Elefantul_umilit | 0:70797f033fe0 | 16 | return (a); |
Elefantul_umilit | 0:70797f033fe0 | 17 | } |
Elefantul_umilit | 0:70797f033fe0 | 18 | |
Elefantul_umilit | 0:70797f033fe0 | 19 | int ArduinoMath::map(int x, int in_min, int in_max, int out_min, int out_max){ |
Elefantul_umilit | 0:70797f033fe0 | 20 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
Elefantul_umilit | 0:70797f033fe0 | 21 | } |
Elefantul_umilit | 0:70797f033fe0 | 22 | |
Elefantul_umilit | 0:70797f033fe0 | 23 | int ArduinoMath::abs(int x){ |
Elefantul_umilit | 0:70797f033fe0 | 24 | if (x < 0) return (-x); |
Elefantul_umilit | 0:70797f033fe0 | 25 | return (x); |
Elefantul_umilit | 0:70797f033fe0 | 26 | } |
Elefantul_umilit | 0:70797f033fe0 | 27 |