View Single Post
  #6   Spotlight this post!  
Unread 01-28-2016, 10:57 PM
mmaunu's Avatar
mmaunu mmaunu is offline
Registered User
FRC #2485 (W.A.R. Lords)
Team Role: Mentor
 
Join Date: Mar 2013
Rookie Year: 2010
Location: San Diego, CA
Posts: 86
mmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the rough
Re: Noob question for teleop

Quote:
Originally Posted by CjDace View Post
Hey, it appears our teleop code, after deploying it to the roboRio, likes to kick out after running through it once.
Code:
public void teleopPeriodic() {
	    	
	 
	    		myDrive.mecanumDrive_Cartesian(moveStick.getRawAxis(1), moveStick.getRawAxis(1), moveStick.getRawAxis(1), gyro.getAngle());
	    		Timer.delay(0.01);
}
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!!
__________________
2014 Las Vegas (Winners with 987, 2478; Excellence in Engineering)
2014 San Diego (Finalists with 987, 3250; Quality Award)
2013 Inland Empire (Winners with 1538, 968; Excellence in Engineering Award)
2013 San Diego (Finalists with 2984, 4322; Creativity Award)
2012 Las Vegas (Finalists with 2034, 3187; Quality Award)

Last edited by mmaunu : 01-29-2016 at 03:40 PM. Reason: Made the port number a good one for gyros. Thanks to RufflesRidge for the correction.
Reply With Quote