OCCRA
Go to Post As usual this was the programmers fault. - Swampdude [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 10-13-2018, 01:38 PM
h1d3m3 h1d3m3 is offline
Registered User
no team
 
Join Date: Feb 2018
Location: NY
Posts: 9
h1d3m3 is an unknown quantity at this point
PID and Analog Feedback Encoder That Wraps

Hello!

Have a TalonSRX attached to an absolute encoder (am-2899) defined as such:

Code:
_talon.configSelectedFeedbackSensor(FeedbackDevice.Analog, PIDLOOP_IDX, TIMEOUT_MS);
_talon.configSetParameter(ParamEnum.eFeedbackNotContinuous, 0, 0, 0, 0); // wrap the position (1023 -> 0)
PID is working as expected, but there is one thing that I'd like to change.

When the encoder is at 1000 (out of 1023) and we set it to 0, it will take the long way back around to 0. In other words, it will revolve -1000 instead of "knowing" that it could have just gone +24 and wrapped to 0.

Is this something the SRX PID algorithm could be adjusted for or is this something that I have to handle a different way. IIRC PIDCommand does the short trip when I used it in a different context. Maybe I'm not thinking about this correctly...

Thanks.
Reply With Quote
  #2   Spotlight this post!  
Unread 10-13-2018, 08:17 PM
asid61's Avatar
asid61 asid61 is offline
Design Simple
AKA: Anand Rajamani
FRC #1072 (Harker Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Cupertino, CA
Posts: 3,053
asid61 has a reputation beyond reputeasid61 has a reputation beyond reputeasid61 has a reputation beyond reputeasid61 has a reputation beyond reputeasid61 has a reputation beyond reputeasid61 has a reputation beyond reputeasid61 has a reputation beyond reputeasid61 has a reputation beyond reputeasid61 has a reputation beyond reputeasid61 has a reputation beyond reputeasid61 has a reputation beyond repute
Re: PID and Analog Feedback Encoder That Wraps

I'd raise a flag with Omar at CTRE about this. I'd also like to see wrapping being handled natively.

You can always check your current position and set the new target equal to 360 or 0, whichever is closer. The easiest way to do that would be to check
current_pos modulo ticks_per_rotation
and see if that's bigger than half a rotation. If it is, make
ticks_per_rotation*((current_pos)/(ticks_per_rotation)+1)
your target. That will make your target equal to the closest multiple of 360. Of course, add your target onto that if your target is greater than 0.
__________________
Team 1072 2017-present
Team 299 2017
Team 115 2013-2016 (student)

2018 Davis Finalists (w/ 6474 and 3880), 2018 Roebling Winners (w/ 3476, 1323, and 1778)

Reply With Quote
  #3   Spotlight this post!  
Unread 10-13-2018, 10:08 PM
Oblarg Oblarg is offline
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,900
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: PID and Analog Feedback Encoder That Wraps

Quote:
Originally Posted by asid61 View Post
I'd raise a flag with Omar at CTRE about this. I'd also like to see wrapping being handled natively.
Always check the github.
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016


FRC Drivetrain Characterization
Reply With Quote
  #4   Spotlight this post!  
Unread 10-13-2018, 10:41 PM
cpapplefamily's Avatar
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 744
cpapplefamily is a splendid one to beholdcpapplefamily is a splendid one to beholdcpapplefamily is a splendid one to beholdcpapplefamily is a splendid one to beholdcpapplefamily is a splendid one to beholdcpapplefamily is a splendid one to beholdcpapplefamily is a splendid one to behold
Re: PID and Analog Feedback Encoder That Wraps

Quote:
Originally Posted by asid61 View Post
I'd raise a flag with Omar at CTRE about this. I'd also like to see wrapping being handled natively.

You can always check your current position and set the new target equal to 360 or 0, whichever is closer. The easiest way to do that would be to check
current_pos modulo ticks_per_rotation
and see if that's bigger than half a rotation. If it is, make
ticks_per_rotation*((current_pos)/(ticks_per_rotation)+1)
your target. That will make your target equal to the closest multiple of 360. Of course, add your target onto that if your target is greater than 0.
I will have to play around now you generated some question. Can you configure a encoder to reset each rotation or will you return a value of 720 after two rotations?

We currently run a PIDcommand to spin our robot to heading. An incomplete snip shown sets the PIDController().setContinuous(true)
Code:
public Drive_Turn_To_Setpoint_InTeleop(double x, double y, double setpoint) {
   
        super("turnController", kP, kI, kD, 0.02);
        getPIDController().setInputRange(-180.0f,  180.0f);
        getPIDController().setOutputRange(-0.75, 0.75);
        getPIDController().setAbsoluteTolerance(kToleranceDegrees);
        getPIDController().setContinuous(true);
 
        requires(Robot.drive);
        m_x = x;
    	m_y = y;
        m_setpoint = setpoint;
        
    }
When we command a heading it all way takes the most direct path. If we are at 89 deg and command -90 it goes through 0, If we are at 91 deg it will go through 180. We are using a NavX gyro and believe the .getAngle() already returns the modulo of the rotation since reset.

Looks like CTRE needs to implement a set feedback as setContinuous. Maybe also set feedback as linear (ex drive trains) or rotational (ex shooter turret with 360 dof)

Looks like they do
Code:
/**
     * Disables wrapping the position. If the signal goes from 1023 to 0 a motor 
     * controller will by default go to 1024. If wrapping the position is disabled,
     * it will go to 0;


configFeedbackNotContinuous(boolean feedbackNotContinuous, int timeoutMs)
__________________
It makes sense in my mind.




Last edited by cpapplefamily : 10-13-2018 at 10:45 PM. Reason: followed the link They do
Reply With Quote
  #5   Spotlight this post!  
Unread 10-14-2018, 09:52 AM
h1d3m3 h1d3m3 is offline
Registered User
no team
 
Join Date: Feb 2018
Location: NY
Posts: 9
h1d3m3 is an unknown quantity at this point
Re: PID and Analog Feedback Encoder That Wraps

Quote:
Originally Posted by asid61 View Post
You can always check your current position and set the new target equal to 360 or 0, whichever is closer.
Thanks for the reply.

I'm a little new to some of this so bear with me. Even if I know the shortest path, you still have to deal with encoder clicks. With PID, I don't know how to say "hey, go from where you are at position 1000 to position 0, but increase your values to get there" (i.e. 1000-> 1023 -> 0) Seems like all I have is a set position function and it does the rest.
Reply With Quote
  #6   Spotlight this post!  
Unread 10-14-2018, 10:08 AM
h1d3m3 h1d3m3 is offline
Registered User
no team
 
Join Date: Feb 2018
Location: NY
Posts: 9
h1d3m3 is an unknown quantity at this point
Re: PID and Analog Feedback Encoder That Wraps

Quote:
Originally Posted by Oblarg View Post
That's interesting. The version of CTRE-phoenix-java i'm using (5.5.1.0) doesn't have that function. Also the docs seem to point to using eFeedbackNotContinuous (see section 7.5.2.1 in the software reference manual). More digging to do I guess.
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 04:48 AM.

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


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