Hey CD,
FTC 14133 is having some trouble getting our drive train working properly. We can get forward or backwards motion correctly working, but the math causing the robot to strafe seems to be mixed up in some way. The wheels begin to fight each other. We know it is a very simple mathematical error, but we spent 3+ hours today trying to find the error with no success.
Here is the link to the drivetrain portion of the code:
FTC 14133 2022-2023 Drivetrain Code
For reference, l = left, r = right, f = front, b = back
We are using the atan2 function to determine the angle the joystick is facing, and then using the sine of that angle times the speed generated from the combination of the x and y components of the joystick (Pythagorean theorem).
double leftPowerY = -gamepad1.left_stick_y; //find the value of y axis on the left joystick;
double leftPowerX = gamepad1.left_stick_x; //find the value of x axis on the left joystick;
double rightPowerX = gamepad1.right_stick_x; //find the value of x axis on the right joystick;
double angleR = Math.atan2(leftPowerY, leftPowerX)-(Math.PI/2); //Calculating angle of which the joystick is commanded to in radians
double angleD = Math.toDegrees(angleR); //Calculating angle of which the joystick is commanded to in degrees
double speed = Math.sqrt((leftPowerY * leftPowerY) + (leftPowerX * leftPowerX)); //Calculating the magnitude of the joystick
Each wheel is sent through a sine function with the angle of the joystick plus some odd multiple of pi/4 to represent the wheels at all 4 corners of the robot (45, 135, 225, and 315 deg) to calculate each wheel’s individual power
double rfpower = (Math.sin(angleR + (1 * Math.PI / 4)) * speed) + (rightPowerX * rotationK); //Power level for leftfront
double lfpower = -(Math.sin(angleR + (3 * Math.PI / 4)) * speed) + (rightPowerX * rotationK); //Power level for rightfront
double lbpower = (Math.sin(angleR + (5 * Math.PI / 4)) * speed) + (rightPowerX * rotationK); //Power level for rightback
double rbpower = -(Math.sin(angleR + (7 * Math.PI / 4)) * speed) + (rightPowerX * rotationK); //Power level for leftback
We have all wheels configured to be “forward”, so when they are all running forward the robot rotates CCW, and backwards > CW. We have tried different combinations of forward and reverse, and different combinations of negative and positive, all of which have struggled to get either the strafing or forward/backwards working properly.
Does anyone have any idea where we are going wrong, or at least suggestions to test and troubleshoot?
Thanks!