| 1 | == Position Mode == |
| 2 | |
| 3 | Things needed to initialize position mode. |
| 4 | |
| 5 | You need to set these variables: |
| 6 | {{{ |
| 7 | P = 100.0, |
| 8 | I = 0.0, |
| 9 | D = 0.0; |
| 10 | }}} |
| 11 | |
| 12 | Change as necessary. These are *not* recommended values. |
| 13 | |
| 14 | Read up on PID loops as necessary. |
| 15 | |
| 16 | In the constructor of your subsystem, you need: |
| 17 | |
| 18 | {{{armMotor.setFeedbackDevice(FeedbackDevice.EncoderType);}}} |
| 19 | |
| 20 | {{{armMotor.configEncoderCodesPerRev(X);}}} |
| 21 | |
| 22 | Note that on QuadEncoders this is the nominal value, not the actual value |
| 23 | |
| 24 | {{{armMotor.setEncPosition(0);}}} |
| 25 | |
| 26 | This will save you a lot of future headache |
| 27 | |
| 28 | You need these methods: |
| 29 | |
| 30 | {{{ |
| 31 | public void enable() { |
| 32 | armMotor.enableControl(); |
| 33 | } |
| 34 | }}} |
| 35 | |
| 36 | {{{ |
| 37 | public void positionMode() { |
| 38 | armMotor.changeControlMode(TalonControlMode.Position); |
| 39 | armMotor.setPID(P, I, D); |
| 40 | } |
| 41 | }}} |
| 42 | |
| 43 | Finally, here's some example code. |
| 44 | |
| 45 | To initialize it, you need to run this: |
| 46 | |
| 47 | {{{ |
| 48 | Robot.armSys.positionMode(); |
| 49 | Robot.armSys.enable(); |
| 50 | }}} |
| 51 | |
| 52 | Finally, once you've initialized the code: |
| 53 | |
| 54 | {{{ |
| 55 | Robot.armSys.setArmTalon(1F); |
| 56 | }}} |
| 57 | |
| 58 | This will make it move one rotation. |