Go to Post Backstabbing your opponents at the last second will not help you win friends and word will get around pretty quick. Your team will be shunned and distrusted for years. People have long memories, and some of us mentors have been playing this game since you kids were playing with blocks. - ChrisH [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-19-2012, 07:39 PM
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
PID Subsystem using direct PWM ouput

I am using a PID subsystem to control our arm. When I start the command to setToSetpoint(setpoint), the PID subsystem actually accesses the PWM port directly, and as I have already made an instance of that PWM port for teleop, I get a NullPointerException for a used PWM port. This stops our code, and is basically detrimental to all our PID controllers. Its worth noting that all of our motor objects are outside of the PID classes, mostly for organization. I am using custom methods to control those motors. These custom commands are perfectly functional, and are not the problem (We use them in teleop). How can I make it so that the PID subsystem does not "reach" into the other portions of the code, and just give the output. Thats it. Is there a workaround for this, or is this not common? I have had very little luck with PID control systems and I am getting fed up with how it has been implemented in the wpilibj libraries. Maybe making my own algorithm might work better.
__________________
All opinions are my own.
Reply With Quote
  #2   Spotlight this post!  
Unread 04-20-2012, 11:10 AM
Sunstroke Sunstroke is offline
Programmer
AKA: Joe Grinstead
FRC #3504 (Girls of Steel)
Team Role: Mentor
 
Join Date: Apr 2009
Rookie Year: 2009
Location: New England
Posts: 49
Sunstroke is an unknown quantity at this point
Re: PID Subsystem using direct PWM ouput

Could you post your PIDSubsystem.
Reply With Quote
  #3   Spotlight this post!  
Unread 04-20-2012, 12:45 PM
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Question Re: PID Subsystem using direct PWM ouput

Code:
package Subsystems;

import Hardware.Arm;
import Hardware.Sensors.Sensors;
import edu.wpi.first.wpilibj.command.PIDSubsystem;

/**
 * PIDarm - 
 * @author Joel Gallant
 */
public class PIDarm extends PIDSubsystem {
    private static final double Kp = 6.0;
    private static final double Ki = 0.0;
    private static final double Kd = 0.0;
    
    private Arm arm = new Arm();


    public PIDarm() {
        super("PIDarm", Kp, Ki, Kd);

        // setSetpoint() -  Sets where the PID controller should move the system to.
        // setStepointRange() - Sets the range that the setpoint may be in.
        // enable() - Enables the PID controller.
        setSetpointRange(arm.HIGH, arm.LOW);
    }
    
    public void initDefaultCommand() {
        // Set the default command for a subsystem here.
    }

    protected double returnPIDInput() {
        // Return your input value for the PID loop.
        return Sensors.getArmPosition();
    }

    protected void usePIDOutput(double output) {
        // Use output to drive your system, like a motor.
        arm.move(output);
    }
}
That's as simple as it gets. Yet it does nothing.
For further detail into the PIDOutput...
Code:
    public void move(double speed){
        if(speed > -0.05 && Sensors.getBack() && Sensors.getArmPosition() < HIGH) {
            leftArm().set(speed*maxArmSpeed);
            rightArm().set(speed*maxArmSpeed);
        }else if(speed > 0.05 && Sensors.getFront() && Sensors.getArmPosition() > LOW) {
            leftArm().set(speed*maxArmSpeed);
            rightArm().set(speed*maxArmSpeed);
        }else {
            leftArm().set(0);
            rightArm().set(0);
        }
    }
That's the method used for move arm.

leftArm() and rightArm() are as followed
Code:
private SpeedController leftArm;
    private SpeedController rightArm;
    
    private SpeedController leftArm() {
        if(leftArm == null) {
            leftArm = new Victor(PortMapping.armLeftChannel);
        }
        return leftArm;
    }
    private SpeedController rightArm() {
        if(rightArm == null) {
            rightArm = new Victor(PortMapping.armRightChannel);
        }
        return rightArm;
    }
Maybe I am not seeing something, but this should not create a new allocation of the PWM.
BTW PWM port 5 is leftArm, which is the one that gets allocated wrongly.
__________________
All opinions are my own.
Reply With Quote
  #4   Spotlight this post!  
Unread 04-20-2012, 04:32 PM
Sunstroke Sunstroke is offline
Programmer
AKA: Joe Grinstead
FRC #3504 (Girls of Steel)
Team Role: Mentor
 
Join Date: Apr 2009
Rookie Year: 2009
Location: New England
Posts: 49
Sunstroke is an unknown quantity at this point
Re: PID Subsystem using direct PWM ouput

Hmm... The PIDSubsystem doesn't do much behind the scenes, it just kind of takes your input and spits back an output.

It seems more likely to me that you have maybe created an arm somewhere else as well or maybe two PIDArms? Maybe you didn't get rid of all the references to Arm in the code when you stuck in PIDArm...

That would be where I first look for the problem.
Reply With Quote
  #5   Spotlight this post!  
Unread 04-20-2012, 08:46 PM
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: PID Subsystem using direct PWM ouput

That's what I found too. Thanks.
Although Im not using PID anymore, as the buttons on smartdashboard do not properly implement the command.
__________________
All opinions are my own.
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 07:48 AM.

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