Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   functions for auto (http://www.chiefdelphi.com/forums/showthread.php?t=134956)

curtis0gj 20-02-2015 07:56

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 :mad: . So if anyone is able to help me here's the github link https://github.com/curtis0gj/5033-2014-15?files=1.

Arhowk 20-02-2015 12:17

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) {

missing a } and i assume you mean ""!r.is..." not "!.ris..." (also, its just Timer.delay)

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;
                                }
                        }

the closed loop structure of this will hurt the robot, periodic ms timers are necessary

Code:

r.robot.drive(-.40, -1)
not Java-standard formatting

Code:

                                Boolean maxarmlimit = r.limit4.get();
capital boolean (also that name scheme is bad, both on the variable and the limit)

Code:

                                        r.armmotor.set(Defines.ARM_SPEED);
                                        r.leftarmwheel.set(Relay.Value.kForward);
                                        r.rightarmwheel.set(Relay.Value.kReverse);

non-standard formatting (camelcase, descriptive names)

Code:

                                if (angle > deg) {
comparing a double and an int

Code:

                                r.robot.drive(-.40, -1);
constant loop? atleast a P loop, preferably PID

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

curtis0gj 20-02-2015 14:19

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1447638)
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) {

missing a } and i assume you mean ""!r.is..." not "!.ris..." (also, its just Timer.delay)

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;
                                }
                        }

the closed loop structure of this will hurt the robot, periodic ms timers are necessary

Code:

r.robot.drive(-.40, -1)
not Java-standard formatting

Code:

                                Boolean maxarmlimit = r.limit4.get();
capital boolean (also that name scheme is bad, both on the variable and the limit)

Code:

                                        r.armmotor.set(Defines.ARM_SPEED);
                                        r.leftarmwheel.set(Relay.Value.kForward);
                                        r.rightarmwheel.set(Relay.Value.kReverse);

non-standard formatting (camelcase, descriptive names)

Code:

                                if (angle > deg) {
comparing a double and an int

Code:

                                r.robot.drive(-.40, -1);
constant loop? atleast a P loop, preferably PID

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

Alright thanks I am going to make those changes.

curtis0gj 20-02-2015 17:32

Re: functions for auto
 
should distance be an int or a double and how should I add the periodic timer?

Arhowk 20-02-2015 18:41

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1447827)
should distance be an int or a double and how should I add the periodic timer?

don't double post, use the edit button.

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

curtis0gj 20-02-2015 18:53

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1447847)
don't double post, use the edit button.

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

Alright I added in some delays inside the while(true) loop. I just put the delay as the first line in the loop I don't know if it matters.
https://github.com/curtis0gj/5033-20...ster/Auto.java

Arhowk 20-02-2015 19:05

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;
                }

this block of code is rather... erm...

Why is your wait function inside of a while(true) loop?

curtis0gj 20-02-2015 19:55

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1447859)
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;
                }

this block of code is rather... erm...

Why is your wait function inside of a while(true) loop?

lol I did a very lousy job of naming things, sorry for that and I will change the names to be more descriptive and properly cased. Anyway how can I get the waits to work again? This is the function,

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;
                        }
        }

I'm not sure how to program it, sorry I'm still fairly new to programming.

Arhowk 20-02-2015 20:20

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1447884)
lol I did a very lousy job of naming things, sorry for that and I will change the names to be more descriptive and properly cased. Anyway how can I get the waits to work again? This is the function,


I'm not sure how to program it, sorry I'm still fairly new to programming.

here's what I'd do

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);
    }
}

except without the broken formatting since I made that in this text editor and not a code editor

E/ misunderstood the point of the code, fixed.

curtis0gj 20-02-2015 20:28

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1447892)
here's what I'd do

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);
  }
}

except without the broken formatting since I made that in this text editor and not a code editor

E/ misunderstood the point of the code, fixed.

So what will this whole function be used for calculating turns?

Arhowk 20-02-2015 20:32

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1447897)
So what will this whole function be used for calculating turns?

hm?

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);
    }
}


curtis0gj 20-02-2015 20:38

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1447902)
hm?

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);
    }
}


Does this turn function replace left turn and right turn?

Arhowk 20-02-2015 20:39

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1447903)
Does this turn function replace left turn and right turn?

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.

curtis0gj 20-02-2015 20:51

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1447904)
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.

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.

Arhowk 20-02-2015 22:58

Re: functions for auto
 
apologies, wrapped up in poe.

Quote:

Should I change the static voids to private and add Robot r.
For now, yeah. End game shouldn't have that "Robot r" parameter

Quote:

Also I wanted to know how I can make the wait function work so the robot waits between certain functions.
hm?

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

curtis0gj 20-02-2015 23:01

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1447931)
apologies, wrapped up in poe.


For now, yeah. End game shouldn't have that "Robot r" parameter



hm?

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

Alright thanks, to replace the Robot r parameter could I extend my public class auto to robot or is there another way to do it?

Arhowk 20-02-2015 23:08

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);

or

Code:

Robot robot
public AutonManager(Robot r){
    this.robot =r;
}

//in Robot.java
AutonManager autonManager;
public void robotInit(){
    autonManager = new AutonManager(this);
}


curtis0gj 20-02-2015 23:11

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1447933)
Something like this

Code:

static Robot r
public static void setRobot(Robot rob){
    r = rob;
}


//in Robot.java
AutonManager.setRobot(this);

or

Code:

Robot robot
public AutonManager(Robot r){
    this.robot =r;
}

//in Robot.java
AutonManager autonManager;
public void robotInit(){
    autonManager = new AutonManager(this);
}


Would this be okay?

Code:

public class Auto {
       
        static Robot r
        public static void setRobot(Robot rob) {
                r = rob;
        }

And when I have this in do I need to put r in front of everything still?

Arhowk 20-02-2015 23:14

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1447934)
Would this be okay?

Code:

public class Auto {
       
        static Robot r
        public static void setRobot(Robot rob) {
                r = rob;
        }

And when I have this in do I need to put r in front of everything still?

yeah thats fine. If you don't want to put r in front of everything, you can either

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;
        }


curtis0gj 20-02-2015 23:21

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1447935)
yeah thats fine. If you don't want to put r in front of everything, you can either

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;
        }


Also I was wondering how I can call the new turn function you showed me do I just call turn(r, deg that I want to turn???); And you also said there was an ugly block in robot will it be an issue?

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);
                }
        }

https://github.com/curtis0gj/5033-2014-15

Arhowk 21-02-2015 11:52

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;
          }

this block of code does nothing. Not only does it check every single possible auto state (the entire block is equivalent to autoMethod != null), returning does nothing since there is no more code to be executed. So, all this code does is stall the processor for a few microseconds.

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.

curtis0gj 21-02-2015 16:27

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1448001)
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;
          }

this block of code does nothing. Not only does it check every single possible auto state (the entire block is equivalent to autoMethod != null), returning does nothing since there is no more code to be executed. So, all this code does is stall the processor for a few microseconds.

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.

Ah now I see that the block does nothing.
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?

Arhowk 22-02-2015 12:32

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1448066)
But will my auto chooser still work without the block or will it be fine.

It will be fine. That block is most likely the remnant of a previous auton selector, but since the auton selection process is now done in your Auton.java class, that code was left behind.

Quote:

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)???
As i said before, this is dependent on the current state of the gyro. At the start of the match, the gyro will read 0 (if reset on autonomousInit). Calling turn(90) will turn untill the gyro reads 90, effectively a 90 degree turn to the right. However, since the gyro is now at 90, another call to turn(90) will do nothing since the gyro is already at 90. If you wanted to turn another 90 degrees to the right, you may either call turn(180) or reset() than turn (90), given reset() is a function that calls gyro.reset().

Quote:

and do I need turn(r, 90)?
No. Now that you followed my steps and made a "public static Robot r", all methods should now have access to the robot and you won't need to pass in the "r" parameter anymore.
Quote:

And should I change all my auto functions to public or keep them all private static voids?
"void" is necessary, since it defines the return type of the function. This is not changing.

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);

I believe this is the implementation you chose. The "static" keyword on methods (apologize if I'm late on this but a method is stuff like turn, move, etc.) says that you can call

Code:

AutonManager.startAuton(autonMode);
Without the static keyword, you have to do
Code:

AutonManager m = new AutonManager();
m.startAuton(autonMode);

So, if you chose this implementation

Code:

Robot robot
public AutonManager(Robot r){
    this.robot =r;
}

//in Robot.java
AutonManager autonManager;
public void robotInit(){
    autonManager = new AutonManager(this);
}

than you cannot use the static keyword since there is no static keyword on "robot", thus needing an enclosing instance.

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.

curtis0gj 22-02-2015 16:52

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1448309)
It will be fine. That block is most likely the remnant of a previous auton selector, but since the auton selection process is now done in your Auton.java class, that code was left behind.


As i said before, this is dependent on the current state of the gyro. At the start of the match, the gyro will read 0 (if reset on autonomousInit). Calling turn(90) will turn untill the gyro reads 90, effectively a 90 degree turn to the right. However, since the gyro is now at 90, another call to turn(90) will do nothing since the gyro is already at 90. If you wanted to turn another 90 degrees to the right, you may either call turn(180) or reset() than turn (90), given reset() is a function that calls gyro.reset().


No. Now that you followed my steps and made a "public static Robot r", all methods should now have access to the robot and you won't need to pass in the "r" parameter anymore.

"void" is necessary, since it defines the return type of the function. This is not changing.

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);

I believe this is the implementation you chose. The "static" keyword on methods (apologize if I'm late on this but a method is stuff like turn, move, etc.) says that you can call

Code:

AutonManager.startAuton(autonMode);
Without the static keyword, you have to do
Code:

AutonManager m = new AutonManager();
m.startAuton(autonMode);

So, if you chose this implementation

Code:

Robot robot
public AutonManager(Robot r){
    this.robot =r;
}

//in Robot.java
AutonManager autonManager;
public void robotInit(){
    autonManager = new AutonManager(this);
}

than you cannot use the static keyword since there is no static keyword on "robot", thus needing an enclosing instance.

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.

Thanks for the awesome reply very detailed and understandable. I have made a lot of changes to the code and I think I am nearing completion. I am very pleased and grateful for the help! Later tonight I will give the code a build in eclipse to check for any syntax errors. If you don't mind giving it a final look over, I have removed all of the "r." and I have changed the name for robot, the RobotDrive variable that I define in my Robot.java class to chassis for less confusion.

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.

Arhowk 22-02-2015 20:14

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

Quote:

Originally Posted by curtis0gj (Post 1448383)
Thanks for the awesome reply very detailed and understandable. I have made a lot of changes to the code and I think I am nearing completion. I am very pleased and grateful for the help! Later tonight I will give the code a build in eclipse to check for any syntax errors. If you don't mind giving it a final look over, I have removed all of the "r." and I have changed the name for robot, the RobotDrive variable that I define in my Robot.java class to chassis for less confusion.

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.....

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.

Quote:

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.
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)

curtis0gj 22-02-2015 20:51

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1448487)
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. :eek:

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.

Arhowk 23-02-2015 12:22

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1448498)
Okay I will start making these changes and to you also asked about my experience in java and mentors and 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. :eek:

Heh, same here, except I have ~10 years of programming experience along with ~3 years of Java experience. Too bad I don't have an active passport, else I'd be willing to physically mentor :/ not a whole fan of the text-per-day thing.

Quote:

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...
Same with everyone else I've ever taught, its np.
Quote:

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 and 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
        }


First thing, when you dont specify an object to draw from (referring to the "robot" in "robot.armMotor"), it automatically draws from either the local space (ex. if you wrote "int i = 0") or it draws from the "this" space.

What you're doing here is a few things
Code:

        public Auto(Robot r){
                this.chassis = r.chassis;

(aside from the constructor stuff I talked about)
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"

</endtangent>)

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:

And the detached head issue the link was a bit technical for me but should I consider using google code or something else?
Nah, I'd just try to slow down on the commits. Once/twice per day is fine, with upwards of 10/12 per competition day (1 before, 1 before every match, 1 at the end of the day)
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:

Also: chassis.drive(0, deltaAngle * kp_rotate);
should I change 0 to 0.25 for a speed?
Again, this was pseudocode. (maybe I should stop that :o) The actual function is
Code:

RobotDrive.arcadeDrive(move,rotate);
as used in your Robot.java. "move" defines the value to move forward or backward and "rotate" defines left or right. Having a 0 move will cause the robot to spin in place. If you want the robot to turn without actually moving anywhere, than a 0 move is needed.
Quote:

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.
Always.

curtis0gj 23-02-2015 12:39

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1448709)
Heh, same here, except I have ~10 years of programming experience along with ~3 years of Java experience. Too bad I don't have an active passport, else I'd be willing to physically mentor :/ not a whole fan of the text-per-day thing.


Same with everyone else I've ever taught, its np.

First thing, when you dont specify an object to draw from (referring to the "robot" in "robot.armMotor"), it automatically draws from either the local space (ex. if you wrote "int i = 0") or it draws from the "this" space.

What you're doing here is a few things
Code:

        public Auto(Robot r){
                this.chassis = r.chassis;

(aside from the constructor stuff I talked about)
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"

</endtangent>)

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.


Nah, I'd just try to slow down on the commits. Once/twice per day is fine, with upwards of 10/12 per competition day (1 before, 1 before every match, 1 at the end of the day)
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)


Again, this was pseudocode. (maybe I should stop that :o) The actual function is
Code:

RobotDrive.arcadeDrive(move,rotate);
as used in your Robot.java. "move" defines the value to move forward or backward and "rotate" defines left or right. Having a 0 move will cause the robot to spin in place. If you want the robot to turn without actually moving anywhere, than a 0 move is needed.

Always.


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.

Arhowk 23-02-2015 13:08

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1448718)
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.

"chassis" is an instance of RobotDrive. The "drive" function of RobotDrive is wierd and "turn" in auton should be using "arcadeDrive", not "drive".

curtis0gj 23-02-2015 14:47

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1448733)
"chassis" is an instance of RobotDrive. The "drive" function of RobotDrive is wierd and "turn" in auton should be using "arcadeDrive", not "drive".

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

Arhowk 23-02-2015 17:17

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1448771)
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)

curtis0gj 23-02-2015 17:40

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1448852)
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...".

Arhowk 23-02-2015 17:50

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1448861)
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"

curtis0gj 23-02-2015 18:14

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1448866)
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);


Arhowk 23-02-2015 20:30

Re: functions for auto
 
looks good, except for the fact that the "this" parameter is no longer necessary.

curtis0gj 23-02-2015 20:39

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1448922)
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

Arhowk 25-02-2015 20:47

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

curtis0gj 25-02-2015 21:44

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1449905)
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.

Arhowk 26-02-2015 14:36

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 (Post 1449926)
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

curtis0gj 26-02-2015 17:40

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1450227)
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);
                }
        }


Arhowk 28-02-2015 16:56

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.

curtis0gj 28-02-2015 17:07

Re: functions for auto
 
Quote:

Originally Posted by Arhowk (Post 1451164)
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?

Arhowk 28-02-2015 19:24

Re: functions for auto
 
Quote:

Originally Posted by curtis0gj (Post 1451165)
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.


All times are GMT -5. The time now is 11:16.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi