Go to Post COMPETE like crazy for the 2 minutes you are on the field, COOPERATE like crazy all the rest of the time. When we play this way, we all win. - Chris Fultz [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-02-2012, 13:44
DPG2013 DPG2013 is offline
Registered User
FRC #4163
 
Join Date: Jan 2012
Location: georgia
Posts: 7
DPG2013 is an unknown quantity at this point
what could be wrong with this code. The robot is not responding

/*----------------------------------------------------------------------------*/
/* 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.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 Team4163 extends SimpleRobot {
/**
* This function is called once each time the robot enters autonomous mode.
*/

Joystick leftStick;
Joystick rightStick;
Jaguar arm;
Jaguar claw;
Jaguar launcher;
RobotDrive drive;
Jaguar launcherOpposite;
boolean constant = true;
double LAUNCH_CONSTANT = 0.5;



public Team4163 () {
leftStick = new Joystick(1);
rightStick = new Joystick(2);
drive = new RobotDrive(1,2);
drive.setInvertedMotor(RobotDrive.MotorType.kFront Left, true);
drive.setInvertedMotor(RobotDrive.MotorType.kFront Right, true);
drive.setInvertedMotor(RobotDrive.MotorType.kRearL eft, true);
drive.setInvertedMotor(RobotDrive.MotorType.kRearR ight, true);
arm = new Jaguar (3);
claw = new Jaguar(4);
launcher = new Jaguar(5);
launcherOpposite = new Jaguar (6);


}



public void autonomous() {

}

///This function is called once each time the robot enters operator control.

public void operatorControl() {

drive.setSafetyEnabled(true);

while (isOperatorControl())
{
drive.tankDrive(leftStick, rightStick);
}




drive.setSafetyEnabled(true);
drive.tankDrive(leftStick, rightStick);
double z = leftStick.getZ();

while(constant = true)
{
if (z > 0.5)
{
launcher.set(LAUNCH_CONSTANT * 2);
launcherOpposite.set(LAUNCH_CONSTANT * -2);

}
else
{
launcher.set(LAUNCH_CONSTANT);
launcherOpposite.set(LAUNCH_CONSTANT * -1);
}
}
if (rightStick.getRawButton(3)) arm.set(0.5);
else
arm.set(0);
{
if (rightStick.getRawButton(2))
{
arm.set(-0.5);
}
else
arm.set(0);
}
if (rightStick.getRawButton(1))
{
claw.set(1);
}
else
claw.set(0);
}
}
}


When I build the project in Netbeans nothing is wrong with it, but when it is deployed the robot doesn't respond. everything seems to be wired up correctly. The robot sees that there is code in it based on the driverstation but the robot doesn't do any of the controls

Last edited by DPG2013 : 21-02-2012 at 13:47. Reason: Forgot something
  #2   Spotlight this post!  
Unread 21-02-2012, 14:01
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: what could be wrong with this code. The robot is not responding

Two comments. My best guess is that you need a sleep() or wait() or whatever the java equivalent is in the body of your while(isOperatorControl()) loop. If the brackets in your post match your robot code, then your launcher code will probably never get run, or will only get run before you disable the robot.
Code:
public void operatorControl() {

drive.setSafetyEnabled(true);

while (isOperatorControl()) <-- as long as you're in operator control, your robot will be in this loop.  It should be responsive to your joysticks though.  You may want to put a wait(0.001) call in (or whatever the java equivalent is) because this thread may be monopolizing the cRio CPU
{
drive.tankDrive(leftStick, rightStick);
}




drive.setSafetyEnabled(true);
drive.tankDrive(leftStick, rightStick); <-- this will only get called once, since you're not in a loop at the time you call it.
double z = leftStick.getZ();

while(constant = true) <-- if this is java or c++, you need to do constant == true.  As this stands, you're assigning true to constant, and then testing if it is true, which means this loop will never end
{
if (z > 0.5)
{
launcher.set(LAUNCH_CONSTANT * 2);
launcherOpposite.set(LAUNCH_CONSTANT * -2);

}
else
{
launcher.set(LAUNCH_CONSTANT);
launcherOpposite.set(LAUNCH_CONSTANT * -1);
}
}
if (rightStick.getRawButton(3)) arm.set(0.5);
else
arm.set(0);
{
if (rightStick.getRawButton(2))
{
arm.set(-0.5);
}
else 
arm.set(0);
}
if (rightStick.getRawButton(1))
{
claw.set(1);
} 
else 
claw.set(0);
}
}
}
Another thing: Our robot was non-responsive yesterday - it turned out we had a gyro in a non-accumulator port, and using the gyro was causing the robot to crash.

Last edited by Bongle : 21-02-2012 at 14:03.
  #3   Spotlight this post!  
Unread 21-02-2012, 14:17
Scimor5 Scimor5 is offline
Registered User
AKA: Brett
FRC #4520 (Misfit Toys)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Post Falls
Posts: 11
Scimor5 is an unknown quantity at this point
Re: what could be wrong with this code. The robot is not responding

wow..... You seriously need to start tabbing your code and keeping track of all your brackets. Also you use while loops inapropriatly. this loop:


Code:
while(constant = true)
	{
		if (z > 0.5)
		{
			launcher.set(LAUNCH_CONSTANT * 2);
			launcherOpposite.set(LAUNCH_CONSTANT * -2);

		}
		else
		{
			launcher.set(LAUNCH_CONSTANT);
			launcherOpposite.set(LAUNCH_CONSTANT * -1);
		}
	}
never ends or updates driving, and its after this loop
Code:
while (isOperatorControl())
{
drive.tankDrive(leftStick, rightStick);
}
that ends when teleop is over, so its going to run when you dissable teleop and then never get out of it.
__________________
Good luck from team 4520
  #4   Spotlight this post!  
Unread 21-02-2012, 14:44
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: what could be wrong with this code. The robot is not responding

Once you clean up the loop issues noted above, you should check why you are inverting 4 motors on a robotDrive instantiated with 2. Typically you would only use kLeft and kRight (or instantiate with 4 controllers) and only invert one
Closed Thread


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 01:41.

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