Go to Post Real projects have good and bad aspects, problems that must be dealt with, and lots of things that dont make any sense from your side of the fence. - KenWittlief [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-03-2012, 16:24
Team1605 Team1605 is offline
Registered User
FRC #1605
 
Join Date: Feb 2012
Location: toronto
Posts: 30
Team1605 is an unknown quantity at this point
Need Serious help !!!!

I have uploaded my code to my robot from netbeans. but the problem is that the robot won't respond when i try to drive it.
driverstation shows:
- its connected
- there is robot code
- there are joysticks connected

do you guys have any idea and also my code is :


/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


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

/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the SimpleRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class Team1605 extends SimpleRobot {


Joystick stickDriverLeft = new Joystick(1);
Joystick stickDriverRight = new Joystick(2);


Jaguar leftMotor = new Jaguar(2);
Jaguar rightMotor = new Jaguar(1);
Jaguar shooterMotor1 = new Jaguar(3);
Jaguar shooterMotor2 = new Jaguar(4);
Jaguar gatherMotor1 = new Jaguar(5);
Jaguar gatherMotor2 = new Jaguar (6);

RobotDrive robotDrive = new RobotDrive(leftMotor,rightMotor);
Shooter shooter = new Shooter(shooterMotor1,shooterMotor2);
Gatherer gatherer = new Gatherer(gatherMotor1, gatherMotor2);

final int TRIGGER_NUMBER = 1;
final int GATHER_START_BUTTON = 2;
final int GATHER_STOP_BUTTON = 3;


/**
* This function is called once each time the robot enters autonomous mode.
*/
public void autonomous() {

}

/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {

robotDrive.tankDrive(stickDriverLeft.getAxis(AxisT ype.kY), stickDriverRight.getAxis(AxisType.kY));


if(stickDriverRight.getRawButton(TRIGGER_NUMBER)) {
shooter.set(1);
}
else {
shooter.set(0);
}


if(stickDriverRight.getRawButton(GATHER_START_BUTT ON)) {
gatherer.set(1);
}
else if(stickDriverRight.getRawButton(GATHER_STOP_BUTTO N)) {
gatherer.set(0);
}


}
}
Reply With Quote
  #2   Spotlight this post!  
Unread 08-03-2012, 16:28
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 990
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Need Serious help !!!!

The operatorControl function is only called a single time so your code runs once, using one set of joystick info then does nothing for a long time.

You should surround the code you currently have in the operatorControl method with a loop:

while(isOperatorControl() && isEnabled())
{
}
Reply With Quote
  #3   Spotlight this post!  
Unread 08-03-2012, 17:45
Team1605 Team1605 is offline
Registered User
FRC #1605
 
Join Date: Feb 2012
Location: toronto
Posts: 30
Team1605 is an unknown quantity at this point
Re: Need Serious help !!!!

Thank you and do you have any idea y the robot won't respond ???
Reply With Quote
  #4   Spotlight this post!  
Unread 08-03-2012, 17:53
Anupam Goli's Avatar
Anupam Goli Anupam Goli is offline
PCH Q&A co-founder/Scouting Mentor
AKA: noops
FRC #1648 (G3 Robotics)
Team Role: Mentor
 
Join Date: Dec 2010
Rookie Year: 2008
Location: Atlanta, Georgia
Posts: 1,242
Anupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond reputeAnupam Goli has a reputation beyond repute
Re: Need Serious help !!!!

You're not looping. The way it's set up, The Operator Control method is being run and stopped because there is no loop. That's why it isn't responding.

When you set your shooter and drive train and gatherer, put all of those in a

Quote:
while(isEnabled()){

}
__________________
Team 1002: 2008-2012
Team 1648: 2012-2016
Georgia Tech Class of 2016
Reply With Quote
  #5   Spotlight this post!  
Unread 08-03-2012, 17:53
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 990
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Need Serious help !!!!

Quote:
Originally Posted by Team1605 View Post
Thank you and do you have any idea y the robot won't respond ???
Yes, because your code runs once, you need it to loop around constantly looking at the updated values of the joysticks like I posted above. Your operatorControl method should look like this (additions in bold):

Code:
/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {
while(isOperatorControl() && isEnabled())
{
robotDrive.tankDrive(stickDriverLeft.getAxis(AxisT ype.kY), stickDriverRight.getAxis(AxisType.kY));


if(stickDriverRight.getRawButton(TRIGGER_NUMBER)) {
shooter.set(1);
}
else {
shooter.set(0);
}


if(stickDriverRight.getRawButton(GATHER_START_BUTT ON)) {
gatherer.set(1);
}
else if(stickDriverRight.getRawButton(GATHER_STOP_BUTTO N)) {
gatherer.set(0);
}
Timer.delay(.01);
}
}
You will also need to add an import:
import edu.wpi.first.wpilibj.Timer;

That will make your code loop every 10 ms.
Reply With Quote
  #6   Spotlight this post!  
Unread 20-03-2012, 16:08
Team1605 Team1605 is offline
Registered User
FRC #1605
 
Join Date: Feb 2012
Location: toronto
Posts: 30
Team1605 is an unknown quantity at this point
Re: Need Serious help !!!!

well i have tried what you guys gave me but it still doesn't respond any other ideas ???
Reply With Quote
  #7   Spotlight this post!  
Unread 20-03-2012, 17:29
Sconrad Sconrad is offline
Registered User
AKA: Connor Young
FRC #0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Yorktown
Posts: 40
Sconrad is an unknown quantity at this point
Re: Need Serious help !!!!

Seeing as our team programs in LabVIEW, I can't say I am an expert on FIRST Java programming. 3 things I see.
1: You are initializing your objects in the class and not in a constructor. It's perfectly possible that that's fine, but I would think that would be done in a constructor.

2: You have 2 custom classes (Shooter and Gatherer) could the code hang there?

3: In the if elseif blocks, it looks like you have some spaces in the variable names. I would imagine this would prevent it from building in the first place, but this could be the source of your issue.

Also, I know in LabVIEW there are vis for writing to the Driver station text box. This could be useful for debugging purposes if you could find the corresponding java functions. Another thing to check is to ensure that each joystick is connected to the right usb port. This can be done by going to the setup tab and pressing a button on each joystick and see which element of the list on the right lights up. If they are mislabeled, you can click and drag to change the order. Just some thoughts. Hope it helps!
Reply With Quote
  #8   Spotlight this post!  
Unread 20-03-2012, 17:50
PAR_WIG1350's Avatar
PAR_WIG1350 PAR_WIG1350 is offline
Registered User
AKA: Alan Wells
FRC #1350 (Rambots)
Team Role: Alumni
 
Join Date: Dec 2009
Rookie Year: 2009
Location: Rhode Island
Posts: 1,190
PAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond repute
Re: Need Serious help !!!!

Can you post the new code? When you do, highlight it and click the # symbol above the box you pasted the code into (whatever you want to call it). This will preserve your spacing.
__________________
Reply With Quote
  #9   Spotlight this post!  
Unread 21-03-2012, 12:57
Team1605 Team1605 is offline
Registered User
FRC #1605
 
Join Date: Feb 2012
Location: toronto
Posts: 30
Team1605 is an unknown quantity at this point
Re: Need Serious help !!!!

Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.Joystick.AxisType;
import edu.wpi.first.wpilibj.*;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Team1605 extends SimpleRobot {
    
    
    Joystick stickDriverLeft = new Joystick(1);
    Joystick stickDriverRight = new Joystick(2);
    
    
    Jaguar leftMotor = new Jaguar(2);
    Jaguar rightMotor = new Jaguar(1);
    Jaguar shooterMotor1 = new Jaguar(3);
    Jaguar shooterMotor2 = new Jaguar(4);
    Jaguar gatherMotor1 = new Jaguar(5);
    Jaguar gatherMotor2 = new Jaguar (6);
    
    RobotDrive robotDrive = new RobotDrive(leftMotor,rightMotor);
    Shooter shooter = new Shooter(shooterMotor1,shooterMotor2);
    Gatherer gatherer = new Gatherer(gatherMotor1, gatherMotor2);
    
    final int TRIGGER_NUMBER = 1;
    final int GATHER_START_BUTTON = 2;
    final int GATHER_STOP_BUTTON = 3;
    
    
    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() {
        
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void OperatorControl() {
        while(isOperatorControl() && isEnabled())
    {
        
        robotDrive.tankDrive(stickDriverLeft.getAxis(AxisType.kY), stickDriverRight.getAxis(AxisType.kY));
        
        
        if(stickDriverRight.getRawButton(TRIGGER_NUMBER)) {
           shooter.set(1);
        }
        else {
            shooter.set(0);
        }
        
        
        if(stickDriverRight.getRawButton(GATHER_START_BUTTON)) {
            gatherer.set(1);
        }
        else if(stickDriverRight.getRawButton(GATHER_STOP_BUTTON)) {
            gatherer.set(0);
        }
        Timer.delay(.01);
    }

    }
}
that is the code the problem is now that it works but only one wheel will spin and none of the buttons will work
Reply With Quote
  #10   Spotlight this post!  
Unread 23-03-2012, 05:05
BurtGummer BurtGummer is offline
Electrical/Mechanical/Programming
FRC #3020
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Southern CA
Posts: 89
BurtGummer will become famous soon enoughBurtGummer will become famous soon enough
Re: Need Serious help !!!!

When you are creating your objects, you create "gatherer" and "shooter" objects from classes named the same. Did you create a "Gatherer" class and a "Shooter" class? If not, the poor compiler has no idea what a "Shooter" or "Gatherer" is.

If you did make those classes somewhere else, can we see the code for those as well?
__________________
I'm a mentor looking for a home in Southern California! I know Java, C++, electrical and mechanical.

Need Java or C++ help? Send me a PM!
Reply With Quote
  #11   Spotlight this post!  
Unread 23-03-2012, 11:34
Team1605 Team1605 is offline
Registered User
FRC #1605
 
Join Date: Feb 2012
Location: toronto
Posts: 30
Team1605 is an unknown quantity at this point
Re: Need Serious help !!!!

i did nto make seperate classes how can i do tht
Reply With Quote
  #12   Spotlight this post!  
Unread 23-03-2012, 18:35
tp2357 tp2357 is offline
Registered User
AKA: Tyler Pawlaczyk
FRC #0340 (Greater Rochester Robotics)
Team Role: Programmer
 
Join Date: Mar 2012
Rookie Year: 2011
Location: North Chili, NY
Posts: 5
tp2357 is an unknown quantity at this point
Re: Need Serious help !!!!

Quote:
Originally Posted by RufflesRidge View Post
The operatorControl function is only called a single time so your code runs once, using one set of joystick info then does nothing for a long time.

You should surround the code you currently have in the operatorControl method with a loop:

while(isOperatorControl() && isEnabled())
{
}
Instead of using a while loop for your entire code, you could try using "iterative robot". You can do this by clicking the "new project" icon in the top left-ish area (it looks like a cardboard box). Then click "FRC Java" entry in the left pane, and the "IterativeRobotTemplateProject" in the right hand pane. Click "Next". The next step should have 5 text fields you can edit. I recommend editing the top, which is the Project Name. I leave the rest alone. Click finish.

It's pretty much the same thing as using the simple robot project, and a while loop, however with iterative robot, your "RobotTemplate" class is looped at a speed which is controlled by the robot. It loops at about 20 times per second if i remember correctly.

This is what robot template should look like:
Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.IterativeRobot;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class RobotTemplate extends IterativeRobot {
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {

    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {

    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        
    }
    
}
At this point I would make separate classes for your teleoperated, and your autonomous code, and call them under the "teleopPeriodic()" and the "autonomousPeriodic()" methods respectively.

Hope this helps!
Reply With Quote
  #13   Spotlight this post!  
Unread 24-03-2012, 15:24
Team1605 Team1605 is offline
Registered User
FRC #1605
 
Join Date: Feb 2012
Location: toronto
Posts: 30
Team1605 is an unknown quantity at this point
Re: Need Serious help !!!!

do under robot int i would put the declaration of joysticks motors and jaguars
Reply With Quote
  #14   Spotlight this post!  
Unread 24-03-2012, 21:16
PAR_WIG1350's Avatar
PAR_WIG1350 PAR_WIG1350 is offline
Registered User
AKA: Alan Wells
FRC #1350 (Rambots)
Team Role: Alumni
 
Join Date: Dec 2009
Rookie Year: 2009
Location: Rhode Island
Posts: 1,190
PAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond repute
Re: Need Serious help !!!!

Quote:
Originally Posted by Team1605 View Post
i did nto make seperate classes how can i do tht
To make a new class you would have to add a new file to the project. Then you would have to write the code for the constructors and various methods in the class
for example:
Code:
public class Gatherer
{
   //this is the constructor
   public void Gatherer (Jaguar jag1, Jaguar jag2)
   {
      //code to set values to instance variables and create objects for use in this class
    }
   
   //these methods can be called to do stuff
   public void set(double thisSpeed)
   {
      //code to sets jags to run at thisSpeed go here
   }
However, based on your code, I would only have one class, and gatherer and shooter would both be objects of that one class.

Code:
public class MotorPair
{
   //these are instance variables
   Jaguar jaguar1, jaguar2;
   boolean isRunnung = false;

   //this is the constructor
   public void MotorPair (Jaguar jag1, Jaguar jag2)
   {
     /* jaguar1 =  jag1;
         jaguar2 =  jag2;*/
    }
   
   //these methods can be called to do stuff
   public void run()
   {
      jaguar1.set(1);
      jaguar2.set(1);
      isRunning = true;
   }

   public void stop()
   {
      jaguar1.set(0);
      jaguar2.set(0);
      isRunning = false;
   }

   public void toggle()
   {
      if (isRunning)
      {
          stop();
      }
      else
      {
          run();
       }
   }
}
__________________
Reply With Quote
Reply


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 12:53.

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