private OwlCommandQueue CommandQueue() { if (_commandQueue == null) { if (_lockObj == null) { _lockObj = new object(); } lock (_lockObj) { _commandQueue = OwlCommandQueue.Instance; } } return(_commandQueue); }
private void InitializeParts() { CommandQueue = new OwlCommandQueue(); PartsList = new List <OwlControllerBase>(); this.LastError = String.Empty; //"Forward" is "righty-tighty" drive from the motor's perspective. Like a hand drill //=================================================== //HEAD AND WINGS try { //Forward = Head moves "right", so we have a forward sensor on it. _head = new StepperControl.OwlStepperController("Head", 19, 26, 13, 6, 5, 21, null, 16, 5, false); _head.IsControlEnabled = _enableHead; _head.MinPosition = 0; _head.MaxPosition = 100; _head.HomePosition = 50; _head.DeviceError += _component_DeviceError; _head.MoveCompleted += _component_MoveCompleted; //one of these is not used _head.BackwardLimitSensorChanged += _head_BackwardLimitReached; _head.ForwardLimitSensorChanged += _head_ForwardLimitReached; CommandQueue.CommandAdded += CommandQueue_CommandAdded; PartsList.Add(_head); } catch (Exception exHead) { this.Status = OwlDeviceStateBase.StatusTypes.InError; this.StatusReason = OwlDeviceStateBase.StatusReasonTypes.InError; this.LastError += exHead.ToString(); } try { //Forward = Wings up //Screw drive travels 0.125 incehes per 100 steps. //2.5 inches is 8 rotations, //Each rotation 200 steps at 1.8 degress per step. //2.5 inches is 1600 steps (8 rotations at 200 steps each) //Converting to position factor: 1600 / 100 = 16 steps per position increment int stepToPositionFactor = 16; _wings = new StepperControl.OwlStepperController("Wings", 17, 18, 22, 23, 24, 25, 12, 4, stepToPositionFactor, true); _wings.IsControlEnabled = _enableWings; _wings.MinPosition = 0; _wings.MaxPosition = 100; _wings.HomePosition = 95; _wings.DeviceError += _component_DeviceError; _wings.MoveCompleted += _component_MoveCompleted; _wings.ForwardLimitSensorChanged += _wings_ForwardLimitReached; _wings.BackwardLimitSensorChanged += _wings_BackwardLimitReached; PartsList.Add(_wings); } catch (Exception exWings) { this.Status = OwlDeviceStateBase.StatusTypes.InError; this.StatusReason = OwlDeviceStateBase.StatusReasonTypes.InError; this.LastError += exWings.ToString(); } //=================================================== try { //Uses the defaultI2C address _pwmDriver = new ServoBoardDriver(); _pwmDriver.Initialize(); try { _leftEye = new ServoBoardDriver.ServoPort("Left Eye", 0, _pwmDriver._pca9685, false); _leftEye.IsControlEnabled = _enableLeftEye; _rightEye = new ServoBoardDriver.ServoPort("Right Eye", 1, _pwmDriver._pca9685, true); _rightEye.IsControlEnabled = _enableRightEye; _leftEye.Initialize(); PartsList.Add(_leftEye); _rightEye.Initialize(); PartsList.Add(_rightEye); } catch (Exception exEyes) { this.Status = OwlDeviceStateBase.StatusTypes.InError; this.StatusReason = OwlDeviceStateBase.StatusReasonTypes.InError; this.LastError += exEyes.ToString(); } } catch (Exception exPWM) { this.Status = OwlDeviceStateBase.StatusTypes.InError; this.StatusReason = OwlDeviceStateBase.StatusReasonTypes.InError; this.LastError += exPWM.ToString(); } }