View Single Post
  #12   Spotlight this post!  
Unread 22-02-2015, 16:52
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
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.

Last edited by curtis0gj : 22-02-2015 at 19:13.
Reply With Quote