V5 Holonomic Drive Coding Help

Hi! So I’m extremely new to Python coding, but I’m trying to program my V5 robot controls via python. I’m using a website (is it an interpreter? Idk, like i said really new) called RobotMesh Studio since it already has all the V5 stuff imported and I don’t have something I can get VEXCode Pro on. I’m getting a syntax error when I try to run my code, and I was hoping for any pointers on what I’m doing wrong, how to fix it, what I should do moving forward and yeah, like i said I’m really new to this. I’ll go ahead and attach my entire code below since y know I’m sure that’ll be useful.

OK so you have made the classic error of trying to program the controls using “logic”. Don’t worry I did that too. What you want is to tell all 4 motors to spin forward, and then have your joystick values set the velocity of each wheel. If the value is negative, you will go in reverse even though your wheels are spinning “forward” ( I know it sounds complicated ). Take a look at this code I wrote for someone else with a similar problem. The device names are different, but I’m sure you can fix that.

     Rfront.set_velocity((controller_1.axis2.position() - controller_1.axis1.position() - controller_1.axis4.position()), PERCENT);
    Lfront.set_velocity((controller_1.axis2.position() + controller_1.axis1.position() + controller_1.axis4.position()), PERCENT);
    Rback.set_velocity((controller_1.axis2.position() + controller_1.axis1.position() - controller_1.axis4.position()), PERCENT);
    Lback.set_velocity((controller_1.axis2.position() - controller_1.axis1.position() + controller_1.axis4.position()), PERCENT);

I see what you are doing, for your if statements, you currently have them as

if con.axis2.position(100),Percent = True

Python evaluates if something is true, so we don’t want to use this equals true. (For other times we use equal signs, 1 equals sign sets a value, and 2 is comparing, as a general rule.) So alright, we now have this for our statement.

if con.axis2.position(100),Percent

Python uses words for and’s and not’s, so if we wanted the controller axis 2 position to be 100, and Percent to be true, we could simply spell it out.

if con.axis2.position(100) and Percent

Now there is one last thing, we are missing a semicolon at the end, so our final if statement will look like

if con.axis2.position(100) and Percent:

Here is another resource on if statements - Python Conditions


1 Like

Thank you so much for this! I ran the code you provided after changing the device names but it still didn’t work, however I’m sure if I do some more tinkering with it I can get it to do something. I had another question though. Since my drivetrain is holonomic how would I go about programming the controller for strafing and turning?

The code I gave you will do strafing and turning as well. If I remember correctly, forward/reverse and left/right strafe should be on the right joystick and turning should be on the left. Essentially, the code tells all the drivetrain motors to spin forward. Then it tells the motors to spin at a certain speed, which is the code I gave you. If you still have problems, try pasting your code here with 3 backticks (```) before. This will allow people to see it properly.