|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Limit switches on a lift -- best practice
So, I'm porting over our 2012 Robot to Java and I was wondering about how best to use limit switches within the confines of the command-based template. OI runs the raise/lower commands while a button is being held. Would it be best to put the limit switch code within the subsystem methods like so:
Code:
private CANJaguar liftMotor1;
private CANJaguar liftMotor2;
private DigitalInput upperLimitSwitch;
private DigitalInput lowerLimitSwitch;
public void initDefaultCommand() {
// Set the default command for a subsystem here.
setDefaultCommand(new ArmDoNothing());
}
public Arm() {
initCAN();
}
.....
public void doNothing() throws CANTimeoutException {
liftMotor1.setX(0.0);
liftMotor2.setX(0.0);
}
public void raiseArm() throws CANTimeoutException {
while(!getTopLimit())
{
liftMotor1.setX(0.1);
liftMotor2.setX(-0.1);
}
}
public void lowerArm() throws CANTimeoutException {
while(!getBottomLimit())
{
liftMotor1.setX(0.1);
liftMotor2.setX(-0.1);
}
}
public boolean getTopLimit() {
if(upperLimitSwitch.get()) {
return true;
} else {
return false;
}
}
public boolean getBottomLimit() {
if(lowerLimitSwitch.get()) {
return true;
} else {
return false;
}
}
Or, would it be best to put the limit switch code within the Commands under execute() or isFinished()? Which I assume would go something like: Quote:
Code:
boolean stop;
// Called repeatedly when this Command is scheduled to run
protected void execute() {
if(arm.getTopLimit()) {
stop = true;
} else {
stop = false;
}
try {
arm.raiseArm();
} catch (CANTimeoutException ex) {
System.out.println(ex);
}
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return stop;
}
![]() |
|
#2
|
||||
|
||||
|
Re: Limit switches on a lift -- best practice
To me, dealing with limit switches is a problem internal to the Subsystem - if it had to be dealt with by Commands, it would make every one of your Commands more complicated, which to me seems like insufficient abstraction. As for how to do it, I'd probably do something similar to how WPILibJ's PIDController works - use an internal TimerTask or Thread to handle the checking and overriding. That way, it doesn't matter what the Commands try to do - the Subsystem simply won't allow it to go beyond the limits.
|
|
#3
|
||||
|
||||
|
Re: Limit switches on a lift -- best practice
A better way to do it is connect the limit switch directly to the Jaguar, so then you don't have to write any software to make it work
![]() |
|
#4
|
|||
|
|||
|
Re: Limit switches on a lift -- best practice
Quote:
However there was a problem with the CAN software in 2011 where if a limit switch was pressed and connected to the jaguar when the robot was turned on, it would cause the scrolling CAN error. (Hundreds of error messages, resulting in a robot that couldn't move) I'm not sure if this was fixed. It probably was. And you might still need some software to prevent the lift from going full speed into the limit switch. Ouch. |
|
#5
|
||||
|
||||
|
Re: Limit switches on a lift -- best practice
We haven't messed around with direct sensor-Jaguar control yet, so I don't know how it all works, but I'm not sure it would work for our situation. We used a screw-style lift (lead screw) which needs limit switches on both the top and the bottom. We also used two motors to drive the lift, which means two Jaguars because the GDC doesn't allow running two motors off of one controller. Correct me if I'm wrong but the Jaguar only allows input from one sensor at a time; and we need it to be able to accept from two. And since we have two Jaguars that also means we'd need 4 limit switches unless there's some way to split or duplicate the signal to both of them.
|
|
#6
|
||||
|
||||
|
Re: Limit switches on a lift -- best practice
The best way is to wire them to the Jag inputs, but if you are doing this for a FIRST competition I think the rule book requires you to wire them to the cRio and do the work in software.
|
|
#7
|
||||
|
||||
|
Re: Limit switches on a lift -- best practice
2012 Rule R58-J: Limit switch jumpers may be removed from a Jaguar speed controller and a custom limit switch circuit may be substituted. Last edited by Ether : 28-10-2012 at 20:02. |
|
#8
|
||||
|
||||
|
Re: Limit switches on a lift -- best practice
Quote:
So the general consensus was to put it on the subsystem side as opposed to in execute()? Last edited by F22Rapture : 28-10-2012 at 20:23. |
|
#9
|
||||
|
||||
|
Re: Limit switches on a lift -- best practice
Quote:
|
|
#10
|
||||
|
||||
|
Re: Limit switches on a lift -- best practice
Quote:
The reason they said "custom" circuit is that in spirit of the rule, it could be anything from a simple limit switch to some crazy ultrasonic circuit. You could even pop in a toggle switch for the rule cares. However, if the lift is like some I've seen/built, then you may have more than two switches involved (like one for each intermediate point used). In that case, then you would have to do at least some of the switches in software, as the jag is only good for two switches. Generally those two are designed to be your high and low points; these are the points where if you were to overshoot it by a considerable margin very bad things would happen (like stripping a gearbox, breaking an arm joint, accidentally firing a ball, etc.) However, if you choose to split your switches between hardware and software, there is no "wrong" answer in terms of functionality. |
|
#11
|
|||
|
|||
|
Re: Limit switches on a lift -- best practice
![]() i like limit switches like this where when the switch is tripped it kills power to the motor in one direction but allows you to power the motor in the other direction http://www.radioshack.com/product/in... rValue=Diodes i've used that diode with 550 china drill motor at 5s to lift 30lb robots |
|
#12
|
|||
|
|||
|
Re: Limit switches on a lift -- best practice
Quote:
Quote:
-David |
|
#13
|
||||
|
||||
|
Re: Limit switches on a lift -- best practice
be careful with while loops. such as;
Code:
while(!getTopLimit()) It is best to use "IF" statements and avoid loops. |
|
#14
|
|||
|
|||
|
Re: Limit switches on a lift -- best practice
Quote:
|
|
#15
|
|||||
|
|||||
|
Re: Limit switches on a lift -- best practice
To answer the original question, Joe has it right. Limit switches should be handled at the level of motor control, not at the level of command input.
Quote:
Effectively, though, the Jaguar does the same thing that the schematic is intended to portray. Activating the forward limit prevents the speed controller from commanding the motor to go forward while still letting it go in reverse, and vice versa. Last edited by Alan Anderson : 29-10-2012 at 13:30. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|