Beispiel #1
0
        protected override IProtocol ExecuteUKitCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command); do

            {
                if (command is UKitCommands.ColorRecognitionCommand)
                {
                    debug = command.debug;
                    var cmd = (UKitCommands.ColorRecognitionCommand)command;
                    if (LineTrace(out var distance, out Color rgb))
                    {
                        result.SetDatas(Misc.Nearly(cmd.color, rgb));
                        result.code = 0;

                        DebugUtility.Log(LoggerTags.Project, "ColorRecognitionCommand Reacted : {0}m", distance);
                    }
                    break;
                }
                if (command is UKitCommands.ColorRecognitionRGBCommand)
                {
                    debug = command.debug;
                    //var cmd = (UKitCommands.UltrasonicCommand)command;
                    if (LineTrace(out var distance, out Color rgb))
                    {
                        result.SetDatas((int)(rgb.r * 255), (int)(rgb.g * 255), (int)(rgb.b * 255));
                        result.code = 0;

                        DebugUtility.Log(LoggerTags.Project, "ColorRecognitionRGBCommand Reacted : {0}m", distance);
                    }
                    break;
                }
            } while (false);

            return(result);
        }
Beispiel #2
0
        private IProtocol ExecuteSoundCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            do
            {
                // 播放音调
                if (command is SoundCommands.PlayPitchCommand)
                {
                    var cmd = (SoundCommands.PlayPitchCommand)command;
                    PlayPitch(cmd.pitch, cmd.duration);
                    result.code = 0;
                    break;
                }

                // 播放频率
                if (command is SoundCommands.PlayFrequencyCommand)
                {
                    var cmd = (SoundCommands.PlayFrequencyCommand)command;
                    PlayFrequency(cmd.frequency, cmd.duration);
                    result.code = 0;
                    break;
                }

                // 停止播放
                if (command is SoundCommands.StopCommand)
                {
                    // var cmd = (SoundCommands.StopCommand)command;
                    StopPlay();
                    result.code = 0;
                    break;
                }
            }while (false);
            return(result);
        }
Beispiel #3
0
        private IProtocol ExecuteMotorCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            do
            {
                if (command is MotorCommands.VelocitySettingCommand)
                {
                    var cmd = (MotorCommands.VelocitySettingCommand)command;
                    jobStatus = WorkStatus.RotationAlways;
                    var job = (RotationAlwaysJob)currentJob;
                    job.velocity = cmd.velocity;
                    result.code  = 0;
                    break;
                }

                if (command is MotorCommands.PWMSettingCommand)
                {
                    var cmd = (MotorCommands.PWMSettingCommand)command;
                    jobStatus = WorkStatus.RotationAlways;
                    var job = (RotationAlwaysJob)currentJob;
                    job.velocity = cmd.pwm;
                    result.code  = 0;
                    break;
                }

                if (command is MotorCommands.ReadVelocityCommand)
                {
                    var cmd = (MotorCommands.ReadVelocityCommand)command;
                    int v   = 0;
                    if (jobStatus == WorkStatus.RotationAlways)
                    {
                        var job = (RotationAlwaysJob)currentJob;
                        v = (int)job.velocity;
                    }
                    result.SetDatas((int)v);
                    result.code = 0;
                    break;
                }

                if (command is MotorCommands.StopCommand)
                {
                    var cmd = (MotorCommands.StopCommand)command;
                    Stop();
                    result.code = 0;
                    break;
                }
            } while (false);

            return(result);
        }
Beispiel #4
0
        protected bool ExecuteUKitCommands(ICommand command, out IProtocol result)
        {
            bool resImme = true;
            var  result2 = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            do
            {
                if (command is UKitCommands.ButtonCommand)
                {
                    debug = command.debug;
                    if (!Populate(result2))
                    {
                        resImme = false;
                    }
                    break;
                }
            } while (false);

            result = result2;
            return(resImme);
        }
Beispiel #5
0
        protected override IProtocol ExecuteUKitCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            do
            {
                if (command is UKitCommands.SoundCommand)
                {
                    debug = command.debug;
                    if (GetEnvironment(out var env))
                    {
                        //var cmd = (UKitCommands.SoundCommand)command;
                        result.SetDatas(Mathf.CeilToInt(env.soundVolume));
                        result.code = 0;
                        DebugUtility.Log(LoggerTags.Project, "SoundCommand Reacted : {0}", env.soundVolume);
                    }
                    break;
                }
            } while (false);

            return(result);
        }
Beispiel #6
0
        protected override IProtocol ExecuteUKitCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            do
            {
                if (command is UKitCommands.InfraredCommand)
                {
                    debug = command.debug;
                    if (LineTrace(out var distance))
                    {
                        result.SetDatas((int)(distance * 100.0f));
                        result.code = 0;

                        DebugUtility.Log(LoggerTags.Project, "InfraredCommand Reacted : {0}m", distance);
                    }
                    break;
                }
            } while (false);

            return(result);
        }
Beispiel #7
0
        protected override IProtocol ExecuteUKitCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            do
            {
                if (command is UKitCommands.TemperatureCommand)
                {
                    debug = command.debug;
                    if (GetEnvironment(out var env))
                    {
                        var cmd = (UKitCommands.TemperatureCommand)command;
                        if (cmd.mode == 0)
                        {
                            var temp = Mathf.CeilToInt(env.temperature);
                            result.SetDatas(temp);
                            DebugUtility.Log(LoggerTags.Project, "TemperatureCommand Reacted : {0}C", temp.ToString());
                        }
                        else if (cmd.mode == 1)
                        {
                            var f = Mathf.CeilToInt(C2F(env.temperature));
                            result.SetDatas(f);
                            DebugUtility.Log(LoggerTags.Project, "TemperatureCommand Reacted : {0}F", f.ToString());
                        }
                        else if (cmd.mode == 2)
                        {
                            var f = Mathf.CeilToInt(env.humidity);
                            result.SetDatas(f);
                            DebugUtility.Log(LoggerTags.Project, "TemperatureCommand Reacted : {0}%", f.ToString());
                        }
                        result.code = 0;
                    }
                    break;
                }
            } while (false);

            return(result);
        }
Beispiel #8
0
        protected virtual IProtocol ExecutePatrolCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            do
            {
                if (command is PatrolSensorCommands.PatrolSensorBasicCommand)
                {
                    debug = command.debug;
                    var cmd = (PatrolSensorCommands.PatrolSensorBasicCommand)command;
                    if (LineTrace(out var distance, out Color rgb))
                    {
                        float gray = Misc.ToGray(rgb);
                        result.SetDatas(gray >= 0.5f && cmd.isGray);
                        result.code = 0;

                        DebugUtility.Log(LoggerTags.Project, "PatrolSensorBasicCommand Reacted : {0}m", distance);
                    }
                    break;
                }
            } while (false);
            return(result);
        }
Beispiel #9
0
        private IProtocol ExecuteCommand(ICommand command)
        {
            var result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            if (command is EyeCommands.DisableLightCommand)
            {
                LightOff();
                result.code = 0;
            }
            else if (command is EyeCommands.EnableLightCommand)
            {
                var cmd = (EyeCommands.EnableLightCommand)command;
                LightUp(cmd.color);
                result.code = 0;
            }
            else if (command is EyeCommands.CustomLightCommand)
            {
                var cmd = (EyeCommands.CustomLightCommand)command;
                ShowCustomLight(cmd.colors, cmd.duration);
                result.code = 0;
            }
            else if (command is EyeCommands.PredefineLightColorCommand)
            {
                var cmd = (EyeCommands.PredefineLightColorCommand)command;
                ShowPredefineLight(cmd.mode, cmd.count);
                result.code = 0;
            }
            else if (command is EyeCommands.ExpressionCommand)
            {
                var cmd = (EyeCommands.ExpressionCommand)command;
                ShowExpression(cmd.mode, cmd.color, cmd.count);
                result.code = 0;
            }

            return(result);
        }
Beispiel #10
0
        private IProtocol ExecuteServoCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            do
            {
                // 舵机角模式
                if (command is ServoCommands.RotateCommand)
                {
                    var cmd = (ServoCommands.RotateCommand)command;

                    jobStatus = WorkStatus.Rotation;
                    var job = (RotationJob)currentJob;
                    job.accumulationTime = 0.0f;
                    job.duration         = cmd.duration;
                    var rawAngle = localEulerAnglesY;
                    rawAngle       = Misc.Convert(convertMode, rawAngle);
                    job.startAngle = rawAngle;
                    job.endAngle   = cmd.angel;
                    result.code    = 0;
                    break;
                }

                // 舵机轮模式
                if (command is ServoCommands.RotationAlwaysCommand)
                {
                    var cmd = (ServoCommands.RotationAlwaysCommand)command;
                    jobStatus = WorkStatus.RotationAlways;
                    var job = (RotationAlwaysJob)currentJob;
                    if (cmd.forward)
                    {
                        job.velocity = cmd.velocity;
                    }
                    else
                    {
                        job.velocity = cmd.velocity * -1.0f;
                    }
                    result.code = 0;
                    break;
                }

                // 停止舵机
                if (command is ServoCommands.StopCommand)
                {
                    var cmd = (ServoCommands.StopCommand)command;
                    Stop();
                    result.code = 0;
                    break;
                }

                // 读取舵机角度
                if (command is ServoCommands.ReadRotationCommand)
                {
                    var cmd = (ServoCommands.ReadRotationCommand)command;
                    if (!cmd.enable)
                    {
                        jobStatus = WorkStatus.Idle;
                    }

                    Vector2 angleRange = new Vector2(-118.0f, 118.0f);
                    float   angle      = localEulerAnglesY;
                    angle = Misc.Convert(convertMode, angle);
                    ProtocolCode code = ProtocolCode.Success;
                    if (angle < angleRange.x || angle > angleRange.y)
                    {
                        code = ProtocolCode.Failure;
                    }
                    result.SetDatas((int)angle);
                    result.code = code == ProtocolCode.Success ? 0 : 1;
                    break;
                }
            } while (false);

            return(result);
        }
Beispiel #11
0
        protected virtual IProtocol ExecuteUKitCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            return(result);
        }
Beispiel #12
0
        public IProtocol ExecuteMainControlCommands(ICommand command)
        {
            ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command);

            do
            {
                if (command is MiscCommands.SetIDCommand)
                {
                    var cmd = (MiscCommands.SetIDCommand)command;
                    result.code = ChangeID(cmd.targetDevice, cmd.oldID, cmd.newID);
                    break;
                }

                if (command is MiscCommands.QueryDeviceCommand)
                {
                    var cmd = (MiscCommands.QueryDeviceCommand)command;
                    result.code = QueryDevice(result);
                    break;
                }

                if (command is MiscCommands.QueryDeviceUpgradableCommand)
                {
                    var cmd = (MiscCommands.QueryDeviceUpgradableCommand)command;
                    break;
                }

                if (command is MiscCommands.StopAllDevicesCommand)
                {
                    var cmd = (MiscCommands.StopAllDevicesCommand)command;
                    Stop();
                    result.code = 0;
                    break;
                }

                if (command is MiscCommands.GetVersionCommand)
                {
                    var cmd = (MiscCommands.GetVersionCommand)command;
                    result.SetDatas("v1.2.4", "v2");
                    result.code = 0;
                    break;
                }

                if (command is MiscCommands.StartUpgradeCommand)
                {
                    var cmd = (MiscCommands.StartUpgradeCommand)command;

                    break;
                }

                if (command is MiscCommands.TickUpgradeCommand)
                {
                    var cmd = (MiscCommands.TickUpgradeCommand)command;

                    break;
                }

                if (command is MiscCommands.EndUpgradeCommand)
                {
                    var cmd = (MiscCommands.EndUpgradeCommand)command;

                    break;
                }
            }while (false);
            return(result);
        }