Go to Post How well does peanut butter transmit heat? - Lil' Lavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #8   Spotlight this post!  
Unread 02-13-2015, 01:39 PM
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: Using Hall Effect Sensors

Quote:
Originally Posted by cstelter View Post
Since your command is ending when done==true, how are you getting another command to run? I think if you tie it to a button with whenPressed() or something like that, it reuses the same object each time. So you have to reinitialize everything in initialize.

Code:
	protected void initialize() {
                //reset fields to values defaulted to on construction
                go=0;
                done=false;
                count=0;
		System.out.println(this);
	}
I suspect you will also want to remember your setpoint and assign that to tcount in the initializer as well since it is being reassigned during execute()

Code:
public class MagicElevator extends Command {

        ...
        int mySetpoint;
        ...

	public MagicElevator(int setpoint) {
		// Use requires() here to declare subsystem dependencies
		requires(Robot.elevator);
		mySetpoint=setpoint;
	}

	// Called just before this Command runs the first time
	protected void initialize() {
                go=0;
                done=false;
                count=0;
		tcount=mySetpoint;
		System.out.println(this);
	}
Thanks cstelter, I did forget to reset the done variable didn't I! I will test your suggestions when I get out of class. Also what would setting another mySetpoint variable do? Would this one carry over between reintialization? Wouldn't it cause the tcount variable to keep adding without resetting on each press of the button that sets the setpoint to (1 -1 or 0)?
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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