Git Product home page Git Product logo

nrhartfrc / position-closed-loop-pid-control Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 15.72 MB

Off-season FRC preparation. Testbench demonstration program for closed loop position control using RoboRio as a PID controller. Includes SmartDashboard features for GUI interaction. Either manual or analog inputs are acceptable. Limit switches are configured as well.

Home Page: https://oceanarobotics.github.io/OceanaFRC/

License: Other

Java 100.00%
can-bus dc-motor encoder frc frc-driverstation java pid position-control potentiometer roborio

position-closed-loop-pid-control's Introduction

Position Closed Loop PID Control

PositionPIDControlTestbench

Figure 1: Coach Werner's testbench with RoboRio, Sparkmax, potentiometer, and JE-PLG-410.

Description

This program demonstrates a closed loop PID postion controller that controls the position of a 'shuttle' along a lead screw. The lead screw is driven by a brushed DC motor using a SparkMax motor controller. There are two different modes/options for position control: manual mode, and analog mode. Manual mode requires the user to manually type the Set Rotations value. Analog mode uses real-time data from the analog input channel of the RoboRio using a potentiometer. A practical application of this code is to command a motor to a known rotational position and hold it there.

Usage

Set the variables at the beginning of the example to match your setup.

  • deviceID - CAN device ID
  • MotorType - kBrushed or kBrushless
  • SparkMaxRelativeEncoder.Type.kQuadrature - KQuadrature or kHallSensor
  • countsPerRev - 4
  • AnalogInput channel - 0

Demo

Position.Closed.Loop.PID.Control.mp4

Walk Through

Code Specifications

Instructions

  • download ZIP file or clone this repository
  • open WPILib VSCode application
  • File > Open Folder...
  • select and open this root folder (Position Closed Loop PID Control)
  • wiring connections
  • deploy: right click build.gradle file > click Deploy Robot Code
  • terminal will appear and confirm BUILD SUCCESSFUL
  • open FRC Driver Station
  • console: click gear icon > View Console
  • open SmartDashboard 2023 application (comes with WPILib Installer for Windows)
  • click big button @ FRC Driver Station (disable if needed)
  • Make SmartDashboard widgets/objects viewable: View > Editable (toggle as needed) & View > Edit Subsystems
  • To get graphs, in Editable state, right click widget Change to... > LinePlot
  • Enable and rotate pot (this is Option 2)
  • Update values as desired (P, I, D, Iz, FF, Max Output, Min Output)

Notes

  1. Linear 0-5V voltage mapping does not actually reach limit switches (reference maxSetpoint and minSetpoint, see Note 2).
  2. Modify mapPotentiometerValueToSetpoint method at bottom of code; widen range for actual limit switch functionality.
  3. Also would need to modify 'supersoft' limits (Math.max(10, Math.min(400, rotations)) to use limit switches.
  4. Power is only truly killed while both limit switches are pressed.
  5. USE EITHER OPTION 1 OR OPTION 2 (manual position control or analog input position control). Do not use both.
  6. Comment one unused option as needed. They appear as m_pidController.setReference(); (this is the Position PID in action).
  7. rotations variable is only used for Option 1.
  8. analogsetpoint variable is only used for Option 2.

Outputs

PID Coefficients can be adjusted on SmartDashboard to tune the controller. Max Output and Min Output values can be adjusted in either in either mode--this controls the speed and power of the output (consider the PID will modulate this raw value). SmartDashboard actively monitors: (i) left & right limit switch statuses; (ii) motor current; (iii) motor speed, and (iv) motor output duty cycle.

For manual mode, use 'Set Rotations' to change position of the shuttle or whatever else you want to control by typing in a value. Off-clicking from SmartDashboard executes the changes made for manual mode. The SetPoint Ref. and ProcessVariable will be displayed on SmartDashboard as shown in Figure 2.
ManualMode

Figure 2: Manual mode from SmartDashboard

For analog option, the potentiometer completely controls the shuttle as shown in Figure 3.
AnalogMode

Figure 3: Analog mode from SmartDashboard

Future

  • Sendable chooser for Option 1 (manual) and Option 2 (analog input) instead of commenting and uncommenting options
  • Partition code into separate classes (.java files) for easy integration purposes

position-closed-loop-pid-control's People

Contributors

nrhartfrc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.