Пример #1
0
        public static void Run()
        {
            var servo = new ServoController(Pins.GPIO_PIN_D9, 600, 3000);

            var button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

            button.OnInterrupt += (data1, data2, time) =>
            {
                //servo.Duration = 1500;
                if (data2 == 1)
                {
                    servo.Rotate(100);
                }
                else
                {
                    servo.Rotate(0);
                }
            };

            while (Debugger.IsAttached)
            {
                Thread.Sleep(1000);
            }

            button.Dispose();
            servo.Dispose();
        }
Пример #2
0
        public void onServoDrop(ServoDragHandler dragHandler)
        {
            var servoUIControls = dragHandler.draggedItem;
            int insertAt        = dragHandler.placeholder.transform.GetSiblingIndex();

            foreach (var pair in WindowManager._servoUIControls)
            {
                if (pair.Value == servoUIControls)
                {
                    var s             = pair.Key;
                    var oldGroupIndex = ServoController.Instance.ServoGroups.FindIndex(g => g.Servos.Contains(s));

                    if (oldGroupIndex < 0)
                    {
                        //error
                        return;
                    }

                    var newGroupIndex = dragHandler.dropZone.parent.GetSiblingIndex();
                    ServoController.MoveServo(ServoController.Instance.ServoGroups[oldGroupIndex], ServoController.Instance.ServoGroups[newGroupIndex], s);
                    WindowManager.guiRebuildPending = true;
                    break;
                }
            }
        }
Пример #3
0
        public static void Run()
        {
            var servo = new ServoController(Pins.GPIO_PIN_D9, 600, 3000);

            var button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            button.OnInterrupt += (data1, data2, time) =>
            {

                //servo.Duration = 1500;
                if (data2 == 1)
                    servo.Rotate(100);
                else
                {
                    servo.Rotate(0);

                }
            };

            while (Debugger.IsAttached)
            {
                Thread.Sleep(1000);

            }

            button.Dispose();
            servo.Dispose();
        }
Пример #4
0
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            //Gps.DisconnectFromUART();
            ServoController.Dispose();

            Activated  = false;
            UpdatingUi = false;
        }
Пример #5
0
        private async Task Initialze()
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }
            else
            {
                throw new Exception("Lightning drivers not enabled. Please enable Lightning drivers.");
            }

            _camera = new Camera();
            await _camera.Initialize();
            
            SpeedSensor.Initialize();
            SpeedSensor.Start();

            SpeechSynthesis.Initialze();

            await AudioPlayerController.Initialize();

            _accelerometerSensor = new AccelerometerGyroscopeSensor();
            await _accelerometerSensor.Initialize();
            _accelerometerSensor.Start();

            _automaticSpeakController = new AutomaticSpeakController(_accelerometerSensor);

            _motorController = new MotorController();
            await _motorController.Initialize(_automaticSpeakController);

            _servoController = new ServoController();
            await _servoController.Initialize();

            _distanceMeasurementSensor = new DistanceMeasurementSensor();
            await _distanceMeasurementSensor.Initialize(I2C_ADDRESS_SERVO);

            _automaticDrive = new AutomaticDrive(_motorController, _servoController, _distanceMeasurementSensor);

            _speechRecognation = new SpeechRecognition();
            await _speechRecognation.Initialze(_motorController, _servoController, _automaticDrive);
            _speechRecognation.Start();

            _gamepadController = new GamepadController(_motorController, _servoController, _automaticDrive, _accelerometerSensor);

            _camera.Start();

            _httpServerController = new HttpServerController(_motorController, _servoController, _automaticDrive, _camera);

            SystemController.Initialize(_accelerometerSensor, _automaticSpeakController, _motorController, _servoController, _automaticDrive, _camera, _httpServerController, _speechRecognation, _gamepadController);

            await SystemController.SetAudioRenderVolume(AUDIO_RENDER_VOLUME, true);
            await SystemController.SetAudioCaptureVolume(AUDIO_CAPTURE_VOLUME, true);
            
            await AudioPlayerController.PlayAndWaitAsync(AudioName.Welcome);

            _automaticSpeakController.Start();
        }
Пример #6
0
        public UAS()
        {
            servoController = ServoController.getInstance();
            servoController.setBaudRate(115200);
            InitializeComponent();

            List <string> devices = WebCamService.Capture.getDevices();

            foreach (string device in devices)
            {
                cameraBox.Items.Add(device);
            }

            foreach (string port in SerialPort.GetPortNames())
            {
                portNameBox.Items.Add(port);
            }

            if (!hud1.Visible)
            {
                hud1.Visible = true;
            }
            if (!hud1.Enabled)
            {
                hud1.Enabled = true;
            }
            if (!hud1.hudon)
            {
                hud1.hudon = true;
            }

            ConnectHandler = new EventHandler(UAS_Connect);
            myhud          = hud1;

            myhud          = hud1;
            timer          = new System.Timers.Timer(3000);
            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            timer.Start();

            hTrackBar.Maximum = 150;
            hTrackBar.Minimum = 50;
            hTrackBar.Value   = 100;
            vTrackBar.Maximum = 150;
            vTrackBar.Minimum = 50;
            vTrackBar.Value   = 100;

            pitchLabel.Text = "Pitch: " + vTrackBar.Value;
            rollLabel.Text  = "Roll: " + hTrackBar.Value;

            stabroll  = true;
            stabpitch = true;
            stabyaw   = true;
            mountMode = MAVLink.MAV_MOUNT_MODE.NEUTRAL;
        }
Пример #7
0
 // This function sets the controllers for a newly created LabBot object
 // Used when a robot is created from file
 public void Initialize()
 {
     wheelController          = gameObject.AddComponent <WheelMotorController>();
     psdController            = gameObject.AddComponent <PSDController>();
     servoController          = gameObject.AddComponent <ServoController>();
     eyeCamController         = gameObject.AddComponent <EyeCameraController>();
     wheelController.wheels   = new List <Wheel>();
     psdController.sensors    = new List <PSDSensor>();
     servoController.servos   = new List <Servo>();
     eyeCamController.cameras = new List <EyeCamera>();
 }
Пример #8
0
        public HttpServer(MotorController motorController,
                          ServoController servoController,
                          AutomaticDrive automaticDrive,
                          Camera camera)
        {
            _motorController = motorController;
            _servoController = servoController;
            _automaticDrive  = automaticDrive;
            _camera          = camera;

            _listener = GetStreamSocketListener();
        }
Пример #9
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var controller = GpioController.GetDefault();
            var pin        = controller.OpenPin(18, GpioSharingMode.Exclusive);

            pin.SetDriveMode(GpioPinDriveMode.Output);


            Pwm   = new SofwarePwm(n => pin.Write(n ? GpioPinValue.High : GpioPinValue.Low), 10, 0);
            Servo = new ServoController(Pwm);
            Servo.Start(1);
            PropertyChanged(this, new PropertyChangedEventArgs("Angle"));
        }
Пример #10
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateUi();

            BtnTargetSpeedIncrease.Click += BtnTargetSpeedIncrease_Click;
            BtnTargetSpeedDecrease.Click += BtnTargetSpeedDecrease_Click;

            BtnToleranceDecreaseKts.Click += BtnToleranceDecreaseKts_Click;
            BtnToleranceIncreaseKts.Click += BtnToleranceIncreaseKts_Click;

            _servo = new ServoController(5);
            await _servo.Connect();

            _servo.SetPosition(ServoPosition).AllowTimeToMove(2000).Go();
        }
Пример #11
0
        public UAS()
        {
            servoController = ServoController.getInstance();
            servoController.setBaudRate(115200);
            InitializeComponent();

            List<string> devices = WebCamService.Capture.getDevices();
            foreach (string device in devices)
            {
                cameraBox.Items.Add(device);
            }

            foreach (string port in SerialPort.GetPortNames())
            {
                portNameBox.Items.Add(port);
            }

            if (!hud1.Visible)
                hud1.Visible = true;
            if (!hud1.Enabled)
                hud1.Enabled = true;
            if (!hud1.hudon)
                hud1.hudon = true;

            ConnectHandler = new EventHandler(UAS_Connect);
            myhud = hud1;

            myhud = hud1;
            timer = new System.Timers.Timer(3000);
            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            timer.Start();

            hTrackBar.Maximum = 150;
            hTrackBar.Minimum = 50;
            hTrackBar.Value = 100;
            vTrackBar.Maximum = 150;
            vTrackBar.Minimum = 50;
            vTrackBar.Value = 100;

            pitchLabel.Text = "Pitch: " + vTrackBar.Value;
            rollLabel.Text = "Roll: " + hTrackBar.Value;

            stabroll = true;
            stabpitch = true;
            stabyaw = true;
            mountMode = MAVLink.MAV_MOUNT_MODE.NEUTRAL;
        }
Пример #12
0
        public GamepadController(MotorController motorController,
                                 ServoController servoController,
                                 AutomaticDrive automaticDrive,
                                 AccelerometerGyroscopeSensor acceleratorSensor)
        {
            if (_shutdown)
            {
                return;
            }

            _motorController   = motorController;
            _servoController   = servoController;
            _automaticDrive    = automaticDrive;
            _acceleratorSensor = acceleratorSensor;

            Gamepad.GamepadAdded   += GamepadAdded;
            Gamepad.GamepadRemoved += GamepadRemoved;
        }
Пример #13
0
        public async Task Initialze(MotorController motorController,
                                    ServoController servoController,
                                    AutomaticDrive automaticDrive)
        {
            _motorController = motorController;
            _servoController = servoController;
            _automaticDrive  = automaticDrive;

            _speechRecognizer = new SpeechRecognizer(new Language("de-DE"));

            var grammerFile = await Package.Current.InstalledLocation.GetFileAsync(@"Audio\SpeechRecognizerGrammer.xml");

            var grammarConstraint = new SpeechRecognitionGrammarFileConstraint(grammerFile);

            _speechRecognizer.Constraints.Add(grammarConstraint);
            var compilationResult = await _speechRecognizer.CompileConstraintsAsync();

            _speechRecognizer.ContinuousRecognitionSession.ResultGenerated += RecognationResult;
            _speechRecognizer.ContinuousRecognitionSession.Completed       += ContinuousRecognitionSession_Completed;
        }
Пример #14
0
 public HttpServerController(MotorController motorController,
                             ServoController servoController,
                             AutomaticDrive automaticDrive,
                             Camera camera)
 {
     Task.Factory.StartNew(() =>
     {
         _httpServer = new HttpServer(motorController,
                                      servoController,
                                      automaticDrive,
                                      camera);
         _httpServer.Start();
     }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default)
     .AsAsyncAction()
     .AsTask()
     .ContinueWith((t) =>
     {
         Logger.Write(nameof(HttpServerController), t.Exception).Wait();
         SystemController.ShutdownApplication(true).Wait();
     }, TaskContinuationOptions.OnlyOnFaulted);
 }
Пример #15
0
        private void ServoControlTask()
        {
            while (Activated)
            {
                // Doing this here for now
                CalculateSpeedAverages();

                var speed = OpertationMode == AutopilotOperationMode.Average && SpeedList.Any()
                    ? SpeedList.Average()
                    : OpertationMode == AutopilotOperationMode.Track ? TrackSpeed : Speed;

                var diff = TargetSpeed - speed;

                if (Math.Abs(diff) > ToleranceSpeed && speed > 0)
                {
                    if (diff < 0.0d)
                    {
                        ServoPosition -= 1;
                        LogAsync(string.Format("{0} km/h off; decreasing by 1 degree to {1}", diff, ServoPosition));
                    }
                    if (diff > 0.0d && ServoPosition >= 0)
                    {
                        ServoPosition += 1;
                        LogAsync(string.Format("{0} km/h off; increasing by 1 degree to {1}", diff, ServoPosition));
                    }
                    ServoController.SetPosition(ServoPosition).AllowTimeToMove(100).Go();
                }
                else
                {
                    LogAsync(string.Format("Speed of {0} withing tolerance or 0; doing nothing", speed));
                }

                Task.Delay((int)(ToleranceSeconds * 1000)).Wait();
            }

            LogAsync("Speed control loop ended. Setting servo back to 0 degree");

            ServoPosition = 0;
            ServoController.SetPosition(0).AllowTimeToMove(2000).Go();
        }
Пример #16
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // Setup Netowrk Socket
            Server = new Socket(SocketType.Stream, ProtocolType.Tcp);
            Server.Bind(new IPEndPoint(IPAddress.Any, 1911));
            Server.Listen(100);

            // Setup Servos
            var controller = GpioController.GetDefault();

            // GPIO 18
            var pin = controller.OpenPin(18, GpioSharingMode.Exclusive);

            pin.SetDriveMode(GpioPinDriveMode.Output);
            Azimuth = new ServoController(new SofwarePwm(n => pin.Write(n ? GpioPinValue.High : GpioPinValue.Low), 50, 0));
            Azimuth.Start(90);

            // GPIO 23
            pin = controller.OpenPin(23, GpioSharingMode.Exclusive);
            pin.SetDriveMode(GpioPinDriveMode.Output);
            Inclenation = new ServoController(new SofwarePwm(n => pin.Write(n ? GpioPinValue.High : GpioPinValue.Low), 50, 0));
            Inclenation.Start(90);

            Server.Listen(10);
            var connectEvent = new AutoResetEvent(false);

            while (true)
            {
                SocketAsyncEventArgs e = new SocketAsyncEventArgs();
                e.Completed += AcceptCallback;
                if (!Server.AcceptAsync(e))
                {
                    AcceptCallback(Server, e);
                    connectEvent.Set();
                }

                connectEvent.WaitOne(1000);
            }
        }
Пример #17
0
        public static void Initialize(AccelerometerGyroscopeSensor accelerometerSensor,
                                      AutomaticSpeakController automaticSpeakController,
                                      MotorController motorController,
                                      ServoController servoController,
                                      AutomaticDrive automaticDrive,
                                      Camera camera,
                                      HttpServerController httpServerController,
                                      SpeechRecognition speechRecognation,
                                      GamepadController gamepadController)
        {
            _accelerometerSensor      = accelerometerSensor;
            _automaticSpeakController = automaticSpeakController;
            _motorController          = motorController;
            _servoController          = servoController;
            _automaticDrive           = automaticDrive;
            _camera = camera;
            _httpServerController = httpServerController;
            _speechRecognation    = speechRecognation;
            _gamepadController    = gamepadController;

            _initialized = true;
        }
Пример #18
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ServoPosition = 0;

            TargetSpeed      = 2.5d;
            ToleranceSpeed   = 0.1d;
            ToleranceSeconds = 1.0d;

            BtnTargetSpeedActivate.Click += BtnTargetSpeedActivate_Click;
            BtnTargetSpeedIncrease.Click += BtnTargetSpeedIncrease_Click;
            BtnTargetSpeedDecrease.Click += BtnTargetSpeedDecrease_Click;

            BtnToleranceDecreaseKmh.Click += BtnToleranceDecreaseKmh_Click;
            BtnToleranceIncreaseKmh.Click += BtnToleranceIncreaseKmh_Click;

            BtnTimeFactorDecrease.Click += BtnTimeFactorDecrease_Click;
            BtnTimeFactorIncrease.Click += BtnTimeFactorIncrease_Click;

            BtnTest.Click += BtnTest_Click;

            TxtDebug.TextChanged += TxtDebug_TextChanged;

            var modes = Enum.GetValues(typeof(AutopilotOperationMode)).Cast <AutopilotOperationMode>();

            CmbMode.ItemsSource = modes.ToList();

            OpertationMode            = 0;
            CmbMode.SelectedIndex     = 0;
            CmbMode.SelectionChanged += CmbModeOnSelectionChanged;

            // Initialize Gps
            try
            {
                StartGps();

                #region Compass Initialize

                // TODO: Check I2C connection of RPi
                //StartCompass();

                //if (Compass.IsConnected())
                //{
                //    _chacheCompassTask = Task.Run(() =>
                //    {
                //        while (true)
                //        {
                //            CompassData.Add(Compass.GetRawData());

                //            if (_compassTaskToken.IsCancellationRequested)
                //            {
                //                _compassTaskToken.ThrowIfCancellationRequested();
                //            }
                //        }
                //    }, _compassTaskToken);
                //}

                #endregion

                #region ServoController

                ServoController = new ServoController(5);
                await ServoController.Connect();

                ServoController.SetPosition(ServoPosition).AllowTimeToMove(2000).Go();

                await Task.Run(async() =>
                {
                    while (UpdatingUi)
                    {
                        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                            CoreDispatcherPriority.Normal, () =>
                        {
                            UpdateUi();
                        });

                        Task.Delay(2000).Wait();
                    }
                });

                #endregion
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Error starting app: {0}", ex.Message));
            }
        }
 void Awake()
 {
     servo_ = ServoController.Instance;
 }
Пример #20
0
 public TLDTracker(int device)
 {
     this.device = device;
     controller = ServoController.getInstance();
 }
Пример #21
0
 public TLDTracker(int device)
 {
     this.device = device;
     controller  = ServoController.getInstance();
 }
Пример #22
0
 void Awake()
 {
     servo_ = ServoController.Instance;
 }
Пример #23
0
 public static IServoController CreateServoController()
 {
     return(_servoController ?? (_servoController = new ServoController()));
 }