Go to Post There's more elegant ways to play defense than beating on the other robot. - Bill Moore [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
  #31   Spotlight this post!  
Unread 23-02-2015, 17:17
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: functions for auto

Quote:
Originally Posted by curtis0gj View Post
Alright that makes sense should I also use arcadeDrive in the move function? Other than this I believe I am done if you don't mind giving it a final look over it would be greatly appreciated I am hoping this will all work for Wednesday we are having a little show casing with other schools.
https://github.com/curtis0gj/5033-20...ster/Auto.java
Code:
			chassis.arcadeDrive(-0.25, angle * Kp);
you never defined a "Kp" variable as far as I can see (which by the way is bad formatting, kP). First of all, you probably want to define a "Kp" variable.
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!
If you don't want to deal with the ambiguous, do the same as above and throw a reset() before the while(true) loop in your turn() function. This way, turn(90) will always turn right 90 degrees, it won't depend on the previous angle.

in Robot.java
Code:
		Auto.run(this, autoMethod);
this is still static. Since you now have a constructor and stuff, this should be "autonManager.run...".

also in Robot.java
Code:
	public AutonManager autonManager; //PUBLIC OR DOES IT MATTER?

		autonManager = new AutonManager(this);
your class is named "Auto", not "AutonManager"

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.
#1 rule of code - it won't. I may have quite finely-tuned intuitions, but I'm not perfect.

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)
Reply With Quote
  #32   Spotlight this post!  
Unread 23-02-2015, 17:40
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: functions for auto

Quote:
Originally Posted by Arhowk View Post
Code:
			chassis.arcadeDrive(-0.25, angle * Kp);
you never defined a "Kp" variable as far as I can see (which by the way is bad formatting, kP). First of all, you probably want to define a "Kp" variable.
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!
If you don't want to deal with the ambiguous, do the same as above and throw a reset() before the while(true) loop in your turn() function. This way, turn(90) will always turn right 90 degrees, it won't depend on the previous angle.

in Robot.java
Code:
		Auto.run(this, autoMethod);
this is still static. Since you now have a constructor and stuff, this should be "autonManager.run...".

also in Robot.java
Code:
	public AutonManager autonManager; //PUBLIC OR DOES IT MATTER?

		autonManager = new AutonManager(this);
your class is named "Auto", not "AutonManager"

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.
#1 rule of code - it won't. I may have quite finely-tuned intuitions, but I'm not perfect.

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)
Okay for the kP I just added a double like this and I added a reset to the drive forward and turn so everything works nicely. I also got rid of the autonmanager's and changed it to Auto.

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);
		}
	}
But I am a bit confused with:

Auto.run(this, autoMethod);
this is still static. Since you now have a constructor and stuff, this should be "autonManager.run...".
Reply With Quote
  #33   Spotlight this post!  
Unread 23-02-2015, 17:50
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: functions for auto

Quote:
Originally Posted by curtis0gj View Post
But I am a bit confused with:

Auto.run(this, autoMethod);
this is still static. Since you now have a constructor and stuff, this should be "autonManager.run...".
To review
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"
Reply With Quote
  #34   Spotlight this post!  
Unread 23-02-2015, 18:14
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: functions for auto

Quote:
Originally Posted by Arhowk View Post
To review
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"
Okay I think I understand,
Will this fix my issue.

Code:
     public Auto auto; 

     auto.run(this, autoMethod);
Reply With Quote
  #35   Spotlight this post!  
Unread 23-02-2015, 20:30
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: functions for auto

looks good, except for the fact that the "this" parameter is no longer necessary.
Reply With Quote
  #36   Spotlight this post!  
Unread 23-02-2015, 20:39
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: functions for auto

Quote:
Originally Posted by Arhowk View Post
looks good, except for the fact that the "this" parameter is no longer necessary.
Alright I am going to transfer all the code onto the class mate and give it another check over to make sure I don't get any errors.

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 one error is with return err; and how void methods cannot return a value.

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.
Reply With Quote
  #37   Spotlight this post!  
Unread 25-02-2015, 20:47
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
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:
I guess this is why I should use an IDE when making changes.
I would.... o.O sometimes I use Sublime or NP++ because it's overall faster and doesn't gun my processor like Eclipse does than just once-through in eclispe
Reply With Quote
  #38   Spotlight this post!  
Unread 25-02-2015, 21:44
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: functions for auto

Quote:
Originally Posted by Arhowk View Post
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?


I would.... o.O sometimes I use Sublime or NP++ because it's overall faster and doesn't gun my processor like Eclipse does than just once-through in eclispe
Everything seemed to work for teleop, because this is all we really had to do...
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.
Reply With Quote
  #39   Spotlight this post!  
Unread 26-02-2015, 14:36
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: functions for auto

Quote:
calling forwardMove didn't move
0.25 is INCREDIBLY slow, it probably could be ~0.6-0.7.

Quote:
Originally Posted by curtis0gj View Post
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...)
Only? As in, it measures distance instead of displacement? That would be bad. I'm assuming you just have your encoder mounted backwards, in which case you can just say
Code:
double encoder = -encoder.get();
or smth.


Quote:
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.
Can't say with any idea since I have no access to your robot
Reply With Quote
  #40   Spotlight this post!  
Unread 26-02-2015, 17:40
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: functions for auto

Quote:
Originally Posted by Arhowk View Post
0.25 is INCREDIBLY slow, it probably could be ~0.6-0.7.


Only? As in, it measures distance instead of displacement? That would be bad. I'm assuming you just have your encoder mounted backwards, in which case you can just say
Code:
double encoder = -encoder.get();
or smth.



Can't say with any idea since I have no access to your robot
Well I bumped up the speeds to .6 but I don't know about the encoder.

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.
Reply With Quote
  #41   Spotlight this post!  
Unread 28-02-2015, 16:56
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
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.
Reply With Quote
  #42   Spotlight this post!  
Unread 28-02-2015, 17:07
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: functions for auto

Quote:
Originally Posted by Arhowk View Post
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.
So I should change all of the breaks for the functions to returns just to make everything look nice?

Last edited by curtis0gj : 28-02-2015 at 20:00.
Reply With Quote
  #43   Spotlight this post!  
Unread 28-02-2015, 19:24
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: functions for auto

Quote:
Originally Posted by curtis0gj View Post
So I could change all of my breaks to returns and it would still do the same thing?
For the code that you've shown me, yes.
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 13:10.

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