problems with the limit switch 2

i have the code now a the problem is that one switch works but the other switch doesn’t i have in a autonomous mode so plz help iam posting it so you can view it thank u all i really need help this is for a school project.
alfa (2.31 KB)

First off, all of your Functions have an End-Less While.

The functions [FONT=Courier New]Autonomous ( 20 ) ;[/FONT] and [FONT=Courier New]OperatorControl ( 254 ) ;[/FONT]
need to have the End-Less While, the Control System will terminate them at the end of their set time period.

Unless some “magic” is occurring, the other functions (alpha, limit, limit2, and beta) will never exit, until the Control System terminates the Autonomous section that called them.

I see this as the Current Call Chain:

main() → Autonomous ( 20 ) → alfa ( ) → StartUltrasonic ( 1 , 11 ) Return–> alfa ( ) → distance = GetUltrasonic ( 1 , 11 ) Return–> alfa ( ) → distance = GetUltrasonic ( 1 , 11 ) Return–> alfa ( ) → distance = GetUltrasonic ( 1 , 11 ) → etc… Until the end of the Autonomous time period.

Can you describe the Behavour you desire in the Autonomous Mode?? We can then help you restructure your Logic to achieve this…

ya the what i want to do is for the bot to turn around and avoid obstacles using the ultrasonic sensor to avoid and the limit switches to help the u.s sensor avoid stuff like cardboard or a blanket that deadens ultrasonic sound so ya the lay out of my bot is a basic box bot ill attach some pictures to show you i got the receiver in Rx 1 and the jumper switch in interrupt pt 5 for autonomous mode and for the RC control in 6 on the controller i want the controls to be on 3 for the left a 2 for the right and if all at possible or a key on the remote to activate the avoid code possible channel 5 or 6 on the controller thank you very munch i appreciate the help.

So to avoid confusion of wheather the Ultrasonic sensor has Valid Data or Not, Check the Limit Switches FIRST.

If One or Both are Pressed, you need to STOP moving forward.

If Both are Pressed, Reverse, and then Stop and Turn Left or Right.

If One is Pressed: Reverse and if it was the Left Switch, Turn Left, while in Reverse (this places the front of the Robot to the Right of where the Switch was pressed. Otherwise, Reverse and it being the Right Switch, Turn Right, while in Reverse (this places the front of the Robot to the Left of where the Switch was pressed.

IF Neither Switch was pressed, then read the Ultrasonic Sensor, if the Value is below ~20, Reverse, and then Stop and Turn Left or Right.

Something like this???

Yes, that is the Basic Square Bot…

Remember that the Orange Jumper in Interrupt 5, ONLY Executes the Autonomous Code and the Orange Jumper in Interrupt 6 the ONLY Executes OperatorControl Code. After either of the Time Periods is done, the Robot will stop.

You are talking about the Control Channels on the Vex Transmitter???

Do you want to be able to Toggle the Avoidance Code ON/OFF with a Button Push on Channel 5 or 6???

You might want to NOT use the Competition Template with the Autonomous and OperatorControl, and just make your program All OperatorControl, and then use Channel 5 or 6 to activate the “avoid code”.

i like you idea of a avoidance code and ill go with the operator template other than that i don’t have eny other specifications just do what you think is best i just want to try to avoid hitting things like a wall or a chair with the u.s. sensor and if the sensor fails then the limit switches will hit the object telling the bot to do the avoidance code thank you very munch