|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#31
|
||||
|
||||
|
Re: functions for auto
Quote:
Code:
chassis.arcadeDrive(-0.25, angle * Kp); Also, I assume you want this code to use the gyro to keep straight. In this case, you might want to add a reset() before the while(true) loop to ensure the gyro is 0. Code:
turn(90); //COULD 90 OR 180! in Robot.java Code:
Auto.run(this, autoMethod); also in Robot.java Code:
public AutonManager autonManager; //PUBLIC OR DOES IT MATTER? autonManager = new AutonManager(this); Code:
it would be greatly appreciated I am hoping this will all work for Wednesday we are having a little show casing with other schools. Your "kP" value(s?) need to be tuned, the 0.01 I gave you was just a rough estimate. For example, if it doesn't turn fast enough, than this should be increased to 0.015 or something. If it turns too fast, than it should be 0.005. If it's turning the wrong way, than it should be -0.01. (honestly, I'd probably start off with 0.035, seems like a decent starting number) |
|
#32
|
|||
|
|||
|
Re: functions for auto
Quote:
Code:
double kP = 0.035;
private void forwardDrive(double distanceToGo) {
reset();
while (true) {
double distance = encoder.get();
double angle = gyro.getAngle();
if (!isAutonomous() || !isEnabled()) return;
chassis.arcadeDrive(-0.25, angle * kP);
//chassis.drive(-0.40, 0);
if (distance < -distanceToGo) {
reset();
return;
}
Timer.delay(0.02);
}
}
Auto.run(this, autoMethod); this is still static. Since you now have a constructor and stuff, this should be "autonManager.run...". |
|
#33
|
||||
|
||||
|
Re: functions for auto
Quote:
Static methods are designated by the "static" keyword, accessed through the classes name itself (ex. "Auto.run"), and do not have accessed to instanced variables and methods Instaneced methods are designated through the lack of the "static" keyword, accessed through an instance of the class (ex. "autonManager.run..."), and have access to instanced variables and methods. The specified piece of code is in Robot.autonomousInit. In robot, you have an instance of Auto named "autonManager", yet you attempt to call the instanced method "run" by designating the class "Auto" instead of the instance "autonManager" |
|
#34
|
|||
|
|||
|
Re: functions for auto
Quote:
Will this fix my issue. Code:
public Auto auto;
auto.run(this, autoMethod);
|
|
#35
|
||||
|
||||
|
Re: functions for auto
looks good, except for the fact that the "this" parameter is no longer necessary.
|
|
#36
|
|||
|
|||
|
Re: functions for auto
Quote:
Okay I just copied it over into eclipse and I found a lot of little errors that I sorted out. But there are some bigger issues in the Auto and Robot class... I guess this is why I should use an IDE when making changes. I fixed the first error still had one static void. A second error is with !isAutonomous() and !isEnabled() and the IDE says "The method isEnabled(), isAutonomous() is undefined for the type Auto". I think if I just add this to my constructor it will work or add robot. A third error is with AUTOS in public void run(AUTOS autoMode) and the IDE says AUTOS cannot be resolved to a type. ^^ I think I had a little typo so I changed AUTOS to Autos I think this will fix it. The fourth error in the Auto.java class is with every case that I have. The error is "AUTO_MOVE_TO_ZONE cannot be resolved to a variable" and this is an error for every case. ^^Changing AUTOS to Autos may also fix this. The fifth error is with deg in double deltaAngle = angleError(deg, gyro.getAngle()); and Eclipse says "deg cannot be resolved to a variable". The last error in Auto.java is the return err; and the error is "Void methods cannot return a value". The only error in Robot.java is with auto.run(autoMethod); and the error is with run and the IDE says "The method run(AUTOS) from the type Auto refers to the missing type AUTOS". ^^I also believe this error will go aways when I change AUTOS to Autos. Changing AUTOS to Autos fixed everything except the !isAutonomous and !isEnabled I don't know how to add them to the constructor. ^^ I just added robot. to both and it seems to work. The only other error I am having is with: Code:
private void angleError(double setpointDegressZeroToThreeSixty, double experimentalDegrees) {
double err = setpointDegressZeroToThreeSixty - experimentalDegrees; // 0 TO 360!
if(err < -180) {
err += 360;
} else if(err > 180) {
err -= 360;
}
return err;
}
double kp_rotate = 0.01;
double MAX_ERROR = 5;
private void turn(double deg) {
reset();
while(true) {
double deltaAngle = angleError(deg, gyro.getAngle());
if(Math.abs(deg - deltaAngle) < MAX_ERROR) {
break;
} else {
chassis.arcadeDrive(0, deltaAngle * kp_rotate);
}
Timer.delay(0.02);
}
}
The other error is with double deltaAngle = angleError(deg, gyro.getAngle()); and how Type mismatch: cannot convert from void to double. And I can fix both of the errors by changing private void angleError to private double angleError. https://github.com/curtis0gj/5033-2014-15 Last edited by curtis0gj : 24-02-2015 at 18:12. |
|
#37
|
||||
|
||||
|
Re: functions for auto
Oh my apologies, I never saw your edit. Good to see that you were able to resolve your issues. You chose the correct path for all of them.
How did it work today? Quote:
|
|
#38
|
|||
|
|||
|
Re: functions for auto
Quote:
But I did do a quick run for autonomous and I noticed a few things, one of which was the robot did not move when I called the move function. I think this is because I would enter a value of 3000 or 450 into the parameters of forwardMove when it should be negative (our encoder only likes negatives I don't know if that's normal...) Also I noticed that there was a long delay in between functions, almost 3 - 5 seconds. I thought this was odd seeing as I only have a 0.5 timer delay between functions. |
|
#39
|
||||
|
||||
|
Re: functions for auto
Quote:
Quote:
Code:
double encoder = -encoder.get(); Quote:
|
|
#40
|
|||
|
|||
|
Re: functions for auto
Quote:
I had a question with this whole function and I was wondering if it's necessary to have distanceToGo negative when I can just say it's negative when I am calling up the function. Also should I have it double -distanceToGo in the parameters? And when I call the function forwardDrive(should it be 3000 or -3000) Also when is it appropriate to use return; and when should I use break; when I look at my code it seems as I use break and return randomly. https://github.com/curtis0gj/5033-20...ster/Auto.java Code:
double kP = 0.035;
private void forwardDrive(double distanceToGo) {
reset();
while (true) {
double distance = encoder.get();
double angle = gyro.getAngle();
if (!robot.isAutonomous() || !robot.isEnabled()) return;
chassis.arcadeDrive(-0.60, angle * kP);
if (distance < -distanceToGo) {
reset();
return;
}
Timer.delay(0.02);
}
}
Last edited by curtis0gj : 26-02-2015 at 21:46. |
|
#41
|
||||
|
||||
|
Re: functions for auto
it doesn't really matter. "break" exits the loop while "return" exits the method. if you have code after the loop which you want to run than "break" should be used. if you want to terminate the method entirely and skip methods after the loop (or if you have no loops), than "return" should be used. if your entirely in a loop with no code after the loop, it doesn't matter.
Though, for uniformity sake, they should all probably be the same. |
|
#42
|
|||
|
|||
|
Re: functions for auto
Quote:
Last edited by curtis0gj : 28-02-2015 at 20:00. |
|
#43
|
||||
|
||||
|
Re: functions for auto
For the code that you've shown me, yes.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|