x drive code

#1

hey guys how to make a relative x drive code.
like the one in this video
https://www.youtube.com/watch?v=_PWg5TXsBFM
But how do you do it for x drives
I am using Robotc by the way

0 Likes

I need help with coding an x-drive in c++
#2

Here is the code for RobotC:

while(true)
{
motor[frontRight] = vexRT[Ch2] - vexRT[Ch4] - vexRT[Ch1];
motor[backRight] = vexRT[Ch2] - vexRT[Ch4] + vexRT[Ch1];
motor[frontLeft] = vexRT[Ch2] + vexRT[Ch4] + vexRT[Ch1];
motor[backLeft] = vexRT[Ch2] + vexRT[Ch4] - vexRT[Ch1];
}

This works for me. The right stick controls forward, backward, left, right, and all of the diagonals. While the left stick simply controls turning.

0 Likes

#3

I have that part but what I want is that then I turn the robot 90 degrees and push the joystick up the robot will begin to strafe forward instead of going left/right even though that’s forward technically

0 Likes

#4

The relative drive is achieved through a gyroscope sensor, which you can see if you look closely in the video.

There’s a thread about this video with code (which is probably the best thing about this forum):
https://vexforum.com/t/omni-directional-motion/22139/1&page=2

0 Likes

#5

What you have programmed is considered “Robot Centric”, meaning that the forward direction is defined by the direction the front of the robot is facing.

What you want is called “Field Centric” control, where the robot moves in correspondence with absolute directions. To achieve this, you need a yaw rate gyroscope. Using the gyroscope, you can tell the rotational displacement of the robot in relation to the field and then based on this value determine the motor power levels.

JPearman has some great posts on this stuff.

0 Likes