Go to Post "You know you're a robotics kid when you sit on Chief Delphi and hit refresh over and over again waiting for new pictures and videos of other teams" - pwnageNick [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, 07:56
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
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 20-02-2015, 12:17
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

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

Last edited by Arhowk : 20-02-2015 at 12:19.
Reply With Quote
  #3   Spotlight this post!  
Unread 20-02-2015, 14:19
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
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 20-02-2015, 17:32
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

should distance be an int or a double and how should I add the periodic timer?
Reply With Quote
  #5   Spotlight this post!  
Unread 20-02-2015, 18:41
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
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
Reply With Quote
  #6   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
  #7   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
  #8   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
  #9   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
  #10   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
  #11   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
  #12   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
  #13   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
  #14   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
  #15   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
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 08:37.

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