summaryrefslogtreecommitdiff
path: root/src/main/java/frc/robot/subsystems/Chain.java
blob: 24857398eb094907ef9aca413e879f488d164612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package frc.robot.subsystems;

import org.littletonrobotics.junction.Logger;

import com.revrobotics.CANSparkMax;

import edu.wpi.first.math.controller.ProfiledPIDController;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;

public class Chain extends SubsystemBase 
{
    private final CANSparkMax m_motor = Constants.chain;
    private final Encoder m_encoder = Constants.chain_encoder;

    private final ProfiledPIDController m_pid = new ProfiledPIDController(Constants.ChainkP, Constants.ChainkI, Constants.ChainkD, Constants.chain_constraints);

    public Chain()
    {
        // m_motor.setInverted(true);
        // m_encoder.setReverseDirection(true);

        m_encoder.setDistancePerPulse(1.0/Constants.ChainEncoderScale);
        m_encoder.reset();
    }

    public void reset() 
    {
        m_encoder.reset();
    }

    // perc between 0 and 1;
    public void atPercentage(double perc) 
    {
        m_motor.setVoltage(m_pid.calculate(m_encoder.getDistance(), perc));
    }

    @Override
    public void periodic() 
    { 
        Logger.recordOutput(getName() + "/position", m_encoder.getDistance());
    }
}