Noob question for teleop

Hey, it appears our teleop code, after deploying it to the roboRio, likes to kick out after running through it once.

public void teleopPeriodic() {
	    	
	 
	    		myDrive.mecanumDrive_Cartesian(moveStick.getRawAxis(1), moveStick.getRawAxis(1), moveStick.getRawAxis(1), gyro.getAngle());
	    		Timer.delay(0.01);
	    
	   }

, and won’t recognize the controller

RobotDrive myDrive, catcherDrive;
	    	Joystick moveStick;
	    	Gyro gyro;
	    	
	    
	    public void robotInit() {
	    	Talon TalLF = new Talon(0);
	    	Talon TalLR = new Talon(1);
	    	Talon TalRF = new Talon(2);
	    	Talon TalRR = new Talon(3);
	    	Talon TalCatcher = new Talon(4);
	    	Talon TalCatcher1 = new Talon(5);
	    	myDrive =  new RobotDrive(TalLF,TalLR,TalRF,TalRR);
	    	moveStick = new Joystick(1);
	    	catcherDrive = new RobotDrive(TalCatcher, TalCatcher1);
	
	    }

This is what we have for the teleOp. Any form of response would be greatly appreciated.

The variable “gyro” is declared and used but never instantiated. This means that “gyro” is null when you call .getAngle on it in Teleop which crashes your code.

2 things to do to fix it:

  1. Either remove “gyro” if you don’t have a gyro or instantiate using a line like gyro= new AnalogGyro(1) if you do.
  2. Set your Driver Station messages window to “+Prints” using the little gear above the messages. You would have seen the stack trace from the code crashing there if you had it set this way which would have told you that it was a Null Pointer exception and the line number.

we are getting error under AnalogGyro when we use the line to instantiate it. Do we need a gyro in the mecanum cartesian or is it optional? could we just take it out of the

myDrive.mecanumDrive_Cartesian(moveStick.getRawAxis(1), moveStick.getRawAxis(1), moveStick.getRawAxis(1), gyro.getAngle());
	    		Timer.delay(0.01);

??

For mecanum without a gyro I think you want to take a look at

RobotDrive::MecanumDrive_Polar(float magnitude, float direction, float rotation)

Not true. You can use mecanum_Cartesian without a gyro if you set the gyro_angle to 0

A couple of other things…

First, you don’t want to use the same raw axis in each position of that method call. The first three parameters to the mecanumDrive_Cartesian() method represent:

  1. A strafe value (typically an x-axis on a joystick)
  2. A forward-backwards value (typically the y-axis from the same joystick that you used for the strafe value)
  3. A rotation value (if you are driving with a single joystick, this would be the z-axis or the “twist” axis)

If you are using an XBox controller (or some other console), then you would typically use the left joystick’s x- and y-axis for the strafe and forward-backwards and the right joystick’s x-axis for the rotation value (think of playing a first person shooter like Halo). You can figure out which axis numbers you want if you plug the controller into your driver’s station laptop and then use the USB/controller tab in the DriverStation. Click on the joystick/controller that you want to use and watch the display as you use it. The parameter that you send to the getRawAxis() method will correspond to the numbers on the DriverStation.

Second, you also don’t want to delay the teleop code with a call to Timer.delay(). If you were using the SampleRobot template (and you don’t want to), then you would put delays like that in your teleop code. With the IterativeRobot template, the teleopPeriodic() method will get called for you ever 20ms (roughly). You don’t need to put delays in this code. If you delay the code too much, you will cause weird behavior. DO NOT PUT DELAYS in teleopPeriodic() or autonomousPeriodic().

Third, I would stick with the cartesian method (unless you want to convert everything to polar…which isn’t too complicated, but unnecessary). What problems are you having with the gyro? Code like this “should” work if you have an analog gyro (a gyro that is plugged in as an analog input on the roboRIO):
gyro = new AnalogGyro( 1 );
This assumes that the gyro is plugged in to analog input 1 (which is the second analog port). You CAN NOT have code like this:
gyro = new Gyro( 1 );
Gyro is an interface and can’t be constructed. You must use a class that implements the interface like AnalogGyro.
What have you tried for the gyro and what error message(s) did you get?

Edit: corrected port number to be a port with an analog accumulator. Thanks to RufflesRidge for the correction and the information!!

The Analog Accumulators required for the gyro are only on ports 0 and 1.

Is the analog input in the roboRio directly next to the Ethernet port? there are ones farther down that are titled analog but our gyro/accelerator only fits in the one next to the Ethernet port. Is this correct? Thanks for the reply, our team is brand new every year so its hard to keep knowledgeable people around for long

So the one next to the ethernet is SPI. What gyro are you using?

This is the gyro we are using as of now.
http://firstchoicebyandymark.com/fc16-000

For that gyro, you are connected to the correct port (the onboard SPI port). To construct a gyro object in code, you will want to use the Java class that was built specifically for this gyro:
http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.html

You should be able to use the default (no parameter) constructor.
gyro = new ADXRS450_Gyro();

Now, in your drive code’s call to the mecanum_Cartesian() method, you should be able to use gyro.getAngle().

Keep asking if it ain’t working.

Thank you so much our team and I greatly appreciate your help and will ask for help in the future.