X-Drive RobotC Programming Help

Hello. As part of this year’s robot we have made an 4 motor x drive. The back two motors also have IME’ s on them.

My question is: can anyone show me how to properly program an x drive with some resources or sample coding?

Also: can someone help with autonomous programming using the imes on this drive? I’ve wanted to look into PID. Is that even possible with this kind of drive?

Thank you for the help!

http://blog.elliotjb.com/

This blog should be able to help you out a bunch. You should be more than able to program PID with IMEs on an X-Drive, but I have too little experience in robotC to help you out with it, sorry.

and obviously there’s this.

Holonomic drives: A video tutorial by Smartkid

For an X Drive, think of your coordinate system offset by 45 degrees. Rotational translation is the term to learn here. You think of the wheels in a different coordinate system than the robot’s forward facing and field coordinates of X and Y.

When programming, look how far each wheel goes at the direction of the wheel’s travel. That is the robot’s best X and Y coordinate system in relation to the IME’s on the wheels. So make the triangles of the vectors to say how far along the robot’s X direction and how far on the Y direction does it need to go.

You then program the pairs of wheels tied to the X and Y coordinates. NE & SW wheels are one pair for the X coordinates, NW and SE are the other pair for the Y coordinates. (or the other way around, it does not matter that much) Control each wheel with it’s own P or PID controllers. PID has many advantages but small distance movements is not one of them. The robot won’t go in an absolute straight line to the new coordinate but manage each X and Y on its own. So that gets the shorter change first and then straight line on the longer one.

There are other mechanisms of doing this that engage all the wheels with more power but that is beyond the scope of most kids.

The other trick is to ensure you minimize rotation on this drive between two points. Going to new a X and Y point accurately depends upon no rotation. So you minimize that by keeping a heading with the gyro on top of the X Y management. (Or just pray if you don’t use a gyro. Mostly it will work until one wheel’s motor gets out of whack)

So before we get into code samples, think about offsetting the coordinate systems and wrap your head about that concept.

Ok. So I’ve taken all of this in which will help immensely for the autonomous portion of this drive. So thank you very much! :slight_smile:

Now today I had everything fully built and was ready to test, but my programmer wasn’t there, and may not be back for a while. (Medical issues). So naturally, I gave it my best go. But, since I am not very good at programming, the best I could do was basically copy over the code from the mecanum sample program and conform it to my motor set up. However, it was only able to drive forward and backwards and strafe(although it was inverted). It could not point turn at all, the motors drive against eachother.
The program I used looked a bit like this:

motor[leftfront] = VexRT[ch3] - VexRT[ch1] - VexRT[ch4];
Motor[rightfront] = VexRT[ch3] - VexRT[ch1] + VexRT[ch4];
Motor[leftrear] = VexRT[ch3] + VexRT[ch1] + VexRT[ch4];
Motor[rightrear]= VexRT[ch3] + VexRT[ch1] - VexRT[ch4];

This program is supposed to have left joystick control forward and strafe movement while the right controls point turning.

Ok so I soon realized that the issues were derived from the combination of the +/-'s so I played around with those for a while and couldn’t seem to get it. My issue here is that I’m not sure what this program does, or what it’s parts mean. Could anyone dissect this for me and help me figure this out? Thank you :smiley:

motor[leftfront] = VexRT[ch3] - VexRT[ch1] - VexRT[ch4];
Motor[rightfront] = VexRT[ch3] - VexRT[ch1] + VexRT[ch4];
Motor[leftrear] = VexRT[ch3] + VexRT[ch1] + VexRT[ch4];
Motor[rightrear]= VexRT[ch3] + VexRT[ch1] - VexRT[ch4];

Should be

motor[leftfront] = VexRT[ch3] + VexRT[ch1] + VexRT[ch4];
Motor[rightfront] = VexRT[ch3] - VexRT[ch1] - VexRT[ch4];
Motor[leftrear] = VexRT[ch3] + VexRT[ch1] - VexRT[ch4];
Motor[rightrear]= VexRT[ch3] - VexRT[ch1] + VexRT[ch4];

If that doesn’t work then you need to reverse some of your motors (I assume you have that sorted out already, though, since you had all of your CH3s +)

Basically Ch3 (left joystick forward/backward movement) moves the robot forwards/backwards, Ch4 (left joystick side-to-side movement) strafes the robot left and right, and Ch1 (right joystick side-to-side) turns the robot left and right.

Ok I can try that out Thursday. But what are the +/-'s for?

OK, so if we look at joystick Ch3, we get positive values if we move the joystick up and negative ones if we move it down. Now, when we move the joystick up, we want the robot to drive forwards. To make this happen all of the wheels have to spin forwards, so all the wheels need to receive positive values as well (again assuming that you configured your motors with forwards being positive on all of them).

Now let’s look at joystick Ch1. This turns left and right (or counterclockwise/clockwise if you like that better). If we move the joystick to the right, we get positive values, and if we move it to the left we get negative values. When we move it to the right, we want the robot to turn right, so we have to get all the motors spinning the right direction to make that happen. Starting with the front-left motor, this motor needs to turn “forwards” in order to turn the robot right, so we give it a positive value. The front-right motor, however, needs to turn backwards (try and visualize this), so we have to turn the positive value from the joystick into a negative one, so we use the -. The back-left motor needs to turn forwards, so we give it positive. The back-right motor needs to turn backwards so we give it negative.

Ok thank you. I’ll try to fix it on Thursday.

Your welcome and hopefully it works. If the robot doesn’t even drive forwards when you just push the left joystick forwards then you need to reverse some of the motors (which you can do either in the code or just by flipping the wire connections if you don’t know how) before changing anything else.