Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Help ME PLEASE ASAP (http://www.chiefdelphi.com/forums/showthread.php?t=143927)

CyberTeam5713 02-15-2016 07:09 PM

Help ME PLEASE ASAP
 
Can someone please fix my code or point me in the right direction so i can use a xbox controller to drive. tank drive or arcade drive it doesnt matter

public class Robot extends IterativeRobot {
RobotDrive drive = new RobotDrive(1,2,3,4);
Joystick mXboxController = new Joystick(0);
Joystick controlStick = new Joystick(1);
Talon frontLeft = new Talon(4);
Talon rearLeft = new Talon(3);
Talon frontRight = new Talon(2);
Talon rearRight = new Talon(1);

public void robotInit() {
drive = new RobotDrive(0,1,2,3);
mXboxController = new Joystick(0);
controlStick = new Joystick(1);
frontLeft = new Talon(1);
frontLeft.enableDeadbandElimination(true);
frontLeft.set(+1.0);
rearLeft = new Talon(2);
rearLeft.enableDeadbandElimination(true);
rearLeft.set(-1.0);
frontRight = new Talon(3);
frontRight.enableDeadbandElimination(true);
frontRight.set(+1.0);
rearRight = new Talon(4);
rearRight.enableDeadbandElimination(true);
rearRight.set(-1.0);

}


public void autonomousInit() {
drive = new RobotDrive(1,2,3,4);
frontLeft = new Talon(1);
frontLeft.enableDeadbandElimination(true);
frontLeft.set(-1.0);
rearLeft = new Talon(2);
rearLeft.enableDeadbandElimination(true);
rearLeft.set(+1.0);
frontRight = new Talon(3);
frontRight.enableDeadbandElimination(true);
frontRight.set(-1.0);
rearRight = new Talon(4);
rearRight.enableDeadbandElimination(true);
rearRight.set(+1.0);

}


public void autonomousPeriodic() {
while (isAutonomous() && isEnabled()) {
drive.setSafetyEnabled(true);
drive.drive(-0.5,0.0);
Timer.delay(5);
drive.drive(0.0,0.0);

}
}




public void teleopInit(){
drive = new RobotDrive(1,2,3,4);
mXboxController = new Joystick(0);
controlStick = new Joystick(1);
frontLeft = new Talon(1);
frontLeft.enableDeadbandElimination(true);
frontLeft.set(-1.0);
rearLeft = new Talon(2);
rearLeft.enableDeadbandElimination(true);
rearLeft.set(+1.0);
frontRight = new Talon(3);
frontRight.enableDeadbandElimination(true);
frontRight.set(-1.0);
rearRight = new Talon(4);
rearRight.enableDeadbandElimination(true);
rearRight.set(+1.0);

}




public void teleopPeriodic() {
while (isOperatorControl() && isEnabled()) {
drive.setSafetyEnabled(true);
double speedControl = 1;
double joystickLeftY = mXboxController.getRawAxis(1)*speedControl;
double joystickLeftX = mXboxController.getRawAxis(0)*-1*speedControl;
drive.arcadeDrive(joystickLeftY, joystickLeftX);

kmodos 02-15-2016 07:21 PM

Re: Help ME PLEASE ASAP
 
Add one of these to the end }

CyberTeam5713 02-15-2016 07:23 PM

Re: Help ME PLEASE ASAP
 
and the code will work?

Mr. Lim 02-15-2016 08:03 PM

Re: Help ME PLEASE ASAP
 
Code:


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

Talon frontLeft = new Talon(4);
Talon rearLeft = new Talon(3);
Talon frontRight = new Talon(2);
Talon rearRight = new Talon(1);

You are declaring and initializing a RobotDrive and you are also declaring your drivetrain Talons individually.

You need to do one or the other, but not both. Doing this will throw an error saying you are declaring and initializing all your drivetrain Talons twice.

Pick which way you want to program your robot: either using the simpler RobotDrive object, or by manually coding commands to your individual Talons, then delete all the code for the method you are not using.

In the future, it is also a good idea to post a description of the problem you are encountering, including any exceptions or errors messages.

TimTheGreat 02-15-2016 08:43 PM

Re: Help ME PLEASE ASAP
 
Quote:

Originally Posted by Mr. Lim (Post 1540829)
[code]

You need to do one or the other, but not both. Doing this will throw an error saying you are declaring and initializing all your drivetrain Talons twice.

Not necessarily. You can do

Code:

Talon = new Talon(0)
Talon2 = new Talon(1)
Talon3 = new Talon(2)
Talon4 = new Talon(3)
drive = new Robotdrive(Talon, Talon2, Talon3, Talon4)

You can do this way, but if you assign the ports to robotdrive then no, you can't do both.

CyberTeam5713 02-15-2016 09:49 PM

Thanks Guys
 
:cool:


All times are GMT -5. The time now is 08:03 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi