|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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
. So if anyone is able to help me here's the github link https://github.com/curtis0gj/5033-2014-15?files=1. |
|
#2
|
||||
|
||||
|
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) {
while (true) {
if (!.risAutonomous() || !r.isEnabled()) return;
r.Timer.delay(waittime); //r or just timer?
return;
}
private static void reset(Robot r) {
passing in Robot for everything is ugh-ly. just make Robot a singleton... or use a static initializer Code:
while (true) {
double distance = r.encoder.get();
double angle = r.gyro.getAngle();
if (!r.isAutonomous() || !r.isEnabled()) return;
r.robot.drive(-0.25, angle * r.Kp);
//r.robot.drive(-0.40, 0);
if (distance < -d) {
reset(r);
return;
}
}
Code:
r.robot.drive(-.40, -1) Code:
Boolean maxarmlimit = r.limit4.get(); Code:
r.armmotor.set(Defines.ARM_SPEED); r.leftarmwheel.set(Relay.Value.kForward); r.rightarmwheel.set(Relay.Value.kReverse); 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 Last edited by Arhowk : 20-02-2015 at 12:19. |
|
#3
|
|||
|
|||
|
Re: functions for auto
Quote:
|
|
#4
|
|||
|
|||
|
Re: functions for auto
should distance be an int or a double and how should I add the periodic timer?
|
|
#5
|
||||
|
||||
|
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 |
|
#6
|
|||
|
|||
|
Re: functions for auto
Quote:
https://github.com/curtis0gj/5033-20...ster/Auto.java |
|
#7
|
||||
|
||||
|
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) {
return;
} else if (autoMethod == Defines.AUTOS.AUTO_MOVE) {
return;
} else if (autoMethod == Defines.AUTOS.AUTO_TWORED) {
return;
} else if (autoMethod == Defines.AUTOS.AUTO_TWOBLUE) {
return;
}
Why is your wait function inside of a while(true) loop? Last edited by Arhowk : 20-02-2015 at 19:09. |
|
#8
|
|||
|
|||
|
Re: functions for auto
Quote:
Code:
public static void turn(Robot r, double deg) {
while (true) {
double angle = r.gyro.getAngle();
if (!r.isAutonomous() || !r.isEnabled()) return;
if(angle < 70) {
turnRight(r, 70);
} else {
turnLeft(r, -70);
reset(r);
break;
}
}
|
|
#9
|
||||
|
||||
|
Re: functions for auto
Quote:
Code:
public static void turn(Robot r, double deg) {
if(deg < gyro.getAngle()){ //this is not right, need to have a function to handle rollovers
//example for such a function: if Math.abs(deg-gyro.getAngle()) < 90 || Math.abs(deg-gyro.getAngle()) > 270
//i dont know, just thinking to myself. see here for further instructions -> http://stackoverflow.com/questions/1878907/the-smallest-difference-between-2-angles
turnLeft(r,deg);
}else{
turnRight(r,deg);
}
}
public static void turnRight(Robot r, double deg){
while(true){
//turn right
if(distanceBetweenAngles(getGyro(),deg) <= MAX_ROTATE_ERROR){
return; //or break; whatever
}
Timer.delay(0.02);
}
}
E/ misunderstood the point of the code, fixed. Last edited by Arhowk : 20-02-2015 at 20:27. |
|
#10
|
|||
|
|||
|
Re: functions for auto
Quote:
|
|
#11
|
||||
|
||||
|
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){
double err = setpointDegressZeroToThreeSixty - experimentalDegrees; //0 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(double deg){
while(true){
double deltaAngle = angleError(deg, gyro.getAngle());
if(Math.abs(deg-deltaAngle) < MAX_ERROR){
break;
}else{
robot.drive(0, deltaAngle*kp_rotate); //drive taking a move and a rotate value
}
Timer.delay(0.02);
}
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|