Beispiel #1
0
        public bool Initialize(PoKeysStepperBoardConfiguration config, int?pokeysIndex)
        {
            if (Initialized)
            {
                return(false);
            }

            if (poKeysDevice == null)
            {
                if (!pokeysIndex.HasValue)
                {
                    return(false);
                }

                poKeysDevice = PoKeysEnumerator.Singleton.PoKeysDevice;

                if (!poKeysDevice.ConnectToDevice(pokeysIndex.Value))
                {
                    Error = Translations.Main.PokeysConnectError;
                    return(false);
                }
            }

            // Configure the positioning device...
            poKeysDevice.PEv2_GetStatus(ref PE);
            for (int i = 0; i < 8; i++)
            {
                PE.param1 = (byte)i;
                poKeysDevice.PEv2_GetAxisConfiguration(ref PE);
            }

            UpdateConfiguration(config);

            //
            // Change Pulse Engine State to RUNNING
            //
            PE.PulseEngineStateSetup = (byte)ePoKeysPEState.peRUNNING;
            poKeysDevice.PEv2_SetState(ref PE);

            //
            // Get Pulse Engine Statue and Check to confirm we are RUNNING
            //
            poKeysDevice.PEv2_GetStatus(ref PE);
            StepperRunning = (PE.PulseEngineState == (byte)ePoKeysPEState.peRUNNING);

            Initialized = true;

            if (posThread == null)
            {
                posThread = new Thread(new ThreadStart(StepperPositioningThreadStub));
                posThread.Start();
            }

            return(true);
        }
Beispiel #2
0
        public void UpdateConfiguration(PoKeysStepperBoardConfiguration config)
        {
            StepperBoardConfig = config;

            // Configure pulse engine with 8 axes
            PE.PulseEngineEnabled = 8;
            PE.PulseGeneratorType = (byte)(0 | (1 << 7)); // Using external pulse generator with IO
            PE.ChargePumpEnabled  = 0;                    // Don't use charge pump output
                                                          //config.EmergencySwitchPin = 0;  // No Emergency Switch Pin
                                                          //                                // 0 - disabled i.e. none
                                                          //                                // 1 - default input Pin 55
                                                          //                                // 10 + 10-based pin ID
            PE.EmergencySwitchPolarity = (byte)(StepperBoardConfig.InvertEmergencySwitchPolarity ? 1 : 0);
            poKeysDevice.PEv2_SetupPulseEngine(ref PE);

            // Configure axes...
            for (int i = 0; i < 8; i++)
            {
                //
                // Set Axis Configuration variables
                //
                PE.AxisEnabledInvertMask[i] = 1; // Use inverted axis enabled signal for PoStep drivers ???
                PE.AxesConfig[i]            = (byte)(ePEv2_AxisConfig.aoENABLED |
                                                     ePEv2_AxisConfig.aoINTERNAL_PLANNER |
                                                     ePEv2_AxisConfig.aoPOSITION_MODE); // Use Position mode
                poKeysDevice.PEv2_GetStatus(ref PE);                                    // Get Status just to DEBUG - Remove for F4toPokeys code
                                                                                        //
                                                                                        // Enable Soft Limits for steppers with STOPs
                                                                                        // - Need to determine which steppers need this from the Config GUI
                                                                                        //
                PE.AxesConfig[i] |= (int)ePEv2_AxisConfig.aoSOFT_LIMIT_ENABLED;
                poKeysDevice.PEv2_GetStatus(ref PE);                                    // Get Status just to DEBUG - Remove for F4toPokeys code

                //
                // My stepper is wired backwards so I added this.
                // We may want to have a REVERSE Direction option as GUI Config Option
                //
                if (StepperBoardConfig.AxisConfig[i].Inverted)
                {
                    PE.AxesConfig[i] |= (int)ePEv2_AxisConfig.aoINVERTED;
                }

                if (StepperBoardConfig.AxisConfig[i].HomeInverted)
                {
                    PE.AxesConfig[i] |= (int)ePEv2_AxisConfig.aoINVERTED_HOME;
                }

                if (StepperBoardConfig.AxisConfig[i].HasHomeSwitch)
                {
                    PE.PinHomeSwitch[i]    = (byte)StepperBoardConfig.AxisConfig[i].PinHomeSwitch;
                    PE.AxesSwitchConfig[i] = (byte)ePEv2_AxisSwitchOptions.aoSWITCH_HOME;
                }
                else
                {
                    PE.PinHomeSwitch[i]    = 0;
                    PE.AxesSwitchConfig[i] = (byte)(ePEv2_AxisSwitchOptions.aoSWITCH_HOME | ePEv2_AxisSwitchOptions.aoSWITCH_INVERT_HOME);
                }

                poKeysDevice.PEv2_GetStatus(ref PE);  // Get Status just to DEBUG - Remove for F4toPokeys code

                //
                // Set Axis Switch Configuration variables
                //
                PE.AxesSwitchConfig[i] = (int)(ePEv2_AxisSwitchOptions.aoSWITCH_HOME |
                                               ePEv2_AxisSwitchOptions.aoSWITCH_INVERT_HOME);
                poKeysDevice.PEv2_GetStatus(ref PE);  // Get Status just to DEBUG - Remove for F4toPokeys code
                                                      //
                                                      // Set Axis Variables
                                                      //
                                                      //
                                                      // GUI Configuration Option
                                                      // - If stepper is 360 degree with a HOME switch we need a GUI configuration option that the pin for the axis.
                                                      //
                if (StepperBoardConfig.AxisConfig[i].HasHomeSwitch)
                {
                    PE.PinHomeSwitch[i] = (byte)StepperBoardConfig.AxisConfig[i].PinHomeSwitch;// Convert.ToByte(i + 8);  // For testing, use Pins 8 - 15 as Home Switches for stepper 0 - 7
                }
                else
                {
                    PE.PinHomeSwitch[i] = 0;
                }
                //config.PinHomeSwitch[i] = 8;  // #Matevz#: select pin 8 for the home switch for this single axis

                PE.HomingSpeed[i]       = (byte)StepperBoardConfig.AxisConfig[i].HomingSpeed;       // 50;   // #Matevz#: homing speed is 50% of the maximum speed
                PE.HomingReturnSpeed[i] = (byte)StepperBoardConfig.AxisConfig[i].HomingReturnSpeed; // 20; // #Matevz#: homing return speed is 20% of the homing speed (therefore 10% of the max speed)
                PE.MaxSpeed[i]          = StepperBoardConfig.AxisConfig[i].MaxSpeed;                // 10; // Max speed: 15 kHz
                PE.MaxAcceleration[i]   = StepperBoardConfig.AxisConfig[i].MaxAcceleration;         // 0.010f; // Acceleration: 15 kHz / s
                PE.MaxDecceleration[i]  = StepperBoardConfig.AxisConfig[i].MaxDecceleration;        // 0.010f; // Acceleration: 15 kHz / s
                                                                                                    //
                                                                                                    // Set Soft Limits to 315 degree (3780 steps) X27 stepper position limits
                PE.SoftLimitMaximum[i] = StepperBoardConfig.AxisConfig[i].SoftLimitMaximum;         // 3780;  // 315 degree
                PE.SoftLimitMinimum[i] = StepperBoardConfig.AxisConfig[i].SoftLimitMinimum;         // 0;     // 0 degree
                PE.param1 = (byte)i;                                                                // Set parameter param1 to the bit mask to indicate what have the above Axis Configs set
                                                                                                    //
                                                                                                    // Write (Set) above Axis Configuration
                                                                                                    //
                poKeysDevice.PEv2_SetAxisConfiguration(ref PE);                                     // Configure the axis
            }
        }