Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Error with joystick controller and driver station (http://www.chiefdelphi.com/forums/showthread.php?t=154396)

CocoGuo 28-01-2017 16:44

Error with joystick controller and driver station
 
I am the programmer from team Yellow Jacket 3345, the driver station is giving me error about the joysticks are not plug in,but ti is plug in right and all show green but we all check the program is no error.And we don't know the problems.

https://www.dropbox.com/s/5bczzz5frj...nshot.png?dl=1

Code:

package org.usfirst.frc.team3345.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.Talon;

public class Robot extends IterativeRobot {
        final String defaultAuto = "Default";
        final String customAuto = "My Auto";
        String autoSelected;
        SendableChooser<String> chooser = new SendableChooser<>();
        private RobotDrive robotDrive1, robotDrive2;
        private Joystick leftJoystick, rightJoystick;
        private Spark gearMotor;
        private Talon fuelGate, scissorLift;
        private double driveBaseSpeed = 1.0;
        private double scissorLiftSpeed = 1.0;
        private double fuelGateSpeed = 1.0;
        private double gearMotorSpeed = 1.0;

        @Override
        public void robotInit() {
                chooser.addDefault("Default Auto", defaultAuto);
                chooser.addObject("My Auto", customAuto);
                SmartDashboard.putData("Auto choices", chooser);
                //spark and function part
                robotDrive1 = new RobotDrive(1, 2);
                robotDrive2 = new RobotDrive(3, 4);
                fuelGate = new Talon(5);
                scissorLift = new Talon(6);
                gearMotor = new Spark(0);
                leftJoystick = new Joystick(1);
                rightJoystick = new Joystick(2);
        }

        @Override
        public void autonomousInit() {
                autoSelected = chooser.getSelected();
                // autoSelected = SmartDashboard.getString("Auto Selector",
                // defaultAuto);
                System.out.println("Auto selected: " + autoSelected);
        }

        @Override
        public void autonomousPeriodic() {
                switch (autoSelected) {
                case customAuto:
                        // Put custom auto code here
                        break;
                case defaultAuto:
                default:
                        // Put default auto code here
                        robotDrive1.arcadeDrive(0.5, 0.0);
                        robotDrive2.arcadeDrive(0.5, 0.0);
                        gearMotor.set(0.5);
                        fuelGate.set(0.5);
                        scissorLift.set(0.5);
                        break;
                }
        }

        @Override
        public void teleopPeriodic() {
                while(true) {
                        robotDrive1.arcadeDrive(leftJoystick.getY()*driveBaseSpeed, rightJoystick.getX());
                        robotDrive2.arcadeDrive(leftJoystick.getY()*driveBaseSpeed, rightJoystick.getX());
                        gearMotor.set(rightJoystick.getY()*gearMotorSpeed);
                       
                        if(rightJoystick.getRawButton(4)) {
                                fuelGate.set(1.0*fuelGateSpeed);
                        } else if(rightJoystick.getRawButton(5)) {
                                fuelGate.set(-1*fuelGateSpeed);
                        } else {
                                fuelGate.set(0);
                        }
                       
                        if(rightJoystick.getRawButton(6)) {
                                scissorLift.set(1.0*scissorLiftSpeed);
                        } else if(rightJoystick.getRawButton(7)) {
                                scissorLift.set(-1*scissorLiftSpeed);
                        } else {
                                scissorLift.set(0);
                        }
                }
        }

        @Override
        public void testPeriodic() {
        }
}


AustinShalit 28-01-2017 16:50

Re: Error with joystick controller and driver station
 
Joysticks are indexed starting at 0. Change your Joystick numbers from 1 & 2 to 0 & 1.

mikets 29-01-2017 23:24

Re: Error with joystick controller and driver station
 
Just curious, why do you have TWO RobotDrive objects? RobotDrive does support 4-motor drive. There is no reason to have two RobotDrive objects.

YairZiv 30-01-2017 07:17

Re: Error with joystick controller and driver station
 
Quote:

Originally Posted by CocoGuo (Post 1637522)
I am the programmer from team Yellow Jacket 3345, the driver station is giving me error about the joysticks are not plug in,but ti is plug in right and all show green but we all check the program is no error.And we don't know the problems.

https://www.dropbox.com/s/5bczzz5frj...nshot.png?dl=1

Code:

package org.usfirst.frc.team3345.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.Talon;

public class Robot extends IterativeRobot {
        final String defaultAuto = "Default";
        final String customAuto = "My Auto";
        String autoSelected;
        SendableChooser<String> chooser = new SendableChooser<>();
        private RobotDrive robotDrive1, robotDrive2;
        private Joystick leftJoystick, rightJoystick;
        private Spark gearMotor;
        private Talon fuelGate, scissorLift;
        private double driveBaseSpeed = 1.0;
        private double scissorLiftSpeed = 1.0;
        private double fuelGateSpeed = 1.0;
        private double gearMotorSpeed = 1.0;

        @Override
        public void robotInit() {
                chooser.addDefault("Default Auto", defaultAuto);
                chooser.addObject("My Auto", customAuto);
                SmartDashboard.putData("Auto choices", chooser);
                //spark and function part
                robotDrive1 = new RobotDrive(1, 2);
                robotDrive2 = new RobotDrive(3, 4);
                fuelGate = new Talon(5);
                scissorLift = new Talon(6);
                gearMotor = new Spark(0);
                leftJoystick = new Joystick(1);
                rightJoystick = new Joystick(2);
        }

        @Override
        public void autonomousInit() {
                autoSelected = chooser.getSelected();
                // autoSelected = SmartDashboard.getString("Auto Selector",
                // defaultAuto);
                System.out.println("Auto selected: " + autoSelected);
        }

        @Override
        public void autonomousPeriodic() {
                switch (autoSelected) {
                case customAuto:
                        // Put custom auto code here
                        break;
                case defaultAuto:
                default:
                        // Put default auto code here
                        robotDrive1.arcadeDrive(0.5, 0.0);
                        robotDrive2.arcadeDrive(0.5, 0.0);
                        gearMotor.set(0.5);
                        fuelGate.set(0.5);
                        scissorLift.set(0.5);
                        break;
                }
        }

        @Override
        public void teleopPeriodic() {
                while(true) {
                        robotDrive1.arcadeDrive(leftJoystick.getY()*driveBaseSpeed, rightJoystick.getX());
                        robotDrive2.arcadeDrive(leftJoystick.getY()*driveBaseSpeed, rightJoystick.getX());
                        gearMotor.set(rightJoystick.getY()*gearMotorSpeed);
                       
                        if(rightJoystick.getRawButton(4)) {
                                fuelGate.set(1.0*fuelGateSpeed);
                        } else if(rightJoystick.getRawButton(5)) {
                                fuelGate.set(-1*fuelGateSpeed);
                        } else {
                                fuelGate.set(0);
                        }
                       
                        if(rightJoystick.getRawButton(6)) {
                                scissorLift.set(1.0*scissorLiftSpeed);
                        } else if(rightJoystick.getRawButton(7)) {
                                scissorLift.set(-1*scissorLiftSpeed);
                        } else {
                                scissorLift.set(0);
                        }
                }
        }

        @Override
        public void testPeriodic() {
        }
}


The joystick are counted from 0, if you look in the SmartDashboard in the USB devices sub-folder, you see that near each joystick there's a number, that is the number in the constructor for Joystick. So if you plugged 2 joysticks, and they were in the first 2 positions, but in the constructor you put 1 and 2, it will not find a device in port 2, that will give you an error.

Sorry for the long comment, here's a potato (head).

.-"'"-.
| |
(`-._____.-')
.. `-._____.-' ..
.', :./'.== ==.`\.: ,`.
: ( : ___ ___ : ) ;
'._.: |0| |0| :._.'
/ `-'_`-' \
_.| / \ |._
.'.-| ( ) |-.`.
//' | .-"`"`-'"`"-. | `\\
|| | `~":-...-:"~` | ||
|| \. `---' ./ ||
|| '-._ _.-' ||
/ \ _/ `~:~` \_ / \
||||\) .-' / \ `-. (/||||
\||| (`.___.')-(`.___.') |||/
'"' `-----' `-----' '"'

(Might come out a little mashed)

YairZiv 30-01-2017 07:18

Re: Error with joystick controller and driver station
 
NVM It came out awful, excuse my failure

CocoGuo 30-01-2017 17:11

Re: Error with joystick controller and driver station
 
lol, but about the joystick number i already try to change it to 0 and 1 it still giving me the same error....much cry

YairZiv 31-01-2017 08:04

Re: Error with joystick controller and driver station
 
Quote:

Originally Posted by CocoGuo (Post 1638337)
lol, but about the joystick number i already try to change it to 0 and 1 it still giving me the same error....much cry

Are they in port 0 and 1 in the SmartDashboard as we? (Inside the driver station go to USB Devices and check the numbers to the left of the joysticks highlighted green).

YairZiv 31-01-2017 08:12

Re: Error with joystick controller and driver station
 
Quote:

Originally Posted by YairZiv (Post 1638519)
Are they in port 0 and 1 in the SmartDashboard as we? (Inside the driver station go to USB Devices and check the numbers to the left of the joysticks highlighted green).

as well*

CocoGuo 31-01-2017 15:51

Re: Error with joystick controller and driver station
 
Yep, I already try the port 0 and 1 and the joystick is turning green at the driver station whenever i press it

pblankenbaker 31-01-2017 19:40

Re: Error with joystick controller and driver station
 
You have a while(true) in your teleopPeriodic() method. You should do that in an IterativeRobot implementation. Try changing:

Code:

        @Override
        public void teleopPeriodic() {
                while(true) {
                        robotDrive1.arcadeDrive(leftJoystick.getY()*driveBaseSpeed, rightJoystick.getX());
                        robotDrive2.arcadeDrive(leftJoystick.getY()*driveBaseSpeed, rightJoystick.getX());
                        gearMotor.set(rightJoystick.getY()*gearMotorSpeed);
                       
                        if(rightJoystick.getRawButton(4)) {
                                fuelGate.set(1.0*fuelGateSpeed);
                        } else if(rightJoystick.getRawButton(5)) {
                                fuelGate.set(-1*fuelGateSpeed);
                        } else {
                                fuelGate.set(0);
                        }
                       
                        if(rightJoystick.getRawButton(6)) {
                                scissorLift.set(1.0*scissorLiftSpeed);
                        } else if(rightJoystick.getRawButton(7)) {
                                scissorLift.set(-1*scissorLiftSpeed);
                        } else {
                                scissorLift.set(0);
                        }
                }
        }

To:

Code:

        @Override
        public void teleopPeriodic() {

// teleopPeriodic() should do something and exit right away (it should not loop forever)
//                while(true) {

                        robotDrive1.arcadeDrive(leftJoystick.getY()*driveBaseSpeed, rightJoystick.getX());
                        robotDrive2.arcadeDrive(leftJoystick.getY()*driveBaseSpeed, rightJoystick.getX());
                        gearMotor.set(rightJoystick.getY()*gearMotorSpeed);
                       
                        if(rightJoystick.getRawButton(4)) {
                                fuelGate.set(1.0*fuelGateSpeed);
                        } else if(rightJoystick.getRawButton(5)) {
                                fuelGate.set(-1*fuelGateSpeed);
                        } else {
                                fuelGate.set(0);
                        }
                       
                        if(rightJoystick.getRawButton(6)) {
                                scissorLift.set(1.0*scissorLiftSpeed);
                        } else if(rightJoystick.getRawButton(7)) {
                                scissorLift.set(-1*scissorLiftSpeed);
                        } else {
                                scissorLift.set(0);
                        }

// Removal of while(true) loop
//                }
        }

Hope that helps,
Paul


All times are GMT -5. The time now is 09:50.

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