Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Simon arm control #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,70 @@

package frc.robot;


import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.networktables.NT4Publisher;

import com.ctre.phoenix6.StatusSignal;
import com.ctre.phoenix6.controls.VoltageOut;
import com.ctre.phoenix6.hardware.TalonFX;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.XboxController;

public class Robot extends LoggedRobot {

private TalonFX armMotor = new TalonFX(16);
XboxController controller = new XboxController(0);
VoltageOut armVoltage = new VoltageOut(0);
StatusSignal<Double> armRotor = armMotor.getRotorPosition();
double xGoalRotations = Rotation2d.fromDegrees(10).getRotations();
double yGoalRotations = Rotation2d.fromDegrees(50).getRotations();


public Robot() {
Logger.getInstance().addDataReceiver(new NT4Publisher());

Logger.getInstance().start();
}

public void setWristAngle(double degrees, double currentRotation) {
double setDegrees = Rotation2d.fromDegrees(degrees).getRotations();

if (setDegrees<currentRotation) {
armMotor.setControl(armVoltage.withOutput(0.2));
if(setDegrees==currentRotation){
armMotor.setControl(armVoltage.withOutput(0));
}
} else if (setDegrees>currentRotation) {
armMotor.setControl(armVoltage.withOutput(-0.2));
if(setDegrees==currentRotation){
armMotor.setControl(armVoltage.withOutput(0));
}
} else if (setDegrees== currentRotation) {
armMotor.setControl(armVoltage.withOutput(0));
}
}
@Override
public void teleopPeriodic() {
boolean aPressed = controller.getAButtonPressed();
boolean xPressed = controller.getXButtonPressed();
boolean yPressed = controller.getYButtonPressed();
boolean bPressed = controller.getBButtonPressed();
double motorRotations = armRotor.getValue();
double armRotations = motorRotations /50;
if(aPressed){
armMotor.disable();
}
if (bPressed) {
armMotor.setRotorPosition(0);
}
if (xPressed) {
setWristAngle(10, armRotations);
}
if(yPressed) {
setWristAngle(50, armRotations);
}
}
}