Go to Post FIRST isnt about getting what you deserve, FIRST is about other people seeing potential in us - and giving us an opportunity that we could never have earned on our own - KenWittlief [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-02-2014, 14:38
Phygon Phygon is offline
Registered User
FRC #0004
 
Join Date: Feb 2014
Location: HTLA
Posts: 4
Phygon is an unknown quantity at this point
Exclamation Issues with arm PID

Our programmers have been working on re-writing the code for our robot, and they're currently working on a PID loop to keep the arm raised at a certain position. To get a reading of the arm's position they have a pot. This code is supposed to hold the arm as it is when it reaches 3v, a value that we measured out beforehand. However, when we execute this code, all the motor does is weakly turn to push the arm down once the pot exceeds 3v, without attempting to lift it at all. This is baffling to me, as this is almost the exact same code as we use for out drivestraight function, which works perfectly.
Attached is the command for the arm subsystem
Code:
package org.usfirst.frc4.Team4Descent.commands;

import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.interfaces.Potentiometer;
import org.usfirst.frc4.Team4Descent.Robot;
import org.usfirst.frc4.Team4Descent.RobotMap;
import org.usfirst.frc4.Team4Descent.subsystems.Shooter;

/**
 *
 * @author Rachel
 */
public class ArmPosition extends Command {
    
   public double 
            speed,
            turn,
            angleMod,
            Kp,
            Kd,
            potRaw,
            botAngle,
            previousP;
   
    AnalogChannel shooterPOT = RobotMap.shooterPOT;
    
    public ArmPosition() {
        requires(Robot.shooter);
    
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        
       //Kp and Kd values for tuning
        Kp          = 0.07;
        Kd          = 0; //Percent
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        //PID loop
        double
            setPoint = 3.00,
            processVariable = shooterPOT.getVoltage(),
            PID_P = -(setPoint - processVariable),
            PID_D = (PID_P - previousP),
            PID = (PID_P * Kp) + (PID_D * Kd);

        //Sets the arm pivot motor equal to the output PID value
        Shooter.shooterTalon.set(PID); 

//Limits arm speed for testing
if(Shooter.shooterTalon.get() >= 0.05)
{
    Shooter.shooterTalon.set(0.05);
}else if(Shooter.shooterTalon.get() <= -0.05)
{
    Shooter.shooterTalon.set(-0.05);
}
	//Sets the previous process variable to the current one
        previousP = processVariable;
        
        System.out.println(shooterPOT.getVoltage());
       
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    }
}
  #2   Spotlight this post!  
Unread 27-02-2014, 14:48
bartv bartv is offline
Registered User
FRC #4946
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Toronto
Posts: 4
bartv is an unknown quantity at this point
Re: Issues with arm PID

Hi,

You have a very small kP value, likely just enough to move the arm when gravity helps (hence the observed motion on the way down). You also don't have an integral. The integral term is used to increase the effort the longer a position error exists.

I.e., lets say you start with the poteniometer at 0v -> an error of 3v. The controller will apply 3*.07 = .21% - > 2.1v at the talon. What would move the arm? If 2.1v is not enough, it will never move. If you had an integral, it would start adding more power the longer the error existed. The kD term is only useful for sudden changes (derivate) in position, which you are not getting at the moment (plus you zeroed it).

Try increasing the kP variable, and adding an integral. Have you looked at the PID class provided?

Cheers,
Bart

Last edited by bartv : 27-02-2014 at 14:55.
  #3   Spotlight this post!  
Unread 27-02-2014, 14:50
efoote868 efoote868 is offline
foote stepped in
AKA: E. Foote
FRC #0868
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2005
Location: Noblesville, IN
Posts: 1,425
efoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond repute
Re: Issues with arm PID

I have a few questions about your design (a picture of your arm would greatly help understand your system!)

Can the motors to the arm be back driven?
Are the motors to the arm fighting gravity in one direction?
Should the motors still be "on" and stalled once the arm reaches the position at 3v?
__________________

Be Healthy. Never Stop Learning. Say It Like It Is. Own It. Like our values? Flexware Innovation is hiring!. We're looking for Senior Automation, Software, and System Engineers. Check us out!
  #4   Spotlight this post!  
Unread 27-02-2014, 14:52
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,113
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: Issues with arm PID

Is sending 0.2 to the motor enough to raise it? Your Kp constant doesn't look nearly large enough to control an arm against gravity, and I don't see an I term to overcome the steady-state error you'll have.

Start by increasing Kp until it oscillates, then dial it back just enough to stop the oscillations. If that doesn't keep the arm where you want it to be, consider adding I to what's now just a P controller.
  #5   Spotlight this post!  
Unread 27-02-2014, 15:22
Phygon Phygon is offline
Registered User
FRC #0004
 
Join Date: Feb 2014
Location: HTLA
Posts: 4
Phygon is an unknown quantity at this point
Re: Issues with arm PID

Quote:
Originally Posted by bartv View Post
Hi,

You have a very small kP value, likely just enough to move the arm when gravity helps (hence the observed motion on the way down). You also don't have an integral. The integral term is used to increase the effort the longer a position error exists.

I.e., lets say you start with the poteniometer at 0v -> an error of 3v. The controller will apply 3*.07 = .21% - > 2.1v at the talon. What would move the arm? If 2.1v is not enough, it will never move. If you had an integral, it would start adding more power the longer the error existed. The kD term is only useful for sudden changes (derivate) in position, which you are not getting at the moment (plus you zeroed it).

Try increasing the kP variable, and adding an integral. Have you looked at the PID class provided?

Cheers,
Bart
The value is definitely not enough to move the arm, we had an issue earlier where the code was always sending a high value to the motor and it swung hard enough to almost break someone's arm/the robot, so we cut it down for testing. However, the issue is that the arms are getting literally 0 power before they pass that 3 mark- When I print the pid value I get 0 and the motor lights don't turn on till it passes that mark.
  #6   Spotlight this post!  
Unread 27-02-2014, 15:29
TRWSHSHLX TRWSHSHLX is offline
Registered User
AKA: Henry Lei
no team
 
Join Date: Jan 2011
Rookie Year: 2008
Location: OR
Posts: 71
TRWSHSHLX is an unknown quantity at this point
Re: Issues with arm PID

What kind of arm is it? For a lot of lifting / arm systems, it might be more beneficial to add a spring instead.
__________________
  #7   Spotlight this post!  
Unread 27-02-2014, 15:37
bartv bartv is offline
Registered User
FRC #4946
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Toronto
Posts: 4
bartv is an unknown quantity at this point
Re: Issues with arm PID

What voltage does your pot read at your low point (before passing 3)?
Stupid question, but just making sure the pot reads in advance.

In the low/start position, what are the other variables reading?
  #8   Spotlight this post!  
Unread 27-02-2014, 15:45
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,600
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Issues with arm PID

You are sending conflicting commands to the motor by having multiple calls to shooterTalon.set. If you want to limit the speed, you need to do that before calling set.
  #9   Spotlight this post!  
Unread 27-02-2014, 16:00
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,082
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Issues with arm PID

Quote:
Originally Posted by Joe Ross View Post
You are sending conflicting commands to the motor by having multiple calls to shooterTalon.set. If you want to limit the speed, you need to do that before calling set.
Besides which, you are limiting power to +/-5% of maximum. I don't know your gear ratio, but that may simply not be enough to hold position.
  #10   Spotlight this post!  
Unread 27-02-2014, 16:23
Bruceb's Avatar
Bruceb Bruceb is offline
Registered User
FRC #0706 (Cyberhawks)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Merton, wi
Posts: 616
Bruceb is a splendid one to beholdBruceb is a splendid one to beholdBruceb is a splendid one to beholdBruceb is a splendid one to beholdBruceb is a splendid one to beholdBruceb is a splendid one to beholdBruceb is a splendid one to behold
Re: Issues with arm PID

we arent using PID at all on our arm.
PG188 in brake mode is all it takes to hold position.
__________________
Mentor Team 706 The CyberHawks
2010 Wisconsin Regional Rockwell Automation Innovation in Control Award
2010 Wisconsin Regional Finalist
2013 Buckeye Regional Finalist
2014 Superior Regional Industrial Design Award
2014 Superior Regional Finalist
2014 Wisconsin Regional Finalist
2014 Wisconsin Motorola Quality Award
2015 Wisconsin Regional Motorola Quality Award
2015 Queen City Creativity Award
2016 Buckeye Regional Finalist
2016 Wisconsin Regional Finalist
2016 Wisconsin Regional Industrial Safety Award
2016 Wisconsin Regional Excellence in Engineering Award

https://www.youtube.com/user/Cyberhawks706
  #11   Spotlight this post!  
Unread 27-02-2014, 16:57
Phygon Phygon is offline
Registered User
FRC #0004
 
Join Date: Feb 2014
Location: HTLA
Posts: 4
Phygon is an unknown quantity at this point
Re: Issues with arm PID

Quote:
Originally Posted by bartv View Post
What voltage does your pot read at your low point (before passing 3)?
Stupid question, but just making sure the pot reads in advance.

In the low/start position, what are the other variables reading?
The pot is reading ~3.5 at the lowest position of the arm and 1 at the highest

Quote:
Originally Posted by Joe Ross View Post
You are sending conflicting commands to the motor by having multiple calls to shooterTalon.set. If you want to limit the speed, you need to do that before calling set.
Even without the limiting code, the exact same movements are observed.

And I know the voltage is too low- the problem is that it isn't outputting anything at all until the value is below 3 (arm up)
  #12   Spotlight this post!  
Unread 27-02-2014, 17:38
bartv bartv is offline
Registered User
FRC #4946
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Toronto
Posts: 4
bartv is an unknown quantity at this point
Re: Issues with arm PID

Given all those things, I would suggest finding out what the variables are actually reading; output each variable, and see where in your equation you are getting zero. Could you post those?
  #13   Spotlight this post!  
Unread 27-02-2014, 17:51
connor.worley's Avatar
connor.worley connor.worley is offline
Registered User
FRC #0973 (Greybots)
Team Role: Mentor
 
Join Date: Mar 2011
Rookie Year: 2010
Location: Berkeley/San Diego
Posts: 601
connor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond repute
Re: Issues with arm PID

Code:
//Limits arm speed for testing
if(Shooter.shooterTalon.get() >= 0.05)
{
    Shooter.shooterTalon.set(0.05);
}else if(Shooter.shooterTalon.get() <= -0.05)
{
    Shooter.shooterTalon.set(-0.05);
}
These limits keep your values barely outside of the Talon's deadbands, and your output could be getting deadbanded depending on calibration.

Also,
Code:
        previousP = processVariable;
should be
Code:
        previousP = PID_P;
although this won't have any effect while Kd = 0.

EDIT: saw OP's last post. Did you increase Kp?
__________________
Team 973 (2016-???)
Team 5499 (2015-2016)
Team 254 (2014-2015)

Team 1538 (2011-2014)
2014 Driver (25W 17L 1T)
日本語でOK

Last edited by connor.worley : 27-02-2014 at 17:56.
  #14   Spotlight this post!  
Unread 27-02-2014, 17:58
kiettyyyy's Avatar
kiettyyyy kiettyyyy is offline
Registered User
FRC #1538 (The Holy Cows)
Team Role: Engineer
 
Join Date: Mar 2006
Rookie Year: 2005
Location: San Diego, CA
Posts: 181
kiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond repute
Send a message via AIM to kiettyyyy
Re: Issues with arm PID

Rachel, just as previous posts have stated, your kP value looks way too small. I'd recommend setting your kP to 1 and work from there. The goal is to make your P component barely oscillate. Once the P component oscillates, remove the oscillation by increasing your kD constant from 0 to what ever value achieves the goal with minimal or no oscillation.

Assuming you've implemented Connor's recommendations, you should be fine. Feel free to contact us if you'd like some additional help.
__________________
-Kiet Chau

2004-2008 - Software Developer/Driver on Team #968
2008-2011 - Software Developer/Coach/Mentor/"Engineer" on Team #968
2011-Present - Mentor & Engineer on Team #1538
www.team1538.com
  #15   Spotlight this post!  
Unread 28-02-2014, 02:44
Phygon Phygon is offline
Registered User
FRC #0004
 
Join Date: Feb 2014
Location: HTLA
Posts: 4
Phygon is an unknown quantity at this point
Re: Issues with arm PID

The issue was with the arm kP. Thanks!
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 02:47.

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