![]() |
functions for auto
Hey guys I just finished my autonomous program on bag night and the next day realised how long and messy it was. So I got some help and made functions but I can't test them :mad: . So if anyone is able to help me here's the github link https://github.com/curtis0gj/5033-2014-15?files=1.
|
Re: functions for auto
FYI you can build them to search for syntax errors... like this
Code:
private static void wait(Robot r, double waittime) {passing in Robot for everything is ugh-ly. just make Robot a singleton... or use a static initializer Code:
while (true) {Code:
r.robot.drive(-.40, -1)Code:
Boolean maxarmlimit = r.limit4.get();Code:
r.armmotor.set(Defines.ARM_SPEED);Code:
if (angle > deg) {Code:
r.robot.drive(-.40, -1);your "turn" and "turn2" functions are quite ineffective, basic angle averaging schemes should be used other than that I'm losing my focus, but there are alot more issues |
Re: functions for auto
Quote:
|
Re: functions for auto
should distance be an int or a double and how should I add the periodic timer?
|
Re: functions for auto
Quote:
for distance, i usually go with doubles for most things so I don't accidentally mess data up with division. don't know what the second thing you asked is in reference to. If it's the closed loop, than just do a Timer.delay(0.02) (20ms, standard 50hz operating cycle) inside the while(true) loop |
Re: functions for auto
Quote:
https://github.com/curtis0gj/5033-20...ster/Auto.java |
Re: functions for auto
Preferably it would be the last line (with it at the first, theres a 20ms delay before any actions are performed)
Your indenting for everything after "wait" is now wrong AUTOS should not be capitalized (and should be descriptive: "AutonMode", "SelectedAutonMode", "AutonEnum", etc) turn and turn2 still need to be turned into feedback loops but for now rename them to turnLeft and turnRight and make one function- turn- that if gyro < desired than turnLeft(angle) else turnRight(angle) capitalization schemes are wrong in Robot.java (http://java.about.com/od/javasyntax/...onventions.htm) Code:
if (autoMethod == Defines.AUTOS.AUTO_ONE) {Why is your wait function inside of a while(true) loop? |
Re: functions for auto
Quote:
Code:
public static void turn(Robot r, double deg) { |
Re: functions for auto
Quote:
Code:
public static void turn(Robot r, double deg) {E/ misunderstood the point of the code, fixed. |
Re: functions for auto
Quote:
|
Re: functions for auto
Quote:
note that I edited that post like 5 times. Anyway, heres a (maybe) working function Code:
public static double angleError(double setpointDegressZeroToThreeSixty, double experimentalDegrees){ |
Re: functions for auto
Quote:
|
Re: functions for auto
Quote:
|
Re: functions for auto
Quote:
|
Re: functions for auto
apologies, wrapped up in poe.
Quote:
Quote:
Timer.delay will wait the desired time. For the new loops, they automatically wait untill finished so this isn't needed. If you wanted to add an extra wait, just throw in a Timer.delay() before turn, drive, etc. calls |
Re: functions for auto
Quote:
|
Re: functions for auto
Something like this
Code:
static Robot rCode:
Robot robot |
Re: functions for auto
Quote:
Code:
public class Auto { |
Re: functions for auto
Quote:
1) rename r to robot (atleast it looks more professional...) 2) Code:
public class Auto { |
Re: functions for auto
Quote:
Code:
public void autonomous() {Code:
public static void angleError(double setpointDegressZeroToThreeSixty, double experimentalDegrees) { |
Re: functions for auto
Code:
if (autoMethod == Defines.Autos.AUTO_GRAB_ONE_BIN_BLUE_SIDE) {To call the turn() code, the "deg" argument will be the angle in reference to the gyro. So if the gyro has just been reset and you call turn(90), the robot will turn untill the gyro reads 90, which will be a 90 degree turn to the right(?). If you call turn(90) when the gyro hasn't been reset and the gyro is, for example 135, the gyro will turn 45 degrees to the left(?). Note that I wrote all of that code in the text editor and it hasn't come anywhere close to being tested. |
Re: functions for auto
Quote:
But will my auto chooser still work without the block or will it be fine. Also just to make sure I understand, say I wanted to turn right(?) I would say turn(90);???? and If I want a left turn could I call turn(-90)??? and do I need turn(r, 90)? And should I change all my auto functions to public or keep them all private static voids? |
Re: functions for auto
Quote:
Quote:
Quote:
Quote:
The "private" keyword defines the accessibility of the function. "private" means that only code within Auton.java may access that function whereas "public" means that code anywhere may access that function. Since there is no point for some of those functions to be called elsewhere (such as "turn", "move", etc.) those should be private. For other functions that are called by other classes, such as startAuton() called by Robot.java, those should remain public in order to be called by other classes. "static" depends on which implementation of the robot instantiation you chose. What "static" means is that, in order for that method to be accessed, a new Object of type $class (in this case, this is referring to the "new AutonMode()"). This is shown in Timer.delay, since "Timer t = new Timer()" is never called. However, in other cases such as "Victor leftDrive = new Victor(1)", non-static methods within the victor "leftDrive" are called since there are multiple different Victors. As you can see in this code posted before Code:
static Robot rCode:
AutonManager.startAuton(autonMode);Code:
AutonManager m = new AutonManager();Code:
Robot robotSee http://stackoverflow.com/questions/4...-do-in-a-class or http://www.javatpoint.com/static-keyword-in-java for more help on the "static" keyword. |
Re: functions for auto
Quote:
Also I may have misunderstood you said I no longer needed the r parameter does this mean I will still need "r." or can I throw it out the window. My understanding of what a parameter is may be wrong..... https://github.com/curtis0gj/5033-2014-15/tree/master The final concern/question I have is regarding an issue I had in the past. The issue was the robot would do two things at once for example, I wanted to the robot to lift a bin wait then move forward. What ended up happening was the robot attempted to lift the bin and move forward at the same time. This was very problematic... Anyway it could have been a bug in the old code I was using. It had some grotesque while and if loops in it. |
Re: functions for auto
Quite tired so I ca't give you another full sweep, but a few things
Code:
public AutonManager autonManager; //PUBLIC OR DOES IT MATTER?Code:
Robot robotBy not specifying a return type, you are making a constructor, which must have the same name of your class [in this case, "Auto"]. I called it "AutonManager" because I couldn't remember what you called it and chose the name I would've used. In this case, "AutonManager" would be "Auto" since the name of the class is "Auto" (as seen by: "Auto auto = new Auto();" (long story short: this should be public Auto(){)) Now, you chose the constructor, which was the proper choice since it followed wpi-standards. However, you left everything else static Code:
public static void run(AUTOS autoMode) {Code:
Robot robotI have some homework to do so I'll have to cut the rest of this short. Please do some independent study on the "static" keyword, constructors, and other fundamentals of Java. I don't know your level of talent with Java and I code it professionally so I may be telling you what to write and not how to write it, which is a mistake that should never be made. On a side note, what is your mentor situation? Quote:
Code:
public class Robot{The "public" keyword means that other stuff can access these variables, if you didn't want them to be changed than you can change them to private but you want these public in this case. "RobotDrive" and "Joystick" are the classes. Somewhere in WPI code there is a Code:
public class Joystick{Anyway, you're not specifying what you want to get "chassis", "gyro", "encoder", etc. You have to call "robot.chassis. ..." since you need to specify what instance of "Robot" you want to draw a variable called "chassis" from. Quote:
long story short: remove "static" keyword, fix indenting, gotta have "robot.chassis" and etc. I'd also recommend not pushing to the github so much as it's not necessary / might cause a detached head (had a couple of those fun little puppies) (I apologize in advance if the link is too technical) |
Re: functions for auto
Quote:
I have about 1-2 months of experience using java and programming in general. I'm fairly new to it all. Unfortunately, we don't have any programming mentors and I am the only one programming this year so everything has been very daunting. :eek: Also I have a few questions to verify some things. Sorry I may be a bit slow with all of this stuff and you may have to repeat things I will try not to offend you... Anyway I think I understand the static part I just need to get rid of them because I now have a construction. But you kind of lost me with: "" Anyway, you're not specifying what you want to get "chassis", "gyro", "encoder", etc. You have to call "robot.chassis. ..." since you need to specify what instance of "Robot" you want to draw a variable called "chassis" from. "" With this ^ do you mean like this.chassis = ??; and this.gyro =??; Okay I put a bit more thought into this and read the older posts. I think I am on the right track here's what I have done to call up variables. Code:
public class Auto {Also: chassis.drive(0, deltaAngle * kp_rotate); should I change 0 to 0.25 for a speed? And I remember another issue I was having with chassis.drive(-0.25, angle * Kp); (The objective was to have the robot drive straight). The issue was the robot would start curving to the left so much that it would curve slowly about 90 degrees and then it would start jittering about (it looked as if it was having a melt down...). Is there a better controller than can handle corrections for both directions (if that makes any sense.) ( I think the one we are using currently is called a P controller but I am not sure). my apologies for not understanding I will read it a few more times but if you are available later some further explanation would be awesome. |
Re: functions for auto
Quote:
Quote:
Quote:
What you're doing here is a few things Code:
public Auto(Robot r){1) You're recieving an instance of Robot to draw data from 2) You're drawing the object "chassis" out of the recieved instance of robot 3) You are then storing the recieved "chassis" object into an object contained within the "Auto" instance also named "chassis". (Note: Java is pass-by-value, which means that if "chassis" inside of the "Robot" instance were to be changed after the time that it was sent to the "Auto" instance, the "chassis" object will remain the same "chassis" object that it was when it was initially constructed. ex. Code:
int i = 0;Anyway, now that you're taking the chassis object from the robot and placing it inside of the "Auto" instance, the "r." is no longer needed since it is now inside the "this." namespace which is automatic. Quote:
Also note that detached heads are really only an issue if you have more than one user accessing the git repo; since you are the only on it probably isn't a huge deal (unless you code with 4 laptops or something silly like that) Quote:
Code:
RobotDrive.arcadeDrive(move,rotate);Quote:
|
Re: functions for auto
Quote:
Okay so the actual function for driving and turning is RobotDrive.arcadeDrive? would chassis.drive do the same thing. Because I have been using chassis.drive in the past. Other than this I think my functions are looking good. |
Re: functions for auto
Quote:
|
Re: functions for auto
Quote:
https://github.com/curtis0gj/5033-20...ster/Auto.java |
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?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) |
Re: functions for auto
Quote:
Code:
double kP = 0.035;Auto.run(this, autoMethod); this is still static. Since you now have a constructor and stuff, this should be "autonManager.run...". |
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" |
Re: functions for auto
Quote:
Will this fix my issue. Code:
public Auto auto; |
Re: functions for auto
looks good, except for the fact that the "this" parameter is no longer necessary.
|
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) {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 |
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:
|
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. |
Re: functions for auto
Quote:
Quote:
Code:
double encoder = -encoder.get();Quote:
|
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; |
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. |
Re: functions for auto
Quote:
|
Re: functions for auto
Quote:
|
| All times are GMT -5. The time now is 11:16. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi