Beispiel #1
0
        public IEnumerator <ITask> SetMotorPowerHandler(motor.SetMotorPower setMotorPower)
        {
            // Requests come too fast, so dump ones that come in too fast.
            if (RequestPending > 0)
            {
                setMotorPower.ResponsePort.Post(new DefaultUpdateResponseType());
                yield break;
            }

            //flip direction if necessary
            double revPow = setMotorPower.Body.TargetPower;

            if (_state.ReversePolarity)
            {
                revPow *= -1.0;
            }

            //update state
            _state.CurrentPower = revPow;

            //convert to native units
            revPow *= 100;
            revPow += 100;
            int power = (int)Math.Round(revPow);

            //send hardware specific motor data
            brick.SetMotorBody motordata = new brick.SetMotorBody();
            motordata.Motor = _state.Name;
            motordata.Speed = power;

            RequestPending++;

            Activate(Arbiter.Choice(_scribblerPort.SetMotor(motordata),
                                    delegate(DefaultUpdateResponseType status)
            {
                setMotorPower.ResponsePort.Post(DefaultUpdateResponseType.Instance);
                RequestPending--;
            },
                                    delegate(soap.Fault failure)
            {
                setMotorPower.ResponsePort.Post(failure);
                RequestPending--;
            }
                                    ));

            yield break;
        }
Beispiel #2
0
        public IEnumerator<ITask> SetMotorPowerHandler(motor.SetMotorPower setMotorPower)
        {
            // Requests come too fast, so dump ones that come in too fast.
            if (RequestPending > 0)
            {
                setMotorPower.ResponsePort.Post(new DefaultUpdateResponseType());
                yield break;
            }

            //flip direction if necessary
            double revPow = setMotorPower.Body.TargetPower;
            if (_state.ReversePolarity)
                revPow *= -1.0;

            //update state
            _state.CurrentPower = revPow;

            //convert to native units
            revPow *= 100;
            revPow += 100;
            int power = (int)Math.Round(revPow);

            //send hardware specific motor data
            brick.SetMotorBody motordata = new brick.SetMotorBody();
            motordata.Motor = _state.Name;
            motordata.Speed = power;

            RequestPending++;

            Activate(Arbiter.Choice(_scribblerPort.SetMotor(motordata),
                 delegate(DefaultUpdateResponseType status)
                 {
                     setMotorPower.ResponsePort.Post(DefaultUpdateResponseType.Instance);
                     RequestPending--;
                 },
                 delegate(soap.Fault failure)
                 {
                     setMotorPower.ResponsePort.Post(failure);
                     RequestPending--;
                 }
            ));

            yield break;
        }