|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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); } } } |
|
#2
|
|||
|
|||
|
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()) { } |
|
#3
|
|||
|
|||
|
Re: Need Serious help !!!!
Thank you and do you have any idea y the robot won't respond ???
|
|
#4
|
||||
|
||||
|
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:
|
|
#5
|
|||
|
|||
|
Re: Need Serious help !!!!
Quote:
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);
}
}
import edu.wpi.first.wpilibj.Timer; That will make your code loop every 10 ms. |
|
#6
|
|||
|
|||
|
Re: Need Serious help !!!!
well i have tried what you guys gave me but it still doesn't respond any other ideas ???
|
|
#7
|
|||
|
|||
|
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! |
|
#8
|
||||
|
||||
|
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.
|
|
#9
|
|||
|
|||
|
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);
}
}
}
|
|
#10
|
|||
|
|||
|
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? |
|
#11
|
|||
|
|||
|
Re: Need Serious help !!!!
i did nto make seperate classes how can i do tht
|
|
#12
|
||||
|
||||
|
Re: Need Serious help !!!!
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
}
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();
}
}
}
|
|
#13
|
|||
|
|||
|
Re: Need Serious help !!!!
Quote:
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() {
}
}
Hope this helps! |
|
#14
|
|||
|
|||
|
Re: Need Serious help !!!!
do under robot int i would put the declaration of joysticks motors and jaguars
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|