Exemple #1
0
        /// <summary>
        /// This command controls a single servo.
        /// </summary>
        /// <param name="channel">Pin / channel to which the servo is connected (0 to 31).</param>
        /// <param name="pulseWidth">Desired pulse width (normally 500 to 2500) in microseconds.</param>
        /// <param name="speed">Servo movement speed in microseconds per second.</param>
        /// <param name="time">Time in microseconds to travel from the current position to the desired position. (65535 max)</param>
        public static Command SingleServo(this Command command, int channel, int pulseWidth, int?speed = null, ushort?time = null)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            SSC32.ValidateServoChannel(channel);
            var sb = command.Builder;

            sb.Append('#');
            sb.Append(channel);
            sb.Append('P');
            sb.Append(pulseWidth);
            if (speed != null)
            {
                sb.Append('S');
                sb.Append(speed);
            }
            if (time != null)
            {
                sb.Append('T');
                sb.Append(time);
            }
            return(command);
        }
Exemple #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
                {
                    SSC32.Dispose();
                }

                isDisposed = true;
            }
        }
Exemple #3
0
        /// <summary>
        /// Immediately stops the specified servo at its current position.
        /// </summary>
        /// <returns>The position offset.</returns>
        /// <param name="channel">Pin / channel to which the servo is connected (0 to 31).</param>
        public static Command StopServo(this Command command, int channel)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            SSC32.ValidateServoChannel(channel);
            var sb = command.Builder;

            sb.Append("STOP");
            sb.Append(channel);
            return(command);
        }
Exemple #4
0
        /// <summary>
        /// The position offset command allows you to change the center position (associated with 1500us)
        /// of one or more servos via software within 15 degrees of the absolute center.
        /// </summary>
        /// <returns>The position offset.</returns>
        /// <param name="channel">Pin / channel to which the servo is connected (0 to 31).</param>
        /// <param name="positionOffset">The position offset is restricted to -100us to 100us (around 15°)</param>
        public static Command ServoPositionOffset(this Command command, int channel, int positionOffset)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            SSC32.ValidateServoChannel(channel);
            if (positionOffset < -100 || positionOffset > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(positionOffset), "The position offset is restricted to -100us to 100us (around 15°)");
            }
            var sb = command.Builder;

            sb.Append('#');
            sb.Append(channel);
            sb.Append("PO");
            sb.Append(positionOffset);
            return(command);
        }
Exemple #5
0
 public void OpenSSC32Connection(string portName, int baud)
 {
     SSC32.Open(portName, baud);
 }