View Single Post
  #1   Spotlight this post!  
Unread 02-18-2016, 05:56 PM
SandySandySand SandySandySand is offline
Registered User
AKA: Chayanne
FRC #2560 (Robodog)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2015
Location: Missouri
Posts: 1
SandySandySand is an unknown quantity at this point
Gyro Value to Motor-Need Help

Hello there, I am a first year programmer with my team and we are working in Java this year, for the first time.(We are using Command-Based, instead of going for the Iterative Robot API.) We have recently looked into using a gyro for this year's autonomous mode and are having trouble. We are able to get a reading of the angle, but no matter what we try we can not modify the motor speed using this newly found angle we have. I have included the code we are using. We have tried 2 different methods to fix this problem. (The first method the code that we have commented out.) Any help is appreciated. Thank you, friends.

Code:
 protected void execute() {
    	//double heading = Robot.gyro.getRawAngle();
        //double motorPower = getSafeTan(heading);
        //Robot.drivetrain.arcadeDrive(0, motorPower);
    	double correction = 0.03;
    	double a =Robot.gyro.getRawAngle()*correction;
    	Robot.drivetrain.drive(0, a);
    }
Code:
public double getSafeTan(double heading)
    {
    	double safeAngle = heading / 45.0;
    	//now safeAngle can be NaN or -56 or some crazy useless number. 
    	//We have elected to just attempt basic corrections in that case.
    	if(safeAngle > 1)
    	{
    		safeAngle = 1;
    	}
    	
    	if(safeAngle < -1)
    	{
    		safeAngle = -1;
    	}
    	
    	if(safeAngle > 1 || safeAngle < -1)
    	{
    		safeAngle = 0;
    	}
    	
    	return safeAngle;
    }
Reply With Quote