Пример #1
0
 /// <summary>
 /// moves the sevo instantly.  used for calibrating a servo's max speed.  returns with the duration when the servo apears to have stoped moving.
 /// </summary>
 /// <param name="position">from -180 - 360</param>
 public async Task <ServoCalibrationMoveResponse> CalibrationMoveAsync(float position)
 {
     return(await _runner.ExecuteAsync(new AsyncCommandFirstServoResponse <ServoCalibrationMoveResponse>(_servoID, new ServoCalibrationMoveCommand()
     {
         ServoID = _servoID, Position = position
     }, timeoutMS : 5000)));
 }
Пример #2
0
 /// <summary>
 /// play a series of notes, return when done
 /// </summary>
 /// <param name="notes">format [note:A-F][#][octave:1-7][duration:1-128] ex. D#5-8,C,A-4,R</param>
 public async Task <SoundPlayNotesResponse> PlayNotesAsync(string notes = null, CancellationToken?cancelationToken = null)
 {
     return(await _runner.ExecuteAsync(new AsyncCommandFirstResponse <SoundPlayNotesResponse>(new SoundPlayNotesCommand()
     {
         Notes = notes, CallbackWhenDone = true
     }, cancelationToken, () => Stop(), null, 4000)));
 }
Пример #3
0
        /// <summary>
        /// Animate all the servos to a position using speed and easing.  Will turn on the servo if off.  Returns when position reached or stopped early for all the servos.
        /// </summary>
        /// <param name="speed">0-100</param>
        /// <param name="easeIn">0-100</param>
        /// <param name="easeOut">0-100</param>
        /// <param name="synchronized">all servos will reach their destination at the same time</param>
        /// <param name="percentageComplete">0-1 representing where to start within the movement</param>
        public async Task <IEnumerable <MoveResponse> > MoveAsync(Pose pose, int?speed = null, int?easeIn = null, int?easeOut = null, bool synchronized = false, float?percentageComplete = null, CancellationToken?cancelationToken = null)
        {
            //validate
            if (pose == null)
            {
                return(null);
            }

            var cmd = (synchronized) ? new MoveAllSynchronizedCommand(_servoCount) : new MoveAllCommand(_servoCount);

            cmd.Servo1_Position    = pose.Servo1_Position;
            cmd.Servo2_Position    = pose.Servo2_Position;
            cmd.Servo3_Position    = pose.Servo3_Position;
            cmd.Servo4_Position    = pose.Servo4_Position;
            cmd.Servo5_Position    = pose.Servo5_Position;
            cmd.Servo6_Position    = pose.Servo6_Position;
            cmd.Servo7_Position    = pose.Servo7_Position;
            cmd.Speed              = speed;
            cmd.EaseIn             = easeIn;
            cmd.EaseOut            = easeOut;
            cmd.PercentageComplete = percentageComplete;

            var result    = new ConcurrentBag <MoveResponse>();
            var poseCount = pose.Servos.Count(e => e != null);

            return(await _runner.ExecuteAsync(new AsyncCommand <IEnumerable <MoveResponse> >(cmd, i =>
            {
                //wait until all move commands are received
                var response = i as MoveResponse;
                if (response != null)
                {
                    if (result.FirstOrDefault(e => e.ServoID == response.ServoID) == null && pose.Get(response.ServoID) != null)
                    {
                        //add to results
                        result.Add(response);

                        //return when all found
                        if (result.Count == poseCount)
                        {
                            return result.OrderBy(e => e.ServoID);
                        }
                    }
                }
                return null;
            }, cancelationToken, () => StopMove(),
                                                                                             async origTask =>
            {
                //wait a bit for the MoveResponses to arrive
                var completedTask = await Task.WhenAny(origTask, Task.Delay(500)); //timeout in .5 sec
                if (completedTask == origTask)
                {
                    return await origTask;
                }
                return null;
            }, EstimateMoveTimeout(speed))));
        }
Пример #4
0
        /// <summary>
        /// Send a ping and awaits a reply
        /// </summary>
        public async Task <bool> PingAsync()
        {
            var command = new AsyncCommand <bool>(new PingCommand(), i =>
            {
                var info = i as InfoResponse;
                if (info != null && info.Message == CommandBuilder.PingMessage)
                {
                    return(true);
                }
                return(false);
            });

            return(await _runner.ExecuteAsync(command));
        }
Пример #5
0
 /// <summary>
 /// request to receive the current position of the knob.  the Position event will fire after this call
 /// </summary>
 public async Task <KnobPositionResponse> GetPositionAsync()
 {
     return(await _runner.ExecuteAsync(new AsyncCommandFirstResponse <KnobPositionResponse>(new KnobPositionCommand())));
 }
Пример #6
0
 /// <summary>
 /// request to receive the current status of the button.  the StatusReceived event will fire after this call
 /// </summary>
 public async Task <ButtonStatusResponse> GetStatusAsync()
 {
     return(await _runner.ExecuteAsync(new AsyncCommandFirstResponse <ButtonStatusResponse>(new ButtonStatusCommand())));
 }