Need helping making a function for 2 subsystems

Needing help with code for one of my teams, we’re not able to make a function to run their drive train and their intake at the same time, not sure if I’m showing them right.

We got it so the drive train works, but cant get the intake to work with it.

# ---------------------------------------------------------------------------- #
#                                                                              #
# 	Module:       main.py                                                      #
# 	Author:       KaldenPrime03                                                #
# 	Created:      Thu Aug 25 2022                                              #
# 	Description:  VEX Competition Template WIS                                 #
#                                                                              #
# ---------------------------------------------------------------------------- #

# Library imports
from vex import *

# Brain should be defined by default
brain=Brain() 

# Robot Configuration Code
Lfw = Motor(Ports.PORT2, GearSetting.RATIO_18_1,False) 
Rfw = Motor(Ports.PORT10, GearSetting.RATIO_18_1,True)
Lbw = Motor(Ports.PORT12, GearSetting.RATIO_18_1,False)
Rbw = Motor(Ports.PORT20, GearSetting.RATIO_18_1,True)
HIntake = Motor(Ports.PORT4, GearSetting.RATIO_6_1,True)
Intake = Motor(Ports.PORT5, GearSetting.RATIO_18_1,True)
Pis1 = DigitalOut(brain.three_wire_port.a)
SeA = Inertial(Ports. PORT13)
# Motor groups
LSide = MotorGroup(Lfw, Lbw)
RSide = MotorGroup(Rfw, Rbw)
Intake1 = MotorGroup(Intake, HIntake)
#FUNtionG = MotorGroup(Lfw, Lbw, Rfw, Rbw, Intake)
# drivetrain and Controller
Smarty = SmartDrive(LSide, RSide, SeA, 300, 320, 320, MM, 2)
Dictator = Controller(PRIMARY)

#Functions
def DriveF(direction, distance, speed):
    Smarty.set_drive_velocity(speed, PERCENT)
    Smarty.drive_for(direction, distance, INCHES)

def LefTurn(direction, angle, speed):
    Smarty.set_turn_velocity(speed, PERCENT)
    Smarty.turn_for(direction, angle, DEGREES) 

def IntakeG(direction, angle, speed):
    #Intake1.set_velocity(speed, PERCENT)
    Intake1.spin_for(direction, angle, DEGREES, speed, PERCENT)

def intake(direction, angle, speed):
    #Intake.set_velocity(speed, PERCENT)
    Intake.spin_for(direction, angle, DEGREES, speed, PERCENT)

def twoFunc(direction1, distance, speed1, angle, speed2, direction2):
    Intake.set_velocity(speed2, PERCENT)
    Smarty.set_turn_velocity(speed1,PERCENT )
    Smarty.drive_for(direction1, distance,)
    Intake.spin_for(direction2,speed2, angle, DEGREES)


def IntakePis(time, dare, poop):
    Pis1.set(dare)
    wait(time, MSEC)
    Pis1.set(poop)




    



#Competition Code
def pre_autonomous():
    
    while True:
       Smarty.set_stopping(COAST)
       SeA.calibrate()
       Smarty.set_turn_constant(1.5)
       Smarty.set_turn_threshold(1)

def autonomous():
   
    while True:
        twoFunc(FORWARD, 80, 100, 800, 100, FORWARD)
        DriveF(FORWARD, 15, 100)
        LefTurn(RIGHT, 40, 65)


    

     


    
      

        wait(150) 

def usercontrol():

    while True:
        
        # controller with joy sticks
        LSide.set_velocity(Dictator.axis3.position() + Dictator.axis1.position(),PERCENT)
        RSide.set_velocity(Dictator.axis3.position() - Dictator.axis1.position(),PERCENT)
        LSide.spin(FORWARD)
        RSide.spin(FORWARD)


        #Buttons
        if Dictator.buttonR1.pressing():
            Intake1.spin(FORWARD, 100, PERCENT)

        elif Dictator.buttonR2.pressing():
            Intake1.spin(REVERSE, 100, PERCENT)

        else:
            Intake1.stop(COAST)


        if Dictator.buttonUp.pressing():
            Pis1.set(True)

        elif Dictator.buttonDown.pressing():
            Pis1.set(False)

        
            

        

        



comp = Competition(usercontrol, autonomous) # type: ignore #do not touch this

So this is the fucntion we’re trying to build, sorry for the crude work:

def twoFunc(direction1, distance, speed1, angle, speed2, direction2):
    Intake.set_velocity(speed2, PERCENT)
    Smarty.set_turn_velocity(speed1,PERCENT )
    Smarty.drive_for(direction1, distance,)
    Intake.spin_for(direction2,speed2, angle, DEGREES)

drive_for (and spin_for) are blocking functions unless told otherwise. Set “wait=False” to allow drive_for to run and move to the next instruction. You may then need to test for completion after the spin_for call, all depends on which function takes longer to run.

https://api.vex.com/v5/home/python/Drivetrain.html

4 Likes