Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   National Instruments LabVIEW and Data Acquisition (http://www.chiefdelphi.com/forums/forumdisplay.php?f=149)
-   -   Limit Switches??? (http://www.chiefdelphi.com/forums/showthread.php?t=104723)

beandip3160 17-03-2012 14:01

Limit Switches???
 
ok so I've used team 358s example on a toggle switch and it works great except what i want the toggle to do is run a motor until a limit switch is pressed, but if the toggle is hit again reverse the same motor, looking for a different limit switch and stop.

At first I thought that it was the limit switches, because for some reason labview is reading normally open switches as true, but in programming as the values were easy to reverse it still wasnt reading my limit switches.

What might be the reason?? Help!!!!!!!!!!!!!

beandip3160 17-03-2012 14:47

Re: Limit Switches???
 
Ok so ive realized that the limit switches aren't being ignored the only problem is that they have to be held down and then the toggle must be activated again to stop the motor I'm so confused

Ether 17-03-2012 14:51

Re: Limit Switches???
 
2 Attachment(s)


I assume you are using either a state machine or a parallel task to do this?

You'll probably get useful answers faster if you post your code.


See attachment. The boxes are states, the arrows are events which cause the state to change.

You might want to add additional events to allow the toggle switch to cycle through all the states.

slijin 12-11-2012 17:51

Re: Limit Switches???
 
Quote:

Originally Posted by Ether (Post 1145291)
You'll probably get useful answers faster if you post your code.

Describing your setup as well would probably help.

In pseudocode, it would be something like:

Code:

direction = forward
toggle_prev = false


loop:
  if report_state(limit_switch_1):
      stop(motor)
      direction = backward

  if report_state(limit_switch_2):
      stop(motor)
      direction = forward

  if report_state(toggle) != toggle_prev:
      if report_state(limit_switch_1) or report_state(limit_switch_2):
        set(motor, direction)
        ## Keep in mind this will only work if set() is a state function
        ## (that is, if set() doesn't have to be looped to keep the motor running())
      elif report_state(motor) == running:
        stop(motor)
      toggle_prev = report_state(toggle)
 
  delay 100

The last delay statement is crucial. Here's why: You start from the center, hit the toggle to move forward, hit a limit switch, stopping the motor Then you hit the toggle again to run it backwards, but if the loop runs fast enough, the limit switch will still be triggered, stopping the motor again and reversing the direction. As a result, you'll be left oscillating at that limit switch. The delay lets the motor run long enough so that the limit switch doesn't stay triggered when the loop repeats.


All times are GMT -5. The time now is 18:32.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi