samedi 31 mars 2018

Python 2: If statements not working

I have 3 if statements one after the other with one extra if statement embedded in the first. The problem is that none of them work unless either the 1st one (and the embedded if statement) is removed (which allows the other two to work) or if the 2nd and 3rd ones are removed, which allows the 1st one to work. Here is the code.

            if usm1 < 350:

                if usm3 < 300:
                    turnRight()

                elif usm2 < 300:
                    turnLeft()

                else:
                    TB.MotorsOff()

            else:
                TB.SetMotors(0.6)


            if usm3 < 200:
                turnRightKinda()
            else:
                TB.SetMotors(0.6)


            if usm2 < 200:
                turnLeftKinda()
            else:
                TB.SetMotors(0.6)

This is the code for the functions:

def turnLeft():
    TB.SetMotor1(-1)
    TB.SetMotor2(1)

def turnRight():
    TB.SetMotor1(1)
    TB.SetMotor2(-1)

def turnLeftKinda():
    TB.SetMotor1(0.4)
    TB.SetMotor2(0.6)

def turnRightKinda():
    TB.SetMotor1(0.6)
    TB.SetMotor2(0.4)

Thanks.

Aucun commentaire:

Enregistrer un commentaire