Coding X drive in blocks

We are making a X drive, and we are coding it in blocks but we are unsure how to do this. Would you have to code a different function for each motor, or could you just use the pre set up drive terrain.

Thanks in advance!

Try this:

Oh and this:

https://www.vexforum.com/search?q=x-drive%20code

3 Likes

I have tried searching but couldn’t find what I was looking for

The way that I coded my team’s autonomous in blocks was by testing the robot, and then using how many units in the code to be each block.
For instance, I have a function called move_forwards(double blocks), which takes in the number of blocks to move forwards.
In it, I just say Drivetrain.driveFor(forward, (14.0 * blocks), inches, true); because in my case, 14 inches is a full block (because we have messed up detection of units).
The way I found this number was by testing every single number from 1-30 to see which one would be the most accurate.
This is not a sustainable solution, though, you should look into buying a distance sensor for your robot.

Are you coding with an X-drive for autonomous or driver control? Are you wondering how to code which direction the wheels need to spin, or how to code them to spin according to the joysticks, or how to make a function to goForward, or something else? Do you know which direction each wheel needs to spin to strafe in every direction, or do you need help with that? Happy to help after I have some more information! :slightly_smiling_face:

1 Like

I am coding it for driver control. I am unaware of how to code it according to the joysticks, and what way the wheels need to spin.

(Not mine found here: https://seas.yale.edu/sites/default/files/imce/other/HolonomicOmniWheelDrive.pdf)image

1 Like

Ok so I have an X-Drive and there’s some different ways to code it using blocks (which is what I use). But here is a simple way of doing it


(Sorry for the wobbliness XD)
So basically this puts it to where on the left analog stick up and down is forward and backwards and left and right makes it strafe left and right. And on the right stick is rotates left and right. If you want to switch things up then just move the axes around till you get what you want. Hope this helps!

3 Likes

How do you make it spin/turn?

As I said in the post above the right stick makes it turn. If you dont want to use the roght stick to turn then you would switch the 1 and the 4 axes in the code

3 Likes

What does the devices page look like?

I have each motor enabled, I dont have it programmed as drivetrain or anything I just have my Front Right, Front Left, Back Right, and Back Left motors enabled separately. As you can see in the piece of code I provided, each motor is set differently with the plusses and minuses for whatever motor it is on

3 Likes

So I’m guessing that the joystick in the “controller” device is not coded in

I just added a device, selected controller and didn’t touch anything else but DONE on the next screen

2 Likes

I tried this and the robot just starts spinning

Please post your code. Chances are you didn’t do it. Also make sure you know which wheel is in which port.

If you spun wheel FR (front right) “forward” (which we define as this direction, in light blue), the robot would go more or less this way (in purple):

And if you spun wheel FL forward, it would go this direction:

So if you spun them both forward at the same time, the arrows would “merge” and the robot would go forward:

But of course, the same thing works on the back; the right-forward arrow from the BR wheel merges with the left-forward arrow from the BL wheel and the left-forward arrow from the FR wheel and the right-forward arrow from the FL wheel. All four of these arrows are going forward, and the two going left (FR, BL) are counteracted by the two going right (FL, BR):


And that’s how you go forward.

If you spin FR backward, it will pull right-backward:

If you spin BR forward, it will pull right-forward:

Etc. for FL and BL. If you spin them all in these directions, you get right-forward, right-backward, right-forward, and right-backward, so that the two forwards are counteracted by the two backwards but all four rights work together so that you go right:

Once you understand this, you just have to figure out how to add and subtract the various axes (plural of axis) of the controller so that you strafe and spin intuitively. You could copy the code HazeL posted, but you’ll learn more and remember it longer if you figure it out yourself. If you opt for figuring it out, I would recommend you start by making it just go forward and backward, and after that works, add strafing side to side. You’ll have something like set FL velocity to axis 1 + axis 2 etc. And after you get strafing in any direction working, you can add in spinning (which of course is important).

I should add, it’s common practice to configure your motors so that when you tell them to spin forward, the motors go this direction:

6 Likes

@BobbyfromJamaica Ok so first of all they aren’t all minuses. You are using all minus blocks which just isn’t going to work in the first place. And secondly it needs to be ((axis 1/axis4) axis 3), you have (axis1 (axis 4/axis 3)).

The stuff that is out to the sides will go in the empty spaces. Notice how they aren’t all minuses. There is a specific set of plusses and minuses that you need to put with each respected wheel. If you follow that and do it correctly it should work with no problems.

2 Likes