Switch help

So we are looking at a wheel that rotates and then hits a switch and stopping. Then a button or trigger is pressed and activates the motor to rotate one revolution to the switch and stopped by the switch. Thus the mechanism is loaded for the next shot. %between%

asking a question on how should I program that and maybe some pics of what teleop would look like. I want the motor to keep rotating until it hits the switch and then stop, a trigger on the controller would activate the cycle again so the motor goes around until it hits the switch again.

How fast will this be rotating? Do you want it to reverse direction when the trigger activates the cycle, or continue on “through” the switch one complete rev?

What motor controller will you be using?

Do you want it to stop at the switch even if the operator is still pressing the button, requiring the button to be released first and then pressed again in order to start another cycle? Or do you want the motor to run continuously if the button is held down?

@Ether, we would like to continue through and use a talon as a motor controller

@Alan Anderson yes we would like the first option with the switch stopping the motor and then you have to release the trigger and press the trigger again to start the cycle.

Thanks!:]

That’s going to involve something a little more complicated than simple combinatorial logic. I suggest implementing it as a flat sequence in Periodic Tasks.

In the first frame, halt the motor and wait for the trigger to be released. In the second frame, halt the motor and wait for the trigger to be pressed. In the third, set the motor to whatever value you want it to run at and wait for the limit switch to be activated. Put the entire sequence in a neverending while loop so it starts over every time it finishes.

The “wait for” parts can be programmed as while loops that terminate when the condition is seen. Make sure to put a delay inside each of those loops so they don’t monopolize the cRIO’s CPU.

If this isn’t enough to start with, let me know and I’ll give you some example code to look at.

I know only a little about labview, so I found the while loops and flat sequences and understand what you’re saying. However, I’m not understanding how to program it. Can you send a pick of what you would do, like a pic of the program?

Thanks!

Sure sounds to me like a snail cam based shooter mechanism with a limit switch for the ‘cocked’ position.

The pseudo-code for what you’re looking for looks a little something like this:


if(camLoadedSwitch = on){
camMotor.setSpeed(0);
}

if(oldTriggerState = off AND currentTriggerState = on){
camMotor.setSpeed(1);
}
oldTriggerState = currentTriggerState;

That would start the motor on a rising edge of the trigger, and stop it when it hits the limit switch, assuming this code is in a function that’s called periodically.

I won’t be near a computer with this year’s installation of LabVIEW on it until later today. I’ll be able to post a snippet of code implementing what I described tonight.

I would recommend using a Hall sensor as opposed to a physical limit switch. My team has had experiences with limit switches failing before. You can get a good cheap sensor kit at west coast products http://www.wcproducts.net/hall-effect/.

I attached a VI snippet of the sort of thing I was talking about. It goes in Periodic Tasks as its own loop, not inside anything else.

It will not work in its current form. Both of the limit switch while loops are configured to continue while the switch value is true. Depending on whether the switch is normally open or normally closed, one or the other of the loops needs to be changed to terminate when the switch value is true instead.

You will also need to use the appropriate Refnum names on the left side, and set the motor output to the proper value to make it run in the direction and at the speed you want.





Thank you so much for replying and having an image. I haven’t tested it but will soon. You’re a big help to team 2883! :smiley:

So I went to go try the program and the limit switch is not working. I tried switching the continuous to stop, and stop to continuous switching the two around. No luck getting it to work :confused: I’ve contacted ni and they came up with something different

[quote] I’ve got some recommendations for you to implement the swtich functionality you’re looking for.

What you described to me sounds more like a home switch than a limit switch. A home switch simply lets the drive that it is in its default location.
For linear drives that normally means going back to start, but for your rotational drive it just means the motor has made a full revolution.

With some time to look at the code you pointed me to, I can think of some simple changes to get the behavior your’e looking for.

As it stands that code will only turn the motor if the axis is positive, ie the xbox trigger pressed, and the swtich will override that axis input when its switched. (determined by the OR function)
I think you’ll want your code to work the opposite way. Essentially the motor should run if the switch isn’t pressed. The trigger could be used to overwrite the switch, when desired, to get the motor to spin another revolution.
The only downside to the above is that the motor will continously run if something goes wrong with the switch. If the digital input isn’t read at the right time, it will continue spinning. We could come up with a few saftey mechanisms to account for that though, like a second switch to stop it programatically, multiple switches, etc.

So, what we really need to change in the code you have is the OR function and the inputs to the Select function. Lets start with the Select function, if you want the motor to run without holding the trigger you’ll need to provide it with two options, a positive value and a 0. The 0 will stop the motor, and the positive value will get it moving. Choose a positive value between 0.1 and 1 depending on the speed you want the motor to turn. If you switch reads true when pressed, lets leave the true output 0, if it reads false when pressed then the false output should be 0.

With the select fucntion’s T/F outputs determined, we’ll now need a way to determine when each is called. Currently the OR function is doing that for us, but that’s not going to work for what we want. As you’ve seen the limit switch will continue to make that output 0 and keep your motor from turning. I’d propose that you use another select function to determine the outcome of the second select. This one will only use booleans. The select input of our new select funtion will be the status of our axis. If its greater than 0 we’ll want a true value to go to the selece, and if its 0 or less we’ll want a false value. So, pressing the trigger will pass along the True ouput and not pressing it will pass the False output. If you set the True output to be False, and the False output the Digital Input value, then when the trigger on the controller isn’t pressed the motor will move as long as the switch isn’t pressed, when the switch is pressed it will stop. The trigger will then act as an override to the switch. Pressing it will allow the motor to start moving again, holding it will keep the motor moving.

I’ve attached a screen shot of what that would look like. I set my output to 0.25 as an example value.

If that’s what you’re looking for great, if not, give us a call back Monday,

Zach

The attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense.

[quote]

http://i857.photobucket.com/albums/ab133/Thanousay_Khamphoune/HomeSwitch_zps7d987fcb.png[/quote]

](http://s857.photobucket.com/user/Thanousay_Khamphoune/media/HomeSwitch_zps7d987fcb.png.html)[/quote]

Is your limit switch physically and electrically working? Use Test mode to monitor its value on the Dashboard and make sure it changes when you activate the switch.

I’ve contacted ni and they came up with something different

What they suggested is basically what I would have suggested before you answered my first question. That code doesn’t have any provision for stopping the motor if the control is held continuously, and you said you wanted to force the trigger to be released and pressed again in order to command another revolution.