Go to Post I personally think mentors should sit behind two-way mirrors and hold a kill switch for all power tools. ;) - SenorZ [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-02-2015, 18:53
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
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
Reply With Quote
  #2   Spotlight this post!  
Unread 20-02-2015, 19:05
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
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?

Last edited by Arhowk : 20-02-2015 at 19:09.
Reply With Quote
  #3   Spotlight this post!  
Unread 20-02-2015, 19:55
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
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 20-02-2015, 20:20
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: functions for auto

Quote:
Originally Posted by curtis0gj View Post
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.

Last edited by Arhowk : 20-02-2015 at 20:27.
Reply With Quote
  #5   Spotlight this post!  
Unread 20-02-2015, 20:28
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
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?
Reply With Quote
  #6   Spotlight this post!  
Unread 20-02-2015, 20:32
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: functions for auto

Quote:
Originally Posted by curtis0gj View Post
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);
    }
}
Reply With Quote
  #7   Spotlight this post!  
Unread 20-02-2015, 20:38
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
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?
Reply With Quote
  #8   Spotlight this post!  
Unread 20-02-2015, 20:39
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: functions for auto

Quote:
Originally Posted by curtis0gj View Post
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.
Reply With Quote
  #9   Spotlight this post!  
Unread 20-02-2015, 20:51
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
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.
Reply With Quote
  #10   Spotlight this post!  
Unread 20-02-2015, 22:58
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
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
Reply With Quote
  #11   Spotlight this post!  
Unread 20-02-2015, 23:01
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
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?
Reply With Quote
  #12   Spotlight this post!  
Unread 20-02-2015, 23:08
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
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);
}
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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