Holonomic drive train code

I am using the standard VEX code v5. It would be great if you could help me!

Text or blocks
I can’t help with blocks sorry
Lmk if it’s text tho

Text in python but C++ is good two. I assume its just a few stranded lines of code right? like the same code can be copied and pasted for everyone?
@ERROR101

The basics of the Python code will be something like this, but this is just a rough guide, not something to copy and paste.

leftFront.spin(FORWARD)
rightFront.spin(FORWARD)
leftRear.spin(FORWARD)
rightRear.spin(FORWARD)


while true:
    leftFront.set_velocity(controller_1.axis1.position() + controller_1.axis2.position() + controller_1.axis3.position(), PERCENT)
    #then your other 3 motor commands here

So at the start, you are spinning all the motors forward. The velocity of these motors is then set within the loop. A negative velocity will make them go backwards.

1 Like

Thanks! But is didn’t work… This is what I used

VEXcode Project x-drve.v5python (1.7 KB)

I hope you can find the issue!
So sorry if this is a burden two you.

2021-03-08 (2) 2021-03-08 (1)

I believe your issue is that you have the wrong axes for driving forward and turning. You had axis 1 to move it forward, but that should be axis 2. Axis 2 was turning your robot, but you want axis 1 to do that.
Using Blocks for Controller Buttons / Joysticks in VEXcode V5 – Knowledge  Base
By switching the axes, like I’ve done here, you should be able to control your robot.
VEXcode Project x-drve.v5python (1.8 KB)

4 Likes

Thanks! but it didn’t work…

I think now that code you gave me must be right!
So there must be a problem with the setup/controls with the brain or controller because when I press run code, nothing happens when I move any of the controller buttons.

some of the wheels move at random tho when I go into drive robot (not in the code)

I can only assume at this point that I am making some rookie mistake in the setup.
Does anybody know what could be wrong?

The drive code won’t help you, it’s only for clawbots. Try making a program that spins each wheel forwards one after another for 1 rotation. That would allow you to see if any are spinning the wrong way, and let you know to reverse that motor in it’s setup

2 Likes

Thanks, all the wheels are moving in the right direction.

The problem is that nothing happens when I move the controller. This is the code have so far,

x-drve Official.v5python (1.9 KB)

In the code you have attached, you are never telling the motors to spin. Setting the velocity doesn’t actually move them, it just tells the motors how fast to go when they are going to move.
You also need a loop to continually update the velocity based on the current controller axis positions.

Take a look at the attached to see the basics. I am not sure if this will work as such, but it will run at least.x-drve Official.v5python (2.0 KB)

4 Likes

I had tremendous help from these wonderful people, back in October. The code they gave me was a little of a rough draft, however, because everyone’s robot is different. This should be the base, but you might have to change some signs around to make it work the way you want. NOTE: This is arcade, which I think is what you want.

Edit: Forgot the Link lol.

1 Like

Thanks but I don’t know how to tell the motors to spin when I move my controller and I also don’t know how to loop the code.

I also fear there is a problem with the ‘while true’ command at the top because i tried running basic code below it and nothing happened where as when I ran that same code above it it worked.

This code also means nothing to me

LeftFront.spin(FORWARD)
RightFront.spin(FORWARD)
LeftRear.spin(FORWARD)
RightRear.spin(FORWARD)

I want to be able to drive the robot with the controller. I already made sure the motors where set right.

Could you just add a loop to it and tell the motors to spin like you said I needed to do because honestly I have know clue how to use python. x-drve Official.v5python

I will be forever grateful to you if you can get it to work!
Thank you so much!

Thanks,
would it make sense for you to copy and past me your full code and then i can adjust it to suit me?

It would be supper awsume if you could!

I also saw you might have use robotC but robotC can only be used with cortex right?

2 Likes

This code was used in VexCode V5 Text, and I no longer have the code since we rebuilt our code, but that code should get your motors to move after they are declared.

RobotC works with V5 and IQ, too, I believe.

It doesn’t move any of the motors and I don’t know what you mean by “after you declare them”

Just Cortex and IQ, not V5.

I tested this before I posted the code and it works fine with a controller so you must have a different issue somewhere.

To explain the code a bit further:
There are two commands in this code relating to the motors - the ones that contain spin e.g. LeftFront.spin(FORWARD) and the ones that contain set_velocity.

The set_velocity commands do not make the motor move at all. They just tell the motor what speed is should turn when it is told to move. It is the spin commands in this case that tell the motors to move.

So at the start of the program we tell all 4 motors to spin. The speed that they spin at is governed by the code in the loop. The fact that we tell them to spin forward is somewhat irrelevant.

The code then enters the infinite loop (while True:) and each time it goes round that loop, it sets the velocities for all 4 motors based on your controller axis positions. When you are not touching the controller axis at all, all values are zero so whilst we have told the motors to spin at the start of the program, we are telling them to spin at zero velocity so therefore they don’t move.
As you move the axis, the various values for velocity are updated and the motors will start to turn. These could be negative velocity values which would make the motor spin backwards, or positive values which make it spin forward.

When I said earlier that the code may not work, what I meant was that it may not do what you want it to do in terms of holonomic movement. But it will work in terms of making your motors move relative to inputs on the controller.

If the motors aren’t moving at all and you are sure you have working motors plugged in to the ports as per the program and you are sure your controller is paired then your issue lies somewhere else.

It may be better for you to start off writing a very simple tank drive program initially before moving onto holonomic code. This way you can learn the basics of motor control via the controller before adding the maths complexity created by using holonomic code.

7 Likes

Wow Thank you so much!!!
It works!!!
I just can’t belevie my eyes, oh the delight when the wheel just moved!!!

When I went to retry the code again I had my controller plugged into my pc instead of the brain.
I was also making lots of other small mistakes along the process but after you explained how the code worked it just made sense

Thank you so much!!!
I have been dying over the last week on how to get it going.
I really I really owe you!!

Like I just cant describe how happy I am!!!

Sorry if this was any burden two you. But now i know better how to use vex code v5

Thank you so much!!

4 Likes

This is the solution but because I tag this topic under “Discussion” there is no solution button.

Thank you all so much for everybody that helped out!!!