Hello, today I will be discussing Joystick Curving in VEXCode, inspired by Pilons 5225A.
Example Code for VEX Clawbot:
turningCurve = 5;
turningRed = false;
forwardCurve = 10;
forwardRed = false;
//graph of red and blue lines from 5225A here
//https://www.desmos.com/calculator/sdcgzah5ya
int curveJoystick(bool red, int input, double t){
int val = 0;
if(red){
val = (std::exp(-t/10)+std::exp((std::abs(input)-100)/10)*(1-std::exp(-t/10))) * input;
}else{
//blue
val = std::exp(((std::abs(input)-100)*t)/1000) * input;
}
return val;
}
void usercontrol(void) {
while(1){
double turnVal = curveJoystick(false, Controller1.Axis1.position(percent), turningCurve); //Get curvature according to settings [-100,100]
double forwardVal = curveJoystick(false, Controller1.Axis3.position(percent), forwardCurve); //Get curvature according to settings [-100,100]
double turnVolts = turnVal * 0.12; //Converts to voltage
double forwardVolts = forwardVal * 0.12; //Converts to voltage
LeftMotor.spin(forward, forwardVolts + turnVolts, voltageUnits::volt); //Apply Via Voltage
RightMotor.spin(forward, forwardVolts - turnVolts, voltageUnits::volt);
vex::task::sleep(20);
}
}
To figure out what values to add, go to this demos that was once originated by Pilons, but which I modified for VEXCode usage: VEXCode Graph
There are two types of curves, a red and a blue curve. To utilize a blue curve, put "turningRed " or "turningRed " false. Otherwise put it as true. There’s a slider for t in the demos graph. If you’re comfortable with the t value, set it as the value of "turningCurve " or "forwardCurve "
If you need any clarification, let me know. Bear in mind, on the top of your main.cpp code where the includes are, you may need to add #include <cmath> to be able to use std::exp and std::abs.
Enjoy ![]()