I made a post a while ago about some issues in my Python code, which I had overlooked in the formatting. It was working until today as I’ve been trying to improve it. I’ve primarily used block coding and I’m basically teaching myself python so any support would be appreciated. I’m having problems with my “ring_intake_motor” if statements and tying to increase it’s speed, which has now spread to whole code not working. VS code is not telling me any issues and I’m really at a loss. The picture is of my entire code.
You have not shared a picture of your entire code, so I can’t see what all the problems you have, but I can see a couple in what you shared.
Every function/method call needs to end with (), sometimes with something inside the parenthesis, sometimes not. You have:
ring_intake_motor.stop
but it should be
ring_intake_motor.stop()
You also are using (or trying to use) a .pressed
method, but it is incorrect and also not what you want to use. You have:
if controller_1.buttonB.pressed:
That won’t do anything. You likely want:
if controller_1.buttonB.pressing():
The .pressed
method requires a callback function is used in a different circumstances.
Also one more note, you should be careful about your indentation and keep it consistent. Python is pretty forgiving a lot of the time, but if you are not consistent you will run into a situation where it will break something. Note that the line:
| if controller_1.buttonB.pressed:
| | | pincher_position.set(False)
The pipes (vertical lines) indicate where the indentation blocks are. The fact that you have a third one on that line and an extra space after it indicates that your indentation is off.
If you run into more problems you can’t debug, paste the entire code into a post. Make sure to use the </> button in the toolbar to make it a code block when you paste it in (that will preserve the formatting).
Good luck!
This is my actual entire code. Realized the picture didn’t give everything.
# ---------------------------------------------------------------------------- #
# #
# Module: main.py #
# Author: deanp #
# Created: 10/17/2024, 1:40:37 PM #
# Description: V5 project #
# #
# ---------------------------------------------------------------------------- #
# Library imports
from vex import*
# Brain should be defined by default
brain=Brain()
brain.screen.print("Main.py")
#robot configuration code
left_motor_back = Motor(Ports.PORT11, GearSetting.RATIO_18_1,True)
right_motor_back = Motor(Ports.PORT19, GearSetting.RATIO_18_1, False)
controller_1 = Controller(PRIMARY)
left_motor_front = Motor(Ports.PORT12, GearSetting.RATIO_18_1, True)
right_motor_front = Motor(Ports.PORT20, GearSetting.RATIO_18_1, False)
ring_intake_motor = Motor(Ports.PORT9, GearSetting.RATIO_18_1, False)
pincher_piston = DigitalOut(brain.three_wire_port.h)
# Main Controller loop to set motors
while True:
left_motor_front.set_velocity((controller_1.axis3.position()+controller_1.axis1.position()), PERCENT)
right_motor_front.set_velocity((controller_1.axis3.position()-controller_1.axis1.position()), PERCENT)
left_motor_back.set_velocity((controller_1.axis3.position()+controller_1.axis1.position()), PERCENT)
right_motor_back.set_velocity((controller_1.axis3.position()-controller_1.axis1.position()), PERCENT)
ring_intake_motor.set_velocity(units=PERCENT, value=100)
ring_intake_motor.set_stopping(BRAKE)
if controller_1.buttonL1.pressing():
ring_intake_motor.spin(FORWARD)
if controller_1.buttonL2.pressing():
ring_intake_motor.spin(REVERSE)
else:
ring_intake_motor.stop()
if controller_1.buttonA.pressing():
pincher_piston.set(True)
else:
pincher_piston.set(False)
left_motor_front.spin(FORWARD)
right_motor_front.spin(FORWARD)
left_motor_back.spin(FORWARD)
right_motor_back.spin(FORWARD)
wait(5, MSEC)