Please Help - Squaring Joystick Inputs Trouble

I was wondering if anyone had a solution to squaring the inputs from a joystick using the Cartesian drive method with mecanum wheels. We currently have it set to use the Java Math.pow function but we are worried that it will convert any negative inputs back to positive. Does anyone have a solution to this? We are in major need of help. Thanks in advance!

You can use Java’s Math.signum() method to get the sign of a number (either 1 or -1):

double input = -0.5;
double output = Math.pow(input, 2.0) * Math.signum(input);
// output == -0.25

Thank you so much for the help!

I’m partial to using odd numbered exponents for this exact reason. I haven’t noticed a HUGE difference in control responsiveness between squared and cubed, but cubed will maintain the sign.

But yes, if squared is your preference, what @andrewda said will work fine


double output = Math.abs(input) * input;

This offseason I plan to document our team’s new equations for driving and post them on here.

The Java Math library will do this for you as well:



Math.copysign(input * input, input);
1 Like

And if you want to skip any function calls at all, there’s always
double output = input>0 ? input*input : -input*input;

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.