|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
|||
|
|||
|
Re: functions for auto
Quote:
|
|
#17
|
||||
|
||||
|
Re: functions for auto
Something like this
Code:
static Robot r
public static void setRobot(Robot rob){
r = rob;
}
//in Robot.java
AutonManager.setRobot(this);
Code:
Robot robot
public AutonManager(Robot r){
this.robot =r;
}
//in Robot.java
AutonManager autonManager;
public void robotInit(){
autonManager = new AutonManager(this);
}
|
|
#18
|
|||
|
|||
|
Re: functions for auto
Quote:
Code:
public class Auto {
static Robot r
public static void setRobot(Robot rob) {
r = rob;
}
|
|
#19
|
||||
|
||||
|
Re: functions for auto
Quote:
1) rename r to robot (atleast it looks more professional...) 2) Code:
public class Auto {
static Robot r
static RobotDrive drive
static DigitalInput upperLimitSwitch
//and so on for other stuff
public static void setRobot(Robot rob) {
r = rob;
drive = r.drive;
upperLimitSwitch = r.limit4;
}
|
|
#20
|
|||
|
|||
|
Re: functions for auto
Quote:
Code:
public void autonomous() {
autoMethod = (Defines.Autos) autoChooser.getSelected();
Auto.run(this, autoMethod);
if (autoMethod == Defines.Autos.AUTO_GRAB_ONE_BIN_BLUE_SIDE) {
return;
} else if (autoMethod == Defines.Autos.AUTO_GRAB_ONE_BIN_RED_SIDE) {
return;
} else if (autoMethod == Defines.Autos.AUTO_MOVE_TO_ZONE) {
return;
} else if (autoMethod == Defines.Autos.AUTO_GRAB_TWO_BINS_RED_SIDE) {
return;
} else if (autoMethod == Defines.Autos.AUTO_GRAB_TWO_BINS_BLUE_SIDE) {
return;
}
}
Code:
public static 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;
public static void turn(Robot r, double deg) {
while(true) {
double deltaAngle = angleError(deg, gyro.getAngle());
if(Math.abs(deg - deltaAngle) < MAX_ERROR) {
break;
} else {
r.robot.drive(0, deltaAngle * kp_rotate);
}
Timer.delay(0.02);
}
}
Last edited by curtis0gj : 21-02-2015 at 00:05. |
|
#21
|
||||
|
||||
|
Re: functions for auto
Code:
if (autoMethod == Defines.Autos.AUTO_GRAB_ONE_BIN_BLUE_SIDE) {
return;
} else if (autoMethod == Defines.Autos.AUTO_GRAB_ONE_BIN_RED_SIDE) {
return;
} else if (autoMethod == Defines.Autos.AUTO_MOVE_TO_ZONE) {
return;
} else if (autoMethod == Defines.Autos.AUTO_GRAB_TWO_BINS_RED_SIDE) {
return;
} else if (autoMethod == Defines.Autos.AUTO_GRAB_TWO_BINS_BLUE_SIDE) {
return;
}
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. Last edited by Arhowk : 21-02-2015 at 11:54. |
|
#22
|
|||
|
|||
|
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? Last edited by curtis0gj : 22-02-2015 at 10:52. |
|
#23
|
||||
|
||||
|
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 r
public static void setRobot(Robot rob){
r = rob;
}
//in Robot.java
AutonManager.setRobot(this);
Code:
AutonManager.startAuton(autonMode); Code:
AutonManager m = new AutonManager(); m.startAuton(autonMode); Code:
Robot robot
public AutonManager(Robot r){
this.robot =r;
}
//in Robot.java
AutonManager autonManager;
public void robotInit(){
autonManager = new AutonManager(this);
}
See 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. |
|
#24
|
|||
|
|||
|
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. Last edited by curtis0gj : 22-02-2015 at 19:13. |
|
#25
|
||||
|
||||
|
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 robot
public AutonManager(Robot r){
this.robot = r;
}
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) {
Code:
Robot robot 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? Quote:
Code:
public class Robot{
public RobotDrive chassis;
public Joystick stick;
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
}
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) Last edited by Arhowk : 22-02-2015 at 20:18. |
|
#26
|
|||
|
|||
|
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. 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
}
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. |
|
#27
|
||||||
|
||||||
|
Re: functions for auto
Quote:
Quote:
Quote:
What you're doing here is a few things Code:
public Auto(Robot r){
this.chassis = r.chassis;
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; Integer integ = new Integer(i); System.out.println(integ.intValue());//will print 0 since it was passed 0 i = 55; System.out.println(integ.intValue());//will still print 0 since it was passed 0, it was passed the value 0 not the variable "i" 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:
) The actual function isCode:
RobotDrive.arcadeDrive(move,rotate); Quote:
|
|
#28
|
|||
|
|||
|
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. Last edited by curtis0gj : 23-02-2015 at 13:08. |
|
#29
|
||||
|
||||
|
Re: functions for auto
"chassis" is an instance of RobotDrive. The "drive" function of RobotDrive is wierd and "turn" in auton should be using "arcadeDrive", not "drive".
|
|
#30
|
|||
|
|||
|
Re: functions for auto
Quote:
https://github.com/curtis0gj/5033-20...ster/Auto.java Last edited by curtis0gj : 23-02-2015 at 15:34. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|