示例#1
0
        //private IMotorController? _motorController;
        //private IImuSensor? _imuSensor;

        public Stabilizer(
            ILoopWorkerFactory workerFactory,
            IPidRegulatorFactory regulatorFactory,
            ISettings setting,
            IMovementTarget target,
            IHostApplicationLifetime lifetime,
            ILogger <Stabilizer>?logger)
        {
            if (workerFactory is null)
            {
                throw new ArgumentNullException(nameof(workerFactory));
            }
            if (regulatorFactory is null)
            {
                throw new ArgumentNullException(nameof(regulatorFactory));
            }
            if (setting is null)
            {
                throw new ArgumentNullException(nameof(setting));
            }
            _target   = target ?? throw new ArgumentNullException(nameof(target));
            _lifetime = lifetime ?? throw new ArgumentNullException(nameof(lifetime));
            _logger   = logger;


            //hardwareManager.ConnectAsync().ContinueWith(result =>
            //{
            //    if (result.Result)
            //    {
            //        _motorController = hardwareManager.GetHardware<IMotorController>()
            //            ?? throw new ArgumentException($"Can't resolve object of type{nameof(IMotorController)}");
            //        _imuSensor = hardwareManager.GetHardware<IImuSensor>()
            //            ?? throw new ArgumentException($"Can't resolve object of type{nameof(IImuSensor)}");
            //    }
            //}, TaskScheduler.Default);
            _worker = workerFactory.Create("StabilizerLoop", Callback);
            var opt = setting.GetBinding <PidRegulatorSetting>("yAxisRegulator");

            opt.DGain       = 4;
            _xAxisRegulator = regulatorFactory.Create("xAxisRegulator");
            _yAxisRegulator = regulatorFactory.Create("yAxisRegulator");
        }
        public bool AddBehaviour(MovementType type, IMovementTarget target)
        {
            var movementData = new MovementData(agent, target);

            // Decorate existing movement behaviours.
            switch (type)
            {
            case MovementType.Seek:
                this.behaviour = new SeekMovementBehaviour(this.behaviour, movementData);
                break;

            case MovementType.Flee:
                this.behaviour = new FleeMovementBehaviour(this.behaviour, movementData);
                break;

            case MovementType.Pursue:
                this.behaviour = new PursueMovementBehaviour(this.behaviour, movementData);
                break;

            case MovementType.Evade:
                this.behaviour = new EvadeMovementBehaviour(this.behaviour, movementData);
                break;

            case MovementType.Wander:
                this.behaviour = new WanderMovementBehaviour(this.behaviour, movementData);
                break;

            case MovementType.Avoid:
                this.behaviour = new AvoidMovementBehaviour(this.behaviour, movementData);
                break;

            default:
                break;
            }

            return(this.behaviour != null);
        }
示例#3
0
 void Awake()
 {
     _targetRb          = GetComponent <Rigidbody>();
     _targetRb.velocity = new Vector3(0, 0, 0);
     _movementTarget    = GetComponent <IMovementTarget>();
 }