Log in

View Full Version : Waiting Until Limit Switch Is Pressed


Wildcats1378
07-02-2014, 23:01
Hello everyone!

So I am the programmer mentor and team lead for the Wildcats #3878 here in Hawaii.

I am writing a piece of code for our shooter that will continue moving a motor until it hits a certain limit switch, and then continues onto the next frame.

I am writing the code in an autonomous program as part of a flat sequence to $@#$@#$@#$@# the catapult to a set area based on limit switch, to determine the power of the shot we want.

How might this be accomplished?

Thanks everyone,
#3878 Head Programmer

wireties
07-02-2014, 23:14
Put it in a loop? I'm not sure how specific to get - depends on what framework you are using. Something like this..

...
while(limit input is not asserted and still in auto mode)
{
set motor speed
}

stop motor
...

virtuald
08-02-2014, 00:14
I would recommend hooking the limit switch up to the Jaguar, so it automatically turns itself off. No code required.

Read the Jaguar's datasheet to determine how the limit switch functionality works and where you need to hook it up to.

Alan Anderson
08-02-2014, 00:51
I am writing a piece of code for our shooter that will continue moving a motor until it hits a certain limit switch, and then continues onto the next frame...
How might this be accomplished?


You mentioned a flat sequence, so I assume you're using LabVIEW.

Just put a while loop in the frame, reading the limit switch inside the loop and using the returned value as the termination condition for the loop. It'll keep looping until the switch is activated. Be sure to also put a 10 ms delay (or thereabouts) inside the loop so it doesn't use up all the CPU cycles just waiting for the switch.

I would recommend hooking the limit switch up to the Jaguar, so it automatically turns itself off. No code required.

In this case, code is definitely required. This is a sequence of events that waits at one step until the switch is hit, so the program needs to be reading the switch.

tcjinaz
08-02-2014, 22:05
Is 10MS good enough to catch one of those switches with the lever arm and roller on the end? I am fretting about catching the signal in time to prevent arms slamming into supports.

I am almost wishing for interrupt driven controls here. Is there a way?

Tim

Whippet
08-02-2014, 22:06
...flat sequence to $@#$@#$@#$@# the catapult...

Wow, CD really doesn't like for people to reload their launchers...

wireties
08-02-2014, 23:28
Is 10MS good enough to catch one of those switches with the lever arm and roller on the end? I am fretting about catching the signal in time to prevent arms slamming into supports.

How far will the mechanism travel in 10ms? How quickly will the motor stop? And is that distance dangerous? In FRC, it is hard to imagine 10ms being too long for most any event-driven response but I would do the math.

HTH

Adamz_
09-02-2014, 00:42
i dont know what language your using, but in java it would look something like this

if(!limitSwitch.get()){
motor.set(1.0);
}else if(limitSwitch.get()){
motor.set(0.0);
}

in englsih all this is doing is saing, if the limit switch if false (not pressed) spin the motor, then in the else if statement, it checks if the limit switch is true (pressed) and if it is, it will stop the motor, if you want it so once its in this state, you press a button to shoot, the code would be this;

if(!limitSwitch.get()){
motor.set(1.0);
}else if(limitSwitch.get()){
motor.set(0.0);
}else if(controller.getRawButton(1)){
motor.set(1.0);
}

Alan Anderson
09-02-2014, 00:45
When we're worried that we might miss a brief switch input between samples, we open the input as a counter instead. Then we watch for the counter to change values, and that tells us the switch was hit.

If something pulses quickly enough to be missed by the FPGA, we've already got some re-engineering to do.

MrRoboSteve
09-02-2014, 09:14
This is as much a question of programming as it is of limit switch positioning.

It's often easier to modify the limit switch position to solve end position problems like this.

Joe Ross
09-02-2014, 13:52
I would be less worried about detecting the limit switch as I would stopping a fast moving part with a lot of inertia. Programming can only minimally impact the latter.