Skip to content

Commit 1ccfaa1

Browse files
authored
Merge pull request #7 from CshCyberhawks/implemetent-coral-end-effector
Implemetent coral end effector
2 parents b2fd247 + 8161f9c commit 1ccfaa1

14 files changed

Lines changed: 272 additions & 101 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,4 @@ compile_commands.json
186186
# Eclipse generated file for annotation processors
187187
.factorypath
188188

189-
gradle.properties
189+
gradle.properties

gradle.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package frc.robot
22

3-
enum class RobotState {
3+
enum class RobotType {
44
Real,
55
Simulated,
66
Empty
77
}
88

99
object RobotConfiguration {
10-
val robotState = RobotState.Empty
10+
val robotType = RobotType.Empty
1111
}

src/main/java/frc/robot/RobotContainer.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ object RobotContainer {
2626

2727
val vision = VisionSystem()
2828

29-
val drivetrain = when (RobotConfiguration.robotState) {
30-
RobotState.Real -> SwerveIOReal()
31-
RobotState.Simulated -> SwerveIOSim()
32-
RobotState.Empty -> SwerveIOBase()
29+
val drivetrain = when (RobotConfiguration.robotType) {
30+
RobotType.Real -> SwerveIOReal()
31+
RobotType.Simulated -> SwerveIOSim()
32+
RobotType.Empty -> SwerveIOBase()
3333
}
3434

35-
val teleopDriveCommand = when (RobotConfiguration.robotState) {
36-
RobotState.Real -> TeleopDriveCommand()
37-
RobotState.Simulated -> SimTeleopDriveCommand()
38-
RobotState.Empty -> Commands.run({})
35+
val teleopDriveCommand = when (RobotConfiguration.robotType) {
36+
RobotType.Real -> TeleopDriveCommand()
37+
RobotType.Simulated -> SimTeleopDriveCommand()
38+
RobotType.Empty -> Commands.run({})
3939
}
4040

4141
init {
@@ -45,8 +45,8 @@ object RobotContainer {
4545
private fun configureBindings() {
4646
drivetrain.setDefaultCommand(teleopDriveCommand)
4747

48-
49-
drivetrain.registerTelemetry(logger::telemeterize)
48+
// We might need this?
49+
// drivetrain.registerTelemetry(logger::telemeterize)
5050
}
5151

5252
val autonomousCommand: Command
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package frc.robot
2+
3+
import frc.robot.subsystems.intake.AlgaeState
4+
import frc.robot.subsystems.intake.CoralState
5+
6+
object RobotState {
7+
// Sure we need these
8+
// I don't think we want to use them in the superstructure, but it might make sense to reference them in swerve or auto
9+
var coralState = CoralState.Empty
10+
var algaeState = AlgaeState.Empty
11+
}

src/main/java/frc/robot/Vision.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import kotlin.math.max
1818
class VisionSystem {
1919
val max_distance_m = 6.0
2020

21-
val limelightNames: Array<String> = when (RobotConfiguration.robotState) {
22-
RobotState.Real -> arrayOf("limelight-front")
21+
val limelightNames: Array<String> = when (RobotConfiguration.robotType) {
22+
RobotType.Real -> arrayOf("limelight-front")
2323
else -> emptyArray()
2424
}
2525

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package frc.robot.subsystems.intake
22

33
object IntakeConstants {
4-
val kG = 0.0
5-
val kS = 0.0
6-
val kV = 0.0
7-
val kA = 0.0
8-
val kP = 0.0
9-
val kI = 0.0
10-
val kD = 0.0
11-
val targetVelocity = 0.0
12-
val targetAcceleration = 0.0
13-
val targetJerk = 0.0
14-
val id = 0
15-
val canbus = ""
4+
const val coralMotorId = 40
5+
const val algaeMotorId = 41
6+
const val coralLaserCANId = 42
7+
const val algaeLaserCANId = 43
8+
9+
const val coralScoreTimeoutSeconds = 0.5
10+
const val algaeScoreTimeoutSeconds = 0.5
1611
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package frc.robot.subsystems.intake
22

3-
import com.ctre.phoenix6.configs.TalonFXConfiguration
4-
import com.ctre.phoenix6.hardware.TalonFX
5-
63
interface IntakeIO {
74
// fun getIntakeEncoder(): Double
85

96
// fun setIntakeMotor(x: Double)
107
fun setCoralIntakeState(state: CoralIntakeState)
118
fun setAlgaeIntakeState(state: AlgaeIntakeState)
9+
10+
fun getCoralState(): CoralState
11+
fun getAlgaeState(): AlgaeState
1212
}
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
package frc.robot.subsystems.intake
22

3-
enum class CoralIntakeState {
4-
Intaking,
5-
Idle,
6-
Scoring
3+
enum class CoralIntakeState(val speed: Double) {
4+
Intaking(0.75),
5+
Idle(0.0),
6+
Scoring(0.5)
77
}
88

99
enum class AlgaeIntakeState {
1010
Intaking,
1111
Idle,
12-
Scoring
12+
Scoring,
13+
Holding
14+
}
15+
16+
enum class CoralState {
17+
Empty,
18+
Stored
19+
}
20+
21+
enum class AlgaeState {
22+
Empty,
23+
Stored
1324
}
Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
package frc.robot.subsystems.intake
22

3+
import edu.wpi.first.wpilibj2.command.Command
4+
import edu.wpi.first.wpilibj2.command.Commands
35
import edu.wpi.first.wpilibj2.command.SubsystemBase
6+
import frc.robot.RobotState
47

58
// By making a subsystem a Kotlin object, we ensure there is only ever one instance of it.
69
// It also reduces the need to have reference variables for the subsystems to be passed around.
710
class IntakeSystem(private val io: IntakeIO) : SubsystemBase() {
8-
/**
9-
* Example command factory method.
10-
*
11-
* @return a command
12-
*/
13-
// fun exampleMethodCommand(): Command = runOnce {
14-
// // Subsystem.runOnce() implicitly add `this` as a required subsystem.
15-
// // TODO: one-time action goes here
16-
// }
17-
18-
/**
19-
* An example method querying a boolean state of the subsystem (for example, a digital sensor).
20-
*
21-
* @return value of some boolean subsystem state, such as a digital sensor.
22-
*/
23-
// fun exampleCondition(): Boolean {
24-
// // Query some boolean state, such as a digital sensor.
25-
// return false
26-
// }
11+
private fun setCoralIntakeState(state: CoralIntakeState) = run { io.setCoralIntakeState(state) }
12+
private fun setAlgaeIntakeState(state: AlgaeIntakeState) = run { io.setAlgaeIntakeState(state) }
13+
14+
private fun awaitCoralState(state: CoralState) = Commands.waitUntil { io.getCoralState() == state }
15+
private fun awaitAlgaeState(state: AlgaeState) = Commands.waitUntil { io.getAlgaeState() == state }
16+
17+
fun coralIntake() = Commands.sequence(
18+
setCoralIntakeState(CoralIntakeState.Intaking),
19+
awaitCoralState(CoralState.Stored),
20+
setCoralIntakeState(CoralIntakeState.Idle)
21+
)
22+
23+
fun coralScore() = Commands.sequence(
24+
setCoralIntakeState(CoralIntakeState.Scoring),
25+
awaitCoralState(CoralState.Empty),
26+
Commands.waitSeconds(IntakeConstants.coralScoreTimeoutSeconds),
27+
setCoralIntakeState(CoralIntakeState.Idle)
28+
)
29+
30+
fun algaeIntake() = Commands.sequence(
31+
setAlgaeIntakeState(AlgaeIntakeState.Intaking),
32+
awaitAlgaeState(AlgaeState.Stored),
33+
setAlgaeIntakeState(AlgaeIntakeState.Holding)
34+
)
35+
36+
fun algaeScore() = Commands.sequence(
37+
setAlgaeIntakeState(AlgaeIntakeState.Scoring),
38+
awaitAlgaeState(AlgaeState.Empty),
39+
Commands.waitSeconds(IntakeConstants.algaeScoreTimeoutSeconds),
40+
setAlgaeIntakeState(AlgaeIntakeState.Idle)
41+
)
42+
2743

2844
override fun periodic() {
29-
// This method will be called once per scheduler run
45+
RobotState.coralState = io.getCoralState()
46+
RobotState.algaeState = io.getAlgaeState()
3047
}
3148

3249
override fun simulationPeriodic() {
33-
// This method will be called once per scheduler run during simulation
34-
}
35-
36-
// fun exampleAction()
37-
// {
38-
// // This action is called by the ExampleCommand
39-
// println("ExampleSubsystem.exampleAction has been called")
40-
// }
41-
42-
fun getPos(): Double {
43-
TODO("Not yet implemented")
44-
return 0.0;
45-
}
46-
47-
fun setPos(x: Double) {
48-
TODO("Not yet implemented")
4950
}
5051
}

0 commit comments

Comments
 (0)