|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
limit switch help
hi
were trying to program the motor on our robot so when it goes one direction. and when it hits the limit switch. it will stop. does anyone know how to program the limit switch to do this or know any links that can help me? any information will be appreciated |
|
#2
|
|||
|
|||
|
Re: limit switch help
You could do something like the attached code picture. If you wire your limit switch to a GPIO (aka DIO) input on the Digital Sidecar so that when the limit switch closes it sends 5V to the DIO, then the code will detect it as True when the motor reaches its limit.
So in the included code the motor is first sent Set Speed of 1 to get it moving. The while loop waits for the motor to reach the limit. When the limit switch returns True, the Set Speed is called again with a 0 to stop the motor. If you make this code into a subVI I would recommend that you call the Open and CLose outside of the main loop of your program and pass in the device references (i.e. MotorControlDevRef, DigitalInputDevRef) into the subVI and back out again. |
|
#3
|
||||
|
||||
|
Re: limit switch help
we tried the code out, the limit switch registers and it picks up the signal, but the motor doesn't stop. did we do something wrong with the code?
|
|
#4
|
|||
|
|||
|
Re: limit switch help
Can you post your own code so I can take a look?
If you want to debug your code, you can turn on highlighting (the lightbulb button), you should be able to see that the limit switch causes the while loop to exit and then the motor should set the speed to zero causing the motion to stop. One issue may be that I'm assuming the DIO input goes True when you want your motor to stop. If the opposite is what you want, then right click the while loop stop sign and select "Continue if True". -Nate |
|
#5
|
||||
|
||||
|
Re: limit switch help
![]() this is the code we have so far, the false has the motor stop because the DIO = true all the time until we hit the limit switch Last edited by program1 : 14-02-2009 at 20:22. |
|
#6
|
|||
|
|||
|
Re: limit switch help
I think you may be missing the (hidden) easiest route: the jags have built in ports for limit switches. Check the datasheet for more info.
Quote:
Admittedly, it is a pain in the posterior to chop up the pwm cables to make a 2-pin connector at one end, but this solution gets rid of one sizable problem with running the limit switches in software - the latency. -jonathan nice filter CD guys ![]() |
|
#7
|
|||||
|
|||||
|
Re: limit switch help
Quote:
![]() Quote:
|
|
#8
|
||||
|
||||
|
Re: limit switch help
Quote:
The attached is a screenshot of how I handled limit switches. This is a subvi that comes off of teleop.vi in the advanced framework. I've built the motor device reference and the limit switches into a typedef and passed them into the subvi. If you're in the basic framework you could open the devices in the same part of the code that the drive motors are opened, pass the references into the teleop execute case, and then drop something like this code in. Basically, if the input signal is sending the turret left, it checks the left limit switch and stops if the switch is active, otherwise it does what it was told. If it's sending the turret right, it checks the right limit switch and stops if the switch is active and does what it's told otherwise. It checks each time teleop runs within the main loop. The extra indicators are not required - they just make it easy to see what's going on with the limit switches from the front panel of the vi. |
|
#9
|
|||
|
|||
|
Re: limit switch help
WOW. okay - thx for telling me.
It seems kinda dumb to prohibit their use .-jonathan |
|
#10
|
|||
|
|||
|
Re: limit switch help
program1, I don't see anything wrong with your code, but it does seem like you have other code to the right side of the picture. Does this other code do anything with the motors? If so, the other code could be interfering with what you are trying to do with the limit switch.
|
|
#11
|
|||
|
|||
|
Re: limit switch help
program 2, why not just "or" the output of the two limit switches and submit that boolean value to a select block true would be 0 and false would be the motor command? I think that will be equivalent to what you want to do.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| limit switch | solomason519 | Programming | 9 | 09-02-2010 08:50 |
| Using a limit switch to limit motion | ManicMechanic | Programming | 16 | 20-12-2007 00:54 |
| limit switch | wedellm | Electrical | 4 | 16-02-2007 13:01 |
| gyro/accelecometer/limit switch help needed | Anton | Programming | 4 | 04-02-2005 16:39 |