Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Reformat robot code #8

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/main/java/frc/robot/Main.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot

import edu.wpi.first.wpilibj.RobotBase
Expand Down
69 changes: 25 additions & 44 deletions src/main/java/frc/robot/Robot.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot

import com.ctre.phoenix6.SignalLogger
Expand All @@ -10,50 +11,36 @@
import edu.wpi.first.wpilibj.PowerDistribution
import edu.wpi.first.wpilibj2.command.Command
import edu.wpi.first.wpilibj2.command.CommandScheduler
import frc.robot.Util.LocalADStarAK
import frc.robot.util.LocalADStarAK
import org.littletonrobotics.junction.LoggedRobot
import org.littletonrobotics.junction.Logger
import org.littletonrobotics.junction.networktables.NT4Publisher
import org.littletonrobotics.junction.wpilog.WPILOGWriter

class Robot : LoggedRobot() {
private var m_autonomousCommand: Command? = null

private var m_robotContainer: RobotContainer? = null
private var robotContainer: RobotContainer = RobotContainer()
private var autonomousCommand: Command? = null

override fun robotInit() {
Pathfinding.setPathfinder(LocalADStarAK())

Logger.recordMetadata("ProjectName", "FRC2024-offseason") // Set a metadata value

// if (isReal()) {
Logger.addDataReceiver(WPILOGWriter()) // Log to a USB stick ("/U/logs") TODO get usb stick
Logger.addDataReceiver(NT4Publisher()) // Publish data to NetworkTables
PowerDistribution(1, PowerDistribution.ModuleType.kRev) // Enables power distribution logging
// }
// else {
// setUseTiming(false) // Run as fast as possible
// val logPath = LogFileUtil.findReplayLog() // Pull the replay log from AdvantageScope (or prompt the user)
// Logger.setReplaySource(WPILOGReader(logPath)) // Read replay log
// Logger.addDataReceiver(
// WPILOGWriter(
// LogFileUtil.addPathSuffix(
// logPath,
// "_sim",
// ),
// ),
// ) // Save outputs to a new log
// }

// Logger.disableDeterministicTimestamps() // See "Deterministic Timestamps" in the "Understanding Data Flow" page
Logger.start() // Start logging! No more data receivers, replay sources, or metadata values may be added.
m_robotContainer = RobotContainer()

m_robotContainer!!.drivetrain.daqThread.setThreadPriority(99)
Logger.recordMetadata("ProjectName", "FRC2024-offseason")
// Log to a USB stick ("/U/logs")
Logger.addDataReceiver(WPILOGWriter()) // TODO get usb stick
// Publish data to NetworkTables
Logger.addDataReceiver(NT4Publisher())
// Enables power distribution logging
PowerDistribution(
1,
PowerDistribution.ModuleType.kRev,
)

// Start logging! No more data receivers, replay sources, or metadata values may be added.
Logger.start()
SignalLogger.start()

DriverStation.silenceJoystickConnectionWarning(true)
SignalLogger.start()
robotContainer.drivetrain.daqThread.setThreadPriority(99)

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Pathfinding.setPathfinder(LocalADStarAK())
PathfindingCommand.warmupCommand().schedule()
}

Expand All @@ -62,40 +49,34 @@
}

override fun disabledInit() {}

override fun disabledPeriodic() {}

override fun disabledExit() {}

override fun autonomousInit() {
m_autonomousCommand = m_robotContainer?.autoCommand
autonomousCommand = robotContainer.autoCommand

if (m_autonomousCommand != null) {
m_autonomousCommand!!.schedule()
if (autonomousCommand != null) {
autonomousCommand?.schedule()
}
}

override fun autonomousPeriodic() {}

override fun autonomousExit() {}

override fun teleopInit() {
if (m_autonomousCommand != null) {
m_autonomousCommand!!.cancel()
if (autonomousCommand != null) {
autonomousCommand!!.cancel()
}
}

override fun teleopPeriodic() {}

override fun teleopExit() {}

override fun testInit() {
CommandScheduler.getInstance().cancelAll()
}

override fun testPeriodic() {}

override fun testExit() {}

override fun simulationPeriodic() {}
}
Loading
Loading