|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: functions for auto
The new turn function does, yes, since the error will be positive or negative depending on where the setpoint is in comparison to the experimental and thus doesn't need seperate cases depending on left or right.
|
|
#2
|
|||
|
|||
|
Re: functions for auto
Should I change the static voids to private and add Robot r. Also I wanted to know how I can make the wait function work so the robot waits between certain functions.
|
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
Re: functions for auto
Quote:
|
|
#5
|
||||
|
||||
|
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);
}
|
|
#6
|
|||
|
|||
|
Re: functions for auto
Quote:
Code:
public class Auto {
static Robot r
public static void setRobot(Robot rob) {
r = rob;
}
|
|
#7
|
||||
|
||||
|
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;
}
|
|
#8
|
|||
|
|||
|
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. |
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||
|
|||
|
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. |
|
#11
|
||||
|
||||
|
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. |
|
#12
|
|||
|
|||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|