Go to Post The only way you can be undermined is if you let yourself be undermined. - DUCKIE [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 04-02-2013, 22:50
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Encoder's PID functional but getRate method not-functional???

I don't have my code to show you at the moment, but I set up a PID Controller from the WPI Java Library (wpilibj) and implemented PIDWrite and PIDOutput to take values and from an encoder on our frisbee shooter and write the value to the Victor controlling the shooter. I also took the data from the encoder and sent it to our SmartDashboard.

Everything seems to be working fine except for the SmartDashboard. I a little bit of troubleshooting and did a simple println of the encoder's getRate value instead. Both yielded zero yet are shooter still spends faster and slower in regards to our joystick. The obvious assumption would be that I have the wrong ports for the encoder or it's wired incorrectly, but since I'm using the joystick to set the set-point for the PID controller in RPMs (or RPS, depending on where you look at it in the code.) you would think that the shooter would spin full speed if it was receiving zero RPMs from the encoder, but it is certainly responding with variable speeds when I adjust the throttle of the joystick.

My current explanation is that perhaps the getRate method is being called too quickly in succession for the encoder class to be ready for it (in regards to whatever loop the library might be using?).

I know there's a lot typed above, but I'd really appreciate it if someone would take the time to clarify and ask some questions about what's been stated above, and show me what I'm doing wrong, as I'm completely clueless.
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
Reply With Quote
  #2   Spotlight this post!  
Unread 05-02-2013, 08:43
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: Encoder's PID functional but getRate method not-functional???

Bump?
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
Reply With Quote
  #3   Spotlight this post!  
Unread 05-02-2013, 14:06
lynca's Avatar
lynca lynca is offline
Andrew Lynch
FRC #2587 (DiscoBots)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2001
Location: Houston, TX
Posts: 1,612
lynca has a reputation beyond reputelynca has a reputation beyond reputelynca has a reputation beyond reputelynca has a reputation beyond reputelynca has a reputation beyond reputelynca has a reputation beyond reputelynca has a reputation beyond reputelynca has a reputation beyond reputelynca has a reputation beyond reputelynca has a reputation beyond reputelynca has a reputation beyond repute
Send a message via AIM to lynca
Re: Encoder's PID functional but getRate method not-functional???

Can you post a link to your code ?

We just got PID on our shooter working well in java last week. Check out our Google Code source.
__________________
History: 624 - Cryptonite --> 118 - Robonauts --> 2158 - AusTIN CANS --> 2587 DiscoBots
Bio: Andrew Lynch "How I Work" ---- LinkedIn , Facebook, Twitter
Reply With Quote
  #4   Spotlight this post!  
Unread 05-02-2013, 15:49
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: Encoder's PID functional but getRate method not-functional???

The Drivetrain subsystem code:

Code:
package edu.wpi.first.wpilibj.templates.subsystems;

import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.templates.RobotMap;
import edu.wpi.first.wpilibj.templates.commands.UserShooter;

/**
 *
 * @author Spencer, Team 3266
 */

public class Shooter extends Subsystem implements PIDOutput, PIDSource {

    Victor spinner;
    Encoder spinnerEncoder;
    PIDController pid;
    
    double rpm = 0;
    
    public void initDefaultCommand() {
        setDefaultCommand(new UserShooter());
    }
    
    public Shooter() {
        spinner = new Victor(RobotMap.spinnerVictor);
        
        spinnerEncoder = new Encoder(RobotMap.spinnerEncoderA, RobotMap.spinnerEncoderB);
        //spinnerEncoder.setPIDSourceParameter(Encoder.PIDSourceParameter.kRate);
        spinnerEncoder.setDistancePerPulse(RobotMap.spinnerEncoderDistancePerPulse);
        
        pid = new PIDController(RobotMap.spinnerKp, RobotMap.spinnerKi, RobotMap.spinnerKd, this, this);
        pid.setContinuous(true);
    }
    
    public void startEncoder() {
        spinnerEncoder.start();
        pid.enable();
    }
    
    public void stopEncoder() {
        spinnerEncoder.stop();
        spinnerEncoder.reset();
        pid.disable();
        pid.reset();
    }
    
    public void setSpinner(double rpm) {
        if(this.rpm!=rpm) {
            pid.reset();
            pid.enable();
            this.rpm = rpm;
        }
        pid.setSetpoint(rpm/60);
    }
    
    public void stopSpinner() {
        setSpinner(0.0);
    }

    public void pidWrite(double d) {
        spinner.set(d);
    }

    public double pidGet() {
        double rate = spinnerEncoder.getRate();
        SmartDashboard.putNumber("Shooter Speed", rate*60);
        return(rate);
    }
}
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me

Last edited by Team3266Spencer : 05-02-2013 at 20:53.
Reply With Quote
  #5   Spotlight this post!  
Unread 05-02-2013, 20:52
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: Encoder's PID functional but getRate method not-functional???

Bump
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
Reply With Quote
  #6   Spotlight this post!  
Unread 06-02-2013, 16:34
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: Encoder's PID functional but getRate method not-functional???

I still havn't figured this out, I think I'll have someone else double check the wiring and maybe replace the encoder.
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
Reply With Quote
  #7   Spotlight this post!  
Unread 06-02-2013, 19:06
xmaams xmaams is offline
Registered User
AKA: Sam Dietrich
FRC #2587 (Discobots)
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Houston
Posts: 12
xmaams will become famous soon enoughxmaams will become famous soon enough
Re: Encoder's PID functional but getRate method not-functional???

I think in your code you want to set the setpoint to rpm, not rpm over 60 or anything like that. Another problem could be that you set the PID controller to be continuous.
What kind of encoder are you using? is it an actual shaft encoder or a light sensor? I would be careful about using the getRate method, as this depends on the distance per pulse, which is not really defined for a shooter. In our code, we use the formula 60.0/getPeriod()/countsPerRev to find the rpm of the shooter and then use that in our PID input. It may be easier to implement all of this in a PIDSubsystem.

If you print spinnerEncoder.get() in your teleopPeriodic method, does it count now while the wheel is spinning, even if not with PID?
Reply With Quote
  #8   Spotlight this post!  
Unread 09-02-2013, 13:04
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: Encoder's PID functional but getRate method not-functional???

So it turns out the problem was the digital side car, although I still don't understand why the joystick was able to implement it. And I changed from using the getRate() method to my own code. Now I've run in to a new issue though in which setting the setpoint to anything immediately revs the shooter up to full speed.

Edit: The code is essentially the same, just a few things added in to the PIDGet and got rid of the setContinuous
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
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 12:48.

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