I know that there is a section on limit switches in the defualt FRC code, but i have tried to use that section many times and failed so what i was wondering was if anyone had written there own limit switch code or could explain to me the process of how i could write one. I will be using digital inputs to limit speed controllers.
Its just a basic limit switch I really dont know why they gave me so much trouble. But i have everything happen from losign all joystick - motor interactivity to having everything work like the senosr wasnt tripped. I was just wondering if someone could give me an example or a pointer, i know its a stupid question but its been stumping me. Now i have time to ponder and experiment.
It’s important to remember that in C “==” is a logical equal to operator and “=” is an assignment operator. “<=” is also a logical operator meaning less than or equal to. So I think you would want your code to look like this:
2 things when i first wrote this post i cound recall the joystic alias its something like p1_y ( i dotn have the code in front of me, and 2nd off what doese this section do :
Joy_1 = ((Joy_1 > 127)** ? 127 : Joy_1**)
On our bot, we had three switches on our lift system; one at the bottom, top, and middle (height for grabbing 2X ball).
Now the problem with our lift is that if we kept trying to run the motor to lift it up past its max, it would bend the shafts. So we tossed the limit switch at the top so when it tripped we couldn’t make it go any higher even if we tried. Our programmer decided to allow the lift to raise up again when we dropped it down to trip the middle limit switch (God knows WHY he did it THIS way… -_-
Anyhow, in one of our matches, our robot fell backwards quite a bit and the top limit switched tripped from hitting the PVC tubing of the stationary goal. Because it tripped (when our lift was all the way down) we couldn’t raise the lift up at all (we couldn’t trip the middle switch) and couldn’t hang.
So after that we forced our programmer to put in an override switch on the joystick.
So whatever it is you’re doing with limit switches, you might want to consider using a button or something to override the code if need be.
Hahaha, i thought that was a sarcastic joke before reading the second sentence. Maybe it should have been though. In programming, like everything else in life (though probably more so) people have there own ways of doing things (and obviously think thats the best or right way). Mike doesn’t like to use ternary operators while some others do. Though a ternary operator can be somewhat harder to read than an if-else statement, it is useful in many situations because the entire if-else can be in one line. In my opinion, if you understand the concept, have seen properly written and used and examples, and are comfortable with it, then go right ahead. The best part about programming, especially with small simple programs, is that it is pretty easy to try stuff out yourself, so don’t hesitate. Follow these guidelines and you should level-up in no time