/// <summary>
 /// Checks whether the specified turn ratio is in range.
 /// </summary>
 /// <param name="turnRatio">The turn ratio.</param>
 /// <param name="parameterName">Name of the parameter.</param>
 /// <param name="usage">The usage.</param>
 internal static void VerifyTurnRatioInRange(TurnRatio turnRatio, string parameterName = null, string usage = null)
 {
     if (turnRatio.CompareTo(TurnRatio.MinValue) < 0 || turnRatio.CompareTo(TurnRatio.MaxValue) > 0)
     {
         throw new ArgumentException($"{usage ?? "Turn ratio"} must be between {TurnRatio.MinValue.Value} and {TurnRatio.MaxValue.Value} inclusive.", parameterName ?? nameof(turnRatio));
     }
 }
 /// <summary>
 /// This function enables to run both motors in turn ratio
 /// (depending on Polarity)
 /// for a specified duration specified in tacho counts at current speed.
 /// </summary>
 /// <param name="tachoCounts">Tacho counts [1 - n]</param>
 /// <param name="ratio">The turn ratio</param>
 public async Task Turn(int tachoCounts, TurnRatio ratio)
 {
     await StepSync(tachoCounts, Speed, (int)ratio);
 }
 /// <summary>
 /// This function enables to run both motors in turn ratio
 /// (depending on Polarity)
 /// for a specified duration specified in tacho counts at current speed and waits for operation to complete
 /// </summary>
 /// <param name="tachoCounts">Tacho counts [1 - n]</param>
 /// <param name="ratio">The turn ratio</param>
 /// <param name="cancellationToken"></param>
 public async Task TurnComplete(int tachoCounts, TurnRatio ratio, CancellationToken cancellationToken = default)
 {
     await StepSyncComplete(tachoCounts, Speed, (int)ratio, cancellationToken : cancellationToken);
 }
Esempio n. 4
0
        /// <summary>
        /// Synchronize timing of motors.
        /// </summary>
        /// <param name="c">The command.</param>
        /// <param name="ports">The port or ports to which the stop command will be sent.</param>
        /// <param name="speed">Speed to turn the motor(s). (-100 to 100)</param>
        /// <param name="turnRatio">The turn ratio to apply. (-200 to 200)</param>
        /// <param name="time">The time to turn the motor(s).</param>
        /// <param name="brake">Brake or coast at the end.</param>
        /// <returns>The updated command.</returns>
        public static Command TimeMotorSync(this Command c, OutputPort ports, Speed speed, TurnRatio turnRatio, uint time, bool brake)
        {
            ParameterHelper.VerifySpeedInRange(speed);
            ParameterHelper.VerifyTurnRatioInRange(turnRatio);

            c.AddOpcode(Opcode.OutputTimeSync);
            c.AddParameter(0x00);
            c.AddParameter((byte)ports);
            c.AddParameter((sbyte)speed);
            c.AddParameter(turnRatio);
            c.AddParameter(time);
            c.AddParameter((byte)(brake ? 0x01 : 0x00));      // brake (0 = coast, 1 = brake)

            return(c);
        }