Team2890HawkCollective / 2023-Sensors

2023 Season FRC Robot code for Team 2890 - The Hawk Collective - Seraph
Other
0 stars 0 forks source link

Balancing on Charging Pad #1

Open gavinjalberghini opened 1 year ago

gavinjalberghini commented 1 year ago

Problem: The robot is able to climb onto the charging pad and balance the pad (not necessarily on the pad alone).

Possible Sensors:

Possible Solutions:

Sub-Tasks:

AAARRRCCC commented 1 year ago

1/11/23 Started working on Pigeon IMU Gyro for balancing looking at Wyvern code where it was originally used in End Game

AAARRRCCC commented 1 year ago

Can get data from the pigeon by first creating the necessary objects with

import com.ctre.phoenix.sensors.PigeonIMU;

private WPI_TalonSRX pidgeonTalon = new WPI_TalonSRX(Constants.PIGEON_TALON_PORT_ID); private PigeonIMU _pigeon = new PigeonIMU(pidgeonTalon);

then using _pigeon.getYawPitchRoll(yawPitchRoll); to get the value for the future PID input

AAARRRCCC commented 1 year ago

1/12/23 Started looking into PID loops, began looking on a FRC PID Control documentation page

AAARRRCCC commented 1 year ago
public class Drive(){
    int P, I, D = 1;
    int integral, previous_error, setpoint = 0;
    Gyro gyro;
    DifferentialDrive robotDrive;

    public Drive(Gyro gyro){
        this.gyro = gyro;
    }

    public void setSetpoint(int setpoint)
    {
        this.setpoint = setpoint;
    }

    public void PID(){
        error = setpoint - gyro.getAngle(); // Error = Target - Actual
        this.integral += (error*.02); // Integral is increased by the error*time (which is .02 seconds using normal IterativeRobot)
        derivative = (error - this.previous_error) / .02;
        this.rcw = P*error + I*this.integral + D*derivative;
    }

    public void execute()
    {
        PID();
        robotDrive.arcadeDrive(0, rcw);
    }
}

reference code from the above page

AAARRRCCC commented 1 year ago

official WPILIB page

They have a library to handle all the calculations, probably going to go with that