Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Using PID controls to center robot on target with camera (http://www.chiefdelphi.com/forums/showthread.php?t=103071)

guoruiwu1994 17-02-2012 09:36

Using PID controls to center robot on target with camera
 
Using the camera, we can get how many pixels we are off target. Is there a way to feed that into the PID controls and then have the PID controls output into the robotdrive?

As far as I know, in the provided PID function you have to give it a source (such as an encoder), you cannot give it a number. Also, I'm not sure if the PID output works with robotdrive (arcade mode).

notmattlythgoe 17-02-2012 09:40

Re: Using PID controls to center robot on target with camera
 
Are you programming in the command based style? If so it is actually really easy to do with a PID subsystem.

guoruiwu1994 17-02-2012 10:35

Re: Using PID controls to center robot on target with camera
 
What do you mean by command based style?

Ether 17-02-2012 10:40

Re: Using PID controls to center robot on target with camera
 
Quote:

Originally Posted by guoruiwu1994 (Post 1128735)
What do you mean by command based style?


See the WPILib Cookbook located in the Documents area on the WPILib FIRSTForge project:


http://firstforge.wpi.edu/sf/go/doc1297?nav=1




guoruiwu1994 17-02-2012 10:42

Re: Using PID controls to center robot on target with camera
 
Right now, we are using IterativeRobot.

notmattlythgoe 17-02-2012 10:50

Re: Using PID controls to center robot on target with camera
 
You will have to create your own PID class that extends the current PID class and override some of the methods to get it to work the way that you want it to.

guoruiwu1994 17-02-2012 10:53

Re: Using PID controls to center robot on target with camera
 
Can you give me some example code on how to do that?

notmattlythgoe 17-02-2012 11:07

Re: Using PID controls to center robot on target with camera
 
Unfortunately there isn't really any example code, and I don't have any written right now.

Ether 17-02-2012 11:36

Re: Using PID controls to center robot on target with camera
 
Quote:

Originally Posted by guoruiwu1994 (Post 1128699)
Using the camera, we can get how many pixels we are off target. Is there a way to feed that into the PID controls and then have the PID controls output into the robotdrive?

A PID takes a setpoint and a processVariable as inputs, and adjusts its output to make the plant's output (the processVariable) equal to the setpoint.

You want the "how many pixels we are off target" to be zero, right?

So your setpoint would be 0 (zero), and "how many pixels we are off target" is your process variable. The output from the PID would be your drivetrain rotation command (assuming that "how many pixels we are off target" is a measure of aim, not range).



guoruiwu1994 17-02-2012 11:40

Re: Using PID controls to center robot on target with camera
 
The input of the PID wants a source though, not a number.

notmattlythgoe 17-02-2012 11:56

Re: Using PID controls to center robot on target with camera
 
http://www.wbrobotics.com/javadoc/ed...PIDSource.html
Create a new class that extends PIDSource and rewrite the pidGet() method to get the offset of the target from 120 and return that value.

Ether 17-02-2012 12:11

Re: Using PID controls to center robot on target with camera
 
Quote:

Originally Posted by guoruiwu1994 (Post 1128785)
The input of the PID wants a source though, not a number.

Give it a source that always returns zero for the setpoint.

Give it a source that returns "how many pixels we are off target" for the processVariable.



jesusrambo 18-02-2012 14:33

Re: Using PID controls to center robot on target with camera
 
https://github.com/jesusrambo/PurpaD...tRotation.java

Look through VerticalTurretRotation and HorizontalTurretRotation, that's how we do it.


All times are GMT -5. The time now is 11:17.

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