Go to Post I didn't get inspired watching my peers and I, I was inspired watching professionals. - 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
  #1   Spotlight this post!  
Unread 18-11-2015, 20:24
josephno1's Avatar
josephno1 josephno1 is offline
Registered User
FRC #3647
Team Role: Programmer
 
Join Date: Oct 2015
Rookie Year: 2015
Location: murica
Posts: 21
josephno1 is an unknown quantity at this point
PID Controller help

So I followed the example on here.

http://wpilib.screenstepslive.com/s/...rs-pid-control

So this is what I got so far.

The PID Controller is plugged in on PWM port 0 and AnalogInput 2

How do I call this in the Robot.java and what do I do next?
I am using IterativeRobot

Code:
import edu.wpi.first.wpilibj.command.PIDSubsystem;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.wpilibj.*;
/**
 *
 */
public class PIDWheel extends PIDSubsystem {
	SpeedController motor = new Talon(0);
	AnalogInput pot = new AnalogInput(2);
	
    // Initialize your subsystem here
    public PIDWheel() {
    	super("Wheel", 1.0, 0.0, 0.0);
    	setAbsoluteTolerance(0.2);
    	getPIDController().setContinuous(false);
    	LiveWindow.addActuator("Wheel", "PIDSubsystem Controller", getPIDController());
        // Use these to get going:
        // setSetpoint() -  Sets where the PID controller should move the system
        //                  to
        // enable() - Enables the PID controller.
    }
    
    public void initDefaultCommand() {
        // Set the default command for a subsystem here.
        //setDefaultCommand(new MySpecialCommand());
    }
    
    protected double returnPIDInput() {
        // Return your input value for the PID loop
        // e.g. a sensor, like a potentiometer:
        // yourPot.getAverageVoltage() / kYourMaxVoltage;
    	return pot.getAverageVoltage();
    }
    
    protected void usePIDOutput(double output) {
    	motor.pidWrite(output);
        // Use output to drive your system, like a motor
        // e.g. yourMotor.set(output);
    }
}
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 10:16.

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