PES_4_Spleisser / Mbed 2 deprecated SpleisserProgramm_v2

Dependencies:   mbed mbed-rtos X_NUCLEO_IHM02A1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "SETUP.h"
00002 
00003 
00004 /* Status Spleisser definieren*/
00005 int StatusSpleisser = ST_SOLO;
00006 
00007 /*Buttons initialisieren*/
00008 InterruptIn buttonSTART(USER_BUTTON);
00009 
00010 volatile bool buttonSTART_pressed = false; // Used in the main loop
00011 volatile bool buttonSTART_enabled = true;  // Used for debouncing
00012 Timeout buttonSTART_timeout;               // Used for debouncing
00013 
00014 /*PWMs initialisieren*/
00015 PwmOut Servo(PB_4);
00016 
00017 /*Input initalisieren für Status Spleisser*/
00018 DigitalIn InputKontrollmodul(COM_SIGNAL);
00019 
00020 /* Motor Control Expansion Board. */
00021 XNucleoIHM02A1 *x_nucleo_ihm02a1_1;
00022 XNucleoIHM02A12 *x_nucleo_ihm02a1_2;
00023 
00024 /* Initialization parameters of the motors connected to the expansion board. */
00025 L6470_init_t init[L6470DAISYCHAINSIZE] = {
00026     /* First Motor. */
00027     {
00028         12.0,                           /* Motor supply voltage in V. */
00029         400,                           /* Min number of steps per revolution for the motor. */
00030         1.7,                           /* Max motor phase voltage in A. */
00031         3.06,                          /* Max motor phase voltage in V. */
00032         300.0,                         /* Motor initial speed [step/s]. */
00033         500.0,                         /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
00034         500.0,                         /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
00035         992.0,                         /* Motor maximum speed [step/s]. */
00036         0.0,                           /* Motor minimum speed [step/s]. */
00037         602.7,                         /* Motor full-step speed threshold [step/s]. */
00038         3.06,                          /* Holding kval [V]. */
00039         3.06,                          /* Constant speed kval [V]. */
00040         3.06,                          /* Acceleration starting kval [V]. */
00041         3.06,                          /* Deceleration starting kval [V]. */
00042         61.52,                         /* Intersect speed for bemf compensation curve slope changing [step/s]. */
00043         392.1569e-6,                   /* Start slope [s/step]. */
00044         643.1372e-6,                   /* Acceleration final slope [s/step]. */
00045         643.1372e-6,                   /* Deceleration final slope [s/step]. */
00046         0,                             /* Thermal compensation factor (range [0, 15]). */
00047         3.06 * 1000 * 1.10,            /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
00048         3.06 * 1000 * 1.00,            /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
00049         StepperMotor::STEP_MODE_1_128, /* Step mode selection. */
00050         0xFF,                          /* Alarm conditions enable. */
00051         0x2E88                         /* Ic configuration. */
00052     },
00053 
00054     /* Second Motor. */
00055     {
00056         12.0,                           /* Motor supply voltage in V. */
00057         400,                           /* Min number of steps per revolution for the motor. */
00058         1.7,                           /* Max motor phase voltage in A. */
00059         3.06,                          /* Max motor phase voltage in V. */
00060         300.0,                         /* Motor initial speed [step/s]. */
00061         500.0,                         /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
00062         500.0,                         /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
00063         992.0,                         /* Motor maximum speed [step/s]. */
00064         0.0,                           /* Motor minimum speed [step/s]. */
00065         602.7,                         /* Motor full-step speed threshold [step/s]. */
00066         3.06,                          /* Holding kval [V]. */
00067         3.06,                          /* Constant speed kval [V]. */
00068         3.06,                          /* Acceleration starting kval [V]. */
00069         3.06,                          /* Deceleration starting kval [V]. */
00070         61.52,                         /* Intersect speed for bemf compensation curve slope changing [step/s]. */
00071         392.1569e-6,                   /* Start slope [s/step]. */
00072         643.1372e-6,                   /* Acceleration final slope [s/step]. */
00073         643.1372e-6,                   /* Deceleration final slope [s/step]. */
00074         0,                             /* Thermal compensation factor (range [0, 15]). */
00075         3.06 * 1000 * 1.10,            /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
00076         3.06 * 1000 * 1.00,            /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
00077         StepperMotor::STEP_MODE_1_128, /* Step mode selection. */
00078         0xFF,                          /* Alarm conditions enable. */
00079         0x2E88                         /* Ic configuration. */
00080     }
00081 };
00082 
00083 
00084 
00085 
00086 //------------------------------------------------------------------------------
00087 //------------------------------------------------------------------------------
00088 //------------------------------------------------------------------------------
00089 //------------------------------------------------------------------------------
00090 
00091 L6470B **motors2;
00092 L6470 **motors;
00093 
00094 
00095 /* Main ----------------------------------------------------------------------*/
00096 
00097 int main()
00098 {
00099 /*----- Initialization. -----*/
00100 /* Initializing Motor Control Expansion Board. */
00101 x_nucleo_ihm02a1_2 = new XNucleoIHM02A12(&init[0], &init[1],A4, A5, D4, D2, D11, D12, D3 );
00102 x_nucleo_ihm02a1_1 = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, D11, D12, D3 );
00103     
00104 /* Building a list of motor control components. */
00105 motors2 = x_nucleo_ihm02a1_2->get_components();
00106 motors = x_nucleo_ihm02a1_1->get_components();
00107     
00108 buttonSTART.fall(callback(buttonSTART_onpressed_cb)); // Attach ISR to handle button press event
00109 
00110  while(1)
00111     {
00112         switch (StatusSpleisser)
00113         {   
00114             case ST_SOLO: 
00115                    if(InputKontrollmodul == 0)
00116                     {
00117                         EntrySOLO(); 
00118                     }    
00119                     else
00120                     {
00121                         StatusSpleisser = ST_DUO;
00122                     }
00123             break;
00124             case ST_DUO:
00125                     if(InputKontrollmodul == 1)
00126                     {
00127                         EntryDUO(); 
00128                     }    
00129                     else
00130                     {
00131                         StatusSpleisser = ST_SOLO;
00132                     }               
00133             break;
00134                
00135             }
00136     }
00137 }