View Single Post
  #26   Spotlight this post!  
Unread 22-02-2015, 20:51
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
Quite tired so I ca't give you another full sweep, but a few things
Code:
	public AutonManager autonManager; //PUBLIC OR DOES IT MATTER?
doesn't matter. Same issue in the following poing

Code:
	Robot robot
	public AutonManager(Robot r){
	this.robot = r;
	}
(first of all, bad indenting)
By 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) {
The static method means that it doesn't need a constructor and thusly cannot access non-static variables, such as

Code:
	Robot robot
(since there is no "static" keyword, it is defaulted to "instanceable" so static methods cannot access it)

I 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?



Yes, you misunderstood me. Let's break it down right fast. in Robot.java

Code:
public class Robot{
	public RobotDrive chassis;
	public Joystick stick;
By being in the class "Robot", the class robot must be accessed in some way in order for "chassis" and "stick" to be accessed, since nothing in Java is global.

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{
//code code code
}
and likewise for robotdrive. Calling Joystick.staticMethod() is only possible if staticMethod is indeed static, since no enclosing instance of Joystick is given. Calling stick.nonStaticMethod() is possible since the "Joystick" object "stick" is given.

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.



Not 100% but that shouldn't be an issue now since all of your while(true) loops are isolated.

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)
Okay I will start making these changes and edit this post as I progress. You also asked about my experience in java and mentors.

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.

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 {
	Robot robot;
	RobotDrive chassis;
	DigitalInput limit;
	DigitalInput limit2;
	DigitalInput limit3;
	Gyro gyro;
	Encoder encoder;
	Relay leftArmWheel;
	Relay rightArmWheel;
	Victor screwMotor1;
	Victor screwMotor2;
	Victor armMotor;
	public Auto(Robot r){
		this.robot = r;
		this.chassis = r.chassis;
		this.gyro = r.gyro;
		this.encoder = r.encoder;
		this.limit = r.limit;
		this.limit2 = r.limit2;
		this.limit3 = r.limit3;
		this.leftArmWheel = r.leftArmWheel;
		this.rightArmWheel = r.rightArmWheel;
		this.screwMotor1 = r.screwMotor1;
		this.screwMotor2 = r.screwMotor2;
		this.armMotor = r.armMotor
	}
And the detached head issue the link was a bit technical for me but should I consider using google code or something else?

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.

Last edited by curtis0gj : 23-02-2015 at 12:16.
Reply With Quote