View Single Post
  #3   Spotlight this post!  
Unread 01-05-2012, 21:53
tyandjel94 tyandjel94 is offline
Registered User
FRC #1647 (Iron Devils)
Team Role: Programmer
 
Join Date: Apr 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
tyandjel94 is an unknown quantity at this point
Re: Multitasking in Java

Ok, that makes sense. Then would this (below) be how you would use threads with the simple robot template. Would you still need a while loop or once you start the thread it will keep running and call the Runnable. Thanks.

Code:
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;

public class RobotTemplate extends SimpleRobot
{

    Joystick stickL = new Joystick(1);
    Joystick stickR = new Joystick(2);

    public void autonomous()
      {
      }

    public void operatorControl()
      {
	Thread drive = new Thread(driveJob);
	drive.start();
      }

    Runnable driveJob = new Runnable()
    {

	RobotDrive myDrive = new RobotDrive(1, 2, 3, 4);

	public void run()
	  {
	    myDrive.tankDrive(-stickL.getAxis(Joystick.AxisType.kY), -stickR.getAxis(Joystick.AxisType.kY));
	  }

    };
}
__________________
-Tyler
Team 1647 Iron Devils
Reply With Quote