The above code initializes the sabertooth. The first part sets up the software serial and transmit pin, in that variable, specifying it’s receive order. The next function sets the pin modes and initializes the SaberSerial connection. The motor controllers needs a minimum of 50 us, and we gave it 2 seconds to play it safe. We then make sure everything is stopped. Next, we have our action function. This function will take in a range from -100 to 100. -100 is a full reverse command, and 100 is a full forward. It utilizes the map () function, which takes a variable within certain ranges(original range) and converts it to an equivalent value within another specified range (range 2). Map(numberpassed in, -100, 100, Full reverse constant (1), Full forward constant (127)). When the function passes in certain values, it can convert them into speed for our motors to go:
The above code initializes the sabertooth. The first part sets up the software serial variable, specifying it’s receive and transmit pin, in that order. The next function sets the pin modes and initializes the SaberSerial connection. The motor controllers needs a minimum of 50 us, and we gave it 2 seconds to play it safe. We then make sure everything is stopped. Next, we have our action function. This function will take in a range from -100 to 100. -100 is a full reverse command, and 100 is a full forward. It utilizes the map () function, which takes a variable within certain ranges(original range) and converts it to an equivalent value within another specified range (range 2). Map(numberpassed in, -100, 100, Full reverse constant (1), Full forward constant (127)). When the function passes in certain values, it can convert them into speed for our motors to go: