Go to Post Patience, grasshopper. They'll get to it. - Rick TYler [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 01-03-2016, 08:23
astronautlevel's Avatar
astronautlevel astronautlevel is offline
Registered User
FRC #2537
 
Join Date: Feb 2016
Location: Maryland
Posts: 4
astronautlevel is an unknown quantity at this point
WPILib PIDController Question

Hi, our team has been having a lot of trouble using the PIDController class to move an arm on our robot based on an angle sensor. We're not really sure how to use the PIDController, for example, what methods are necessary to initialize the PIDController for it for set motor values correctly? We are using Java and the Command-based Architecture.

Here is what our code is doing (within a Subsystem class):
Code:
public static Double setpoint;
	
	private final CANTalon angleMotor = new CANTalon(Ports.SHOOTER_ANGLE_PORT);
	
	PIDController controller;
	
	PIDSource source;
	
	public AnglePIDControllerSubsystem() {
		source = new PIDSource() {
			
			@Override
			public void setPIDSourceType(PIDSourceType pidSource) {
				
			}
			
			@Override
			public double pidGet() {
				System.out.println("Getting value: " + currentAngle);
				return currentAngle;
			}
			
			@Override
			public PIDSourceType getPIDSourceType() {
				return PIDSourceType.kDisplacement;
			}
		};
		controller = new PIDController(10, 0 ,0, source, angleMotor);
		controller.setContinuous(false);
		controller.setAbsoluteTolerance(3);
		controller.setInputRange(-90, 90);
		controller.setOutputRange(-1, 1);
		angleMotor.changeControlMode(CANTalon.TalonControlMode.PercentVbus);
		angleMotor.ConfigFwdLimitSwitchNormallyOpen(true);
		angleMotor.ConfigRevLimitSwitchNormallyOpen(true);
		angleMotor.enableForwardSoftLimit(false);
		angleMotor.enableReverseSoftLimit(false);
		controller.enable();
	}

void setSetpoint(double val) {
		controller.setSetpoint(val*10);
		System.out.println("Voltage: " + controller.get());
		System.out.println("Error: " + controller.getError());
		System.out.println("Setpoint: " + controller.getSetpoint());
		System.out.println("On target: " + controller.onTarget());
	}
The default command for this subsystem is calling setSetpoint each cycle.

Has anyone else had success with the PIDController?
Reply With Quote
 


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 17:57.

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