Is anything wrong with my code? (python vexcodeV5)

I’m just starting robotics, and i am not good at programming quite yet. I have basic python skills, but not in robotics. I have not tested it yet, but i have a feeling something is wrong in it. Here is my code:

controller_1.axis3.position(100,motor_right.spin(FORWARD)) #up and down movement
    controller_1.axis3.position(-100,motor_right.spin(REVERSE))
    
    controller_1.axis3.position(0, motor_right.set_stopping(BRAKE))
   
    controller_1.axis4.position(100,motor_right.spin(REVERSE)) #left and right movement 
   controller_1.axis4.position(100,motor_left.spin(FORWARD))

   controller_1.axis4.position(-100,motor_right.spin(FORWARD))
   controller_1.axis4.position(-100,motor_left.spin(REVERSE)))

controller_1.axis3.position(100,motor_right.spin(FORWARD)) #up and down movement
    controller_1.axis3.position(-100,motor_right.spin(REVERSE))
    
    controller_1.axis3.position(0, motor_right.set_stopping(BRAKE))
   
    controller_1.axis4.position(100,motor_right.spin(REVERSE)) #left and right movement 
   controller_1.axis4.position(100,motor_left.spin(FORWARD))

   controller_1.axis4.position(-100,motor_right.spin(FORWARD))
   controller_1.axis4.position(-100,motor_left.spin(REVERSE)))
1 Like

yea, about as wrong as it can get. I’ll let others explain though.
(perhaps look at some of the VEXcode example code)

5 Likes

Like jpearman said, this really is impressively wrong. No worries though, you’re writing code with functions you’ve never seen probably in an unfamiliar environment as well. First time for everything.

Big Problem #1:
There’s no loop here. Your code will run almost instantaneously and after it does so, input to the joysticks will be useless.

Big Problem #2:
You don’t seem to understand the motor.spin function or the axis.position function. Probably you want to affect the speed the motor spins with the position of the axis, so something like motor.spin(fwd, axis.position, rpm); would be more appropriate.

Big Problem #3:
The values you send to the drive motors don’t add, so your joystick controls would fight each other. A typical way to code an arcade drive would be to spin the left motor with a speed of throttle+turn and the right motor with a speed of throttle-turn.

Hope this helps.

7 Likes

Thanks, this is really helpful :grinning: . (By the way it is in a loop, but I i did not paste that over.)

1 Like

There are a number of sample programs in the VexCode software, or you can visit kb.vex.com, click on the VEXcode V5 tab, and look for the Python tutorials.

They can give you insight on best practices for programming your robot.

5 Likes