Thread: Switch help
View Single Post
  #14   Spotlight this post!  
Unread 23-01-2014, 21:31
nelson.ke@ nelson.ke@ is offline
Registered User
FRC #2883
 
Join Date: Jan 2012
Location: United States
Posts: 6
nelson.ke@ is an unknown quantity at this point
Re: Switch help

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 :/ 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]

Reply With Quote