![]() |
Limit Switch
In java I'm trying to code a limit switch to my single motor called hunt
Code:
package edu.wpi.first.wpilibj.templates; |
Re: Limit Switch
Quote:
|
Re: Limit Switch
Quote:
|
Re: Limit Switch
Programming for a limit switch is straightforward. You just need to read the value of the switch and test for "active". Sometimes a limit switch will return a True when it's inactive, and False when it's active; sometimes it will be the other way around. You also need to know whether the motor would be moving "forward" or "reverse" when it hits the switch.
When you see that the switch is active and the motor is being asked to travel in the direction you don't want it to go anymore, set the motor value to zero. That's it. If the switch is not active, don't do anything special; that will let the motor move normally. If the motor isn't being told to go in the direction you don't want it to go, don't do anything special; that will let the motor go back away from the limit. |
Re: Limit Switch
In the API, theres a class called, DigitalInput. Once you create the class and specified with GPIO to keep track of, you can use the get() function to keep track of the state of the switch. Then you can use it as the boolean expression for the "if" statement.
|
Re: Limit Switch
Quote:
What is the "if" statement for the limit switch. |
Re: Limit Switch
Say if you made a limit switch and named it switch.
DigitalInput switch = new DigitalInput ( 4, 1 ); //switch on digital side car channel 1 the if may look something like if ( switch.get () ) //do something when the switch is not tripped else //do something when the switch is tripped |
Re: Limit Switch
Quote:
|
Re: Limit Switch
Slight tip:
Take out the true in Code:
while (true && isAutonomous() && isEnabled()) {It's not a biggy at all, but you only want while(true) when you want it to infinitly loop. With other conditionals, it's pointless. |
| All times are GMT -5. The time now is 03:37. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi