robotdotnet / WPILib

DotNet implementation of WPILib for FIRST Robotics Competition (FRC)
27 stars 8 forks source link

Additional support for command-based robots #116

Closed msoucy closed 7 years ago

codecov-io commented 7 years ago

Codecov Report

Merging #116 into master will decrease coverage by -0.03%. The diff coverage is 0%.

@@            Coverage Diff             @@
##           master     #116      +/-   ##
==========================================
- Coverage   16.09%   16.07%   -0.03%     
==========================================
  Files         125      127       +2     
  Lines        7864     7877      +13     
  Branches      971      971              
==========================================
  Hits         1266     1266              
- Misses       6505     6518      +13     
  Partials       93       93
Impacted Files Coverage Δ
WPILib.Extras/CommandRobot.cs 0% <ø> (ø)
WPILib.Extras/SubsystemCommand.cs 0% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update aefadc6...642b5af. Read the comment docs.

msoucy commented 7 years ago

(Copied from the depths of the pull review)

I found the SubsystemCommand class to be very helpful when playing with WPILib in F#. It might seem hacky, but I personally feel that it's actually more hacky to have the Requires as a separate step. Example:

type Drive() =
    inherit Subsystem()
    // remaining setup, as needed
    override drive.InitDefaultCommand() =
        let cmd = {
            new SubsystemCommand(drive, "TurnZero") with
            override cmd.Initialize() = cmd.m_subsystem.ResetGyro()
            override cmd.Execute() = cmd.m_subsystem.TurnAngle(0.0)
            override cmd.IsFinished() = Math.Abs(cmd.m_subsystem.AngleError) < 0.1
            override cmd.End() = cmd.m_subsystem.StopMotors()
            override cmd.Interrupted() = cmd.End()
            }
        drive.SetDefaultCommand(cmd)

Admittedly, in my actual practice, instead of cmd.m_subsystem I used drive because the scoping rules are a bit different, but adding the Subsystem reference as m_subsystem was an afterthought from when I was porting it back to C#