|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Waiting Until Limit Switch Is Pressed
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 |
|
#2
|
||||
|
||||
|
Re: Waiting Until Limit Switch Is Pressed
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 ... |
|
#3
|
||||
|
||||
|
Re: Waiting Until Limit Switch Is Pressed
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. |
|
#4
|
|||||
|
|||||
|
Re: Waiting Until Limit Switch Is Pressed
Quote:
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. 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. |
|
#5
|
|||
|
|||
|
Re: Waiting Until Limit Switch Is Pressed
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 |
|
#6
|
|||||
|
|||||
|
Re: Waiting Until Limit Switch Is Pressed
Wow, CD really doesn't like for people to reload their launchers...
|
|
#7
|
||||
|
||||
|
Re: Waiting Until Limit Switch Is Pressed
Quote:
HTH |
|
#8
|
||||
|
||||
|
Re: Waiting Until Limit Switch Is Pressed
i dont know what language your using, but in java it would look something like this
Code:
if(!limitSwitch.get()){
motor.set(1.0);
}else if(limitSwitch.get()){
motor.set(0.0);
}
Code:
if(!limitSwitch.get()){
motor.set(1.0);
}else if(limitSwitch.get()){
motor.set(0.0);
}else if(controller.getRawButton(1)){
motor.set(1.0);
}
|
|
#9
|
|||||
|
|||||
|
Re: Waiting Until Limit Switch Is Pressed
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. |
|
#10
|
|||
|
|||
|
Re: Waiting Until Limit Switch Is Pressed
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. |
|
#11
|
||||||
|
||||||
|
Re: Waiting Until Limit Switch Is Pressed
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|