Go to Post This pic became proof that engineers should never give up thier day jobs! :p - Jay H 237 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rating: Thread Rating: 30 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 16-02-2015, 18:47
seraine seraine is offline
Registered User
FRC #4693
 
Join Date: Sep 2013
Location: Minnesota
Posts: 4
seraine is an unknown quantity at this point
Using a rangefinder and a PID controller with a lift (Java)

We are attempting to use a rangefinder and a PIDController to set the height of our lift. Our lift has a winch that is only able to lift the elevator, and relies on gravity to pull the elevator down. When I currently test the code, I set the pidController to values between 0.1134 volts and 0.6048 volts, which correspond to ranges between 12 and 64 inches. These values have been verified by printing both the inches and volts output from the rangefinder.

If I set the PID controller to 0.1 volts, the winch spins in the wrong direction at a slow speed, and it slowly unspools the cable. If I set it to 0.2 volts, it also unspools in the wrong direction, just faster. As I increase the PID controller voltage setpoint, the speed it unspools increases.

What the controller should do is raise until the setpoint matches the voltage, and then maintain position, but it only unspools the wire at various speeds.

Does anyone have any idea what my problem is? Here is the code:

Code:
public class Robot extends IterativeRobot {

  Victor elevatorMotor;
  AnalogInput rangefinder;
  Joystick right;
  PIDController elevatorControl;

  double elevatorPoint = 0;

  public void robotInit() {
    
    elevatorMotor = new Victor(4);
    rangefinder = new AnalogInput(0);
    right = new Joystick(1);
    elevatorControl = new PIDController(0.5, 0.001, 0, rangefinder, elevatorMotor);
    elevatorControl.enable();

  }

  public void teleopPeriodic() {

    double range = (rangefinder.getVoltage()) / 0.00945;
    double volts = rangefinder.getVoltage();

    if (right.getRawButton(6) == true) {
      elevatorPoint = 0.1134;
    } else if (right.getRawButton(7) == true) {
      elevatorPoint = 0.2268;
    } else if (right.getRawButton(8) == true) {
       elevatorPoint = 0.3402;
    } else if (right.getRawButton(9) == true) {
       elevatorPoint = 0.4536;
    } else if (right.getRawButton(10) == true) { 
       elevatorPoint = 0.5670;
    } else if (right.getRawButton(11) == true) {
       elevatorPoint = 0.6048;
    }

    elevatorControl.setSetPoint(elevatorControl);

    Timer.delay(0.01);

  }

}
  #2   Spotlight this post!  
Unread 16-02-2015, 18:57
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Using a rangefinder and a PID controller with a lift (Java)

Is the problem that the motor is just running in the wrong direction? The simple fix is to swap its wires coming from the speed controller. The software fix is to negate the PID constants so that it computes a control value that goes in the other direction from what it's doing now.
  #3   Spotlight this post!  
Unread 16-02-2015, 19:17
seraine seraine is offline
Registered User
FRC #4693
 
Join Date: Sep 2013
Location: Minnesota
Posts: 4
seraine is an unknown quantity at this point
Re: Using a rangefinder and a PID controller with a lift (Java)

The fix really was that simple. Thanks for your help!
Closed Thread


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:04.

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