예제 #1
0
        public void DriveRotateHandler(diffdrive.RotateDegrees rotate)
        {
            if (this.driveEntity == null)
            {
                throw new InvalidOperationException("Simulation entity not registered with service");
            }

            if (!this.state.DriveState.IsEnabled)
            {
                rotate.ResponsePort.Post(Fault.FromException(new Exception("Drive is not enabled.")));
                LogError("RotateDegrees request to disabled drive.");
                return;
            }

            this.state.DriveState.RotateDegreesStage = rotate.Body.RotateDegreesStage;
            if (rotate.Body.RotateDegreesStage == diffdrive.DriveStage.InitialRequest)
            {
                var entityResponse = new Port <engine.OperationResult>();
                Activate(
                    Arbiter.Receive(
                        false,
                        entityResponse,
                        result =>
                {
                    // post a message to ourselves indicating that the drive distance has completed
                    var req = new diffdrive.RotateDegreesRequest(0, 0);
                    switch (result)
                    {
                    case engine.OperationResult.Error:
                        req.RotateDegreesStage = diffdrive.DriveStage.Canceled;
                        break;

                    case engine.OperationResult.Canceled:
                        req.RotateDegreesStage = diffdrive.DriveStage.Canceled;
                        break;

                    case engine.OperationResult.Completed:
                        req.RotateDegreesStage = diffdrive.DriveStage.Completed;
                        break;
                    }

                    this.drivePort.Post(new diffdrive.RotateDegrees(req));
                }));

                this.driveEntity.RotateDegrees((float)rotate.Body.Degrees, (float)rotate.Body.Power, entityResponse);

                var req2 = new diffdrive.RotateDegreesRequest(0, 0)
                {
                    RotateDegreesStage = diffdrive.DriveStage.Started
                };
                this.drivePort.Post(new diffdrive.RotateDegrees(req2));
            }
            else
            {
                SendNotification(this.subMgrPort, rotate);
            }

            rotate.ResponsePort.Post(DefaultUpdateResponseType.Instance);
        }
예제 #2
0
 /// <summary>
 /// Request the drive to rotate or turn in position (positive values turn counterclockwise).
 /// </summary>
 /// <param name="body"></param>
 public RotateDegrees(RotateDegreesRequest body)
 {
     Body = body;
 }