Go to Post Perfection of a system comes not when you can add nothing more but instead when you can remove nothing. - Andrew Schreiber [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 Rating: Thread Rating: 29 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 20-12-2011, 01:59
Mk.32's Avatar
Mk.32 Mk.32 is offline
Registered User
AKA: Mark
FRC #2485 (W.A.R. Lords)
Team Role: Engineer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: San Diego
Posts: 770
Mk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud of
JAVA PID with Encoders

Hello all,
We were able to get the PIDController to work great with the gyro but are having problems with the encoders.

Here is the part of the code we are using: the problem is when I run autoN it does nothing. The Output class doesn't print nor does the robot move.

Quote:
package TestRobot;
import edu.wpi.first.wpilibj.*;

public class RobotMain extends IterativeRobot {

public static LinearVictor VictorLeft = new LinearVictor(1);
public static LinearVictor VictorRight = new LinearVictor(3);

Encoder LeftEncoder = new Encoder(4,6,4,7,false,CounterBase.EncodingType.k2X );
PIDEncoderClass PidWriteEncoder = new PIDEncoderClass();
PIDController PidEncoder1 = new PIDController(0.1,0,0,LeftEncoder,PidWriteEncoder) ;

public void robotInit() {
System.out.println("ROBOT IS ON.");
LeftEncoder.start();
}

public void autonomousPeriodic() {
System.out.println("AutoN");
PidEncoder1.enable();
PidEncoder1.setSetpoint(10000);
}

public void teleopPeriodic() {
System.out.println("TeloP");
System.out.println(LeftEncoder.getRaw());
}

}
Quote:
package TestRobot;
import edu.wpi.first.wpilibj.PIDOutput;

public class PIDEncoderClass implements PIDOutput{

public void pidWrite(double output) {

System.out.println("Output " + output);

RobotMain.VictorLeft.set(output);
RobotMain.VictorRight.set(output);
}

}
__________________
Engineering mentor: Team 2485: WARLords 2013-

Team President: Team 3647 2010-2013

Last edited by Mk.32 : 20-12-2011 at 02:07.
Reply With Quote
  #2   Spotlight this post!  
Unread 20-12-2011, 03:02
Jeremy Germita's Avatar
Jeremy Germita Jeremy Germita is offline
Co-Advisor/Lead Engineering Mentor
AKA: wood is good. plastic is fantastic.
FRC #5012 (Gryffingear) / (Antelope Valley FIRST Teams)
Team Role: Coach
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Lancaster, CA
Posts: 285
Jeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond repute
Re: JAVA PID with Encoders

Mark,

Quote:
Encoder LeftEncoder = new Encoder(4,6,4,7,false,CounterBase.EncodingType.k2X );
are you using the KOP Encoders? They are quadrature encoders, if I remember correctly.

This constructor should work:
Code:
Encoder(DigitalSource aSource, DigitalSource bSource, boolean reverseDirection)
the constructor seems to be the only issue that jumps out at me. Also, there is always the usual "double check your connections and wiring".
__________________
Drive Coach Team 5012 Gryffingear / Antelope Valley FIRST teams / EWCP - (2013 - Current)
Student / Driver / Programmer / CAD - FRC Team 399: Eagle Robotics / FTC Team 72: GarageBots - (2009 - 2013)
Los Angeles Region FTC FTA/CSA/Head Ref
[FF] FIRST Pick
2014 FTC Los Angeles Regional Compass Award Winner.

2017 - San Diego Regional / Sacramento Regional / Las Vegas Regional
2016 - Los Angeles Regional Creativity + Winners (1197, 987, 5012) / Las Vegas Regional Team Spirit + SF (5012, 5851, 5049) / Galileo Subdivision
2015 - Inland Empire QF (597, 5012, 4413) / Las Vegas Imagery + Winners (148, 987, 5012) / Newton Subdivision and World Champions (118, 1678, 1671, 5012)
2014 - Inland Empire Rookie All Star + Highest Rookie Seed + SF (2339, 1967, 5012) / Las Vegas Rookie All Star / Galileo Division Imagery
Reply With Quote
  #3   Spotlight this post!  
Unread 20-12-2011, 03:14
Mk.32's Avatar
Mk.32 Mk.32 is offline
Registered User
AKA: Mark
FRC #2485 (W.A.R. Lords)
Team Role: Engineer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: San Diego
Posts: 770
Mk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud of
Re: JAVA PID with Encoders

Yes they are the usDigital KOP encoders.
You can set them to be 1x 2x or 4x, I have tried all four without success. I have also used that constructor without the "CounterBase.EncodingType.k2X" and it still refused to work.

Running encoder.get() the values print fine.
__________________
Engineering mentor: Team 2485: WARLords 2013-

Team President: Team 3647 2010-2013
Reply With Quote
  #4   Spotlight this post!  
Unread 20-12-2011, 03:19
Jeremy Germita's Avatar
Jeremy Germita Jeremy Germita is offline
Co-Advisor/Lead Engineering Mentor
AKA: wood is good. plastic is fantastic.
FRC #5012 (Gryffingear) / (Antelope Valley FIRST Teams)
Team Role: Coach
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Lancaster, CA
Posts: 285
Jeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond repute
Re: JAVA PID with Encoders

If you want a working solution now, I suggest writing your own PID controller.

You are using P only, so this should be easy.

Code:
output = P * (encoder.get() - setpoint);
__________________
Drive Coach Team 5012 Gryffingear / Antelope Valley FIRST teams / EWCP - (2013 - Current)
Student / Driver / Programmer / CAD - FRC Team 399: Eagle Robotics / FTC Team 72: GarageBots - (2009 - 2013)
Los Angeles Region FTC FTA/CSA/Head Ref
[FF] FIRST Pick
2014 FTC Los Angeles Regional Compass Award Winner.

2017 - San Diego Regional / Sacramento Regional / Las Vegas Regional
2016 - Los Angeles Regional Creativity + Winners (1197, 987, 5012) / Las Vegas Regional Team Spirit + SF (5012, 5851, 5049) / Galileo Subdivision
2015 - Inland Empire QF (597, 5012, 4413) / Las Vegas Imagery + Winners (148, 987, 5012) / Newton Subdivision and World Champions (118, 1678, 1671, 5012)
2014 - Inland Empire Rookie All Star + Highest Rookie Seed + SF (2339, 1967, 5012) / Las Vegas Rookie All Star / Galileo Division Imagery
Reply With Quote
  #5   Spotlight this post!  
Unread 20-12-2011, 07:53
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,080
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: JAVA PID with Encoders

The issue is with the encoder. Because you can use encoders to measure either speed or distance (or both), you need to tell the encoder which measurement to use when the PIDController calls pidGet().

You can do this by adding the line (assuming you want to use distance as your measurement):
Code:
LeftEncoder.setPIDSourceParameter(Encoder.PIDSourceParameter.kDistance);
...after you instantiate the encoder but before you instantiate the PIDController.
Reply With Quote
  #6   Spotlight this post!  
Unread 20-12-2011, 17:58
Mk.32's Avatar
Mk.32 Mk.32 is offline
Registered User
AKA: Mark
FRC #2485 (W.A.R. Lords)
Team Role: Engineer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: San Diego
Posts: 770
Mk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud of
Re: JAVA PID with Encoders

The kDistance what kind of value does it return with pidGet()?
__________________
Engineering mentor: Team 2485: WARLords 2013-

Team President: Team 3647 2010-2013
Reply With Quote
  #7   Spotlight this post!  
Unread 21-12-2011, 07:56
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,080
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: JAVA PID with Encoders

Quote:
Originally Posted by Mk.32 View Post
The kDistance what kind of value does it return with pidGet()?
It returns the result of GetDistance().
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 12:58.

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