Go to Post TL;DR: The robot battery (and your car battery) aren't going to electrocute you unless you stab a positive and negative wire from them into your heart. In which case you have plenty of other problems besides. - Kevin Sevcik [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 15-01-2015, 18:09
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Gyro Help

Hi everyone this is my first year programming in First Robotics and I need some help programming a gyro in autonomus. My goal is to have our bot drive forward and make a sudden 90 degree turn. I have figured out how to make a sudden turn however, the bot does not stop and it continues to spin. Any help would be greatly appreciated.

Here's my code:

Code:
public void autonomous() {
    	
    	while (isAutonomous() && isEnabled()) {
    		
    		SmartDashboard.putNumber(" angle " , gyro1.getAngle());
    	
    		double angle = gyro1.getAngle() + 90;
    		
    		//robot.drive(-0.15, angle * Kp); this is for driving straight
    		robot.drive(-0.10, angle / 30); // the turn
    		gyro1.reset();

    		if(angle < 90) {

    			robot.stopMotor();
    			
    		}
    		 
    	}
    	}
Reply With Quote
  #2   Spotlight this post!  
Unread 15-01-2015, 18:55
Bryan Herbst's Avatar
Bryan Herbst Bryan Herbst is offline
Registered User
AKA: Bryan
FRC #2052 (KnightKrawler)
Team Role: Mentor
 
Join Date: Sep 2007
Rookie Year: 2007
Location: Minneapolis, Minnesota
Posts: 545
Bryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond repute
Re: Gyro Help

The first problem is that you are resetting the gyro in every iteration of your loop. Thus the angle variable is always going to contain the number of degrees that you have turned since the last iteration of the loop (plus 90 degrees).

Unless you are turning really fast, you are never going to get the gyro to read a full 90 degrees.

I'm also not sure why you are adding 90 degrees to the angle each time. If you are turning in the positive direction, your angle will always be greater than 90 degrees. If you are turning in the negative direction, your angle will always be less than 90 degrees because of the above problem. Either way, the magic +90 is probably not what you intended and the stopMotor() method is not going to be called when you want it to be called.

What you probably want is to reset the gyro in the robotInit() method or before your autonomous while loop, then leave it alone.
__________________
Team 2052- KnightKrawler
Mentor and volunteer
Reply With Quote
  #3   Spotlight this post!  
Unread 15-01-2015, 19:48
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Gyro Help

Quote:
Originally Posted by Tanis View Post
The first problem is that you are resetting the gyro in every iteration of your loop. Thus the angle variable is always going to contain the number of degrees that you have turned since the last iteration of the loop (plus 90 degrees).

Unless you are turning really fast, you are never going to get the gyro to read a full 90 degrees.

I'm also not sure why you are adding 90 degrees to the angle each time. If you are turning in the positive direction, your angle will always be greater than 90 degrees. If you are turning in the negative direction, your angle will always be less than 90 degrees because of the above problem. Either way, the magic +90 is probably not what you intended and the stopMotor() method is not going to be called when you want it to be called.

What you probably want is to reset the gyro in the robotInit() method or before your autonomous while loop, then leave it alone.
Thanks for the help I moved the reset into the robotInit and I removed the +90. But I don't understand what I need to do to fix the stopMotor() issue you were talking about. If you don't mind elaborating it would be greatly appreciated.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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