X Drive Issues

Ok. We’re back again unfortunately. Our x drive has randomly stopped working. Nothing has been changed mechanically or through the program. It drives forward, backward, and turns normally, however, it does not strafe. No matter what combination of +'s and -'s we try, we cannot get it to work normally again.

I’m not sure if it helps, but here is our drive code:

task usercontrol()
	int X2 = 0, Y1 = 0, X1 = 0, threshold = 15;
	while (1==1)

		if(abs(vexRT[Ch2]) > threshold)
   	  Y1 = vexRT[Ch2];

      Y1 = 0;

    if(abs(vexRT[Ch4]) > threshold)
      X1 = vexRT[Ch4];

      X1 = 0;

    if(abs(vexRT[Ch1]) > threshold)
      X2 = vexRT[Ch1];

      X2 = 0;
		//Remote Control Commands - [Toggle]

			motor[frontleft] = Y1 + X2 + X1;
			motor[frontright] = Y1 - X2 - X1;
			motor[backleft] = Y1 + X2 - X1;
			motor[backright] = Y1 - X2 + X1;

Are you using code you got from here:

If so, have you changed Ch3 to Ch2 on purpose?

int deadband(int foo) {
	return (abs(foo) > 15) ? foo : 0; 

task usercontrol() {

	// Controller 1/2, Stick L/R, Axis X/Y
	int C1LY, C1LX, C1RX;

	while (true) {

		C1LX = deadband(vexRT[Ch4]);
		C1LY = deadband(vexRT[Ch3]);
		C1RX = deadband(vexRT[Ch1]);

		// Y component, X component, Rotation
		motor[FL] = -C1LY - C1LX - C1RX;
		motor[FR] =  C1LY - C1LX - C1RX;
		motor[BR] =  C1LY + C1LX - C1RX;
		motor[BL] = -C1LY + C1LX - C1RX;

		// ...

NEVER EVER EVER change ANY of the ROTATION values from negatives. THEY ARE ALWAYS SUBTRACTED (at least the way I do it)!

Also you lost Ch3 somehow, which is kind of amazing.

Functions make nice code.

I improved your labels so that they convey much more descriptiveness that way things don’t get confused later. Like saying Left instead of 1/2.

So we tried it this way. After we did this, it does the same thing. It still cant strafe correctly.

Give me an exact account of how the motors are wired including the polarity of the H bridges, and screenshot your ROBOTC motor config.

The H bridges should not switch the polarity, make sure black goes to black and red goes to red.

Also, all of our motor connections are not inverted. as in we have the black wire to black wire consistently throughout the entire robot.

Any input on this? We are really stumped…

I believe that Jarred was meaning to use the right joystick (Ch1 and Ch2) for x/y movement, and the left joystick (Ch4) for rotation.

Jarred, an easy way to figure out which motors need to be reversed on an “x” holonomic drive is to consider positive to be forwards, as with most other drive types. As such, write your code as if positive motor power leads to the drive moving forwards. An example of doing this with your code (with similar styling to Cody’s) would be:

word deadband(word input, unsigned word threshold)
    return (abs(input) > threshold) ? input : 0;

task usercontrol()
    const unsigned word kThreshold = 15;
    word x = 0, y = 0, r = 0;
    while (true) {
        x = deadband(vexRT[Ch1], kThreshold);
        y = deadband(vexRT[Ch2], kThreshold);
        r = deadband(vexRT[Ch4], kThreshold);
        //Remote Control Commands - [Toggle]
        motor[frontleft]  = y + x + r;
        motor[frontright] = y - x - r;
        motor[backleft]   = y - x + r;
        motor[backright]  = y + x - r;

This code will work on any “x” holonomic drive, as long as the motors have already been reversed correctly in Motors and Sensors Setup such that positive motor power leads to forwards movement. An easy way to determine whether or not any of your motors need to be reversed differently is to use a program such as the following:

task usercontrol()
    while (true) {
        motor[frontleft] = motor[frontright] = motor[backleft] = motor[backright]  = vexRT[Ch2];

When running this code, see if pushing the right joystick forwards makes the robot move forwards. If not, determine which wheels are spinning in the wrong direction, taking note that the associated motors need to be reversed. Reverse those motors in your original software through the Motors and Sensors Setup.

Use my code uncheck all the reverse chechboxes AND set the sides all to none in the motor cofig. Then swap back left with back right in the config.

Then verify that
Port 2 goes to the front left.
Port 3 goes to the front right.
Port 4 goes to the back right.
Port 5 goes to the back left.

Also be aware that the left stick is movement and the right is rotation. This can be changed after we get it working obviously.

Ok thank you. I can’t test anymore right now since my meeting is over, however, I will begin working with it again tomorrow morning.

Thank you all for the help so far. We really appreciate it. We have a competition Saturday, and this is a huge setback for us so far.

My personal phone # is [redacted]

Sorry for the strange format, as this is a public site I have to obfuscate the number to keep the web crawlers from recognizing it.

Call me if you have issues.

Thank you. We have finally gotten it. After another hour of trying to figure out how this works, I got it to work correctly. Do you have any explanation of HOW exactly the code works in this way? Like how it goes

motor[FL] = -C1LY - C1LX - C1RX;
		motor[FR] =  C1LY - C1LX - C1RX;
		motor[BR] =  C1LY + C1LX - C1RX;
		motor[BL] = -C1LY + C1LX - C1RX;

… I don’t get the logic behind this so I was struggling. But i finally saw your comments in the code saying that C1LY was the Y axis etc and it clicked. But I’d like to know why it works in this format.

This detailed video tutorial and possibly this older one if you want more.

I figured you already knew about these, most people do these days.

NOTE that the signs are all backwards in the video.