CSharpRoboticsLib.Drive.Interfaces.GyroscopeDriveExtensions.DriveStraightForTime C# (CSharp) Method

DriveStraightForTime() public static method

Drives the robot in a straight line for a set time using a IMotionController to correct heading
public static DriveStraightForTime ( this d, IMotionController correction, double power, double time, bool brake, double interval = 0.02 ) : void
d this
correction IMotionController to use for correcting heading
power double
time double
brake bool
interval double
return void
        public static void DriveStraightForTime(this IGyroscopeDrive d, IMotionController correction, double power, double time, bool brake, double interval = 0.02)
        {
            correction.SetPoint = d.Gyroscope.GetAngle();
            Stopwatch s = new Stopwatch();

            while (s.Elapsed.TotalSeconds < time)
            {
                double correctingPower = correction.Get(d.Gyroscope.GetAngle());
                d.SetPowers(power + correctingPower, power - correctingPower);
                AccurateWaitSeconds(interval);
            }

            if(brake)
                d.SetPowers(0, 0);
        }