Guest User

Untitled

a guest
May 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package frc.team5190.robot.drive
  2.  
  3. import com.ctre.phoenix.motorcontrol.ControlMode
  4. import edu.wpi.first.wpilibj.command.Command
  5. import org.apache.commons.math3.stat.regression.SimpleRegression
  6.  
  7. @Suppress("unused")
  8. class CharacterizationCommand : Command() {
  9. private var outPct = 0.0
  10. private var lastIncrementTime = 0L
  11.  
  12. private var vIntercept = 0.0
  13.  
  14. private val linReg = SimpleRegression()
  15. private val dataPts = ArrayList<Pair<Double, Double>>()
  16.  
  17. private val avgDriveSpd
  18. get() = ((DriveSubsystem.leftVelocity + DriveSubsystem.rightVelocity) / 2.0).FPS.value
  19.  
  20. init {
  21. requires(DriveSubsystem)
  22. }
  23.  
  24. override fun initialize() {
  25. lastIncrementTime = System.currentTimeMillis()
  26. dataPts.add(outPct to avgDriveSpd)
  27. }
  28.  
  29. override fun execute() {
  30. if (System.currentTimeMillis() - lastIncrementTime > 1000) {
  31. lastIncrementTime = System.currentTimeMillis()
  32. if (avgDriveSpd > 0.01) {
  33. if (vIntercept == 0.0) vIntercept = outPct
  34. dataPts.add(outPct to avgDriveSpd)
  35. println("Added Data Point: $outPct% --> $avgDriveSpd FT per second.")
  36. }
  37. outPct += 0.02
  38. }
  39. DriveSubsystem.set(ControlMode.PercentOutput, outPct, outPct)
  40. }
  41.  
  42. override fun end() {
  43. dataPts.forEach { linReg.addData(it.first, it.second) }
  44. println("V: ${1 / linReg.slope}, V Intercept: $vIntercept, Linearity: ${linReg.rSquare}")
  45. }
  46.  
  47. override fun isFinished() = outPct > 1.0
  48. }
Add Comment
Please, Sign In to add comment