Go to Post I cannot inspire greatness with mediocrity! - Jim Zondag [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, 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
  #2   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
  #3   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
  #4   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
  #5   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
  #6   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
  #7   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
  #8   Spotlight this post!  
Unread 20-02-2015, 23:11
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
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?
Reply With Quote
  #9   Spotlight this post!  
Unread 20-02-2015, 23:14
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
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;
	}
Reply With Quote
  #10   Spotlight this post!  
Unread 20-02-2015, 23:21
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
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

Last edited by curtis0gj : 21-02-2015 at 00:05.
Reply With Quote
  #11   Spotlight this post!  
Unread 21-02-2015, 11:52
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

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.

Last edited by Arhowk : 21-02-2015 at 11:54.
Reply With Quote
  #12   Spotlight this post!  
Unread 21-02-2015, 16:27
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
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?

Last edited by curtis0gj : 22-02-2015 at 10:52.
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