Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Disable Robot in Code (http://www.chiefdelphi.com/forums/showthread.php?t=148990)

Mikey Richards 06-16-2016 11:10 PM

Disable Robot in Code
 
Our team is trying to add a button to our joystick that disables the robot. Right now we are using java's System.exit(0), but this also loses the robot code. Is there a way to disable the robot, but not lose robot code.

cgmv123 06-16-2016 11:23 PM

Re: Disable Robot in Code
 
Pseudo(ish)code:
Code:

boolean disabled = false;
if (button pressed)
disabled  = !disabled;
if (disabled)
all motors set at 0
else
normal code executes

This needs to go in the main control loop.

otherguy 06-17-2016 08:15 AM

If you're using a command based project the above code may be difficult to integrate.

Instead you could just stop the scheduler from running (preventing your commands from executing) by calling Scheduler.getInstance().disable();

When you want to enable the scheduler again call Scheduler.getInstance().enable();

Note that depending on how you output values to your motor controllers, they could latch on the last command they received before you pressed the button. Test your code out with the robot on blocks and with a mechanism that can't stall out and break itself before you use it for anything safety related.

Note that the robot is still "enabled" so it's possible for things to move of they are commanded to do so (if you have code that sets outputs that's not run within a command).

Sent from my LGLS751 using Tapatalk

FrankJ 06-17-2016 09:44 AM

Re: Disable Robot in Code
 
Put something on the DS that sends a [enter] keyboard command when the button is pressed? We tested this at one time on our teeshirt cannon. We haven't actually implemented it yet though.

euhlmann 06-17-2016 01:23 PM

Re: Disable Robot in Code
 
Edit: DriverStation has a function called InDisabled(boolean)

Try calling that with true; it might work.

---

You can override isDisabled() in your robot class like this:

Code:

public boolean isDisabled() {
    return super.isDisabled() || myDisableFlag;
}

This should work whether you extend RobotBase or IterativeRobot

Two things:
- The Driver Station won't recognize that you are disabled when you set the flag
- You'll need to make sure to clear the flag yourself when you want to enable again


All times are GMT -5. The time now is 08:20 AM.

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