Hi there,
So my teams are trying to figure out how to toggle their punchers / flywheels / other mechanisms so they dont have to hold the button down during driver control and help their team mates out during match loads.
Heres a code we’re trying to figure out, I thought I got the function correct but I am guessing not cause its not working for us:
# ---------------------------------------------------------------------------- #
# #
# Module: main.py #
# Author: Kamalei10 #
# Created: Thu Aug 31 2023 #
# Description: VEX Competition Template WIS #
# #
# ---------------------------------------------------------------------------- #
# Library imports
from vex import *
# Brain should be defined by default
brain=Brain()
# Robot Configuration Code
Lef = Motor(Ports.PORT20,GearSetting.RATIO_18_1, False)
Leb = Motor(Ports.PORT2,GearSetting.RATIO_18_1, False)
Rif = Motor(Ports.PORT11,GearSetting.RATIO_18_1, True)
Rib = Motor(Ports.PORT1,GearSetting.RATIO_18_1, True)
PnCh = Motor(Ports.PORT3,GearSetting.RATIO_36_1)
SeA = Inertial(Ports.PORT4)
# Motor groups
LSide = MotorGroup(Lef, Leb)
RSide = MotorGroup(Rif, Rib)
# drivetrain and Controller
Liam = SmartDrive(Lef, Rif, SeA, 300, 320, 320, MM)
Sear = Controller(PRIMARY)
#Functions
def DriveF(direction, distance, speed):
Liam.set_drive_velocity(speed, PERCENT)
Liam.drive_for(direction, distance, INCHES)
def TurningT(angle, speed):
Liam.set_turn_velocity(speed, PERCENT)
Liam.turn_to_heading(angle,DEGREES,speed)
def PunchG(direction, time, speed):
PnCh.set_velocity(speed)
PnCh.spin(direction)
wait(time, SECONDS)
PnCh.stop(COAST)
def DripuN():
PnCh.set_velocity(100)
PnCh.spin(FORWARD)
while not not Sear.buttonUp.pressing():
wait(5, MSEC)
PnCh.stop()
#Competition Code
def pre_autonomous():
while True:
SeA.calibrate()
def autonomous():
while True:
PunchG(FORWARD, 30, 100)
wait(60000)
def usercontrol():
Sear.buttonUp.pressed(DripuN)
while True:
# controller with joy sticks
LSide.set_velocity((Sear.axis3.position() + Sear.axis4.position()), PERCENT)
RSide.set_velocity((Sear.axis3.position() - Sear.axis4.position()), PERCENT)
LSide.spin(FORWARD)
RSide.spin(FORWARD)
#Buttons
if Sear.buttonDown.pressing():
PnCh.set_velocity(85, PERCENT)
PnCh.spin(FORWARD)
elif Sear.buttonB.pressing():
PnCh.set_velocity(85, PERCENT)
PnCh.spin(REVERSE)
else:
PnCh.stop(HOLD)
comp = Competition(usercontrol, autonomous) #do not touch this
So DripuN is the function my student made from pulling it from vex code blocks to python translate. We also have the pressed command before the while true. Also did it after the while true and the brain gave me an error.
Any ideas? Sorry for dumb questions