Coding a Field-Oriented Robot

I have been doing some research on how I would go about programming a field-oriented robot.

Click here to see the thread from the quote above.

I honestly have no idea where to even start when programming a robot with this functionality. I have looked all over the forums and the internet and I can’t find anything useful. Could someone possibly help me program a field-oriented robot? Thanks in advance.

It’s pretty straight forward, there is some code in this post.

also see this project (line 324).

essentially having read the ‘forward’, ‘turn’ and ‘right’ (ie. strafe) values from the joystick you rotate them in this way before sending to the drive motors.

        // Get gyro angle in radians
        theta = degreesToRadians( GyroGetAngle() );

        // rotate coordinate system
        temp  = forward * cos(theta) - right * sin(theta);
        right = forward * sin(theta) + right * cos(theta);
        forward = temp;

Thank you, this is very helpful information.

So I have been going through the code that you have posted on Github, and I am honestly lost. I am not the best programmer in the world, so I apologize if I don’t understand. I am trying to incorporate the field-oriented code into the existing code I have below. I believe that I understand what the code that you provided me with means, but I am just unsure of how I would incorporate it into my mecanum drive code so that it works seamlessly. Could you please help out me and point me in the right direction? Thank you very much.

task usercontrol()
	//Create "deadzone" variables. Adjust threshold value to increase/decrease deadzone
	int X2 = 0, Y1 = 0, X1 = 0, threshold = 15;
	//Create "deadzone" for Y1/Ch3
	if(abs(vexRT[Ch3]) > threshold)
		Y1 = vexRT[Ch3];
		Y1 = 0;
	//Create "deadzone" for X1/Ch4
	if(abs(vexRT[Ch4]) > threshold)
		X1 = vexRT[Ch4];
		X1 = 0;
	//Create "deadzone" for X2/Ch1
	if(abs(vexRT[Ch1]) > threshold)
		X2 = vexRT[Ch1];
		X2 = 0;

	//Remote Control Commands
	motor[frontRight] = Y1 - X2 - X1;
	motor[backRight] =  Y1 - X2 + X1;
	motor[frontLeft] = Y1 + X2 + X1;
	motor[backLeft] =  Y1 + X2 - X1;

Actually, I believe I found what I need in this post from @jpearman .