Go to Post Even in the eighties, driver practice won competitions. - Brian Maher [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: 4 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 16-01-2015, 19:38
admrialkunkka admrialkunkka is offline
Registered User
FRC #2815
 
Join Date: Feb 2013
Location: Columbia
Posts: 9
admrialkunkka is an unknown quantity at this point
How to program Encoders with PID Subsystem

We need help programming our encoders with a PID subsystem because of lack of documentation. We intend to use the encoders for our drive train PID subsystem.
Reply With Quote
  #2   Spotlight this post!  
Unread 17-01-2015, 12:28
nickmcski nickmcski is offline
Registered User
AKA: Nicholas McCurry
FRC #1482 (Grandin Ghosts)
Team Role: Alumni
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Canada
Posts: 112
nickmcski has a spectacular aura aboutnickmcski has a spectacular aura aboutnickmcski has a spectacular aura about
Re: How to program Encoders with PID Subsystem

Will you be hooking them up directly to your roboRIO or to a talon SRX?
Reply With Quote
  #3   Spotlight this post!  
Unread 17-01-2015, 12:43
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How to program Encoders with PID Subsystem

Quote:
Originally Posted by admrialkunkka View Post
We need help programming our encoders with a PID subsystem because of lack of documentation. We intend to use the encoders for our drive train PID subsystem.
What motor controllers will you be using?

Will you be commanding them with CAN or PWM?

What part number encoder?

What type of drive train?

Are you trying to control wheel speed or wheel distance?

Is this for autonomous, Teleop, or both?



Reply With Quote
  #4   Spotlight this post!  
Unread 17-01-2015, 13:30
admrialkunkka admrialkunkka is offline
Registered User
FRC #2815
 
Join Date: Feb 2013
Location: Columbia
Posts: 9
admrialkunkka is an unknown quantity at this point
Re: How to program Encoders with PID Subsystem

We will be plugging them into the roboRio and we will be using Victors and controlling them with a pwm connections. We will be using a H-drive train system and we want to be able to control the wheel distance and possible the wheel speed. This is for both teleop and autonomous. We are using the am-0180 Andy Mark Encoders.
Reply With Quote
  #5   Spotlight this post!  
Unread 17-01-2015, 13:33
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How to program Encoders with PID Subsystem

Quote:
Originally Posted by admrialkunkka View Post
We will be plugging them into the roboRio and we will be using Victors and controlling them with a pwm connections. We will be using a H-drive train system and we want to be able to control the wheel distance and possible the wheel speed. This is for both teleop and autonomous. We are using the am-0180 Andy Mark Encoders.
Good detail.

Do you have specific questions about PID, or do you just need some links to general information?


Reply With Quote
  #6   Spotlight this post!  
Unread 17-01-2015, 13:45
admrialkunkka admrialkunkka is offline
Registered User
FRC #2815
 
Join Date: Feb 2013
Location: Columbia
Posts: 9
admrialkunkka is an unknown quantity at this point
Re: How to program Encoders with PID Subsystem

If we could get both general information and specific help that would be great. We have created an encoder object in our PID subsystem drive train, for testing purposes we have only created one and we are only dealing with one encoder. We are fairly lost on what our P I and ad constants should be and we have only been getting a PID output of one with our encoder.pidGet in our return statement for the returnPIDInput method. I can post a copy of the code we have done so far if it will help.
Reply With Quote
  #7   Spotlight this post!  
Unread 17-01-2015, 13:50
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How to program Encoders with PID Subsystem

Quote:
Originally Posted by admrialkunkka View Post
If we could get both general information and specific help that would be great.
Here are a bunch of links to PID on chiefdelphi:
https://www.google.com/?gws_rd=ssl#q....com+%22PID%22

Here's an FRC-specific discussion of PID from WPILib:
http://wpilib.screenstepslive.com/s/...in-pid-control

Quote:
Originally Posted by admrialkunkka View Post
I can post a copy of the code we have done so far if it will help.
Posting your code will allow the Java gurus on CD to give specific help.


Reply With Quote
  #8   Spotlight this post!  
Unread 17-01-2015, 14:04
admrialkunkka admrialkunkka is offline
Registered User
FRC #2815
 
Join Date: Feb 2013
Location: Columbia
Posts: 9
admrialkunkka is an unknown quantity at this point
Re: How to program Encoders with PID Subsystem

Code:
public class DriveTrain extends PIDSubsystem {
	private Victor leftMotors[] = new Victor[2];
	private Victor rightMotors[] = new Victor[2];
	private Talon hDriveMotor;
	private double lTarget;
	private double rTarget;
	private double lspeed;
	private double rspeed;
	private final double ACCEL;
	private Encoder encoder;
	
	/**
     * This function is run when the class is initialized and should be
     * used for any initialization code.
     */
	public DriveTrain() {
		super("Drive Train",3,2,0);
		leftMotors[0] = new Victor(RobotMap.leftMotors[0]);
		leftMotors[1] = new Victor(RobotMap.leftMotors[1]);
		rightMotors[0] = new Victor(RobotMap.rightMotors[0]);
		rightMotors[1] = new Victor(RobotMap.rightMotors[1]);
		hDriveMotor = new Talon(RobotMap.hDriveMotor);
		ACCEL = .1;
		rspeed = 0;
		lspeed = 0;
		encoder = new Encoder(RobotMap.encoder[0], RobotMap.encoder[1],false, Encoder.EncodingType.k4X);
		encoder.setDistancePerPulse(4*Math.PI);
	}

	/** Set the default command for a subsystem here.
     * setDefaultCommand(new MySpecialCommand());
     */
	public void initDefaultCommand() {
		
		setDefaultCommand(new HDriveWithJoystick());
	}
public void tankDrive(double leftSpeed, double rightSpeed) {
		for (Victor lv : leftMotors)
			lv.set(leftSpeed);
		for (Victor rv : rightMotors)
			rv.set(rightSpeed);
	}
public void setHDriveMotor(double speed){
		hDriveMotor.set(speed);
	}

	@Override
	protected double returnPIDInput() {
		// TODO Auto-generated method stub
		return encoder.pidGet();
	}

	@Override
	protected void usePIDOutput(double output) {
		// TODO Auto-generated method stub
		tankDrive(output,output);
	}

}
This is our code, we do not know if we are setting up the encoder object correctly or know if we are instantiating the PID correctly outside of this class
Reply With Quote
  #9   Spotlight this post!  
Unread 18-01-2015, 15:50
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,586
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: How to program Encoders with PID Subsystem

The PID Subsystem was designed for a single sensor input and a single output. The way you're doing it will use a single sensor and send the same output value to both the left and right motors, which would allow you to drive a distance approximately straight. Is that what you want?
Reply With Quote
  #10   Spotlight this post!  
Unread 18-01-2015, 19:14
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: How to program Encoders with PID Subsystem

Quote:
Originally Posted by admrialkunkka View Post
We need help programming our encoders with a PID subsystem because of lack of documentation. We intend to use the encoders for our drive train PID subsystem.
If you create an example java project in eclipse and choose GearsBot you can see some samples of PIDSubsystem classes. Look in the subsystem package (folder) and look at Elevator and Wrist. In both cases it shows how to write the PID subsystem uses a potentiometer as the sensor.

Then to control the height of the elevator or the angle of the wrist, look at the commands SetElevatorSetpoint and SetWristSetpoint. The idea is that the PIDController is embedded in the PID Subsystem and the setting of the set point is in the command. The command finishes when the mechanism actual value is at the stepping +/- the tolerance (set in the subsystem).

There is also a video that describes how to write that program from scratch that's here: http://wp.wpi.edu/wpilib/2012/02/15/...-videos-posted.

Hope that helps.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
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 18:05.

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