Go to Post I don't think we really fit into those rigidly defined categories, my team builds our robot. - AdamHeard [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
  #16   Spotlight this post!  
Unread 11-24-2015, 03:25 PM
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 516
ozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant future
Re: Using encoder with talon SRX

If you are using RobotBuilder then you can to a "whenPressed" action...
https://wpilib.screenstepslive.com/s...e-to-a-command

If you are using command classes yourself there is a Button class you could wire into the scheduler.

If you are just writing straight java, I usually just copy/paste the following...

Code:
//instance variables
    boolean [] btns  = new boolean [] {false,false,false,false,false};
    boolean [] last  = new boolean [] {false,false,false,false,false};
Code:
//get latest
    public void teleopPeriodic() {

        btns[1] = _joy.getRawButton(1);
    	btns[2] = _joy.getRawButton(2);
    	btns[3] = _joy.getRawButton(3);
    	btns[4] = _joy.getRawButton(4);
Code:
    	if(!last[3] && btns[3]){
    		//btn3 just pressed, do something
    	}

Code:
// bottom of teleop save all btns into last
		for(i=0;i<last.length;++i)
			last[i] = btns[i];
Reply With Quote
  #17   Spotlight this post!  
Unread 11-24-2015, 03:46 PM
riftware riftware is offline
Parent Mentor
AKA: Andrew Chandler
FRC #0031
Team Role: Mentor
 
Join Date: Dec 2013
Rookie Year: 2011
Location: Tulsa
Posts: 27
riftware is an unknown quantity at this point
Re: Using encoder with talon SRX

As for the self-test and PID things - I had already verified the encoder position is increasing when the talon flashes green so we're good there. The pid values were just ones that were in example earlier in the thread. Honestly I have a bit of a mental block on PID. I must have read the tutorials a dozen times. I'll take a look at it in just a moment. Thankfully I've got my first decent stretch of time with a test rig of my own so I can use my usual tactic of sheer stubbornness to get this down pat. Thanks for all the help everyone.
Reply With Quote
  #18   Spotlight this post!  
Unread 11-24-2015, 03:48 PM
riftware riftware is offline
Parent Mentor
AKA: Andrew Chandler
FRC #0031
Team Role: Mentor
 
Join Date: Dec 2013
Rookie Year: 2011
Location: Tulsa
Posts: 27
riftware is an unknown quantity at this point
Re: Using encoder with talon SRX

I think I had found my problem - I am using the 2016 version of Robotbuilder I built from source (yay talon srx now works!) - I hadn't noticed when I threw the button in that it defaulted to while pressed not when pressed.


Quote:
Originally Posted by ozrien View Post
If you are using RobotBuilder then you can to a "whenPressed" action...
https://wpilib.screenstepslive.com/s...e-to-a-command

If you are using command classes yourself there is a Button class you could wire into the scheduler.

If you are just writing straight java, I usually just copy/paste the following...

Code:
//instance variables
    boolean [] btns  = new boolean [] {false,false,false,false,false};
    boolean [] last  = new boolean [] {false,false,false,false,false};
Code:
//get latest
    public void teleopPeriodic() {

        btns[1] = _joy.getRawButton(1);
    	btns[2] = _joy.getRawButton(2);
    	btns[3] = _joy.getRawButton(3);
    	btns[4] = _joy.getRawButton(4);
Code:
    	if(!last[3] && btns[3]){
    		//btn3 just pressed, do something
    	}

Code:
// bottom of teleop save all btns into last
		for(i=0;i<last.length;++i)
			last[i] = btns[i];
Reply With Quote
  #19   Spotlight this post!  
Unread 11-24-2015, 09:27 PM
riftware riftware is offline
Parent Mentor
AKA: Andrew Chandler
FRC #0031
Team Role: Mentor
 
Join Date: Dec 2013
Rookie Year: 2011
Location: Tulsa
Posts: 27
riftware is an unknown quantity at this point
Re: Using encoder with talon SRX

Quote:
Originally Posted by ozrien View Post
Hey riftware,

ClosedLoopErr is what is multiplied by Kp, and is equal to your target - current sensor position (or velocity if that's selected). Since you are using quad encoder, then there is 4XCPR units per rotation where CPR=countsPerRotation. Talon is always in 4X mode.

Integral accum sums closedLoopErr every 1ms.
dErr is the change in ClosedLoopErr per 1ms.
Ok so let me expose the massive understanding issue I have.
I want to travel 10' on one wheel.
1: Asuming a 6" wheel diameter I get a circumfrence of 18.84 inches I believe this means I will need to travel 6.36 revolutions.
2: I am using the e4p-360 encoder so its 360 ticks per revolution, except that its quadrature so I multiply that by 4 meaning we really see 1440 counts per revolution. Based on that I think I want a target of +9158.4 (or negative if I'm going backwards.

3: (a little hazier here) - Do I need to include current position or is that implied? My concern is I don't want to do whatever it takes to get to count 5000, I want to add or subtract 5000 to where I am now - or do I need to reset the counter to 0 first?
Code:
int currentPosition = talon.getEncPosition();
talon.set((currentPosition + 9158));
4: PID - P is the constant that gets multiplied by the error (initially the error is 9158 when we start?). Is there a good rule of thumb for picking a P on a drive system as opposed to something like an Arm?
'I' is the Integral - a smaller value gives faster control? - Is there a range to work within or a rough rule of thumb?
'D' is the derivative which if I understood correctly helps prevent overshoot? Higher value reacts faster?


I've tried the numbers from both previous examples and I'm going to continue to try them, but what I don't understand is how they were chosen.

Also in all of this is there a way to indicate an acceptable error margin? Like +/- 5 inches or something?

Finally - when I call this command is there a way for me to set how fast I want to travel (like 1/2 speed or something?)

Last edited by riftware : 11-24-2015 at 09:31 PM.
Reply With Quote
  #20   Spotlight this post!  
Unread 11-24-2015, 09:42 PM
riftware riftware is offline
Parent Mentor
AKA: Andrew Chandler
FRC #0031
Team Role: Mentor
 
Join Date: Dec 2013
Rookie Year: 2011
Location: Tulsa
Posts: 27
riftware is an unknown quantity at this point
Re: Using encoder with talon SRX

I may have just got it to work (perhaps)!

I think my problem was I was calling talon.set(9158) instead of setPosition(9158)
I say perhaps because the selftest screen shows much different numbers than talon.getEncPosition() ...still working on it but I may be making progress.
Reply With Quote
  #21   Spotlight this post!  
Unread 11-24-2015, 10:27 PM
riftware riftware is offline
Parent Mentor
AKA: Andrew Chandler
FRC #0031
Team Role: Mentor
 
Join Date: Dec 2013
Rookie Year: 2011
Location: Tulsa
Posts: 27
riftware is an unknown quantity at this point
Re: Using encoder with talon SRX

Ok - I seem to have gotten it working. Understanding is coming slowly. By calling set or setPosition (either seems to work?) I am basically telling the system the encoder current position is 9158 away from a 0 error state, at which point the PID system works to try and correct that. These values seem to work for me, not really sure why (placebo effect maybe?) but the longer version of setPid really seemed to cut down on the overshoot issue. The following code isn't pretty and I'm definitely cleaning it up but it gives me repeatable results. If anyone has any comments or wants to help me know why the values I've chosen seem to work well I'll be happy but I'm no longer banging my head against the wall. Thank you to everyone who patiently helped out. I'm excited that we may have a more intelligent autonomous mode than previous years (drive forward 4 seconds to get into next zone).
Code:
    protected void execute() {
    	if(busy) {return;}
    	busy = true;
    	finished = false;
    	System.out.println("Start of Execute");
    	RobotDrive drive = RobotMap.driveSystemdrive;
    	CANTalon talon =  RobotMap.driveSystemCANTalon2;
    	talon.changeControlMode(ControlMode.Position); //Change control mode of talon, default is PercentVbus (-1.0 to 1.0)
    	talon.setFeedbackDevice(FeedbackDevice.QuadEncoder); //Set the feedback device that is hooked up to the talon
    
    	talon.setPID(0.5, 0.001, 0.00, 0.00, 360, 36, 0); //Set the PID constants (p, i, d)
    	
    	talon.enableControl(); //Enable PID control on the talon
    	int currentPosition = talon.getEncPosition();
    	System.out.println(currentPosition);
    	talon.setPosition( 9158); 
    }

// Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
    	if(RobotMap.driveSystemCANTalon2.getPosition() < 80){
    		finished = true;
    		busy = false;
    	}
        return finished;
    }
Reply With Quote
  #22   Spotlight this post!  
Unread 11-24-2015, 11:18 PM
Poseidon5817's Avatar
Poseidon5817 Poseidon5817 is offline
"Cool" Squad
AKA: Mitchel Stokes
FRC #5817 (Uni-Rex)
Team Role: Mentor
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Clovis, CA
Posts: 341
Poseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to behold
Re: Using encoder with talon SRX

set() and setPosition() do not do the same thing. set() changes the setpoint of the motor (make it go to 7530 counts, etc.), while setPosition() "zeroes" the encoder, keeping the setpoint the same. For example, setPosition(0) redefines the current encoder position to be 0. However, if the previous setpoint was 7350 before zeroing, it will auto-correct to the new 7350 (7350 counts ahead of where the old 7350 used to be).
__________________
My FRC History:

2014 - Team 1671: Central Valley Regional Finalist and Chairman's Award Winner, Sacramento Regional Finalist, Archimedes Quarterfinalist
2015 - Team 1671: Central Valley Regional Semifinalist, Sacramento Regional Semifinalist and Chairman's Award Winner, Newton Winner, Einstein Winner
2016 - Team 5817: Central Valley Regional Finalist and Rookie All-Star, Orange County Regional Quarterfinalist and Rookie All-Star, Newton Division


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 07:53 AM.

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