Go to Post There is no feeling greater than being a part of a group that would walk through fire with you. Complete commitment, complete trust, and total respect. - Rich Kressly [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 Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 06-02-2016, 07:12
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 103
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Threading?

When you create a Thread in Java, you only need to use the start() method to start the thread running in the background (you do not need to call the Thread's run() method directly). Try the following changes:

Code:
         Thread kickThread = new Thread() {
		public void run() {
			int i = 0;
			for (; i < 20; i++) {
				if (i == 1) {
					setKickAngle(RobotMap.kickDefaultAngle);
					doneKicking = false;
				} else if (i == 4) {
					setKickAngle(RobotMap.kickHitAngle);
					doneKicking = false;
				} else if (i == 15) {
					setKickAngle(RobotMap.kickDefaultAngle);
					doneKicking = true;
				}
				Timer.delay(0.05);

			}
			doneKicking = true;

                        // CHANGE 1: Thread will terminate here, you don't need to try and have your thread interrupt itself
			// kickThread.interrupt();
		}
	};

	public void autoKick() {
                // CHANGE 2: You only need to start your thread once per kick,
                // its run() method will be done in the background
		if (!kickThread.isAlive()) {
			kickThread.start();
		}
	}
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 10:55.

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