![]() |
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() {Code:
public double getSafeTan(double heading) |
Re: Gyro Value to Motor-Need Help
I don't see anything obviously wrong. Looking at your code, I don't think it will correct for NaN errors though. By outputting your values to SmartDashboard with code like
Code:
SmartDashboard.putNumber("Raw Gyro Angle",Robot.gyro.getRawAngle()) |
Re: Gyro Value to Motor-Need Help
When you first start up, your gyro angle might be zero because that is what it defaults to typically. So if you get your gyro angle and multiply by your .03 you get 0 for motor power. Instead of multiplying the gyros angle by some number like .03, typically you want to subtract the difference between a desired angle and the gyro angle and then multiply by that .03. For example, if you wanted to turn 90 degrees, you would take .03 times (90 - gyro.getAngle()). After finding this product, you might want to check to see if it is greater than 1 and then set it equal to 1 if it is.
|
Re: Gyro Value to Motor-Need Help
It looks to me that you are in the process of creating a command that will rotate you robot a fixed amount and then stop and that you want to set the power used for the turn based on how far away you are from your final resting place.
This is often done with a PIDController and it appears to me you are on your way to making your own custom PIDController that uses just the "P" (proportional constant that you currently have set to 0.03). Some general comments:
Here is some rough code which demonstrates the above concepts. Code:
package org.usfirst.frc.team868.robot.commands; |
| All times are GMT -5. The time now is 08:59 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi