Go to Post If you see Navy ships in port, you're going to be fine. If you see ships pulling out, or no ships at all, go East. Fast. - Matt Howard [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 05-02-2017, 15:37
IamCshort IamCshort is offline
Registered User
FRC #5713 (Cyber Bucs)
Team Role: Team Spirit / Cheering
 
Join Date: Jan 2017
Rookie Year: 2016
Location: Flint
Posts: 7
IamCshort is an unknown quantity at this point
Send a message via AIM to IamCshort
Talking PID controller that would allow me to drive forward in auto

I want to create a command that uses pid with a ultrasonic sensor to drive forward a distance i set. I looked into some example code and i made one of my own. I am using the command based robot with robot builder. Keep in mind i have no prior knowledge of pid controllers so if it wrong dont be surprised.


The Code is below in a command



package org.usfirst.frc5713.BuckyBot.commands;

import org.usfirst.frc5713.BuckyBot.Robot;

import edu.wpi.first.wpilibj.PIDController;
import edu.wpi.first.wpilibj.PIDOutput;
import edu.wpi.first.wpilibj.PIDSource;
import edu.wpi.first.wpilibj.PIDSourceType;
import edu.wpi.first.wpilibj.command.Command;

/** This Class drive the robot forward using a rangefinder a set distance you determine
*
*/
public class SetDistanceToPeg extends Command {

private PIDController pid;


public SetDistanceToPeg(double distance) {
requires(Robot.driveTrain);
pid = new PIDController(-2, 0, 0, new PIDSource() {
PIDSourceType m_sourceType = PIDSourceType.kDisplacement;

@Override
public double pidGet() {
return Robot.driveTrain.getDistanceToObstacle();
}

@Override
public void setPIDSourceType(PIDSourceType pidSource) {
m_sourceType = pidSource;
}

@Override
public PIDSourceType getPIDSourceType() {
return m_sourceType;
}
}, new PIDOutput() {
@Override
public void pidWrite(double d) {
Robot.driveTrain.drive(d, d);
}
});

pid.setAbsoluteTolerance(0.01);
pid.setSetpoint(distance);
}

// Called just before this Command runs the first time
@Override
protected void initialize() {
// Get everything in a safe starting state.
Robot.driveTrain.reset();
pid.reset();
pid.enable();
}

// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return pid.onTarget();
}

// Called once after isFinished returns true
@Override
protected void end() {
// Stop PID and the wheels
pid.disable();
Robot.driveTrain.drive(0, 0);
}
}
Reply With Quote
  #2   Spotlight this post!  
Unread 06-02-2017, 12:09
dvanvoorst dvanvoorst is offline
Registered User
FRC #2771 (Code Red)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Grand Rapids, MI
Posts: 73
dvanvoorst is an unknown quantity at this point
Re: PID controller that would allow me to drive forward in auto

Have you tried running this program? If so, what were the results?
After a quick scan of the code, the negative P value jumps out at me as odd. Also, have you confirmed that getDistanceToObstacle() is returning a good value?
__________________

Reply With Quote
  #3   Spotlight this post!  
Unread 06-02-2017, 20:19
IamCshort IamCshort is offline
Registered User
FRC #5713 (Cyber Bucs)
Team Role: Team Spirit / Cheering
 
Join Date: Jan 2017
Rookie Year: 2016
Location: Flint
Posts: 7
IamCshort is an unknown quantity at this point
Send a message via AIM to IamCshort
Re: PID controller that would allow me to drive forward in auto

We switched to using encoders
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 09:44.

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