My robotics team has had some troubles with threshold codes. We have a threshold code for our X-Drive, but it does something funny to the X-Drive. It only runs one side at once, and cannot run both sides at the same time. I have included a code below, so any feedback you can give would be great.
X Drives can be a bit finicky, the best way to do thresholds with them is to clamp their values with a function. I can’t remember if ROBOTC implements a
clamp
function or not, but it should be pretty easy to implement regardless.
For example, this is my clamp function from last year
int clamp(int d, int max) {
return abs(d) > max ? d : 0
}
What you’ll want to do is remove all your threshold conditionals, and at the top of your main loop, create three variables for each joystick, for example:
int threshold = 45;
while(true) {
int x1 = clamp(vexRT[Ch2], threshold);
int x2 = clamp(vexRT[Ch3], threshold);
int y1 = clamp(vexRT[Ch4], threshold);
// ...
}
What that “clamp” function does is it checks whether the distance between zero and the number “d” is greater than the maximum value (“max”). If it is, it will return the number “d.” Otherwise, it will return zero.
Here’s what it looks like without using a ternary statement (it’s just a compressed if-statement):
int clamp(int d, int max) {
if (abs(d) > max) {
return d;
} else {
return 0;
}
}
This implements what is known as a “deadband,” which means that anything less than some value “max” will be ignored.
Thanks! That makes a bit more sense now. I will try to implement this on our new H-Base. Do you know if the code for it will be any different from that of the X-Drive?