Created
January 22, 2017 16:59
-
-
Save pinski1/fe8d9816d71a15c47faa73e617e76b60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @brief RC Mixer | |
* @detailed Takes 2 RC signals and mixes them to produce tank style steering. The results are scaled to ensure no stick travel is wasted. | |
* | |
* Algorithm copied from here: http://electronics.stackexchange.com/questions/19669/algorithm-for-mixing-2-axis-analog-input-to-control-a-differential-motor-drive | |
* | |
* @param inThrottle The throttle channel RC value, constrained to -255 and +255 | |
* @param inYaw The steering channel RC value, constrained to -255 and +255 | |
* @param outLeft The left motor output, constrained to -255 and +255 | |
* @param outRight The right motor output, constrained to -255 and +255 | |
*/ | |
void mixer(int inThrottle, int inYaw, int &outLeft, int &outRight) { | |
int left = inThrottle + inYaw; | |
int right = inThrottle - inYaw; | |
float scaleLeft = abs(left/255.0); | |
float scaleRight = abs(right/255.0); | |
float scaleMax = max(scaleLeft, scaleRight); | |
scaleMax = max(1, scaleMax); | |
outLeft = int(constrain(left/scaleMax, -255, 255)); | |
outRight = int(constrain(right/scaleMax, -255, 255)); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment