|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Java x axis on joystick
Quote:
What is the purpose of a PID subsystem? I have never understood why PIDSubsystems are used -- couldn't this have been accomplished using just a regular subsystem? What are the advantages to using a PIDSubsystem and when should it be used? |
|
#2
|
|||||
|
|||||
|
Re: Java x axis on joystick
Quote:
PID allows you to set a target speed or position (or any other measurable quantity), and the code automatically seeks to attain and maintain that value. The key requirement of PID (or any other feedback technique) is that you are regularly measuring the output state of the system. This year on our lift, we're using a 10-turn potentiometer as a sensor. The current mechanical setup is the electrified tape measure similar to the one shown in this post. One of our mentors doesn't trust return springs in cheap tape measures, so we may switch to something that engages a 22-tooth idle sprocket with our lift chain. Tuning the PID to minimize settle time, overshoot, oscillation, and droop is at least as much art as science, but we're going to take that plunge again this year. We have also used PID loops in the past (and will again this year) to automatically aim our game piece manipulators. For Rebound Rumble, Ultimate Ascent and Aerial Assist, this meant driving the robot so that we were properly positioned to score when we threw the game piece. For Recycle Rush, our goal is to align on the totes (and RCs) so consistently that they form a neat, stable, stack. For these applications the sensor has been, or at least included, a camera. The desired "output" in this case is the size and location of a vision target as reported by some openCV scripts. |
|
#3
|
||||
|
||||
|
Re: Java x axis on joystick
Quote:
![]() Would it make sense to setup your Drive Train subsystem itself as a PIDSubsystem using encoders? |
|
#4
|
|||||
|
|||||
|
Re: Java x axis on joystick
Quote:
We like to keep our subsystems as simple as possible and do the bulk of our work in the commands. This is one of the reasons we prefer the command route. |
|
#5
|
||||
|
||||
|
Re: Java x axis on joystick
This is my first year using Command Based and I haven't used PID-anything yet. I'm going to have to look into them -- what makes you prefer PIDCommands over PIDSubsystems?
|
|
#6
|
|||||
|
|||||
|
Re: Java x axis on joystick
Quote:
One class you can take a look at is our DriveAtSpeed class. Last edited by notmattlythgoe : 12-02-2015 at 14:17. |
|
#7
|
|||||
|
|||||
|
Re: Java x axis on joystick
If you're interested in controlling speed, yes. If you're going to use it to drive a precise distance and stay at that location, no. This is because as you approach the desired condition (stationary), you aren't getting feedback. And no, I would not consider "drive into the AutoZone" as requiring a precise distance measurement for this purpose.
|
|
#8
|
|||
|
|||
|
Re: Java x axis on joystick
Quote:
Something like Code:
public class NordicSpeedController extends PIDSubsystem implements SpeedController {
SpeedController m_motor;
Encoder m_encoder;
public NordicSpeedController(SpeedController motor, Encoder encoder) {
super(1.0,0,0); // pass PID to PIDSubsystem construtor
}
public void usePIDOutput(double output) {
motor.set(output)
}
public double returnPIDInput() {
//Be sure encoder setDistancePerPulse() is set such that this returns
//values between -1.0 and +1.0 over the full range of speed you can go
return encoder.getRate();
}
//Next functions implment SpeedController Interface
public void set(double speed) {
enable();
setSetpoint(speed)
}
public void set(double speed, int syncGroup) {
//We don't need syncGroup so simplify implmenetation
set(speed)
}
//Not entirely sure this shouldn't return getPIDController.getSetpoint()
public double get() {
return encoder.getRate();
}
}
This allows us to call driveTrain.mecanumDrive which in turn calls m_robotDrive.mecanumDrive_Cartesian() and we can request that we drive 0.1 (10 % of full speed). To move the robot, the PID can apply 1.0 power for a few ms and as the wheels start turning our rate increases until the robot can move, then the PID keeps increasing/decreasing motor power to maintain 10% speed. Without PID, 0.1 power would likely not even overcome friction. You can then create PIDCommands to act on the drive train as a whole for DriveToDistance or RotateToAngle or DriveAlongAngle and it will call tankDrive or mecanumDrive in the usePIDOutput() function and read the distance off an appropriate encoder or the angle off the gyro to make adjustments to the rotation or forward speed. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|