Beispiel #1
0
 /// <summary>
 /// Animate the servo to a position using speed and easing.  Will turn on the servo if off.  Returns when position reached or stopped early.
 /// </summary>
 /// <param name="position">from -180 - 360</param>
 /// <param name="speed">0-100</param>
 /// <param name="easeIn">0-100</param>
 /// <param name="easeOut">0-100</param>
 public async Task <MoveResponse> MoveAsync(float position, int?speed = null, int?easeIn = null, int?easeOut = null, CancellationToken?cancelationToken = null)
 {
     return(await _runner.ExecuteAsync(new AsyncCommandFirstServoResponse <MoveResponse>(_servoID, new MoveCommand()
     {
         ServoID = _servoID, Position = position, Speed = speed, EaseIn = easeIn, EaseOut = easeOut
     }, cancelationToken, () => StopMove(),
                                                                                         async origTask =>
     {
         //wait a bit for the MoveResponse to arrive
         var completedTask = await Task.WhenAny(origTask, Task.Delay(200));     //timeout in .2 sec
         if (completedTask == origTask)
         {
             return await origTask;
         }
         return null;
     }, Servos.EstimateMoveTimeout(speed))));
 }
Beispiel #2
0
        public Arm(ICommunication comm, int servoCount = 5)
        {
            //set fields
            Communication = comm;
            Behaviors     = new BehaviorManager(this);
            _runner       = new CommandRunner(comm);
            Led           = new Led(_runner, this);
            Button        = new Button(_runner, this);
            Knob          = new Knob(_runner, this);
            Sound         = new Sound(_runner, this);
            Servos        = new Servos(_runner, this, servoCount);

            //register responses
            _runner.RegisterForResponse <ErrorResponse>(ErrorResponse);
            _runner.RegisterForResponse <InfoResponse>(InfoResponse);
            _runner.RegisterForResponse <SoftResetResponse>(SoftResetResponse);
        }