rainbow

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Tue May 12 07:43:44 2020 +0000
Revision:
67:c2812cf26c38
Parent:
66:a8e6799dbce3
Child:
68:328e1be06f5d
20200512_2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GiJeongKim 0:51c43836c1d7 1 #include "mbed.h"
GiJeongKim 0:51c43836c1d7 2 #include "FastPWM.h"
GiJeongKim 0:51c43836c1d7 3 #include "INIT_HW.h"
jobuuu 2:a1c0a37df760 4 #include "function_CAN.h"
GiJeongKim 0:51c43836c1d7 5 #include "SPI_EEP_ENC.h"
GiJeongKim 0:51c43836c1d7 6 #include "I2C_AS5510.h"
GiJeongKim 0:51c43836c1d7 7 #include "setting.h"
Lightvalve 11:82d8768d7351 8 #include "function_utilities.h"
Lightvalve 16:903b5a4433b4 9 #include "stm32f4xx_flash.h"
Lightvalve 65:a2d7c63419c2 10 #include "FlashWriter.h"
Lightvalve 61:bc8c8270f0ab 11
Lightvalve 61:bc8c8270f0ab 12 using namespace std;
Lightvalve 61:bc8c8270f0ab 13 Timer t;
GiJeongKim 0:51c43836c1d7 14
Lightvalve 31:66738bfecec5 15 ///191008////
Lightvalve 31:66738bfecec5 16
jobuuu 7:e9086c72bb22 17 // dac & check ///////////////////////////////////////////
GiJeongKim 0:51c43836c1d7 18 DigitalOut check(PC_2);
GiJeongKim 0:51c43836c1d7 19 DigitalOut check_2(PC_3);
GiJeongKim 0:51c43836c1d7 20 AnalogOut dac_1(PA_4);
GiJeongKim 0:51c43836c1d7 21 AnalogOut dac_2(PA_5);
Lightvalve 14:8e7590227d22 22 AnalogIn adc1(PC_4); //pressure_1
Lightvalve 14:8e7590227d22 23 AnalogIn adc2(PB_0); //pressure_2
Lightvalve 14:8e7590227d22 24 AnalogIn adc3(PC_1); //current
GiJeongKim 0:51c43836c1d7 25
Lightvalve 24:ef6e1092e9e6 26
jobuuu 7:e9086c72bb22 27 // PWM ///////////////////////////////////////////
Lightvalve 30:8d561f16383b 28 float dtc_v=0.0f;
Lightvalve 30:8d561f16383b 29 float dtc_w=0.0f;
GiJeongKim 0:51c43836c1d7 30
jobuuu 7:e9086c72bb22 31 // I2C ///////////////////////////////////////////
GiJeongKim 0:51c43836c1d7 32 I2C i2c(PC_9,PA_8); // SDA, SCL (for K22F)
GiJeongKim 0:51c43836c1d7 33 const int i2c_slave_addr1 = 0x56;
GiJeongKim 0:51c43836c1d7 34 unsigned int value; // 10bit output of reading sensor AS5510
GiJeongKim 0:51c43836c1d7 35
jobuuu 7:e9086c72bb22 36 // SPI ///////////////////////////////////////////
Lightvalve 16:903b5a4433b4 37 //SPI eeprom(PB_15, PB_14, PB_13); // EEPROM //(SPI_MOSI, SPI_MISO, SPI_SCK);
Lightvalve 16:903b5a4433b4 38 //DigitalOut eeprom_cs(PB_12);
Lightvalve 16:903b5a4433b4 39 //FlashWriter writer(6);//2부터 7까지 되는듯 아마 sector
GiJeongKim 0:51c43836c1d7 40 SPI enc(PC_12,PC_11,PC_10);
GiJeongKim 0:51c43836c1d7 41 DigitalOut enc_cs(PD_2);
Lightvalve 11:82d8768d7351 42 DigitalOut LED(PA_15);
GiJeongKim 0:51c43836c1d7 43
jobuuu 7:e9086c72bb22 44 // UART ///////////////////////////////////////////
GiJeongKim 0:51c43836c1d7 45 Serial pc(PA_9,PA_10); // _ UART
GiJeongKim 0:51c43836c1d7 46
jobuuu 7:e9086c72bb22 47 // CAN ///////////////////////////////////////////
GiJeongKim 0:51c43836c1d7 48 CAN can(PB_8, PB_9, 1000000);
GiJeongKim 0:51c43836c1d7 49 CANMessage msg;
Lightvalve 11:82d8768d7351 50 void onMsgReceived()
Lightvalve 11:82d8768d7351 51 {
Lightvalve 11:82d8768d7351 52 CAN_RX_HANDLER();
Lightvalve 11:82d8768d7351 53 }
jobuuu 2:a1c0a37df760 54
jobuuu 7:e9086c72bb22 55 // Variables ///////////////////////////////////////////
jobuuu 7:e9086c72bb22 56 State pos;
jobuuu 7:e9086c72bb22 57 State vel;
jobuuu 7:e9086c72bb22 58 State Vout;
jobuuu 7:e9086c72bb22 59 State torq;
jobuuu 7:e9086c72bb22 60 State pres_A;
jobuuu 7:e9086c72bb22 61 State pres_B;
jobuuu 7:e9086c72bb22 62 State cur;
Lightvalve 14:8e7590227d22 63 State valve_pos;
Lightvalve 14:8e7590227d22 64
Lightvalve 14:8e7590227d22 65 State INIT_Vout;
Lightvalve 14:8e7590227d22 66 State INIT_Valve_Pos;
Lightvalve 14:8e7590227d22 67 State INIT_Pos;
Lightvalve 14:8e7590227d22 68 State INIT_torq;
jobuuu 5:a4319f79457b 69
Lightvalve 19:23b7c1ad8683 70 extern int CID_RX_CMD;
Lightvalve 19:23b7c1ad8683 71 extern int CID_RX_REF_POSITION;
Lightvalve 49:e7bcfc244d40 72 extern int CID_RX_REF_VALVE_POS;
Lightvalve 45:35fa6884d0c6 73 extern int CID_RX_REF_PWM;
Lightvalve 19:23b7c1ad8683 74
Lightvalve 19:23b7c1ad8683 75 extern int CID_TX_INFO;
Lightvalve 19:23b7c1ad8683 76 extern int CID_TX_POSITION;
Lightvalve 19:23b7c1ad8683 77 extern int CID_TX_TORQUE;
Lightvalve 19:23b7c1ad8683 78 extern int CID_TX_PRES;
Lightvalve 19:23b7c1ad8683 79 extern int CID_TX_VOUT;
Lightvalve 19:23b7c1ad8683 80 extern int CID_TX_VALVE_POSITION;
Lightvalve 19:23b7c1ad8683 81
Lightvalve 61:bc8c8270f0ab 82
Lightvalve 61:bc8c8270f0ab 83
Lightvalve 61:bc8c8270f0ab 84
jobuuu 7:e9086c72bb22 85 // =============================================================================
jobuuu 7:e9086c72bb22 86 // =============================================================================
jobuuu 7:e9086c72bb22 87 // =============================================================================
jobuuu 7:e9086c72bb22 88
Lightvalve 12:6f2531038ea4 89 /*******************************************************************************
Lightvalve 12:6f2531038ea4 90 * REFERENCE MODE
Lightvalve 12:6f2531038ea4 91 ******************************************************************************/
Lightvalve 13:747daba9cf59 92 enum _REFERENCE_MODE {
Lightvalve 13:747daba9cf59 93 MODE_REF_NO_ACT = 0, //0
Lightvalve 12:6f2531038ea4 94 MODE_REF_DIRECT, //1
Lightvalve 12:6f2531038ea4 95 MODE_REF_COS_INC, //2
Lightvalve 12:6f2531038ea4 96 MODE_REF_LINE_INC, //3
Lightvalve 12:6f2531038ea4 97 MODE_REF_SIN_WAVE, //4
Lightvalve 12:6f2531038ea4 98 MODE_REF_SQUARE_WAVE, //5
Lightvalve 12:6f2531038ea4 99 };
Lightvalve 12:6f2531038ea4 100
Lightvalve 12:6f2531038ea4 101 /*******************************************************************************
Lightvalve 12:6f2531038ea4 102 * CONTROL MODE
Lightvalve 12:6f2531038ea4 103 ******************************************************************************/
Lightvalve 13:747daba9cf59 104 enum _CONTROL_MODE {
Lightvalve 12:6f2531038ea4 105 //control mode
Lightvalve 12:6f2531038ea4 106 MODE_NO_ACT = 0, //0
Lightvalve 47:fdcb8bd86fd6 107 MODE_VALVE_POSITION_CONTROL, //1
Lightvalve 47:fdcb8bd86fd6 108 MODE_JOINT_CONTROL, //2
Lightvalve 50:3c630b5eba9f 109
Lightvalve 47:fdcb8bd86fd6 110 MODE_VALVE_OPEN_LOOP, //3
Lightvalve 12:6f2531038ea4 111 MODE_JOINT_POSITION_TORQUE_CONTROL_VALVE_POSITION, //4
Lightvalve 12:6f2531038ea4 112 MODE_VALVE_POSITION_TORQUE_CONTROL_LEARNING, //5
Lightvalve 13:747daba9cf59 113
Lightvalve 12:6f2531038ea4 114 MODE_JOINT_POSITION_PRES_CONTROL_PWM, //6
Lightvalve 12:6f2531038ea4 115 MODE_JOINT_POSITION_PRES_CONTROL_VALVE_POSITION, //7
Lightvalve 12:6f2531038ea4 116 MODE_VALVE_POSITION_PRES_CONTROL_LEARNING, //8
Lightvalve 13:747daba9cf59 117
Lightvalve 12:6f2531038ea4 118 MODE_TEST_CURRENT_CONTROL, //9
Lightvalve 12:6f2531038ea4 119 MODE_TEST_PWM_CONTROL, //10
Lightvalve 21:e5f1a43ea6f9 120
Lightvalve 14:8e7590227d22 121 MODE_CURRENT_CONTROL, //11
Lightvalve 14:8e7590227d22 122 MODE_JOINT_POSITION_TORQUE_CONTROL_CURRENT, //12
Lightvalve 14:8e7590227d22 123 MODE_JOINT_POSITION_PRES_CONTROL_CURRENT, //13
Lightvalve 13:747daba9cf59 124
Lightvalve 12:6f2531038ea4 125 //utility
Lightvalve 12:6f2531038ea4 126 MODE_TORQUE_SENSOR_NULLING = 20, //20
Lightvalve 12:6f2531038ea4 127 MODE_VALVE_NULLING_AND_DEADZONE_SETTING, //21
Lightvalve 12:6f2531038ea4 128 MODE_FIND_HOME, //22
Lightvalve 57:f4819de54e7a 129 MODE_VALVE_GAIN_SETTING, //23
Lightvalve 12:6f2531038ea4 130 MODE_PRESSURE_SENSOR_NULLING, //24
Lightvalve 12:6f2531038ea4 131 MODE_PRESSURE_SENSOR_CALIB, //25
Lightvalve 12:6f2531038ea4 132 MODE_ROTARY_FRICTION_TUNING, //26
Lightvalve 13:747daba9cf59 133
Lightvalve 12:6f2531038ea4 134 MODE_DDV_POS_VS_PWM_ID = 30, //30
Lightvalve 12:6f2531038ea4 135 MODE_DDV_DEADZONE_AND_CENTER, //31
Lightvalve 12:6f2531038ea4 136 MODE_DDV_POS_VS_FLOWRATE, //32
Lightvalve 57:f4819de54e7a 137 MODE_SYSTEM_ID, //33
Lightvalve 12:6f2531038ea4 138 };
Lightvalve 12:6f2531038ea4 139
Lightvalve 65:a2d7c63419c2 140 void SystemClock_Config(void)
Lightvalve 65:a2d7c63419c2 141 {
Lightvalve 65:a2d7c63419c2 142 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
Lightvalve 65:a2d7c63419c2 143 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
Lightvalve 65:a2d7c63419c2 144
Lightvalve 65:a2d7c63419c2 145 /** Configure the main internal regulator output voltage
Lightvalve 65:a2d7c63419c2 146 */
Lightvalve 65:a2d7c63419c2 147 __HAL_RCC_PWR_CLK_ENABLE();
Lightvalve 65:a2d7c63419c2 148 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
Lightvalve 65:a2d7c63419c2 149 /** Initializes the CPU, AHB and APB busses clocks
Lightvalve 65:a2d7c63419c2 150 */
Lightvalve 65:a2d7c63419c2 151 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
Lightvalve 65:a2d7c63419c2 152 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
Lightvalve 65:a2d7c63419c2 153 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
Lightvalve 65:a2d7c63419c2 154 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
Lightvalve 65:a2d7c63419c2 155 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
Lightvalve 65:a2d7c63419c2 156 RCC_OscInitStruct.PLL.PLLM = 8;//8
Lightvalve 65:a2d7c63419c2 157 RCC_OscInitStruct.PLL.PLLN = 180; //180
Lightvalve 65:a2d7c63419c2 158 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
Lightvalve 65:a2d7c63419c2 159 RCC_OscInitStruct.PLL.PLLQ = 2;
Lightvalve 65:a2d7c63419c2 160 RCC_OscInitStruct.PLL.PLLR = 2;
Lightvalve 65:a2d7c63419c2 161 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
Lightvalve 65:a2d7c63419c2 162 {
Lightvalve 65:a2d7c63419c2 163 //Error_Handler();
Lightvalve 65:a2d7c63419c2 164 }
Lightvalve 65:a2d7c63419c2 165 /** Activate the Over-Drive mode
Lightvalve 65:a2d7c63419c2 166 */
Lightvalve 65:a2d7c63419c2 167 if (HAL_PWREx_EnableOverDrive() != HAL_OK)
Lightvalve 65:a2d7c63419c2 168 {
Lightvalve 65:a2d7c63419c2 169 //Error_Handler();
Lightvalve 65:a2d7c63419c2 170 }
Lightvalve 65:a2d7c63419c2 171 /** Initializes the CPU, AHB and APB busses clocks
Lightvalve 65:a2d7c63419c2 172 */
Lightvalve 65:a2d7c63419c2 173 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
Lightvalve 65:a2d7c63419c2 174 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
Lightvalve 65:a2d7c63419c2 175 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
Lightvalve 65:a2d7c63419c2 176 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
Lightvalve 65:a2d7c63419c2 177 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
Lightvalve 65:a2d7c63419c2 178 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
Lightvalve 65:a2d7c63419c2 179
Lightvalve 65:a2d7c63419c2 180 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
Lightvalve 65:a2d7c63419c2 181 {
Lightvalve 65:a2d7c63419c2 182 //Error_Handler();
Lightvalve 65:a2d7c63419c2 183 }
Lightvalve 65:a2d7c63419c2 184 }
Lightvalve 65:a2d7c63419c2 185
Lightvalve 65:a2d7c63419c2 186
Lightvalve 67:c2812cf26c38 187 float f_future[num_input_array] = {0.0f};
Lightvalve 66:a8e6799dbce3 188
Lightvalve 66:a8e6799dbce3 189 float input[num_input] = { 0.0f };
Lightvalve 65:a2d7c63419c2 190
Lightvalve 66:a8e6799dbce3 191 const float h1[num_input][32] = {
Lightvalve 67:c2812cf26c38 192 {-4.230629920959473f,3.7482995986938477f,0.10087299346923828f,-1.249260663986206f,0.4228786528110504f,-0.5900165438652039f,-0.28529417514801025f,4.176730632781982f,-0.22588196396827698f,-3.8898375034332275f,-0.18891912698745728f,0.591685950756073f,-0.18402203917503357f,0.2365148514509201f,-0.20103082060813904f,-0.9443630576133728f,0.11390197277069092f,0.23753002285957336f,-0.3451942503452301f,1.7862669229507446f,-0.3459416627883911f,0.1018887460231781f,-0.31691664457321167f,-0.07546886801719666f,0.9590144157409668f,0.1750296652317047f,-0.16833457350730896f,0.05917641147971153f,0.3100067973136902f,-0.17902883887290955f,0.22342900931835175f,0.07611003518104553f},
Lightvalve 67:c2812cf26c38 193 {-2.969736337661743f,2.6268742084503174f,0.2844829857349396f,-1.2572543621063232f,0.2949725389480591f,-0.40602585673332214f,0.09208345413208008f,2.812852144241333f,-0.1288408488035202f,-2.4199726581573486f,-0.27550092339515686f,0.3135509788990021f,0.020206838846206665f,0.15749837458133698f,0.04370078444480896f,-0.6972789764404297f,-0.07285691052675247f,0.059967368841171265f,0.27244070172309875f,1.3432673215866089f,-0.05647682026028633f,-0.11504809558391571f,-0.0905606746673584f,0.2640003263950348f,0.6242079734802246f,0.2797521650791168f,0.12084531784057617f,0.2831539213657379f,-0.14650659263134003f,0.09343862533569336f,-0.05422786623239517f,0.09386715292930603f},
Lightvalve 67:c2812cf26c38 194 {-0.9856688976287842f,1.2492953538894653f,-0.004022121429443359f,-0.2416287362575531f,0.08375676721334457f,-0.31567850708961487f,-0.014427455142140388f,1.2782719135284424f,0.019761085510253906f,-1.0968167781829834f,0.26836007833480835f,0.12039636820554733f,-0.031272560358047485f,0.16259945929050446f,-0.3021453320980072f,-0.4570225477218628f,0.29755106568336487f,-0.25322937965393066f,0.1318707913160324f,0.6320580840110779f,0.18409328162670135f,-0.14585837721824646f,0.1290973722934723f,-0.23490183055400848f,0.21291287243366241f,0.13848352432250977f,-0.14778463542461395f,0.18564558029174805f,-0.369647353887558f,0.28840622305870056f,-0.3577423691749573f,-0.18625950813293457f},
Lightvalve 67:c2812cf26c38 195 {0.6824329495429993f,-0.5322751998901367f,-0.19558930397033691f,-0.2689341902732849f,-0.5242046117782593f,0.013336426578462124f,-0.05194856598973274f,-0.6233313083648682f,0.2818599343299866f,0.4670529365539551f,0.1137142926454544f,0.05919991806149483f,-0.11249050498008728f,0.2839790880680084f,-0.12209486961364746f,-0.020275995135307312f,-0.1303829848766327f,-0.22630342841148376f,-0.24653835594654083f,-0.31501466035842896f,-0.2647970914840698f,-0.08376853168010712f,-0.14013314247131348f,-0.277662992477417f,-0.22086156904697418f,0.1348792016506195f,0.12745562195777893f,-0.10462278127670288f,-0.016341594979166985f,0.1260412633419037f,-0.21633583307266235f,0.16906705498695374f},
Lightvalve 67:c2812cf26c38 196 {2.6963932514190674f,-2.061609983444214f,0.08011308312416077f,0.3819923400878906f,-0.7255011200904846f,0.13847801089286804f,-0.13927656412124634f,-2.6796464920043945f,-0.21323607861995697f,2.575685501098633f,-0.23677363991737366f,-0.27583199739456177f,0.20140400528907776f,0.16035087406635284f,-0.2388615608215332f,0.46706220507621765f,-0.33553919196128845f,-0.17562326788902283f,0.10578251630067825f,-1.319668173789978f,0.1036451905965805f,0.22469106316566467f,-0.2337813377380371f,-0.07104292511940002f,-0.7000943422317505f,-0.32632216811180115f,0.038649410009384155f,-0.4758243262767792f,-0.16495253145694733f,-0.15546131134033203f,-0.20156465470790863f,0.025572150945663452f},
Lightvalve 67:c2812cf26c38 197 {5.074757099151611f,-4.697023391723633f,0.2906685173511505f,1.6116559505462646f,-0.9414765238761902f,0.3160191774368286f,-0.2238575667142868f,-4.803736209869385f,-0.3351536691188812f,4.746501922607422f,0.2679271101951599f,-1.120054006576538f,-0.029951006174087524f,-0.020948145538568497f,0.20863232016563416f,0.342511385679245f,-0.6690735220909119f,-0.30441316962242126f,-0.3538511395454407f,-2.1590168476104736f,0.10130328685045242f,-0.009217172861099243f,0.11990180611610413f,0.3152395784854889f,-1.3119330406188965f,0.19827589392662048f,-0.278697669506073f,-0.05627449229359627f,-0.5008052587509155f,-0.0012509822845458984f,-0.6269418001174927f,-0.053316205739974976f},
Lightvalve 67:c2812cf26c38 198 {0.13194701075553894f,-1.1968308687210083f,0.15515866875648499f,0.4829818904399872f,0.15424390137195587f,-0.11621054261922836f,-0.34514543414115906f,-0.8330129981040955f,-0.13495880365371704f,0.5151646137237549f,-0.09287907183170319f,-0.43318071961402893f,0.09392929077148438f,-0.007367492653429508f,-0.17407774925231934f,-0.3366681933403015f,-0.12277928739786148f,-0.07779207825660706f,0.28259533643722534f,-0.5168511867523193f,-0.1835738867521286f,-0.16872906684875488f,-0.2501657009124756f,-0.23358337581157684f,-0.46349969506263733f,-0.14798402786254883f,-0.1072954386472702f,-0.16134178638458252f,-0.20340396463871002f,-0.033211708068847656f,-0.11329694092273712f,0.11262083053588867f},
Lightvalve 67:c2812cf26c38 199 {-0.6218560338020325f,-0.5857181549072266f,0.1585540771484375f,0.2830691635608673f,0.1954178363084793f,-0.35701751708984375f,-0.12434191256761551f,-0.49757781624794006f,0.24989964067935944f,0.3961395025253296f,-0.22606085240840912f,-0.5804455280303955f,0.10294389724731445f,-0.06342104822397232f,0.052227020263671875f,0.14480942487716675f,-0.04316595196723938f,-0.272625207901001f,-0.3562246263027191f,-0.3108222186565399f,-0.09970086812973022f,0.021598905324935913f,-0.12170252203941345f,-0.027094602584838867f,-0.15801021456718445f,0.016911834478378296f,-0.32526659965515137f,-0.07739252597093582f,-0.1867571920156479f,0.00411224365234375f,-0.2395312786102295f,0.24875596165657043f},
Lightvalve 67:c2812cf26c38 200 {-0.9577339887619019f,-1.231973648071289f,0.1305990219116211f,0.31612005829811096f,-0.04141230881214142f,-0.4076184630393982f,-0.18367885053157806f,-0.3815915286540985f,-0.03675880655646324f,0.27151361107826233f,-0.28397804498672485f,0.10056844353675842f,0.10954022407531738f,0.24071356654167175f,0.23004469275474548f,0.02405562624335289f,-0.12682388722896576f,0.05736207962036133f,0.12340593338012695f,-0.23699147999286652f,-0.3174220621585846f,-0.02127060294151306f,-0.2822587490081787f,0.08045688271522522f,-0.5912472605705261f,-0.07828792929649353f,-0.08483991026878357f,0.15951544046401978f,0.22402171790599823f,-0.11358706653118134f,-0.38293948769569397f,0.0935753881931305f},
Lightvalve 67:c2812cf26c38 201 {-0.45305922627449036f,-0.8603971600532532f,-0.2328716218471527f,0.3233547508716583f,0.2811950743198395f,-0.31350186467170715f,0.06394220143556595f,0.06857368350028992f,-0.30230626463890076f,-0.0428517684340477f,-0.3395269215106964f,0.10702203214168549f,0.08001843094825745f,0.1195649728178978f,-0.2551456391811371f,-0.49434688687324524f,0.20916220545768738f,0.316246896982193f,0.07910750806331635f,-0.11669608950614929f,-0.22036723792552948f,0.1560649871826172f,-0.11126312613487244f,-0.30638599395751953f,-0.3052792549133301f,0.05366125702857971f,0.1294359266757965f,0.1745939552783966f,0.202530175447464f,0.28930428624153137f,-0.010545541532337666f,0.1775827705860138f},
Lightvalve 67:c2812cf26c38 202 {0.4335167407989502f,0.6084941029548645f,-0.0634300708770752f,-0.23047587275505066f,-0.1927889883518219f,-0.4711085557937622f,-0.0406518280506134f,0.6740919351577759f,-0.28920698165893555f,-1.185210943222046f,-0.3287361264228821f,-0.3320023715496063f,-0.17047008872032166f,0.26946544647216797f,0.016325324773788452f,0.04435703158378601f,-0.24857361614704132f,-0.23234836757183075f,0.1807047724723816f,-0.004559496883302927f,0.13267749547958374f,-0.24138674139976501f,0.2283824384212494f,0.010796308517456055f,-0.02628307417035103f,0.09781908988952637f,0.07673224806785583f,-0.3335549533367157f,0.21806660294532776f,0.02820834517478943f,-0.04227491095662117f,0.17321613430976868f},
Lightvalve 67:c2812cf26c38 203 {1.5479638576507568f,2.243504285812378f,-0.29345569014549255f,-0.6306607723236084f,-0.36697518825531006f,-0.627920925617218f,-0.27119821310043335f,0.7452946305274963f,-0.22403128445148468f,-1.40024733543396f,0.2792316973209381f,-0.23776952922344208f,-0.03579244017601013f,-0.1521511673927307f,-0.28509521484375f,0.14541488885879517f,-0.04063437134027481f,-0.17347121238708496f,-0.3063865900039673f,0.06307438760995865f,0.24736933410167694f,0.21679124236106873f,-0.22265808284282684f,0.31252244114875793f,-0.34505316615104675f,0.2008223831653595f,0.3222421705722809f,0.08012430369853973f,0.26425454020500183f,0.14098921418190002f,0.05007125437259674f,-0.04709109663963318f},
Lightvalve 67:c2812cf26c38 204 {1.1522587537765503f,-2.1747663021087646f,0.1837349236011505f,0.40434226393699646f,-0.12145937234163284f,-0.08323094993829727f,-0.3496353328227997f,0.15441910922527313f,-0.10960858315229416f,1.152055263519287f,-0.13892297446727753f,0.003560970537364483f,-0.2591227889060974f,-0.362162321805954f,0.061814457178115845f,-0.15229834616184235f,-0.3534192144870758f,0.20787635445594788f,-0.03223574534058571f,-0.5005717873573303f,-0.26889294385910034f,0.025913476943969727f,0.011856883764266968f,-0.002827882766723633f,-0.1408006101846695f,0.028789907693862915f,0.3261648118495941f,-0.10949914902448654f,-0.09778116643428802f,-0.32888755202293396f,-0.40911802649497986f,0.09549155831336975f},
Lightvalve 67:c2812cf26c38 205 {0.2676979601383209f,-1.3534437417984009f,0.05985936522483826f,0.38052743673324585f,-0.2598187327384949f,0.06489779055118561f,0.13378676772117615f,-0.0681387335062027f,-0.06396450847387314f,1.0828841924667358f,0.2811009883880615f,-0.3700156807899475f,0.031953901052474976f,0.0015934938564896584f,0.1021522581577301f,-0.10323778539896011f,-0.23296494781970978f,0.08450636267662048f,-0.12172722816467285f,-0.08527509868144989f,-0.24145641922950745f,-0.014602094888687134f,0.11327552795410156f,-0.31571850180625916f,-0.29319894313812256f,-0.14150118827819824f,0.24654820561408997f,-0.30221912264823914f,-0.005436727777123451f,0.23035290837287903f,-0.3906380236148834f,0.2325780689716339f},
Lightvalve 67:c2812cf26c38 206 {0.06700637936592102f,-0.08303394168615341f,0.24405649304389954f,0.03128955513238907f,-0.45866742730140686f,0.14298471808433533f,0.018601972609758377f,-0.36369210481643677f,0.0789068192243576f,0.6512700915336609f,-0.04079161584377289f,-0.26272720098495483f,0.18033960461616516f,-0.3406867980957031f,0.03770804405212402f,0.2529774606227875f,-0.019213126972317696f,-0.06876960396766663f,0.22808204591274261f,0.07092312723398209f,0.2719727158546448f,0.2508205473423004f,0.025177806615829468f,0.2262592613697052f,-0.3923889100551605f,0.1852022111415863f,0.18975666165351868f,-0.5460088849067688f,-0.35677704215049744f,-0.09938693046569824f,-0.40601199865341187f,-0.1806284636259079f},
Lightvalve 67:c2812cf26c38 207 {-0.08479766547679901f,0.3207172751426697f,-0.13136014342308044f,0.16793455183506012f,-0.4321121871471405f,0.21849192678928375f,-0.3697195053100586f,-0.503350555896759f,-0.18693950772285461f,0.9609227776527405f,-0.30470871925354004f,-0.006775724235922098f,0.05990728735923767f,-0.24202655255794525f,0.26781734824180603f,-0.35483014583587646f,0.03515452891588211f,-0.13362249732017517f,-0.2844195067882538f,-0.4494897127151489f,0.14731274545192719f,0.06692108511924744f,-0.12372803688049316f,0.041742414236068726f,0.017781872302293777f,-0.11748671531677246f,-0.11852662265300751f,-0.1426704227924347f,-0.23248130083084106f,0.2662833034992218f,-0.09097664803266525f,0.17151817679405212f},
Lightvalve 67:c2812cf26c38 208 {-0.03969593718647957f,0.08671023696660995f,0.22696831822395325f,-0.20662827789783478f,-0.02556598000228405f,-0.051771845668554306f,0.17967931926250458f,-0.44331681728363037f,0.30235540866851807f,0.7842848300933838f,-0.3279753029346466f,-0.20199066400527954f,0.011522531509399414f,-0.09567585587501526f,-0.03764382004737854f,-0.14156456291675568f,-0.031191840767860413f,0.23899778723716736f,0.11486408859491348f,-0.1731787919998169f,0.18458501994609833f,0.2893877923488617f,-0.006054013967514038f,-0.10518202185630798f,-0.28643080592155457f,-0.27516937255859375f,-0.05509433150291443f,0.0013699403498321772f,-0.011218680068850517f,-0.14826560020446777f,-0.6032581329345703f,-0.16339246928691864f},
Lightvalve 67:c2812cf26c38 209 {-0.267282098531723f,-0.15963980555534363f,0.30063238739967346f,-0.5436930656433105f,-0.5086090564727783f,-0.32418474555015564f,0.05498194321990013f,-0.4829002320766449f,0.06115914136171341f,0.4195326566696167f,0.16549015045166016f,-0.36930403113365173f,0.25101223587989807f,-0.23357032239437103f,0.10770025849342346f,-0.008421609178185463f,-0.06767242401838303f,0.06214180588722229f,-0.16396768391132355f,-0.1145302876830101f,0.22987458109855652f,-0.2509557604789734f,0.010174989700317383f,0.07912516593933105f,-0.32788777351379395f,0.022580862045288086f,0.09753298759460449f,-0.15826599299907684f,-0.4203484058380127f,0.3270951211452484f,-0.564437985420227f,-0.027072906494140625f},
Lightvalve 67:c2812cf26c38 210 {-0.545842170715332f,0.15384531021118164f,-0.01902279257774353f,-0.3912962079048157f,-0.5790053009986877f,0.24453280866146088f,0.12503334879875183f,-0.39908960461616516f,-0.17422115802764893f,0.8160369396209717f,0.16292835772037506f,-0.1888384073972702f,0.15116563439369202f,0.22249086201190948f,0.112009197473526f,-0.36792871356010437f,0.06428104639053345f,-0.09951440989971161f,-0.37176713347435f,-0.014535467140376568f,-0.02545744553208351f,-0.22721576690673828f,-0.058719635009765625f,0.2827478349208832f,-0.5208176970481873f,-0.11849872767925262f,-0.0910792350769043f,-0.5736068487167358f,-0.18935924768447876f,0.1612793505191803f,0.0008475360227748752f,-0.3307521343231201f},
Lightvalve 67:c2812cf26c38 211 {-0.5873463153839111f,-0.21215161681175232f,-0.22018472850322723f,-0.1165526732802391f,-0.048116281628608704f,0.2596314251422882f,-0.4138343632221222f,-0.4551394581794739f,-0.16201747953891754f,0.682412326335907f,-0.15030591189861298f,-0.03957514837384224f,0.17184868454933167f,-0.25196483731269836f,0.17424550652503967f,0.12593847513198853f,-0.03053038939833641f,-0.14159934222698212f,0.047994229942560196f,-0.3698164224624634f,0.1708088517189026f,0.034713178873062134f,0.04339686036109924f,-0.1864316463470459f,-0.3897135555744171f,-0.08606395125389099f,0.018100887537002563f,-0.12216664850711823f,-0.03601347655057907f,0.25916776061058044f,0.004807629156857729f,0.028863340616226196f},
Lightvalve 67:c2812cf26c38 212 {-0.46963363885879517f,0.00842958688735962f,-0.07112669944763184f,-0.25665736198425293f,-0.13443860411643982f,0.07957783341407776f,-0.11848480999469757f,-0.21702025830745697f,-0.2156369537115097f,0.410529226064682f,-0.3150181770324707f,-0.3411242365837097f,-0.21931910514831543f,0.21745339035987854f,-0.15002036094665527f,-0.583783745765686f,-0.3345203995704651f,-0.1280200481414795f,0.03466592729091644f,0.34970608353614807f,0.22630873322486877f,-0.18634438514709473f,0.16605710983276367f,0.2803939878940582f,-0.27209964394569397f,0.3151257336139679f,-0.10340547561645508f,-0.06792658567428589f,-0.035161323845386505f,-0.28105688095092773f,-0.23525622487068176f,0.02959480881690979f},
Lightvalve 67:c2812cf26c38 213 {-0.24767370522022247f,-0.5062268972396851f,-0.31935176253318787f,0.01446946244686842f,0.019070051610469818f,0.13124142587184906f,-0.28055378794670105f,-0.37363162636756897f,0.019363218918442726f,-0.07367568463087082f,-0.22565722465515137f,-0.2858344316482544f,-0.243825763463974f,0.17212820053100586f,-0.053373098373413086f,0.07847514003515244f,-0.08251450955867767f,0.2269948422908783f,-0.20244447886943817f,-0.13683776557445526f,-0.27434465289115906f,-0.039089351892471313f,-0.04909595847129822f,-0.32456254959106445f,-0.24301311373710632f,0.10373988747596741f,0.19934538006782532f,-0.08322369307279587f,-0.20240508019924164f,-0.3250839114189148f,-0.0010883818613365293f,-0.28260526061058044f},
Lightvalve 65:a2d7c63419c2 214 };
Lightvalve 65:a2d7c63419c2 215
Lightvalve 66:a8e6799dbce3 216 const float h2[32][32] = {
Lightvalve 67:c2812cf26c38 217 {-0.19307275116443634f,-0.10295046865940094f,-0.04925942420959473f,0.005745674483478069f,-0.15490937232971191f,0.027541013434529305f,-0.15088897943496704f,0.06396704912185669f,-0.30411389470100403f,-0.10008957982063293f,-0.20804470777511597f,-3.0952818393707275f,-0.04591958969831467f,0.7205867171287537f,-0.09547919034957886f,-0.621465802192688f,0.07803884148597717f,-0.21483641862869263f,-0.01851428486406803f,0.02391211874783039f,-0.298857182264328f,-0.5293326377868652f,-0.23983746767044067f,-0.21143370866775513f,3.425938606262207f,-0.9079028964042664f,1.7516283988952637f,-1.1632829904556274f,0.23828622698783875f,-0.019066963344812393f,-0.24613501131534576f,-0.18507002294063568f},
Lightvalve 67:c2812cf26c38 218 {-0.22047388553619385f,0.002147972583770752f,-0.04321768879890442f,0.21018564701080322f,0.039372533559799194f,-0.2765212059020996f,-0.8219893574714661f,-0.05986310541629791f,0.24677053093910217f,0.048597872257232666f,-0.145189568400383f,0.0862545520067215f,0.117829330265522f,-1.5123645067214966f,-0.021691346541047096f,-2.8992412090301514f,0.056778669357299805f,-0.2737269401550293f,-0.28047558665275574f,0.23282590508460999f,-0.2320939302444458f,-0.11584651470184326f,-0.2732713222503662f,0.29149511456489563f,-0.3339754045009613f,0.8974737524986267f,-1.7021849155426025f,2.400773286819458f,-0.28620439767837524f,-0.1962459534406662f,0.19307708740234375f,0.06311527639627457f},
Lightvalve 66:a8e6799dbce3 219 {-0.1579037755727768f,0.28447648882865906f,-0.1789936125278473f,0.20799604058265686f,0.025723248720169067f,0.17740526795387268f,-0.1666354387998581f,-0.06060470640659332f,-0.017253071069717407f,-0.2790656089782715f,-0.16800916194915771f,-0.2990717589855194f,0.07126197218894958f,-0.08032660186290741f,-0.1799015998840332f,-0.1891922950744629f,0.2556300461292267f,0.2080206573009491f,-0.24888339638710022f,0.27691522240638733f,-0.21319638192653656f,-0.14012537896633148f,-0.30466505885124207f,-0.013728171586990356f,-0.1629670113325119f,0.2530798614025116f,0.0633285641670227f,0.0011726915836334229f,-0.14820529520511627f,0.2823629677295685f,0.10884168744087219f,-0.2637729346752167f},
Lightvalve 67:c2812cf26c38 220 {-0.14158807694911957f,-0.01806354522705078f,-0.23058539628982544f,0.01444769836962223f,-0.27190759778022766f,-0.38016778230667114f,-0.22250047326087952f,0.08759373426437378f,-0.06944303214550018f,0.09271347522735596f,-0.36198750138282776f,-0.17815805971622467f,-0.29218652844429016f,-0.5358395576477051f,-0.3249095678329468f,-2.335254669189453f,0.10996055603027344f,0.24023392796516418f,-0.032462429255247116f,-0.1884155571460724f,-0.409393846988678f,-0.8763270378112793f,-0.22002318501472473f,-0.21236775815486908f,-0.08007029443979263f,-0.7104129195213318f,-0.14489786326885223f,-0.18411876261234283f,-0.22396358847618103f,0.10107194632291794f,0.03394383192062378f,0.12347844243049622f},
Lightvalve 67:c2812cf26c38 221 {-0.18258020281791687f,0.2506926953792572f,-0.0804666131734848f,0.036993905901908875f,0.02918580174446106f,-0.37934544682502747f,-0.2223806530237198f,0.0013494789600372314f,0.043158918619155884f,-0.2690317630767822f,-0.11942647397518158f,-0.4592708945274353f,-0.4080348312854767f,-0.41777125000953674f,-0.350312203168869f,-0.31490519642829895f,-0.10307048261165619f,0.15626338124275208f,-0.300653874874115f,0.03295828029513359f,-0.0033501936122775078f,-0.06808088719844818f,0.03979063406586647f,-0.25683170557022095f,-0.3598131239414215f,-0.31870344281196594f,-0.1962815374135971f,0.07710067182779312f,0.2695164978504181f,-0.2185228317975998f,0.008398771286010742f,-0.16780559718608856f},
Lightvalve 67:c2812cf26c38 222 {-0.19158349931240082f,-0.004258692264556885f,0.032371193170547485f,-0.3139747083187103f,-0.023485273122787476f,-0.29336631298065186f,0.10373451560735703f,-0.14440131187438965f,-0.03548547625541687f,0.08825305104255676f,-0.22853513062000275f,0.3744160532951355f,-0.2578849494457245f,0.005520757753401995f,-0.3508349657058716f,-0.2882671058177948f,0.2371552288532257f,0.24713221192359924f,0.16838091611862183f,0.18546201288700104f,-0.012777712196111679f,0.06621339172124863f,-0.1307595670223236f,-0.08340707421302795f,-0.016662748530507088f,-0.2519686818122864f,0.023772694170475006f,0.17473013699054718f,0.05800282955169678f,-0.26823562383651733f,0.17187702655792236f,0.17345115542411804f},
Lightvalve 67:c2812cf26c38 223 {-0.21433322131633759f,-0.1279313862323761f,-0.11171227693557739f,0.22548486292362213f,-0.26441383361816406f,0.2845393121242523f,0.006005025003105402f,-0.20844537019729614f,-0.26620519161224365f,0.17144301533699036f,-0.13259942829608917f,-0.006703587714582682f,0.29584869742393494f,-0.3097950220108032f,-0.1625986099243164f,0.13927125930786133f,-0.16153597831726074f,0.18742787837982178f,-0.14897000789642334f,0.08457143604755402f,0.02401861734688282f,0.02421507239341736f,-0.07988794147968292f,-0.15143592655658722f,-0.19305813312530518f,0.26127201318740845f,0.12294835597276688f,0.024624167010188103f,-0.11822041869163513f,0.19546762108802795f,-0.16657039523124695f,-0.06051725521683693f},
Lightvalve 67:c2812cf26c38 224 {0.29264822602272034f,0.11346611380577087f,0.04012581706047058f,-0.024864500388503075f,0.22828009724617004f,-0.2142239511013031f,-0.3920200765132904f,0.004197537899017334f,0.2864855229854584f,0.01006925106048584f,-0.32860270142555237f,3.1985983848571777f,-0.21106116473674774f,-1.591800570487976f,-0.03926673159003258f,-0.20629765093326569f,-0.2721019387245178f,0.2706601917743683f,-0.05631055310368538f,-0.11725504696369171f,-0.04956214502453804f,-0.23963265120983124f,-0.20263491570949554f,0.2198345959186554f,2.4053735733032227f,2.541543960571289f,1.5968725681304932f,1.3761701583862305f,-0.14135785400867462f,0.07403197884559631f,0.16089555621147156f,0.0857221707701683f},
Lightvalve 67:c2812cf26c38 225 {0.28564146161079407f,0.2890130579471588f,-0.021617114543914795f,0.11687019467353821f,0.29321715235710144f,0.07065775990486145f,-0.26538729667663574f,-0.23997274041175842f,0.29470762610435486f,-0.06864601373672485f,0.10823128372430801f,-0.09475591033697128f,0.24146446585655212f,-0.01334434188902378f,0.26754143834114075f,0.22709563374519348f,0.046292245388031006f,0.06025278568267822f,0.051363926380872726f,0.28983888030052185f,0.1971740424633026f,0.04203718900680542f,0.28743305802345276f,0.00652727484703064f,0.04128388687968254f,-0.16709722578525543f,-0.04815554618835449f,0.13445638120174408f,0.2501918375492096f,-0.14010676741600037f,-0.24744901061058044f,-0.2277265042066574f},
Lightvalve 67:c2812cf26c38 226 {0.13951389491558075f,0.08643358945846558f,-0.29237738251686096f,-0.2688630223274231f,0.15896368026733398f,-0.36117541790008545f,-0.141963392496109f,-0.15540927648544312f,0.18755429983139038f,-0.07031691074371338f,-0.3229299783706665f,0.017042644321918488f,-0.012791069224476814f,0.8792362809181213f,-0.28568053245544434f,1.3660327196121216f,-0.015168905258178711f,-0.2859399914741516f,-0.46301740407943726f,-0.21217438578605652f,-0.035294994711875916f,-0.22042036056518555f,-0.3712178170681f,0.1717528998851776f,0.17725077271461487f,-1.6507924795150757f,1.0928548574447632f,-1.2063889503479004f,0.2113950550556183f,-0.07135621458292007f,-0.0010054409503936768f,-0.3029117286205292f},
Lightvalve 67:c2812cf26c38 227 {0.19981321692466736f,0.1956864297389984f,-0.033508092164993286f,-0.22838544845581055f,-0.12505969405174255f,0.026693344116210938f,0.09025825560092926f,0.14285165071487427f,-0.17670965194702148f,0.17403557896614075f,-0.19006575644016266f,0.11083012074232101f,-0.1060299277305603f,-0.0026709232479333878f,-0.21540889143943787f,0.02191716432571411f,0.03990337252616882f,0.0716913640499115f,0.14751584827899933f,-0.07140263170003891f,0.2718442380428314f,0.1245347261428833f,0.07470300793647766f,0.27806827425956726f,0.06195899471640587f,0.04646524414420128f,-0.030715929344296455f,-0.2532255947589874f,0.13817378878593445f,0.17853263020515442f,-0.009185433387756348f,0.021303126588463783f},
Lightvalve 67:c2812cf26c38 228 {-0.2546439468860626f,-0.09556084871292114f,0.12328919768333435f,0.05140380933880806f,-0.258735328912735f,0.09819073975086212f,-0.47578656673431396f,-0.10312946140766144f,0.17735600471496582f,0.009893029928207397f,0.12318730354309082f,-0.06690111756324768f,-0.22998879849910736f,-0.3743883967399597f,0.16854317486286163f,-0.16554808616638184f,0.009990394115447998f,0.10842388868331909f,0.11252931505441666f,0.19874988496303558f,-0.14147105813026428f,-0.1998625248670578f,-0.042370978742837906f,0.0693114697933197f,-0.20608723163604736f,-0.2954014241695404f,-0.30971524119377136f,-0.01753866672515869f,-0.288028746843338f,-0.3510532081127167f,0.17687886953353882f,0.28428298234939575f},
Lightvalve 66:a8e6799dbce3 229 {-0.08816954493522644f,0.2728963792324066f,-0.07170480489730835f,0.1482785940170288f,0.07727676630020142f,0.20119628310203552f,0.03849402070045471f,0.02873826026916504f,-0.15294449031352997f,-0.038666754961013794f,-0.1574239432811737f,0.27019134163856506f,0.1312139928340912f,-0.26498496532440186f,0.1620480716228485f,0.12264445424079895f,0.023397088050842285f,0.21900424361228943f,0.25839516520500183f,0.2068612277507782f,-0.29656288027763367f,0.045920878648757935f,-0.19714993238449097f,0.22523340582847595f,0.07844719290733337f,0.22350957989692688f,-0.04062908887863159f,-0.26378923654556274f,0.18573936820030212f,0.15478622913360596f,0.013760745525360107f,0.010002970695495605f},
Lightvalve 67:c2812cf26c38 230 {0.14700931310653687f,0.1833711564540863f,-0.0858893096446991f,0.09618024528026581f,-0.25116482377052307f,0.2733006179332733f,0.11431895196437836f,-0.16134384274482727f,0.000652611255645752f,-0.22920364141464233f,0.16174325346946716f,-0.09235791116952896f,0.26723334193229675f,0.11812976002693176f,0.0023734138812869787f,-0.32235515117645264f,-0.07963520288467407f,0.14483880996704102f,-0.2671002745628357f,-0.1824713796377182f,-0.0681203231215477f,0.23082366585731506f,-0.2228696048259735f,0.25642916560173035f,-0.09580084681510925f,0.08665821701288223f,0.0067785969004035f,0.13350535929203033f,-0.011228948831558228f,0.26896968483924866f,-0.28556761145591736f,-0.1239108145236969f},
Lightvalve 66:a8e6799dbce3 231 {-0.23982827365398407f,0.03880670666694641f,-0.013682037591934204f,-0.11685100197792053f,-0.020662933588027954f,0.30190005898475647f,-0.14934301376342773f,-0.15993990004062653f,0.1152651309967041f,-0.11991468071937561f,-0.15497799217700958f,0.11116543412208557f,-0.2045515924692154f,0.2403949797153473f,-0.21275603771209717f,0.05732181668281555f,-0.2770107090473175f,0.088544100522995f,0.19012078642845154f,-0.07119561731815338f,-0.18914666771888733f,-0.10413256287574768f,-0.16050675511360168f,0.11598068475723267f,-0.03151249885559082f,-0.1937510371208191f,0.18474078178405762f,0.19502457976341248f,0.22045472264289856f,-0.29474368691444397f,0.09864541888237f,0.06054645776748657f},
Lightvalve 67:c2812cf26c38 232 {-0.1617974042892456f,0.1317739188671112f,0.03260180354118347f,-0.2138894945383072f,-0.05160003900527954f,-0.31576403975486755f,-0.16622759401798248f,0.11372503638267517f,0.05445769429206848f,0.07657262682914734f,-0.2957029938697815f,-0.23527882993221283f,0.08313271403312683f,-0.2537977397441864f,0.1639070212841034f,-0.3779769539833069f,-0.25386664271354675f,-0.18997573852539062f,-0.35596129298210144f,-0.24175596237182617f,-0.14318881928920746f,-0.24810399115085602f,-0.44596153497695923f,0.2513379752635956f,-0.09769667685031891f,-0.20499902963638306f,-0.04501406103372574f,-0.19436898827552795f,-0.0006675124168395996f,-0.2239055633544922f,-0.035532981157302856f,0.26834914088249207f},
Lightvalve 67:c2812cf26c38 233 {0.036086976528167725f,-0.062024205923080444f,0.10704237222671509f,-0.213651642203331f,-0.04875987768173218f,0.1497061848640442f,0.16129396855831146f,0.27597710490226746f,-0.23304778337478638f,-0.035415440797805786f,0.15584498643875122f,-0.08892472088336945f,0.17716765403747559f,-0.18608617782592773f,0.08455783128738403f,-0.2233312726020813f,-0.027234435081481934f,0.19620582461357117f,0.1906617432832718f,-0.24169227480888367f,-0.01818273775279522f,-0.08570264279842377f,-0.19671492278575897f,-0.30205652117729187f,-0.18303924798965454f,-0.365916907787323f,0.17161621153354645f,0.2550062835216522f,-0.2531542181968689f,0.24004116654396057f,-0.21812304854393005f,-0.14883364737033844f},
Lightvalve 67:c2812cf26c38 234 {0.1379433274269104f,-0.16078773140907288f,0.11784148216247559f,0.2671110928058624f,0.2693568766117096f,0.19759181141853333f,0.08533552289009094f,0.17868870496749878f,0.040603965520858765f,-0.2119520902633667f,0.1136421263217926f,-0.24326792359352112f,-0.07898660004138947f,0.2795462906360626f,-0.22247430682182312f,-0.0708579272031784f,0.18204066157341003f,0.2297056019306183f,0.034212857484817505f,0.05284380912780762f,-0.15357805788516998f,-0.2940097451210022f,0.26029130816459656f,0.2647087275981903f,0.1594548225402832f,0.04613301157951355f,-0.22981436550617218f,0.10197556018829346f,-0.08671019971370697f,-0.019541800022125244f,0.30332449078559875f,0.15016543865203857f},
Lightvalve 67:c2812cf26c38 235 {0.09298902750015259f,0.2841971218585968f,-0.0814327746629715f,-0.004546761512756348f,-0.017610490322113037f,0.11057800054550171f,-0.24655841290950775f,0.20642486214637756f,-0.2925014793872833f,0.022429823875427246f,-0.11732623726129532f,-0.04579321667551994f,-0.2097223699092865f,-0.049489278346300125f,0.05468165874481201f,0.21256521344184875f,0.1296386420726776f,0.027322769165039062f,0.20760050415992737f,-0.0020481518004089594f,0.26488128304481506f,0.094583660364151f,0.06231796741485596f,0.14984634518623352f,0.010063239373266697f,0.18980668485164642f,-0.057489991188049316f,-0.07644679397344589f,0.14345040917396545f,-0.11986468732357025f,-0.19420018792152405f,0.16833952069282532f},
Lightvalve 67:c2812cf26c38 236 {-0.14775772392749786f,0.29651907086372375f,0.02990397810935974f,-0.07488551735877991f,0.1826970875263214f,-0.46603310108184814f,-0.285008043050766f,0.26979032158851624f,-0.2325194776058197f,-0.2458522766828537f,-0.41051793098449707f,0.30334722995758057f,-0.34271419048309326f,-0.48440420627593994f,0.07543947547674179f,-2.4028096199035645f,0.2577105462551117f,0.11064860224723816f,-0.27560433745384216f,0.001421709661372006f,-0.05778167024254799f,-0.6405932307243347f,-0.2221977710723877f,0.007911205291748047f,-0.8065847754478455f,-0.15133118629455566f,-0.004577671643346548f,0.20768174529075623f,-0.2205982804298401f,0.13175755739212036f,-0.1669490486383438f,0.0952540934085846f},
Lightvalve 67:c2812cf26c38 237 {0.2703488767147064f,-0.16041381657123566f,0.12738299369812012f,-0.03611093759536743f,0.1169431209564209f,0.1861400008201599f,-0.17030863463878632f,0.28177282214164734f,0.1474648416042328f,-0.23766008019447327f,-0.0035725825000554323f,0.07456761598587036f,0.09594401717185974f,-0.1590109020471573f,-0.16805587708950043f,-0.06561297923326492f,-0.22846683859825134f,0.08700510859489441f,-0.2656046748161316f,0.07154610753059387f,-0.14272311329841614f,0.22832396626472473f,-0.18301571905612946f,-0.17816279828548431f,-0.03099125809967518f,0.27422162890434265f,0.18036122620105743f,-0.27214667201042175f,0.08541131019592285f,0.08213254809379578f,-0.29332536458969116f,0.09465399384498596f},
Lightvalve 66:a8e6799dbce3 238 {-0.06283275783061981f,-0.26753589510917664f,-0.10381917655467987f,-0.13344663381576538f,0.2644997537136078f,0.2204643189907074f,0.2924788296222687f,-0.17931663990020752f,-0.09078609943389893f,-0.17306232452392578f,0.02247890830039978f,-0.26996222138404846f,0.22075030207633972f,-0.3029964864253998f,0.21873190999031067f,-0.0030784308910369873f,0.18228653073310852f,0.09971508383750916f,-0.242676243185997f,-0.1424383968114853f,0.19031599164009094f,0.3004438579082489f,-0.23650792241096497f,-0.2683113217353821f,0.29957786202430725f,0.08561205863952637f,-0.1366746425628662f,-0.15950153768062592f,-0.07675467431545258f,-0.2218506634235382f,-0.2795913517475128f,0.1869203746318817f},
Lightvalve 66:a8e6799dbce3 239 {0.2003176510334015f,-0.27792131900787354f,0.055196613073349f,-0.27959588170051575f,0.18430876731872559f,-0.05316638946533203f,0.16156336665153503f,-0.18850930035114288f,0.09482413530349731f,0.021483391523361206f,0.009039878845214844f,0.1586727499961853f,0.11457142233848572f,0.2876913249492645f,-0.24802550673484802f,0.14089101552963257f,-0.06842575967311859f,-0.10107968747615814f,0.06239110231399536f,-0.2528536915779114f,-0.27538973093032837f,0.15457189083099365f,-0.15549622476100922f,0.20245882868766785f,0.08544808626174927f,0.22650876641273499f,-0.05268847942352295f,0.20387354493141174f,0.24724552035331726f,0.21444126963615417f,0.05186706781387329f,-0.11084021627902985f},
Lightvalve 66:a8e6799dbce3 240 {-0.19810965657234192f,0.2745245397090912f,0.1767616868019104f,0.19752147793769836f,0.0650932788848877f,0.29138168692588806f,-0.29061684012413025f,0.010446667671203613f,0.025284886360168457f,-0.10202452540397644f,-0.10358673334121704f,0.14746251702308655f,0.15136101841926575f,0.04500553011894226f,-0.2497977316379547f,-0.29277902841567993f,0.02556520700454712f,-0.09509801864624023f,0.16731274127960205f,-0.25266408920288086f,-0.3004688322544098f,-0.19769597053527832f,-0.14847496151924133f,0.3053832948207855f,0.07563886046409607f,-0.10258816182613373f,-0.060128673911094666f,0.0016401112079620361f,-0.29647189378738403f,-0.18869297206401825f,0.05497395992279053f,0.16092956066131592f},
Lightvalve 67:c2812cf26c38 241 {-0.011267274618148804f,-0.25281068682670593f,-0.10565309226512909f,-0.09762091934680939f,0.2702934443950653f,-0.11367733776569366f,0.1341124027967453f,-0.19997140765190125f,-0.06814777851104736f,-0.24531681835651398f,-0.1716013252735138f,-0.0033979713916778564f,-0.14755940437316895f,-0.23567239940166473f,0.12773697078227997f,-0.2996436059474945f,0.2015441358089447f,0.04417389631271362f,0.09142428636550903f,0.1179143562912941f,0.054856207221746445f,-0.2911127507686615f,-0.2520882785320282f,0.28407761454582214f,-0.27176207304000854f,-0.3154577314853668f,-0.01299607940018177f,0.2984158992767334f,-0.18211489915847778f,-0.15127526223659515f,0.20075061917304993f,0.29822757840156555f},
Lightvalve 66:a8e6799dbce3 242 {-0.10580866038799286f,-0.17215237021446228f,-0.01352420449256897f,-0.13443149626255035f,-0.10265451669692993f,-0.2169143706560135f,0.30098411440849304f,-0.2986297905445099f,0.07908004522323608f,-0.30061498284339905f,0.10424068570137024f,-0.018799901008605957f,-0.18665757775306702f,0.005998075008392334f,-0.2969498336315155f,0.18525955080986023f,0.2379322350025177f,0.15184926986694336f,0.215760737657547f,-0.19088758528232574f,0.08620095252990723f,0.019999295473098755f,-0.0752219706773758f,0.11181813478469849f,0.1881926953792572f,0.2210972011089325f,0.13236162066459656f,-0.06690356135368347f,-0.18345263600349426f,-0.14861416816711426f,0.08577704429626465f,-0.09683996438980103f},
Lightvalve 66:a8e6799dbce3 243 {0.03951254487037659f,0.23604217171669006f,0.012746036052703857f,-0.12561996281147003f,-0.1283164620399475f,0.25823846459388733f,0.10610169172286987f,0.22718152403831482f,0.1749366819858551f,0.007794857025146484f,0.11289489269256592f,0.2725127637386322f,-0.13616766035556793f,-0.03546282649040222f,-0.1685536652803421f,-0.24492129683494568f,0.15760570764541626f,0.017505377531051636f,-0.273531436920166f,-0.005667984485626221f,0.18370777368545532f,-0.023328542709350586f,0.2379932701587677f,-0.048420339822769165f,0.10376441478729248f,-0.295401930809021f,-0.20498433709144592f,0.22346952557563782f,-0.26649031043052673f,-0.08466874063014984f,0.23347875475883484f,-0.03380200266838074f},
Lightvalve 67:c2812cf26c38 244 {0.3014208972454071f,-0.11652402579784393f,0.24921879172325134f,0.16698147356510162f,-0.2817712128162384f,-0.19414515793323517f,-0.09085875004529953f,-0.11968852579593658f,0.23963233828544617f,0.21321198344230652f,-0.08583731949329376f,-0.016897331923246384f,-0.16443446278572083f,-0.08818752318620682f,-0.12168966978788376f,-0.16220392286777496f,-0.19791248440742493f,0.2487291395664215f,-0.3189976215362549f,-0.2740984261035919f,-0.17073604464530945f,0.1657804548740387f,-0.09928475320339203f,-0.23017358779907227f,-0.14394551515579224f,0.23745566606521606f,-0.0032865963876247406f,-0.0809517502784729f,-0.03476092219352722f,0.2736774981021881f,0.004408210515975952f,-0.05008556693792343f},
Lightvalve 67:c2812cf26c38 245 {-0.17075178027153015f,0.009595632553100586f,0.2466227114200592f,0.03346799314022064f,-0.29828932881355286f,-0.38547036051750183f,-0.19653308391571045f,-0.15331926941871643f,-0.2516406178474426f,0.012286126613616943f,0.10522765666246414f,-0.2340439409017563f,-0.09437626600265503f,-0.16300281882286072f,-0.07974293828010559f,-0.1176222637295723f,-0.24087269604206085f,-0.048499464988708496f,-0.3416144847869873f,0.03414249047636986f,-0.3273044228553772f,-0.35161736607551575f,-0.031352698802948f,0.2817048728466034f,-0.2626217305660248f,-0.3778424561023712f,-0.44531628489494324f,0.21453265845775604f,-0.07090267539024353f,-0.37734028697013855f,-0.2543276250362396f,-0.005844636354595423f},
Lightvalve 66:a8e6799dbce3 246 {-0.01348048448562622f,0.08233943581581116f,0.18838337063789368f,0.21852442622184753f,-0.04740855097770691f,0.19177213311195374f,-0.0060100555419921875f,0.20933791995048523f,0.06356173753738403f,0.063028484582901f,0.09440034627914429f,0.29559019207954407f,-0.2545689642429352f,-0.09652335941791534f,-0.2841038703918457f,-0.03553757071495056f,0.02329021692276001f,-0.08720272779464722f,-0.0750999003648758f,-0.10468094050884247f,-0.03761094808578491f,-0.030853450298309326f,0.2112145721912384f,0.2599640190601349f,-0.2969062626361847f,-0.13667742908000946f,0.24173608422279358f,0.09566575288772583f,0.021116197109222412f,-0.005982398986816406f,-0.26417285203933716f,0.1879688799381256f},
Lightvalve 67:c2812cf26c38 247 {-0.1763739138841629f,-0.17203155159950256f,0.0620841383934021f,-0.04856610670685768f,-0.07396678626537323f,-0.19284456968307495f,0.03173454850912094f,0.17422041296958923f,-0.21029016375541687f,0.2210421860218048f,-0.3324827253818512f,-0.06602592766284943f,-0.108514204621315f,-0.07790359109640121f,-0.22736021876335144f,-0.29743078351020813f,0.10771593451499939f,-0.29308468103408813f,-0.12540867924690247f,-0.16075392067432404f,0.1266261339187622f,-0.329983651638031f,-0.22302524745464325f,0.1760808229446411f,-0.05630595237016678f,-0.22295409440994263f,-0.09866481274366379f,-0.08952933549880981f,0.17976179718971252f,-0.22928372025489807f,0.28763797879219055f,0.11966504156589508f},
Lightvalve 66:a8e6799dbce3 248 {-0.09888127446174622f,-0.22750279307365417f,-0.22503364086151123f,-0.008032619953155518f,-0.012498408555984497f,-0.24329537153244019f,-0.07913157343864441f,0.08175003528594971f,-0.016126900911331177f,0.06972584128379822f,0.06827792525291443f,0.2120952308177948f,-0.031845152378082275f,-0.30540701746940613f,0.18349257111549377f,0.20412376523017883f,-0.09216172993183136f,0.04617339372634888f,-0.09483018517494202f,-0.06833663582801819f,-0.026390254497528076f,-0.28567367792129517f,-0.06047184765338898f,-0.28923499584198f,0.01265987753868103f,-0.2029699683189392f,0.29187360405921936f,-0.2903735339641571f,-0.16326025128364563f,0.11664235591888428f,-0.02675291895866394f,0.1267804503440857f},
Lightvalve 65:a2d7c63419c2 249 };
Lightvalve 65:a2d7c63419c2 250
Lightvalve 66:a8e6799dbce3 251 const float h3[32][32] = {
Lightvalve 67:c2812cf26c38 252 {-0.2551194727420807f,-0.09101890027523041f,-0.026477575302124023f,-0.24469062685966492f,-0.10447631776332855f,-0.04626281186938286f,0.23563924431800842f,0.21467849612236023f,-0.17011712491512299f,0.034586966037750244f,-0.12415538728237152f,0.28293344378471375f,0.045914679765701294f,0.1754785180091858f,-0.2476848065853119f,0.13452908396720886f,0.033751994371414185f,0.2061004936695099f,-0.022569477558135986f,-0.10083381831645966f,-0.11890523135662079f,0.024368882179260254f,-0.22618433833122253f,0.044178664684295654f,0.22860786318778992f,-0.1258748173713684f,0.2930828630924225f,-0.22120264172554016f,0.08456003665924072f,0.2922307550907135f,-0.21407078206539154f,-0.1853330433368683f},
Lightvalve 66:a8e6799dbce3 253 {0.05588451027870178f,0.19731858372688293f,-0.055143773555755615f,0.030042022466659546f,-0.13887283205986023f,-0.1361943781375885f,-0.2855546772480011f,0.011247634887695312f,0.1085631251335144f,0.021339505910873413f,0.17599248886108398f,0.09762296080589294f,-0.05771490931510925f,-0.14660483598709106f,-0.21469902992248535f,0.03876742720603943f,-0.21865856647491455f,-0.12651903927326202f,0.22753819823265076f,-0.23926785588264465f,-0.14443452656269073f,0.06739777326583862f,0.14157342910766602f,0.049514561891555786f,-0.1251431256532669f,-0.25851932168006897f,0.0932874083518982f,0.2900666892528534f,-0.023782014846801758f,0.050485759973526f,0.09447437524795532f,0.0058679282665252686f},
Lightvalve 66:a8e6799dbce3 254 {-0.2800689935684204f,-0.038760632276535034f,0.13974270224571228f,0.01585569977760315f,0.11945047974586487f,-0.19458696246147156f,0.11322265863418579f,0.25643888115882874f,-0.061097174882888794f,-0.07816044986248016f,-0.07445238530635834f,-0.22145158052444458f,-0.1081896424293518f,-0.09452249109745026f,0.16234496235847473f,0.1413259506225586f,-0.2648085951805115f,-0.054869145154953f,-0.05491623282432556f,0.17325228452682495f,0.23639705777168274f,0.0748760998249054f,-0.1324603259563446f,0.15828460454940796f,-0.22871175408363342f,-0.027338534593582153f,-0.06307074427604675f,0.13438841700553894f,0.13834497332572937f,0.1633671224117279f,0.259930282831192f,-0.21565306186676025f},
Lightvalve 67:c2812cf26c38 255 {0.2906629145145416f,0.19203472137451172f,-0.2048129439353943f,0.2633720338344574f,0.0835457369685173f,-0.04125579074025154f,-0.061309605836868286f,-0.17915479838848114f,-0.0403551384806633f,-0.0227642934769392f,-0.09506386518478394f,0.24970653653144836f,0.13110019266605377f,0.08913688361644745f,0.22106656432151794f,-0.23978039622306824f,-0.28915077447891235f,0.030949801206588745f,-0.29493460059165955f,0.1836264431476593f,0.22231431305408478f,-0.017441337928175926f,-0.16484108567237854f,-0.27595841884613037f,0.21659795939922333f,-0.11024686694145203f,-0.09994620084762573f,-0.017832186073064804f,-0.1939506083726883f,-0.25852420926094055f,0.05653107166290283f,0.0037463903427124023f},
Lightvalve 67:c2812cf26c38 256 {0.07563930749893188f,-0.0864691436290741f,-0.2677825689315796f,0.1497999131679535f,-0.2632053792476654f,-0.12118913233280182f,-0.09772239625453949f,0.2470131814479828f,-0.2551872134208679f,-0.2740214169025421f,0.2979947626590729f,-0.24627932906150818f,-0.23258495330810547f,-0.1546318233013153f,0.06802645325660706f,-0.048776447772979736f,0.20131775736808777f,0.013118326663970947f,0.0808630883693695f,0.2585393488407135f,-0.03326711058616638f,0.21529874205589294f,0.1718432903289795f,0.20571765303611755f,-0.19813477993011475f,0.12758469581604004f,0.2959180772304535f,-0.20305807888507843f,0.17249789834022522f,-0.09959287941455841f,-0.07189898192882538f,0.007399916648864746f},
Lightvalve 67:c2812cf26c38 257 {0.10931676626205444f,0.2396949827671051f,0.12925085425376892f,-0.01787710189819336f,-0.10811276733875275f,0.03854062035679817f,-0.061815500259399414f,0.04091137647628784f,0.005855432711541653f,-0.15699732303619385f,0.08972057700157166f,-0.21529507637023926f,-0.003787398338317871f,-0.13041286170482635f,0.2971965968608856f,0.25175121426582336f,-0.2889891266822815f,-0.13035915791988373f,0.16576141119003296f,0.06524023413658142f,0.08899233490228653f,-0.2364676594734192f,0.023232191801071167f,0.27409639954566956f,-0.16286388039588928f,-0.18302330374717712f,0.09057381749153137f,-0.010836521163582802f,-0.27729424834251404f,-0.29547566175460815f,-0.25800079107284546f,0.24402263760566711f},
Lightvalve 67:c2812cf26c38 258 {-0.21155381202697754f,0.2683173716068268f,-0.1991964429616928f,-0.08913922309875488f,0.3132401406764984f,0.05693900212645531f,-0.07957221567630768f,0.2444917857646942f,0.21739666163921356f,-0.3040415346622467f,0.18606118857860565f,-0.25618287920951843f,0.022712847217917442f,-0.2396537810564041f,0.25543639063835144f,-0.1192857176065445f,-0.18917083740234375f,0.011466026306152344f,0.10695753246545792f,0.10936067253351212f,0.2850911021232605f,-0.21246646344661713f,-0.23246735334396362f,-0.2255190908908844f,-0.36790895462036133f,-0.2910519242286682f,-0.29311150312423706f,-0.18528589606285095f,0.2900647521018982f,-0.09532724320888519f,0.13197943568229675f,-0.16733309626579285f},
Lightvalve 67:c2812cf26c38 259 {-0.01093912124633789f,-0.23583689332008362f,0.28153905272483826f,0.2877257764339447f,0.08201509714126587f,-0.2699383497238159f,0.036741942167282104f,-0.0059101879596710205f,-0.24633634090423584f,-0.27182313799858093f,0.09319102764129639f,-0.08139897882938385f,0.19774547219276428f,-0.020215511322021484f,0.0685860812664032f,-0.29903873801231384f,0.1317853033542633f,0.20550194382667542f,-0.12251400947570801f,-0.28424710035324097f,0.24172750115394592f,0.11755815148353577f,0.0343703031539917f,0.12564969062805176f,0.03227102756500244f,0.23886635899543762f,-0.2778390347957611f,0.13853725790977478f,0.28547611832618713f,0.17161712050437927f,-0.017215043306350708f,-0.05991865694522858f},
Lightvalve 66:a8e6799dbce3 260 {-0.20420776307582855f,0.1970202624797821f,0.23591408133506775f,-0.282694011926651f,0.09019026160240173f,0.20012763142585754f,0.028453975915908813f,0.23323127627372742f,0.15246456861495972f,-0.1270071268081665f,0.20025727152824402f,0.13077861070632935f,-0.2238168716430664f,-0.20709244906902313f,-0.0045506954193115234f,-0.16448761522769928f,0.28163614869117737f,0.1971360743045807f,0.30405697226524353f,-0.28959211707115173f,-0.2255709171295166f,0.15360668301582336f,0.24163606762886047f,0.19554737210273743f,-0.1804599016904831f,0.07604315876960754f,-0.1459394246339798f,-0.14081311225891113f,-0.29656586050987244f,0.19529584050178528f,-0.05168652534484863f,-0.03415781259536743f},
Lightvalve 66:a8e6799dbce3 261 {0.27550336718559265f,-0.14170598983764648f,-0.21542268991470337f,-0.2159879207611084f,0.06500789523124695f,-0.21155211329460144f,-0.01575431227684021f,0.0617731511592865f,0.13126209378242493f,-0.04922589659690857f,-0.23877641558647156f,-0.06292802095413208f,0.01433342695236206f,0.14592674374580383f,-0.23886999487876892f,0.08878573775291443f,0.1853090226650238f,-0.05102238059043884f,-0.13667166233062744f,-0.24401302635669708f,0.25155118107795715f,-0.20339438319206238f,0.03535670042037964f,0.048473477363586426f,-0.13871997594833374f,-0.15382859110832214f,-0.13837768137454987f,0.26085415482521057f,0.2491457164287567f,0.157204270362854f,0.14108964800834656f,0.12518465518951416f},
Lightvalve 67:c2812cf26c38 262 {-0.023678362369537354f,0.2771764099597931f,-0.18073804676532745f,0.024388136342167854f,0.11399489641189575f,0.14202310144901276f,0.0393199622631073f,0.196751207113266f,-0.11065163463354111f,0.18980243802070618f,0.12294309586286545f,-0.06168833374977112f,-0.16705156862735748f,-0.047078777104616165f,0.080221027135849f,-0.2471318244934082f,0.026521950960159302f,0.28880444169044495f,0.1908019483089447f,-0.18669141829013824f,-0.08038117736577988f,0.12832704186439514f,0.08564630150794983f,0.2614522874355316f,0.24017862975597382f,-0.25962090492248535f,-0.04607417806982994f,0.08219635486602783f,0.18719901144504547f,-0.2912617325782776f,-0.3248916268348694f,-0.3832399249076843f},
Lightvalve 67:c2812cf26c38 263 {0.2680447995662689f,-0.03854561224579811f,-0.3660450577735901f,-0.1488519161939621f,-0.17513911426067352f,-0.691161572933197f,0.018974244594573975f,-0.33520975708961487f,0.18661729991436005f,-0.42184093594551086f,2.517235517501831f,0.12751655280590057f,0.2537161409854889f,2.522364377975464f,0.23152390122413635f,-0.07731422781944275f,0.21101722121238708f,-0.15284278988838196f,0.19197319447994232f,-0.07092756032943726f,-1.365535855293274f,-0.6164852976799011f,-0.2813482880592346f,0.12308406829833984f,-1.2782386541366577f,0.0252631064504385f,-0.30039823055267334f,0.0019148463616147637f,-0.13056938350200653f,-0.1739533692598343f,-0.3481394648551941f,-0.8318305015563965f},
Lightvalve 67:c2812cf26c38 264 {0.10771462321281433f,0.1270637810230255f,-0.1647956818342209f,-0.00161704421043396f,0.164594829082489f,0.3211824297904968f,-0.2502448558807373f,-0.05063694715499878f,-0.4380391538143158f,-0.11501708626747131f,0.24353471398353577f,0.11519002914428711f,-0.1879904866218567f,0.21820327639579773f,-0.0055807530879974365f,0.05870962142944336f,-0.0561012327671051f,-0.1419317126274109f,-0.24982497096061707f,-0.05947013199329376f,-0.3615858256816864f,-0.11345167458057404f,0.2986377775669098f,-0.2888573110103607f,-0.006877906620502472f,-0.03866580128669739f,0.09892630577087402f,0.03904371336102486f,0.1267586350440979f,0.024399906396865845f,-0.264041006565094f,-0.037910252809524536f},
Lightvalve 67:c2812cf26c38 265 {0.07240793108940125f,-0.0312206894159317f,-0.10276530683040619f,-0.04875331372022629f,-0.6880882978439331f,0.7194241881370544f,0.1558125615119934f,-0.13074719905853271f,-18.506288528442383f,-0.5441223382949829f,-0.933298647403717f,-0.08782672882080078f,-0.33647942543029785f,-0.411403626203537f,0.13272255659103394f,-0.0684008002281189f,-0.13351139426231384f,0.08981440961360931f,-0.14014141261577606f,-0.207076758146286f,-0.2637980580329895f,-0.494296133518219f,-0.11964787542819977f,-0.07838685065507889f,-0.09116172790527344f,-0.1976800560951233f,-0.31309351325035095f,-0.3691823482513428f,-0.20949368178844452f,-0.29330405592918396f,-0.12672506272792816f,-0.7348046898841858f},
Lightvalve 67:c2812cf26c38 266 {-0.27890223264694214f,0.08861199021339417f,0.18213510513305664f,0.20657816529273987f,-0.1439138948917389f,-0.04376927390694618f,-0.2505151033401489f,-0.2674597501754761f,-0.44301697611808777f,0.11925610154867172f,0.06391887366771698f,0.04456409811973572f,0.07699105143547058f,0.1712622046470642f,-0.02410009503364563f,0.10129088163375854f,0.22686699032783508f,-0.30486053228378296f,0.8882251977920532f,-0.08399965614080429f,-0.07070387154817581f,-0.018823737278580666f,-0.09317314624786377f,0.11354613304138184f,0.059403806924819946f,-0.025903940200805664f,-0.15464875102043152f,0.010013561695814133f,-0.09546275436878204f,0.06508117914199829f,0.02118399739265442f,-0.12279052287340164f},
Lightvalve 67:c2812cf26c38 267 {0.3047083914279938f,0.12143945693969727f,-0.3327127993106842f,-0.6801210641860962f,0.15692952275276184f,0.13042594492435455f,0.007496643345803022f,-0.25786101818084717f,0.09291999787092209f,0.020215269178152084f,-2.258894205093384f,-0.08983127027750015f,0.03013843297958374f,1.8863211870193481f,0.062144935131073f,-0.28920799493789673f,0.03473195433616638f,-0.15892919898033142f,-0.03284023702144623f,-0.7306706309318542f,0.935397744178772f,0.18801145255565643f,0.19243986904621124f,-0.10173973441123962f,-0.5918514132499695f,-0.031148135662078857f,-0.2262621372938156f,-1.0362893342971802f,-0.16790373623371124f,0.017086774110794067f,-0.27719104290008545f,-0.48113712668418884f},
Lightvalve 66:a8e6799dbce3 268 {-0.06136500835418701f,-0.11579577624797821f,-0.23311558365821838f,-0.020844489336013794f,0.161813884973526f,0.22929790616035461f,0.11958792805671692f,-0.0384809672832489f,-0.10647237300872803f,-0.09010881185531616f,0.22322741150856018f,-0.1071339100599289f,0.05349445343017578f,-0.23458370566368103f,0.040097206830978394f,0.08616101741790771f,-0.15468145906925201f,-0.21275553107261658f,-0.21210846304893494f,-0.23840199410915375f,0.12352427840232849f,0.282552570104599f,0.14114680886268616f,0.09007054567337036f,-0.05948364734649658f,0.12031787633895874f,-0.184563547372818f,0.07786750793457031f,-0.2169322669506073f,-0.24735762178897858f,-0.0892629474401474f,-0.11765947937965393f},
Lightvalve 67:c2812cf26c38 269 {0.1169951856136322f,0.06741076707839966f,0.014288008213043213f,-0.1894388198852539f,0.2306886613368988f,0.08970087766647339f,0.29362860321998596f,0.2666439712047577f,-0.1488228738307953f,0.22382596135139465f,-0.1313140094280243f,0.02602824568748474f,0.029441386461257935f,-0.1546926349401474f,0.10762849450111389f,0.06951633095741272f,0.0639207661151886f,0.27696695923805237f,-0.2749756872653961f,0.2684275209903717f,-0.240950807929039f,-0.08405844867229462f,0.26762983202934265f,0.09600964188575745f,-0.20394444465637207f,0.012219250202178955f,-0.09225042164325714f,-0.12637756764888763f,-0.21354423463344574f,-0.29393887519836426f,-0.056166648864746094f,0.002250969409942627f},
Lightvalve 67:c2812cf26c38 270 {-0.16101892292499542f,0.06696435809135437f,0.26537272334098816f,0.13802723586559296f,-0.07356492429971695f,-0.22056643664836884f,0.1589156985282898f,-0.17396175861358643f,0.23447562754154205f,-0.11376987397670746f,0.8681742548942566f,-0.04377517104148865f,-0.10034412145614624f,-0.013810606673359871f,-0.2592318058013916f,0.1978430449962616f,0.18047624826431274f,0.2863751947879791f,-0.1513826847076416f,-0.021152565255761147f,-0.10252142697572708f,0.13373371958732605f,0.29893049597740173f,0.13123968243598938f,-0.06929916888475418f,-0.28873488306999207f,-0.08428265154361725f,0.2385406792163849f,0.18354523181915283f,0.18439257144927979f,0.17250561714172363f,0.11700647324323654f},
Lightvalve 67:c2812cf26c38 271 {0.261911004781723f,-0.28497835993766785f,-0.2993849217891693f,-0.02538192830979824f,0.06466203182935715f,0.06408461928367615f,-0.06670857965946198f,-0.030254334211349487f,-0.28592967987060547f,0.1197996437549591f,0.01667046546936035f,-0.2924177646636963f,0.18459643423557281f,-0.11980186402797699f,-0.20773646235466003f,-0.10781967639923096f,-0.15712574124336243f,0.16112294793128967f,0.22504061460494995f,0.19123370945453644f,0.1921442449092865f,0.1372140496969223f,-0.3001303970813751f,0.14906415343284607f,0.16232232749462128f,0.0025720298290252686f,-0.05664414167404175f,-0.22436802089214325f,0.0802077054977417f,0.21125611662864685f,-0.05751854181289673f,-0.22727590799331665f},
Lightvalve 67:c2812cf26c38 272 {0.14277681708335876f,-0.19113287329673767f,0.14885470271110535f,-0.23454684019088745f,-0.08871281147003174f,-0.015389661304652691f,0.1624150574207306f,-0.27022814750671387f,0.07831501960754395f,-0.29604676365852356f,-0.2852642238140106f,0.18551066517829895f,0.26866111159324646f,0.07514987140893936f,-0.03100520372390747f,-0.2484396994113922f,0.06366744637489319f,-0.2764144539833069f,0.21208719909191132f,0.22303004562854767f,-0.29591599106788635f,0.23730474710464478f,0.2572875916957855f,-0.0716068297624588f,-0.1530940979719162f,-0.19159743189811707f,0.1941693127155304f,-0.13109204173088074f,-0.23412373661994934f,-0.10488687455654144f,-0.21563708782196045f,0.17678798735141754f},
Lightvalve 67:c2812cf26c38 273 {0.29069945216178894f,-0.23835359513759613f,0.019009560346603394f,-0.28021278977394104f,0.14941081404685974f,-0.15978194773197174f,0.045349299907684326f,-0.17138783633708954f,-0.41256099939346313f,0.028545528650283813f,-0.11207889765501022f,-0.15074089169502258f,-0.0936775803565979f,-0.172922745347023f,0.09875330328941345f,0.08164769411087036f,0.2294725477695465f,0.10683679580688477f,-0.23611131310462952f,-0.08497139811515808f,0.22895678877830505f,0.2478323131799698f,0.16651621460914612f,-0.3457367718219757f,0.299380362033844f,0.023651927709579468f,-0.1729920208454132f,0.20944736897945404f,0.09858408570289612f,0.19045329093933105f,0.02994692325592041f,-0.18855193257331848f},
Lightvalve 67:c2812cf26c38 274 {0.1991647183895111f,0.12534403800964355f,-0.04112154245376587f,0.23123982548713684f,-0.17588619887828827f,-0.2963615953922272f,-0.1610087752342224f,-0.031804412603378296f,0.10051681846380234f,-0.25018924474716187f,0.15975651144981384f,-0.057292819023132324f,0.1464652419090271f,0.0827544778585434f,0.2151305377483368f,0.2952744662761688f,-0.21319252252578735f,0.04970458149909973f,0.10210192203521729f,0.3050673305988312f,0.2109866440296173f,-0.1488206833600998f,0.13887640833854675f,0.25299301743507385f,-0.1060284674167633f,-0.07015113532543182f,-0.287551611661911f,-0.03226654231548309f,-0.07337476313114166f,-0.24420931935310364f,0.015819430351257324f,-0.10595546662807465f},
Lightvalve 67:c2812cf26c38 275 {0.12202468514442444f,0.10608518123626709f,-0.10034829378128052f,-0.2956502139568329f,0.16320201754570007f,0.0862378180027008f,-0.06113804876804352f,-0.11568751931190491f,0.2868335545063019f,-0.3037929832935333f,-0.06917986273765564f,-0.11160935461521149f,-0.13285431265830994f,-0.17888973653316498f,-0.06735922396183014f,0.05864924192428589f,-0.25733181834220886f,-0.17565661668777466f,0.05582946538925171f,-0.1147834062576294f,-0.2570425271987915f,0.18900752067565918f,0.173453688621521f,-0.05681343376636505f,0.24433693289756775f,0.1795230209827423f,0.19069638848304749f,0.010025888681411743f,-0.1604132354259491f,0.2425754964351654f,-0.22172409296035767f,-0.009572982788085938f},
Lightvalve 67:c2812cf26c38 276 {-0.3055141270160675f,-0.22692157328128815f,-0.20365740358829498f,-0.3820209205150604f,-0.37759122252464294f,-0.1571020931005478f,0.044530466198921204f,0.1983473151922226f,2.231644630432129f,-0.1290184110403061f,-1.2446476221084595f,-0.13216577470302582f,0.0050718579441308975f,-16.06584358215332f,-0.023131370544433594f,0.036719828844070435f,0.16260939836502075f,-0.10293128341436386f,-0.32223081588745117f,-0.3185373842716217f,0.6189641952514648f,-0.6450173258781433f,0.05254721641540527f,0.3393881618976593f,-0.9625877737998962f,-0.02825927734375f,-0.26312947273254395f,0.3635375201702118f,-0.09834510833024979f,0.1865309774875641f,0.07833396643400192f,-0.6565374135971069f},
Lightvalve 67:c2812cf26c38 277 {0.1782623827457428f,-0.013843556866049767f,-0.37928324937820435f,-0.16980238258838654f,-0.09471401572227478f,-0.3263455629348755f,-0.22474172711372375f,-0.06365322321653366f,0.12617868185043335f,-0.2255554348230362f,-2.657351016998291f,-0.3574104607105255f,-0.031867168843746185f,-8.026864051818848f,-0.2527656555175781f,-0.3049176335334778f,0.032145023345947266f,-0.25376296043395996f,-0.07019277662038803f,-0.28491973876953125f,-1.303757667541504f,-0.9391974210739136f,0.1247415542602539f,-0.1490761637687683f,-0.8861213326454163f,-0.05805254727602005f,0.0312337726354599f,0.6083393096923828f,-0.5665671825408936f,0.1616479754447937f,-0.30380979180336f,-0.44227972626686096f},
Lightvalve 67:c2812cf26c38 278 {-0.17396044731140137f,-0.10267387330532074f,-0.26454415917396545f,-0.16845640540122986f,0.08382441848516464f,0.15326650440692902f,-0.65500807762146f,-0.4207763969898224f,-1.2663618326187134f,-0.32407379150390625f,0.45029065012931824f,-0.24252228438854218f,0.10268369317054749f,-0.35246387124061584f,-0.19851773977279663f,-0.10762731730937958f,0.14198419451713562f,-0.05348384380340576f,-0.06869904696941376f,-0.2651658058166504f,-1.947196125984192f,-0.6143497228622437f,0.10647851228713989f,-0.6422523260116577f,-1.36721932888031f,-0.2665709853172302f,0.13455313444137573f,0.892333984375f,-0.0020804572850465775f,-0.1200934648513794f,-0.19396400451660156f,-0.3172096610069275f},
Lightvalve 67:c2812cf26c38 279 {-0.12546227872371674f,-0.21582737565040588f,-0.20127394795417786f,0.027476642280817032f,-0.11040297150611877f,0.44096648693084717f,-0.28310835361480713f,-0.21471625566482544f,0.9995805025100708f,-0.5645689964294434f,-0.7588157057762146f,-0.08105679601430893f,-0.07958275079727173f,-2.0097312927246094f,-0.0649729073047638f,0.2468220293521881f,0.060016900300979614f,-0.16779978573322296f,0.01961516961455345f,-0.21380092203617096f,1.0298441648483276f,-0.3370063900947571f,-0.26878347992897034f,0.15960951149463654f,-2.458930015563965f,-0.13535909354686737f,-0.2872529625892639f,0.5198270678520203f,-0.03059946745634079f,-0.000007510185241699219f,-0.023944508284330368f,-0.31227779388427734f},
Lightvalve 66:a8e6799dbce3 280 {0.07555973529815674f,-0.0029259920120239258f,-0.08789914846420288f,0.06678077578544617f,-0.11083845794200897f,0.11010000109672546f,-0.14982634782791138f,0.12075316905975342f,-0.2766430675983429f,0.013024389743804932f,0.18159812688827515f,-0.20200279355049133f,0.2637675702571869f,-0.1856893002986908f,0.2882818281650543f,0.05304515361785889f,-0.15297894179821014f,0.07341468334197998f,0.05268138647079468f,0.1067940890789032f,-0.2661813795566559f,-0.2009473443031311f,0.1843600869178772f,0.2517976462841034f,-0.07343396544456482f,-0.051110416650772095f,-0.23432010412216187f,0.16746872663497925f,-0.2205146849155426f,-0.017525076866149902f,0.20926335453987122f,-0.2141496241092682f},
Lightvalve 67:c2812cf26c38 281 {0.06582912802696228f,0.2796666920185089f,-0.2556927502155304f,0.0023079216480255127f,0.2043982446193695f,0.10505693405866623f,0.06556430459022522f,0.29767414927482605f,0.26687973737716675f,-0.16670267283916473f,-0.14499664306640625f,-0.06570860743522644f,-0.015925198793411255f,0.15823403000831604f,-0.014884740114212036f,-0.05300724506378174f,0.26490333676338196f,0.15243005752563477f,-0.07319167256355286f,0.2353842556476593f,0.24263548851013184f,0.14348316192626953f,-0.04174882173538208f,-0.11559568345546722f,-0.09051717817783356f,0.21069613099098206f,-0.19532959163188934f,-0.21369075775146484f,0.020931687206029892f,-0.2712400257587433f,-0.19435247778892517f,-0.23200613260269165f},
Lightvalve 67:c2812cf26c38 282 {-0.1299392580986023f,-0.06208275258541107f,-0.18067686259746552f,0.062329649925231934f,-0.22588664293289185f,-0.06877543032169342f,-0.19175797700881958f,0.02903696894645691f,-0.2614779472351074f,0.016345679759979248f,-0.24767392873764038f,0.2033931314945221f,-0.30105409026145935f,0.08271035552024841f,0.13206014037132263f,0.15829482674598694f,-0.21012049913406372f,0.2088232934474945f,0.07014858722686768f,-0.19175665080547333f,0.28649166226387024f,0.05041047930717468f,-0.27260470390319824f,-0.025072306394577026f,0.2722422182559967f,-0.007939159870147705f,-0.22979341447353363f,0.11936154961585999f,0.1298319399356842f,0.18135693669319153f,-0.008151531219482422f,0.15906798839569092f},
Lightvalve 67:c2812cf26c38 283 {0.07638216018676758f,0.07996532320976257f,-0.30373215675354004f,-0.2870197892189026f,0.13120616972446442f,0.014201237820088863f,0.2795381247997284f,-0.25668495893478394f,-0.08007447421550751f,0.17683254182338715f,-0.026776641607284546f,0.02524423599243164f,0.11132927238941193f,0.25622642040252686f,-0.029521822929382324f,-0.19500072300434113f,0.06506577134132385f,-0.011876672506332397f,0.12332364171743393f,0.26962023973464966f,0.13634969294071198f,-0.001175098237581551f,-0.15799765288829803f,-0.17324526607990265f,0.21663552522659302f,0.1901901364326477f,-0.2591228187084198f,-0.061639491468667984f,-0.10711086541414261f,0.22636333107948303f,-0.2677184045314789f,0.19854798913002014f},
Lightvalve 66:a8e6799dbce3 284 };
Lightvalve 65:a2d7c63419c2 285
Lightvalve 67:c2812cf26c38 286 const float hout[32] = { 0.3285340666770935f,0.32875439524650574f,0.010172058828175068f,-0.11305646598339081f,-0.021411199122667313f,0.2888892889022827f,-0.10024870932102203f,0.09909168630838394f,-0.07379823178052902f,-0.01775532402098179f,0.022316712886095047f,-0.06981132924556732f,-0.17286384105682373f,0.14635762572288513f,0.2356991171836853f,-0.1462659239768982f,0.09851181507110596f,-0.14480170607566833f,-0.07469630241394043f,-0.19646649062633514f,-0.03418174758553505f,-0.008110888302326202f,-0.14705289900302887f,-0.03402183949947357f,0.07437916845083237f,0.124146468937397f,-0.3058450520038605f,-0.21908646821975708f,-0.05386931076645851f,-0.3257754445075989f,-0.23496197164058685f,-0.007552365306764841f };
Lightvalve 66:a8e6799dbce3 287
Lightvalve 67:c2812cf26c38 288 const float b1[32] = { 0.33975231647491455f,2.7712650299072266f,-1.7145336866378784f,-0.1526036560535431f,1.1354074478149414f,0.623417854309082f,-0.2046075314283371f,1.8505465984344482f,0.5339886546134949f,-2.64107346534729f,0.5785035490989685f,1.5429713726043701f,-0.3425353467464447f,-0.8584070205688477f,-1.087764859199524f,0.945876955986023f,0.6164156794548035f,-0.26377663016319275f,0.21929186582565308f,0.9238426089286804f,-0.31435057520866394f,-1.1118980646133423f,-1.6770726442337036f,-1.2263047695159912f,1.9988690614700317f,-2.0880801677703857f,-1.0489267110824585f,0.6953904032707214f,0.39424675703048706f,-1.0887231826782227f,1.480643391609192f,-0.4426153898239136f };
Lightvalve 65:a2d7c63419c2 289
Lightvalve 67:c2812cf26c38 290 const float b2[32] = {-0.2411857545375824f,-0.7642630338668823f,-1.4564176797866821f,-0.5187940001487732f,-0.6939148902893066f,-0.043579138815402985f,-0.04268971085548401f,-0.30969977378845215f,-1.20063054561615f,-1.912178635597229f,-0.08107675611972809f,-0.16169233620166779f,-0.21833471953868866f,1.7211838960647583f,-0.05936155840754509f,0.6158673167228699f,-1.798204779624939f,-1.5844906568527222f,-0.02391055040061474f,-0.3057551085948944f,-0.19083930552005768f,-0.07528141140937805f,-0.062231115996837616f,-1.0450503826141357f,-1.8296034336090088f,0.02526227943599224f,-0.31291842460632324f,-1.3643138408660889f,-0.6323830485343933f,-0.5739799737930298f,-1.178520679473877f,-1.3432109355926514f };
Lightvalve 65:a2d7c63419c2 291
Lightvalve 67:c2812cf26c38 292 const float b3[32] = { -1.963319182395935f,-0.49465635418891907f,-0.03699754178524017f,-0.2572087049484253f,-0.3335331678390503f,0.04053334891796112f,-0.5232781171798706f,-0.8866004347801208f,-1.5523405075073242f,0.026659280061721802f,-1.5444074869155884f,-0.07711746543645859f,-0.6993189454078674f,-1.9827897548675537f,-1.1428403854370117f,-0.3598397970199585f,-1.3594286441802979f,-1.1742689609527588f,-0.4667721092700958f,-0.1322062909603119f,-0.7905310988426208f,0.1004210114479065f,-1.1005918979644775f,-0.9819951057434082f,0.026299534365534782f,-0.5231139063835144f,-0.23480124771595f,0.03585260361433029f,0.10936892032623291f,-2.3236680030822754f,-0.11923135071992874f,0.3063691556453705f };
Lightvalve 66:a8e6799dbce3 293
Lightvalve 67:c2812cf26c38 294 const float bout[1] = { -0.09089279919862747f};
Lightvalve 61:bc8c8270f0ab 295
Lightvalve 61:bc8c8270f0ab 296
GiJeongKim 0:51c43836c1d7 297 int main()
GiJeongKim 0:51c43836c1d7 298 {
Lightvalve 66:a8e6799dbce3 299
Lightvalve 65:a2d7c63419c2 300 HAL_Init();
Lightvalve 65:a2d7c63419c2 301 SystemClock_Config();
Lightvalve 65:a2d7c63419c2 302
jobuuu 6:df07d3491e3a 303 /*********************************
jobuuu 1:e04e563be5ce 304 *** Initialization
jobuuu 6:df07d3491e3a 305 *********************************/
Lightvalve 57:f4819de54e7a 306 LED = 1;
Lightvalve 61:bc8c8270f0ab 307 pc.baud(9600);
Lightvalve 21:e5f1a43ea6f9 308
GiJeongKim 0:51c43836c1d7 309 // i2c init
Lightvalve 8:5d2eebdad025 310 i2c.frequency(400 * 1000); // 0.4 mHz
Lightvalve 8:5d2eebdad025 311 wait_ms(2); // Power Up wait
Lightvalve 8:5d2eebdad025 312 look_for_hardware_i2c(); // Hardware present
Lightvalve 8:5d2eebdad025 313 init_as5510(i2c_slave_addr1);
Lightvalve 11:82d8768d7351 314 make_delay();
jobuuu 2:a1c0a37df760 315
GiJeongKim 0:51c43836c1d7 316 // // spi init
Lightvalve 16:903b5a4433b4 317 //eeprom.format(8,3);
Lightvalve 16:903b5a4433b4 318 //eeprom.frequency(5000000); //5M
GiJeongKim 0:51c43836c1d7 319 enc.format(8,0);
GiJeongKim 0:51c43836c1d7 320 enc.frequency(5000000); //5M
Lightvalve 11:82d8768d7351 321 make_delay();
Lightvalve 21:e5f1a43ea6f9 322
Lightvalve 16:903b5a4433b4 323 //rom
Lightvalve 19:23b7c1ad8683 324 ROM_CALL_DATA();
Lightvalve 16:903b5a4433b4 325 make_delay();
Lightvalve 13:747daba9cf59 326
GiJeongKim 0:51c43836c1d7 327 // ADC init
jobuuu 5:a4319f79457b 328 Init_ADC();
Lightvalve 11:82d8768d7351 329 make_delay();
jobuuu 2:a1c0a37df760 330
GiJeongKim 0:51c43836c1d7 331 // Pwm init
GiJeongKim 0:51c43836c1d7 332 Init_PWM();
GiJeongKim 0:51c43836c1d7 333 TIM4->CR1 ^= TIM_CR1_UDIS;
Lightvalve 11:82d8768d7351 334 make_delay();
Lightvalve 13:747daba9cf59 335
Lightvalve 11:82d8768d7351 336 // TMR3 init
Lightvalve 11:82d8768d7351 337 Init_TMR3();
Lightvalve 11:82d8768d7351 338 TIM3->CR1 ^= TIM_CR1_UDIS;
Lightvalve 11:82d8768d7351 339 make_delay();
Lightvalve 21:e5f1a43ea6f9 340
Lightvalve 50:3c630b5eba9f 341 // TMR2 init
Lightvalve 56:6f50d9d3bfee 342 // Init_TMR2();
Lightvalve 56:6f50d9d3bfee 343 // TIM2->CR1 ^= TIM_CR1_UDIS;
Lightvalve 56:6f50d9d3bfee 344 // make_delay();
Lightvalve 21:e5f1a43ea6f9 345
GiJeongKim 0:51c43836c1d7 346 // CAN
jobuuu 2:a1c0a37df760 347 can.attach(&CAN_RX_HANDLER);
Lightvalve 11:82d8768d7351 348 CAN_ID_INIT();
Lightvalve 11:82d8768d7351 349 make_delay();
Lightvalve 34:bb2ca2fc2a8e 350
Lightvalve 23:59218d4a256d 351 //Timer priority
Lightvalve 23:59218d4a256d 352 NVIC_SetPriority(TIM3_IRQn, 2);
Lightvalve 57:f4819de54e7a 353 //NVIC_SetPriority(TIM2_IRQn, 3);
Lightvalve 54:647072f5307a 354 NVIC_SetPriority(TIM4_IRQn, 3);
Lightvalve 34:bb2ca2fc2a8e 355
Lightvalve 23:59218d4a256d 356 //can.reset();
Lightvalve 19:23b7c1ad8683 357 can.filter(msg.id, 0xFFFFF000, CANStandard);
Lightvalve 34:bb2ca2fc2a8e 358
GiJeongKim 0:51c43836c1d7 359 // spi _ enc
GiJeongKim 0:51c43836c1d7 360 spi_enc_set_init();
Lightvalve 11:82d8768d7351 361 make_delay();
Lightvalve 13:747daba9cf59 362
Lightvalve 11:82d8768d7351 363 //DAC init
Lightvalve 58:2eade98630e2 364 if (SENSING_MODE == 0) {
Lightvalve 58:2eade98630e2 365 dac_1 = TORQUE_VREF / 3.3f;
Lightvalve 58:2eade98630e2 366 dac_2 = 0.0f;
Lightvalve 58:2eade98630e2 367 } else if (SENSING_MODE == 1) {
Lightvalve 58:2eade98630e2 368 dac_1 = PRES_A_VREF / 3.3f;
Lightvalve 58:2eade98630e2 369 dac_2 = PRES_B_VREF / 3.3f;
Lightvalve 58:2eade98630e2 370 }
Lightvalve 11:82d8768d7351 371 make_delay();
Lightvalve 13:747daba9cf59 372
Lightvalve 19:23b7c1ad8683 373 for (int i=0; i<50; i++) {
Lightvalve 11:82d8768d7351 374 if(i%2==0)
Lightvalve 38:118df027d851 375 ID_index_array[i] = - i * 0.5f;
Lightvalve 11:82d8768d7351 376 else
Lightvalve 38:118df027d851 377 ID_index_array[i] = (i+1) * 0.5f;
Lightvalve 11:82d8768d7351 378 }
Lightvalve 61:bc8c8270f0ab 379
Lightvalve 61:bc8c8270f0ab 380
jobuuu 6:df07d3491e3a 381 /************************************
jobuuu 1:e04e563be5ce 382 *** Program is operating!
jobuuu 6:df07d3491e3a 383 *************************************/
GiJeongKim 0:51c43836c1d7 384 while(1) {
Lightvalve 66:a8e6799dbce3 385 // if(timer_while==1000 && OPERATING_MODE==5) {
Lightvalve 66:a8e6799dbce3 386 //if(timer_while==1000) {
Lightvalve 65:a2d7c63419c2 387 //i2c
Lightvalve 66:a8e6799dbce3 388
Lightvalve 65:a2d7c63419c2 389 read_field(i2c_slave_addr1);
Lightvalve 65:a2d7c63419c2 390 if(DIR_VALVE_ENC < 0) value = 1023 - value;
Lightvalve 65:a2d7c63419c2 391 // if(LED==1) {
Lightvalve 65:a2d7c63419c2 392 // LED=0;
Lightvalve 65:a2d7c63419c2 393 // } else
Lightvalve 65:a2d7c63419c2 394 // LED = 1;
Lightvalve 65:a2d7c63419c2 395 timer_while = 0;
Lightvalve 66:a8e6799dbce3 396 //}
Lightvalve 66:a8e6799dbce3 397
Lightvalve 66:a8e6799dbce3 398 timer_while ++;
Lightvalve 66:a8e6799dbce3 399
Lightvalve 66:a8e6799dbce3 400
Lightvalve 66:a8e6799dbce3 401 if(NN_Control_Flag == 1) {
Lightvalve 66:a8e6799dbce3 402 float output1[32] = { 0.0f };
Lightvalve 66:a8e6799dbce3 403 float output2[32] = { 0.0f };
Lightvalve 66:a8e6799dbce3 404 float output3[32] = { 0.0f };
Lightvalve 66:a8e6799dbce3 405 float output = 0.0f;
Lightvalve 65:a2d7c63419c2 406
Lightvalve 66:a8e6799dbce3 407
Lightvalve 65:a2d7c63419c2 408
Lightvalve 66:a8e6799dbce3 409 for (int index2 = 0; index2 < 32; index2++) {
Lightvalve 66:a8e6799dbce3 410 for (int index1 = 0; index1 < 22; index1++) {
Lightvalve 66:a8e6799dbce3 411 output1[index2] = output1[index2]
Lightvalve 66:a8e6799dbce3 412 + h1[index1][index2] * input[index1];
Lightvalve 66:a8e6799dbce3 413 }
Lightvalve 66:a8e6799dbce3 414 output1[index2] = output1[index2] + b1[index2];
Lightvalve 66:a8e6799dbce3 415 if (output1[index2] < 0) {
Lightvalve 66:a8e6799dbce3 416 output1[index2] = 0;
Lightvalve 66:a8e6799dbce3 417 }
Lightvalve 66:a8e6799dbce3 418 }
Lightvalve 65:a2d7c63419c2 419
Lightvalve 66:a8e6799dbce3 420 for (int index2 = 0; index2 < 32; index2++) {
Lightvalve 66:a8e6799dbce3 421 for (int index1 = 0; index1 < 32; index1++) {
Lightvalve 66:a8e6799dbce3 422 output2[index2] = output2[index2]
Lightvalve 66:a8e6799dbce3 423 + h2[index1][index2] * output1[index1];
Lightvalve 66:a8e6799dbce3 424 }
Lightvalve 66:a8e6799dbce3 425 output2[index2] = output2[index2] + b2[index2];
Lightvalve 66:a8e6799dbce3 426 if (output2[index2] < 0) {
Lightvalve 66:a8e6799dbce3 427 output2[index2] = 0;
Lightvalve 66:a8e6799dbce3 428 }
Lightvalve 66:a8e6799dbce3 429 }
Lightvalve 65:a2d7c63419c2 430
Lightvalve 66:a8e6799dbce3 431 for (int index2 = 0; index2 < 32; index2++) {
Lightvalve 66:a8e6799dbce3 432 for (int index1 = 0; index1 < 32; index1++) {
Lightvalve 66:a8e6799dbce3 433 output3[index2] = output3[index2]
Lightvalve 66:a8e6799dbce3 434 + h3[index1][index2] * output2[index1];
Lightvalve 66:a8e6799dbce3 435 }
Lightvalve 66:a8e6799dbce3 436 output3[index2] = output3[index2] + b3[index2];
Lightvalve 66:a8e6799dbce3 437 if (output3[index2] < 0) {
Lightvalve 66:a8e6799dbce3 438 output3[index2] = 0;
Lightvalve 66:a8e6799dbce3 439 }
Lightvalve 65:a2d7c63419c2 440 }
Lightvalve 66:a8e6799dbce3 441
Lightvalve 66:a8e6799dbce3 442 for (int index2 = 0; index2 < 1; index2++) {
Lightvalve 66:a8e6799dbce3 443 for (int index1 = 0; index1 < 32; index1++) {
Lightvalve 66:a8e6799dbce3 444 output = output + hout[index2] * output3[index1];
Lightvalve 66:a8e6799dbce3 445 }
Lightvalve 66:a8e6799dbce3 446 output = output + bout[index2];
Lightvalve 66:a8e6799dbce3 447 output = 1.0f/(1.0f+exp(-output));
Lightvalve 66:a8e6799dbce3 448 }
Lightvalve 66:a8e6799dbce3 449
Lightvalve 66:a8e6799dbce3 450 output = output * 24000.0f - 12000.0f;
Lightvalve 66:a8e6799dbce3 451 if(output>=0) {
Lightvalve 66:a8e6799dbce3 452 valve_pos.ref = output*0.0001f*((double)VALVE_MAX_POS - (double) VALVE_CENTER) + (double) VALVE_CENTER;
Lightvalve 66:a8e6799dbce3 453 } else {
Lightvalve 66:a8e6799dbce3 454 valve_pos.ref = -output*0.0001f*((double)VALVE_MIN_POS - (double) VALVE_CENTER) + (double) VALVE_CENTER;
Lightvalve 65:a2d7c63419c2 455 }
Lightvalve 65:a2d7c63419c2 456 }
Lightvalve 62:b5452adfb2cd 457
Lightvalve 65:a2d7c63419c2 458
Lightvalve 65:a2d7c63419c2 459 if(LED==1) {
Lightvalve 65:a2d7c63419c2 460 LED=0;
Lightvalve 65:a2d7c63419c2 461 } else
Lightvalve 65:a2d7c63419c2 462 LED = 1;
Lightvalve 66:a8e6799dbce3 463
GiJeongKim 0:51c43836c1d7 464 }
jobuuu 1:e04e563be5ce 465 }
jobuuu 1:e04e563be5ce 466
Lightvalve 33:91b17819ec30 467 float DDV_JOINT_POS_FF(float REF_JOINT_VEL)
Lightvalve 14:8e7590227d22 468 {
Lightvalve 14:8e7590227d22 469
Lightvalve 13:747daba9cf59 470 int i = 0;
Lightvalve 48:889798ff9329 471 float Ref_Valve_Pos_FF = 0.0f;
Lightvalve 14:8e7590227d22 472 for(i=0; i<VALVE_POS_NUM; i++) {
Lightvalve 14:8e7590227d22 473 if(REF_JOINT_VEL >= min(JOINT_VEL[i],JOINT_VEL[i+1]) && REF_JOINT_VEL <= max(JOINT_VEL[i],JOINT_VEL[i+1])) {
Lightvalve 14:8e7590227d22 474 if(i==0) {
Lightvalve 50:3c630b5eba9f 475 if(JOINT_VEL[i+1] == JOINT_VEL[i]) {
Lightvalve 57:f4819de54e7a 476 Ref_Valve_Pos_FF = (float) VALVE_CENTER;
Lightvalve 50:3c630b5eba9f 477 } else {
Lightvalve 57:f4819de54e7a 478 Ref_Valve_Pos_FF = ((float) 10/(JOINT_VEL[i+1] - JOINT_VEL[i]) * (REF_JOINT_VEL - JOINT_VEL[i])) + (float) VALVE_CENTER;
Lightvalve 38:118df027d851 479 }
Lightvalve 14:8e7590227d22 480 } else {
Lightvalve 50:3c630b5eba9f 481 if(JOINT_VEL[i+1] == JOINT_VEL[i-1]) {
Lightvalve 57:f4819de54e7a 482 Ref_Valve_Pos_FF = (float) VALVE_CENTER;
Lightvalve 50:3c630b5eba9f 483 } else {
Lightvalve 57:f4819de54e7a 484 Ref_Valve_Pos_FF = ((float) 10*(ID_index_array[i+1] - ID_index_array[i-1])/(JOINT_VEL[i+1] - JOINT_VEL[i-1]) * (REF_JOINT_VEL - JOINT_VEL[i-1])) + (float) VALVE_CENTER + (float) (10*ID_index_array[i-1]);
Lightvalve 38:118df027d851 485 }
Lightvalve 13:747daba9cf59 486 }
Lightvalve 13:747daba9cf59 487 break;
Lightvalve 13:747daba9cf59 488 }
Lightvalve 13:747daba9cf59 489 }
Lightvalve 14:8e7590227d22 490 if(REF_JOINT_VEL > max(JOINT_VEL[VALVE_POS_NUM-1], JOINT_VEL[VALVE_POS_NUM-2])) {
Lightvalve 33:91b17819ec30 491 Ref_Valve_Pos_FF = (float) VALVE_MAX_POS;
Lightvalve 14:8e7590227d22 492 } else if(REF_JOINT_VEL < min(JOINT_VEL[VALVE_POS_NUM-1], JOINT_VEL[VALVE_POS_NUM-2])) {
Lightvalve 33:91b17819ec30 493 Ref_Valve_Pos_FF = (float) VALVE_MIN_POS;
Lightvalve 13:747daba9cf59 494 }
Lightvalve 36:a46e63505ed8 495
Lightvalve 57:f4819de54e7a 496 Ref_Valve_Pos_FF = (float) VELOCITY_COMP_GAIN * 0.01f * (float) (Ref_Valve_Pos_FF - (float) VALVE_CENTER);
Lightvalve 13:747daba9cf59 497 return Ref_Valve_Pos_FF;
Lightvalve 50:3c630b5eba9f 498
Lightvalve 13:747daba9cf59 499 }
jobuuu 6:df07d3491e3a 500
jobuuu 6:df07d3491e3a 501
Lightvalve 30:8d561f16383b 502 void VALVE_POS_CONTROL(float REF_VALVE_POS)
Lightvalve 14:8e7590227d22 503 {
Lightvalve 13:747daba9cf59 504 int i = 0;
Lightvalve 13:747daba9cf59 505
Lightvalve 38:118df027d851 506 if(REF_VALVE_POS > VALVE_MAX_POS) {
Lightvalve 38:118df027d851 507 REF_VALVE_POS = VALVE_MAX_POS;
Lightvalve 38:118df027d851 508 } else if(REF_VALVE_POS < VALVE_MIN_POS) {
Lightvalve 38:118df027d851 509 REF_VALVE_POS = VALVE_MIN_POS;
Lightvalve 38:118df027d851 510 }
Lightvalve 38:118df027d851 511
Lightvalve 13:747daba9cf59 512 valve_pos_err = REF_VALVE_POS - value;
Lightvalve 13:747daba9cf59 513 valve_pos_err_diff = valve_pos_err - valve_pos_err_old;
Lightvalve 13:747daba9cf59 514 valve_pos_err_old = valve_pos_err;
Lightvalve 13:747daba9cf59 515 valve_pos_err_sum += valve_pos_err;
Lightvalve 13:747daba9cf59 516 if (valve_pos_err_sum > 1000) valve_pos_err_sum = 1000;
Lightvalve 13:747daba9cf59 517 if (valve_pos_err_sum<-1000) valve_pos_err_sum = -1000;
Lightvalve 13:747daba9cf59 518
Lightvalve 13:747daba9cf59 519 VALVE_PWM_RAW_FB = P_GAIN_VALVE_POSITION * valve_pos_err + I_GAIN_VALVE_POSITION * valve_pos_err_sum + D_GAIN_VALVE_POSITION * valve_pos_err_diff;
Lightvalve 14:8e7590227d22 520
Lightvalve 18:b8adf1582ea3 521 for(i=0; i<24; i++) {
Lightvalve 14:8e7590227d22 522 if(REF_VALVE_POS >= min(VALVE_POS_VS_PWM[i],VALVE_POS_VS_PWM[i+1]) && REF_VALVE_POS <= max(VALVE_POS_VS_PWM[i],VALVE_POS_VS_PWM[i+1])) {
Lightvalve 14:8e7590227d22 523 if(i==0) {
Lightvalve 48:889798ff9329 524 VALVE_PWM_RAW_FF = (float) 1000.0f / (float) (VALVE_POS_VS_PWM[i+1] - VALVE_POS_VS_PWM[i]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[i]);
Lightvalve 14:8e7590227d22 525 } else {
Lightvalve 48:889798ff9329 526 VALVE_PWM_RAW_FF = (float) 1000.0f* (float) (ID_index_array[i+1] - ID_index_array[i-1])/(VALVE_POS_VS_PWM[i+1] - VALVE_POS_VS_PWM[i-1]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[i-1]) + 1000.0f * (float) ID_index_array[i-1];
Lightvalve 13:747daba9cf59 527 }
Lightvalve 13:747daba9cf59 528 break;
Lightvalve 13:747daba9cf59 529 }
Lightvalve 13:747daba9cf59 530 }
Lightvalve 59:f308b1656d9c 531 Vout.ref = VALVE_PWM_RAW_FF + VALVE_PWM_RAW_FB;
Lightvalve 13:747daba9cf59 532 }
Lightvalve 13:747daba9cf59 533
Lightvalve 14:8e7590227d22 534 #define LT_MAX_IDX 57
Lightvalve 30:8d561f16383b 535 float LT_PWM_duty[LT_MAX_IDX] = {-100.0f, -80.0f, -60.0f, -50.0f, -40.0f, -35.0f, -30.0f, -25.0f, -20.0f,
Lightvalve 34:bb2ca2fc2a8e 536 -19.0f, -18.0f, -17.0f, -16.0f, -15.0f, -14.0f, -13.0f, -12.0f, -11.0f, -10.0f,
Lightvalve 34:bb2ca2fc2a8e 537 -9.0f, -8.0f, -7.0f, -6.0f, -5.0f, -4.0f, -3.0f, -2.0f, -1.0f, 0.0f,
Lightvalve 34:bb2ca2fc2a8e 538 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f,
Lightvalve 34:bb2ca2fc2a8e 539 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f,
Lightvalve 34:bb2ca2fc2a8e 540 25.0f, 30.0f, 35.0f, 40.0f, 50.0f, 60.0f, 80.0f, 100.0f
Lightvalve 34:bb2ca2fc2a8e 541 }; // duty
Lightvalve 67:c2812cf26c38 542 float LT_Voltage_Output[LT_MAX_IDX] = {-230.0f, -215.0f, -192.5f, -185.0f, -177.5f, -170.0f, -164.0f, -160.0f, -150.0f,
Lightvalve 67:c2812cf26c38 543 -150.0f, -145.0f, -145.0f, -145.0f, -135.0f, -135.0f, -135.0f, -127.5f, -127.5f, -115.0f,
Lightvalve 67:c2812cf26c38 544 -115.0f, -115.0F, -100.0f, -100.0f, -100.0f, -60.0f, -60.0f, -10.0f, -5.0f, 0.0f,
Lightvalve 67:c2812cf26c38 545 7.5f, 14.0f, 14.0f, 14.0f, 42.5f, 42.5f, 42.5f, 80.0f, 80.0f, 105.0f,
Lightvalve 67:c2812cf26c38 546 105.0f, 105.0f, 120.0f, 120.0f, 120.0f, 131.0f, 131.0f, 140.0f, 140.0f, 140.0f,
Lightvalve 67:c2812cf26c38 547 155.0f, 160.0f, 170.0f, 174.0f, 182.0f, 191.0f, 212.0f, 230.0f
Lightvalve 34:bb2ca2fc2a8e 548 }; // mV
Lightvalve 13:747daba9cf59 549
Lightvalve 30:8d561f16383b 550 float PWM_duty_byLT(float Ref_V)
Lightvalve 14:8e7590227d22 551 {
Lightvalve 30:8d561f16383b 552 float PWM_duty = 0.0f;
Lightvalve 13:747daba9cf59 553 if(Ref_V<LT_Voltage_Output[0]) {
Lightvalve 30:8d561f16383b 554 PWM_duty = (Ref_V-LT_Voltage_Output[0])/1.5f+LT_PWM_duty[0];
Lightvalve 13:747daba9cf59 555 } else if (Ref_V>=LT_Voltage_Output[LT_MAX_IDX-1]) {
Lightvalve 30:8d561f16383b 556 PWM_duty = (Ref_V-LT_Voltage_Output[LT_MAX_IDX-1])/1.5f+LT_PWM_duty[LT_MAX_IDX-1];
Lightvalve 13:747daba9cf59 557 } else {
Lightvalve 13:747daba9cf59 558 int idx = 0;
Lightvalve 13:747daba9cf59 559 for(idx=0; idx<LT_MAX_IDX-1; idx++) {
Lightvalve 30:8d561f16383b 560 float ini_x = LT_Voltage_Output[idx];
Lightvalve 30:8d561f16383b 561 float fin_x = LT_Voltage_Output[idx+1];
Lightvalve 30:8d561f16383b 562 float ini_y = LT_PWM_duty[idx];
Lightvalve 30:8d561f16383b 563 float fin_y = LT_PWM_duty[idx+1];
Lightvalve 13:747daba9cf59 564 if(Ref_V>=ini_x && Ref_V<fin_x) {
Lightvalve 13:747daba9cf59 565 PWM_duty = (fin_y-ini_y)/(fin_x-ini_x)*(Ref_V-ini_x) + ini_y;
Lightvalve 13:747daba9cf59 566 break;
Lightvalve 13:747daba9cf59 567 }
Lightvalve 13:747daba9cf59 568 }
Lightvalve 13:747daba9cf59 569 }
Lightvalve 14:8e7590227d22 570
Lightvalve 13:747daba9cf59 571 return PWM_duty;
Lightvalve 13:747daba9cf59 572 }
jobuuu 6:df07d3491e3a 573
Lightvalve 57:f4819de54e7a 574
Lightvalve 57:f4819de54e7a 575
Lightvalve 57:f4819de54e7a 576
Lightvalve 57:f4819de54e7a 577
jobuuu 2:a1c0a37df760 578 /*******************************************************************************
jobuuu 2:a1c0a37df760 579 TIMER INTERRUPT
jobuuu 2:a1c0a37df760 580 *******************************************************************************/
jobuuu 2:a1c0a37df760 581
Lightvalve 51:b46bed7fec80 582 float FREQ_TMR4 = (float)FREQ_20k;
Lightvalve 51:b46bed7fec80 583 float DT_TMR4 = (float)DT_20k;
Lightvalve 57:f4819de54e7a 584 long CNT_TMR4 = 0;
Lightvalve 57:f4819de54e7a 585 int TMR4_FREQ_10k = (int)FREQ_10k;
jobuuu 1:e04e563be5ce 586 extern "C" void TIM4_IRQHandler(void)
jobuuu 1:e04e563be5ce 587 {
Lightvalve 19:23b7c1ad8683 588 if (TIM4->SR & TIM_SR_UIF ) {
Lightvalve 21:e5f1a43ea6f9 589
Lightvalve 21:e5f1a43ea6f9 590 /*******************************************************
Lightvalve 21:e5f1a43ea6f9 591 *** Sensor Read & Data Handling
Lightvalve 21:e5f1a43ea6f9 592 ********************************************************/
Lightvalve 13:747daba9cf59 593
Lightvalve 57:f4819de54e7a 594 //Encoder
Lightvalve 57:f4819de54e7a 595 if (CNT_TMR4 % (int) ((int) FREQ_TMR4/TMR4_FREQ_10k) == 0) {
Lightvalve 57:f4819de54e7a 596 ENC_UPDATE();
Lightvalve 57:f4819de54e7a 597 }
Lightvalve 61:bc8c8270f0ab 598
Lightvalve 61:bc8c8270f0ab 599 ADC1->CR2 |= 0x40000000;
Lightvalve 58:2eade98630e2 600 if (SENSING_MODE == 0) {
Lightvalve 58:2eade98630e2 601 // Torque Sensing (0~210)bar =============================================
Lightvalve 58:2eade98630e2 602 float pres_A_new = (((float) ADC1->DR) - 2047.5f);
Lightvalve 58:2eade98630e2 603 double alpha_update_ft = 1.0f / (1.0f + FREQ_TMR4 / (2.0f * 3.14f * 100.0f)); // f_cutoff : 200Hz
Lightvalve 58:2eade98630e2 604 pres_A.sen = (1.0f - alpha_update_ft) * pres_A.sen + alpha_update_ft * pres_A_new;
Lightvalve 67:c2812cf26c38 605 torq.sen = -pres_A.sen / TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 67:c2812cf26c38 606
Lightvalve 67:c2812cf26c38 607
Lightvalve 67:c2812cf26c38 608 // float alpha_update_pres_A = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f));
Lightvalve 67:c2812cf26c38 609 //// float pres_A_new = ((float)ADC1->DR - PRES_A_NULL) / PRES_SENSOR_A_PULSE_PER_BAR;
Lightvalve 67:c2812cf26c38 610 // float pres_A_new = ((float)ADC1->DR);
Lightvalve 67:c2812cf26c38 611 // pres_A.sen = pres_A.sen*(1.0f-alpha_update_pres_A)+pres_A_new*(alpha_update_pres_A);
Lightvalve 67:c2812cf26c38 612 // torq.sen = - (pres_A.sen-2048.0f); //pulse -2047~2047
Lightvalve 67:c2812cf26c38 613
Lightvalve 17:1865016ca2e7 614
Lightvalve 58:2eade98630e2 615 } else if (SENSING_MODE == 1) {
Lightvalve 58:2eade98630e2 616 // Pressure Sensing (0~210)bar =============================================
Lightvalve 58:2eade98630e2 617 float pres_A_new = (((float)ADC1->DR) - PRES_A_NULL);
Lightvalve 58:2eade98630e2 618 float pres_B_new = (((float)ADC2->DR) - PRES_B_NULL);
Lightvalve 58:2eade98630e2 619 double alpha_update_pres = 1.0f / (1.0f + FREQ_TMR4 / (2.0f * 3.14f * 200.0f)); // f_cutoff : 500Hz
Lightvalve 58:2eade98630e2 620 pres_A.sen = (1.0f - alpha_update_pres) * pres_A.sen + alpha_update_pres * pres_A_new;
Lightvalve 58:2eade98630e2 621 pres_B.sen = (1.0f - alpha_update_pres) * pres_B.sen + alpha_update_pres * pres_B_new;
Lightvalve 58:2eade98630e2 622 CUR_PRES_A_BAR = pres_A.sen / PRES_SENSOR_A_PULSE_PER_BAR;
Lightvalve 58:2eade98630e2 623 CUR_PRES_B_BAR = pres_B.sen / PRES_SENSOR_B_PULSE_PER_BAR;
Lightvalve 50:3c630b5eba9f 624
Lightvalve 58:2eade98630e2 625 if ((OPERATING_MODE & 0x01) == 0) { // Rotary Actuator
Lightvalve 58:2eade98630e2 626 torq.sen = (PISTON_AREA_A * CUR_PRES_A_BAR - PISTON_AREA_B * CUR_PRES_B_BAR) * 0.0001f; // mm^3*bar >> Nm
Lightvalve 58:2eade98630e2 627 } else if ((OPERATING_MODE & 0x01) == 1) { // Linear Actuator
Lightvalve 58:2eade98630e2 628 torq.sen = (PISTON_AREA_A * CUR_PRES_A_BAR - PISTON_AREA_B * CUR_PRES_B_BAR) * 0.1f; // mm^2*bar >> N
Lightvalve 58:2eade98630e2 629 }
Lightvalve 58:2eade98630e2 630 }
Lightvalve 61:bc8c8270f0ab 631
Lightvalve 58:2eade98630e2 632 // //Pressure sensor A
Lightvalve 58:2eade98630e2 633 // ADC1->CR2 |= 0x40000000; // adc _ 12bit
Lightvalve 58:2eade98630e2 634 // //while((ADC1->SR & 0b10));
Lightvalve 58:2eade98630e2 635 // float alpha_update_pres_A = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f));
Lightvalve 58:2eade98630e2 636 // float pres_A_new = ((float)ADC1->DR);
Lightvalve 58:2eade98630e2 637 // pres_A.sen = pres_A.sen*(1.0f-alpha_update_pres_A)+pres_A_new*(alpha_update_pres_A);
Lightvalve 58:2eade98630e2 638 // torq.sen = - (pres_A.sen-2048.0f); //pulse -2047~2047 //SW just changed the sign to correct the direction of loadcell on LIGHT. Correct later.
Lightvalve 58:2eade98630e2 639 //
Lightvalve 58:2eade98630e2 640 //
Lightvalve 58:2eade98630e2 641 // //Pressure sensor B
Lightvalve 58:2eade98630e2 642 // float alpha_update_pres_B = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f));
Lightvalve 58:2eade98630e2 643 // float pres_B_new = ((float)ADC2->DR);
Lightvalve 58:2eade98630e2 644 // pres_B.sen = pres_B.sen*(1.0f-alpha_update_pres_B)+pres_B_new*(alpha_update_pres_B);
Lightvalve 58:2eade98630e2 645 // //torq.sen = pres_A.sen * (float) PISTON_AREA_A - pres_B.sen * (float) PISTON_AREA_B;
Lightvalve 17:1865016ca2e7 646
Lightvalve 17:1865016ca2e7 647
Lightvalve 21:e5f1a43ea6f9 648 //Current
Lightvalve 21:e5f1a43ea6f9 649 //ADC3->CR2 |= 0x40000000; // adc _ 12bit
Lightvalve 25:3e6b574cab5c 650 //int raw_cur = ADC3->DR;
Lightvalve 21:e5f1a43ea6f9 651 //while((ADC3->SR & 0b10));
Lightvalve 51:b46bed7fec80 652 float alpha_update_cur = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*500.0f)); // f_cutoff : 500Hz
Lightvalve 30:8d561f16383b 653 float cur_new = ((float)ADC3->DR-2048.0f)*20.0f/4096.0f; // unit : mA
Lightvalve 30:8d561f16383b 654 cur.sen=cur.sen*(1.0f-alpha_update_cur)+cur_new*(alpha_update_cur);
Lightvalve 25:3e6b574cab5c 655 //cur.sen = raw_cur;
Lightvalve 58:2eade98630e2 656
Lightvalve 57:f4819de54e7a 657 CNT_TMR4++;
Lightvalve 21:e5f1a43ea6f9 658 }
Lightvalve 11:82d8768d7351 659 TIM4->SR = 0x0; // reset the status register
Lightvalve 11:82d8768d7351 660 }
Lightvalve 19:23b7c1ad8683 661
Lightvalve 19:23b7c1ad8683 662
Lightvalve 18:b8adf1582ea3 663 int j =0;
Lightvalve 54:647072f5307a 664 float FREQ_TMR3 = (float)FREQ_5k;
Lightvalve 48:889798ff9329 665 float DT_TMR3 = (float)DT_5k;
Lightvalve 45:35fa6884d0c6 666 int cnt_trans = 0;
Lightvalve 48:889798ff9329 667 double VALVE_POS_RAW_FORCE_FB_LOGGING = 0.0f;
Lightvalve 57:f4819de54e7a 668 int can_rest =0;
Lightvalve 48:889798ff9329 669
Lightvalve 11:82d8768d7351 670 extern "C" void TIM3_IRQHandler(void)
Lightvalve 21:e5f1a43ea6f9 671 {
Lightvalve 19:23b7c1ad8683 672 if (TIM3->SR & TIM_SR_UIF ) {
Lightvalve 57:f4819de54e7a 673
Lightvalve 57:f4819de54e7a 674 if (((OPERATING_MODE&0b110)>>1) == 0) {
Lightvalve 57:f4819de54e7a 675 K_v = 0.4f; // Moog (LPM >> mA) , 100bar
Lightvalve 57:f4819de54e7a 676 mV_PER_mA = 500.0f; // 5000mV/10mA
Lightvalve 57:f4819de54e7a 677 mV_PER_pulse = 0.5f; // 5000mV/10000pulse
Lightvalve 57:f4819de54e7a 678 mA_PER_pulse = 0.001f; // 10mA/10000pulse
Lightvalve 57:f4819de54e7a 679 } else if (((OPERATING_MODE&0b110)>>1) == 1) {
Lightvalve 57:f4819de54e7a 680 K_v = 0.5f; // KNR (LPM >> mA) , 100bar
Lightvalve 57:f4819de54e7a 681 mV_PER_mA = 166.6666f; // 5000mV/30mA
Lightvalve 57:f4819de54e7a 682 mV_PER_pulse = 0.5f; // 5000mV/10000pulse
Lightvalve 57:f4819de54e7a 683 mA_PER_pulse = 0.003f; // 30mA/10000pulse
Lightvalve 57:f4819de54e7a 684 }
Lightvalve 50:3c630b5eba9f 685
Lightvalve 50:3c630b5eba9f 686 if(MODE_POS_FT_TRANS == 1) {
Lightvalve 48:889798ff9329 687 alpha_trans = (float)(1.0f - cos(3.141592f * (float)cnt_trans * DT_TMR3 /3.0f))/2.0f;
Lightvalve 45:35fa6884d0c6 688 cnt_trans++;
Lightvalve 46:2694daea349b 689 torq.err_sum = 0;
Lightvalve 48:889798ff9329 690 if((float)cnt_trans * DT_TMR3 > 3.0f)
Lightvalve 45:35fa6884d0c6 691 MODE_POS_FT_TRANS = 2;
Lightvalve 50:3c630b5eba9f 692 } else if(MODE_POS_FT_TRANS == 3) {
Lightvalve 48:889798ff9329 693 alpha_trans = (float)(1.0f + cos(3.141592f * (float)cnt_trans * DT_TMR3 /3.0f))/2.0f;
Lightvalve 45:35fa6884d0c6 694 cnt_trans++;
Lightvalve 46:2694daea349b 695 torq.err_sum = 0;
Lightvalve 48:889798ff9329 696 if((float) cnt_trans * DT_TMR3 > 3.0f )
Lightvalve 45:35fa6884d0c6 697 MODE_POS_FT_TRANS = 0;
Lightvalve 50:3c630b5eba9f 698 } else if(MODE_POS_FT_TRANS == 2) {
Lightvalve 58:2eade98630e2 699 alpha_trans = 1.0f;
Lightvalve 45:35fa6884d0c6 700 cnt_trans = 0;
Lightvalve 50:3c630b5eba9f 701 } else {
Lightvalve 58:2eade98630e2 702 alpha_trans = 0.0f;
Lightvalve 45:35fa6884d0c6 703 cnt_trans = 0;
Lightvalve 45:35fa6884d0c6 704 }
Lightvalve 45:35fa6884d0c6 705
Lightvalve 50:3c630b5eba9f 706
Lightvalve 57:f4819de54e7a 707 int UTILITY_MODE = 0;
Lightvalve 57:f4819de54e7a 708 int CONTROL_MODE = 0;
Lightvalve 58:2eade98630e2 709
Lightvalve 57:f4819de54e7a 710 if (CONTROL_UTILITY_MODE >= 20 || CONTROL_UTILITY_MODE == 0) {
Lightvalve 57:f4819de54e7a 711 UTILITY_MODE = CONTROL_UTILITY_MODE;
Lightvalve 57:f4819de54e7a 712 CONTROL_MODE = MODE_NO_ACT;
Lightvalve 57:f4819de54e7a 713 } else {
Lightvalve 57:f4819de54e7a 714 CONTROL_MODE = CONTROL_UTILITY_MODE;
Lightvalve 57:f4819de54e7a 715 UTILITY_MODE = MODE_NO_ACT;
Lightvalve 57:f4819de54e7a 716 }
Lightvalve 56:6f50d9d3bfee 717
Lightvalve 56:6f50d9d3bfee 718
Lightvalve 56:6f50d9d3bfee 719
Lightvalve 57:f4819de54e7a 720 // UTILITY MODE ------------------------------------------------------------
Lightvalve 56:6f50d9d3bfee 721
Lightvalve 57:f4819de54e7a 722 switch (UTILITY_MODE) {
Lightvalve 57:f4819de54e7a 723 case MODE_NO_ACT: {
Lightvalve 13:747daba9cf59 724 break;
Lightvalve 13:747daba9cf59 725 }
Lightvalve 14:8e7590227d22 726
Lightvalve 14:8e7590227d22 727 case MODE_TORQUE_SENSOR_NULLING: {
Lightvalve 13:747daba9cf59 728 // DAC Voltage reference set
Lightvalve 14:8e7590227d22 729 if (TMR3_COUNT_TORQUE_NULL < TMR_FREQ_5k * 2) {
Lightvalve 15:bd0d12728506 730 CUR_TORQUE_sum += torq.sen;
Lightvalve 19:23b7c1ad8683 731
Lightvalve 14:8e7590227d22 732 if (TMR3_COUNT_TORQUE_NULL % 10 == 0) {
Lightvalve 30:8d561f16383b 733 CUR_TORQUE_mean = CUR_TORQUE_sum / 10.0f;
Lightvalve 13:747daba9cf59 734 CUR_TORQUE_sum = 0;
Lightvalve 14:8e7590227d22 735
Lightvalve 59:f308b1656d9c 736 TORQUE_VREF += 0.0003f * (0.0f - CUR_TORQUE_mean);
Lightvalve 19:23b7c1ad8683 737
Lightvalve 30:8d561f16383b 738 if (TORQUE_VREF > 3.3f) TORQUE_VREF = 3.3f;
Lightvalve 59:f308b1656d9c 739 if (TORQUE_VREF < 0.0f) TORQUE_VREF = 0.0f;
Lightvalve 50:3c630b5eba9f 740
Lightvalve 16:903b5a4433b4 741 //spi_eeprom_write(RID_TORQUE_SENSOR_VREF, (int16_t) (TORQUE_VREF * 1000.0));
Lightvalve 30:8d561f16383b 742 dac_1 = TORQUE_VREF / 3.3f;
Lightvalve 13:747daba9cf59 743 }
Lightvalve 13:747daba9cf59 744 } else {
Lightvalve 58:2eade98630e2 745 CONTROL_UTILITY_MODE = MODE_NO_ACT;
Lightvalve 14:8e7590227d22 746 TMR3_COUNT_TORQUE_NULL = 0;
Lightvalve 13:747daba9cf59 747 CUR_TORQUE_sum = 0;
Lightvalve 13:747daba9cf59 748 CUR_TORQUE_mean = 0;
Lightvalve 19:23b7c1ad8683 749
Lightvalve 16:903b5a4433b4 750 ROM_RESET_DATA();
Lightvalve 19:23b7c1ad8683 751
Lightvalve 30:8d561f16383b 752 dac_1 = TORQUE_VREF / 3.3f;
Lightvalve 14:8e7590227d22 753
Lightvalve 13:747daba9cf59 754 }
Lightvalve 14:8e7590227d22 755 TMR3_COUNT_TORQUE_NULL++;
Lightvalve 13:747daba9cf59 756 break;
Lightvalve 19:23b7c1ad8683 757 }
Lightvalve 14:8e7590227d22 758
Lightvalve 50:3c630b5eba9f 759 // case MODE_VALVE_NULLING_AND_DEADZONE_SETTING: {
Lightvalve 50:3c630b5eba9f 760 // if (TMR3_COUNT_DEADZONE == 0) {
Lightvalve 50:3c630b5eba9f 761 // if (pos_plus_end == pos_minus_end) need_enc_init = true;
Lightvalve 50:3c630b5eba9f 762 // else temp_time = 0;
Lightvalve 50:3c630b5eba9f 763 // }
Lightvalve 50:3c630b5eba9f 764 // if (need_enc_init) {
Lightvalve 50:3c630b5eba9f 765 // if (TMR3_COUNT_DEADZONE < (int) (0.5f * (float) TMR_FREQ_5k)) {
Lightvalve 50:3c630b5eba9f 766 // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 50:3c630b5eba9f 767 // pos_plus_end = pos.sen;
Lightvalve 50:3c630b5eba9f 768 // } else if (TMR3_COUNT_DEADZONE < TMR_FREQ_5k) {
Lightvalve 50:3c630b5eba9f 769 // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 50:3c630b5eba9f 770 // pos_minus_end = pos.sen;
Lightvalve 50:3c630b5eba9f 771 // } else if (TMR3_COUNT_DEADZONE == TMR_FREQ_5k) need_enc_init = false;
Lightvalve 50:3c630b5eba9f 772 // temp_time = TMR_FREQ_5k;
Lightvalve 50:3c630b5eba9f 773 // }
Lightvalve 50:3c630b5eba9f 774 //
Lightvalve 50:3c630b5eba9f 775 // if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + TMR_FREQ_5k)) {
Lightvalve 50:3c630b5eba9f 776 // V_out = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
Lightvalve 50:3c630b5eba9f 777 // VALVE_CENTER = VALVE_DEADZONE_PLUS = VALVE_DEADZONE_MINUS = 0;
Lightvalve 50:3c630b5eba9f 778 //
Lightvalve 50:3c630b5eba9f 779 // } else if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + (int) (1.9f * (float) TMR_FREQ_5k))) {
Lightvalve 50:3c630b5eba9f 780 // V_out = 0;
Lightvalve 50:3c630b5eba9f 781 // CUR_VELOCITY_sum += CUR_VELOCITY;
Lightvalve 50:3c630b5eba9f 782 // } else if (TMR3_COUNT_DEADZONE == (temp_time + 2 * TMR_FREQ_5k)) {
Lightvalve 50:3c630b5eba9f 783 // if (CUR_VELOCITY_sum == 0) DZ_dir = 1;
Lightvalve 50:3c630b5eba9f 784 // else if (CUR_VELOCITY_sum > 0) DZ_dir = 1;
Lightvalve 50:3c630b5eba9f 785 // else if (CUR_VELOCITY_sum < 0) DZ_dir = -1;
Lightvalve 50:3c630b5eba9f 786 // else DZ_temp_cnt2 = DZ_end;
Lightvalve 50:3c630b5eba9f 787 // CUR_VELOCITY_sum = 0;
Lightvalve 50:3c630b5eba9f 788 // } else if (TMR3_COUNT_DEADZONE > (temp_time + 2 * TMR_FREQ_5k)) {
Lightvalve 50:3c630b5eba9f 789 // if (TMR3_COUNT_DEADZONE > (temp_time + 10 * TMR_FREQ_5k)) DZ_temp_cnt2 = DZ_end;
Lightvalve 50:3c630b5eba9f 790 //
Lightvalve 50:3c630b5eba9f 791 // // Position of Dead Zone
Lightvalve 50:3c630b5eba9f 792 // // (CUR_VELOCITY < 0) (CUR_VELOCITY == 0) (CUR_VELOCITY > 0)
Lightvalve 50:3c630b5eba9f 793 // // | / | / |/
Lightvalve 50:3c630b5eba9f 794 // // | ______/ ___|___/ ______/|
Lightvalve 50:3c630b5eba9f 795 // // |/ / | / |
Lightvalve 50:3c630b5eba9f 796 // // /| / | / |
Lightvalve 50:3c630b5eba9f 797 // // 0V 0V 0V
Lightvalve 50:3c630b5eba9f 798 //
Lightvalve 50:3c630b5eba9f 799 // if (DZ_temp_cnt2 < DZ_end) {
Lightvalve 50:3c630b5eba9f 800 // if (TMR3_COUNT_DEADZONE % 20 != 0) {
Lightvalve 50:3c630b5eba9f 801 // CUR_VELOCITY_sum += CUR_VELOCITY;
Lightvalve 50:3c630b5eba9f 802 // } else {
Lightvalve 50:3c630b5eba9f 803 // V_out -= DZ_dir;
Lightvalve 50:3c630b5eba9f 804 // if (CUR_VELOCITY_sum * DZ_dir < 0) DZ_temp_cnt++;
Lightvalve 50:3c630b5eba9f 805 // CUR_VELOCITY_sum = 0;
Lightvalve 50:3c630b5eba9f 806 // }
Lightvalve 50:3c630b5eba9f 807 // if (DZ_temp_cnt == 5) {
Lightvalve 50:3c630b5eba9f 808 // if (DZ_dir >= 0) VALVE_DEADZONE_MINUS = (int16_t) V_out;
Lightvalve 50:3c630b5eba9f 809 // else VALVE_DEADZONE_PLUS = (int16_t) V_out;
Lightvalve 50:3c630b5eba9f 810 // DZ_dir = -DZ_dir;
Lightvalve 50:3c630b5eba9f 811 // DZ_temp_cnt = 0;
Lightvalve 50:3c630b5eba9f 812 // DZ_temp_cnt2++;
Lightvalve 50:3c630b5eba9f 813 // }
Lightvalve 50:3c630b5eba9f 814 // } else {
Lightvalve 50:3c630b5eba9f 815 // TMR3_COUNT_DEADZONE = -1;
Lightvalve 50:3c630b5eba9f 816 // VALVE_CENTER = VALVE_DEADZONE_PLUS / 2 + VALVE_DEADZONE_MINUS / 2;
Lightvalve 50:3c630b5eba9f 817 // if (VALVE_DEADZONE_PLUS < VALVE_DEADZONE_MINUS) {
Lightvalve 50:3c630b5eba9f 818 // VALVE_DEADZONE_PLUS = VALVE_CENTER;
Lightvalve 50:3c630b5eba9f 819 // VALVE_DEADZONE_MINUS = VALVE_CENTER;
Lightvalve 50:3c630b5eba9f 820 // }
Lightvalve 50:3c630b5eba9f 821 // V_out = 0;
Lightvalve 50:3c630b5eba9f 822 //
Lightvalve 50:3c630b5eba9f 823 // ROM_RESET_DATA();
Lightvalve 50:3c630b5eba9f 824 //
Lightvalve 50:3c630b5eba9f 825 // //spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, VALVE_DEADZONE_PLUS);
Lightvalve 50:3c630b5eba9f 826 // //spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, VALVE_DEADZONE_MINUS);
Lightvalve 50:3c630b5eba9f 827 //
Lightvalve 50:3c630b5eba9f 828 // CONTROL_MODE = MODE_NO_ACT;
Lightvalve 50:3c630b5eba9f 829 // DZ_temp_cnt2 = 0;
Lightvalve 50:3c630b5eba9f 830 // }
Lightvalve 50:3c630b5eba9f 831 // }
Lightvalve 50:3c630b5eba9f 832 // TMR3_COUNT_DEADZONE++;
Lightvalve 50:3c630b5eba9f 833 // break;
Lightvalve 50:3c630b5eba9f 834 // }
Lightvalve 14:8e7590227d22 835
Lightvalve 14:8e7590227d22 836 case MODE_FIND_HOME: {
Lightvalve 29:69f3f5445d6d 837 if (FINDHOME_STAGE == FINDHOME_INIT) {
Lightvalve 14:8e7590227d22 838 cnt_findhome = 0;
Lightvalve 14:8e7590227d22 839 cnt_vel_findhome = 0;
Lightvalve 14:8e7590227d22 840 //REFERENCE_MODE = MODE_REF_NO_ACT; // Stop taking reference data from PODO
Lightvalve 59:f308b1656d9c 841 pos.ref = pos.sen;
Lightvalve 59:f308b1656d9c 842 vel.ref = 0.0f;
Lightvalve 29:69f3f5445d6d 843 FINDHOME_STAGE = FINDHOME_GOTOLIMIT;
Lightvalve 29:69f3f5445d6d 844 } else if (FINDHOME_STAGE == FINDHOME_GOTOLIMIT) {
Lightvalve 67:c2812cf26c38 845 int cnt_check_enc = (TMR_FREQ_5k/20);
Lightvalve 29:69f3f5445d6d 846 if(cnt_findhome%cnt_check_enc == 0) {
Lightvalve 29:69f3f5445d6d 847 FINDHOME_POSITION = pos.sen;
Lightvalve 29:69f3f5445d6d 848 FINDHOME_VELOCITY = FINDHOME_POSITION - FINDHOME_POSITION_OLD;
Lightvalve 29:69f3f5445d6d 849 FINDHOME_POSITION_OLD = FINDHOME_POSITION;
Lightvalve 29:69f3f5445d6d 850 }
Lightvalve 29:69f3f5445d6d 851 cnt_findhome++;
Lightvalve 14:8e7590227d22 852
Lightvalve 29:69f3f5445d6d 853 if (abs(FINDHOME_VELOCITY) <= 1) {
Lightvalve 29:69f3f5445d6d 854 cnt_vel_findhome = cnt_vel_findhome + 1;
Lightvalve 29:69f3f5445d6d 855 } else {
Lightvalve 29:69f3f5445d6d 856 cnt_vel_findhome = 0;
Lightvalve 29:69f3f5445d6d 857 }
Lightvalve 19:23b7c1ad8683 858
Lightvalve 57:f4819de54e7a 859 if ((cnt_vel_findhome < 3*TMR_FREQ_5k) && cnt_findhome < 10*TMR_FREQ_5k) { // wait for 3sec
Lightvalve 29:69f3f5445d6d 860 //REFERENCE_MODE = MODE_REF_NO_ACT;
Lightvalve 67:c2812cf26c38 861 if (HOMEPOS_OFFSET > 0) pos.ref = pos.ref + 12.0f;
Lightvalve 67:c2812cf26c38 862 else pos.ref = pos.ref - 12.0f;
Lightvalve 61:bc8c8270f0ab 863
Lightvalve 59:f308b1656d9c 864 // pos.err = pos.ref_home_pos - pos.sen;
Lightvalve 59:f308b1656d9c 865 // float VALVE_POS_RAW_POS_FB = 0.0f;
Lightvalve 59:f308b1656d9c 866 // VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * pos.err/(float) ENC_PULSE_PER_POSITION * 0.01f;
Lightvalve 59:f308b1656d9c 867 // valve_pos.ref = VALVE_POS_RAW_POS_FB + (float) VALVE_CENTER;
Lightvalve 59:f308b1656d9c 868 // VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 61:bc8c8270f0ab 869
Lightvalve 59:f308b1656d9c 870 CONTROL_MODE = MODE_JOINT_CONTROL;
Lightvalve 59:f308b1656d9c 871 alpha_trans = 0.0f;
Lightvalve 61:bc8c8270f0ab 872
Lightvalve 34:bb2ca2fc2a8e 873
Lightvalve 29:69f3f5445d6d 874 } else {
Lightvalve 29:69f3f5445d6d 875 ENC_SET(HOMEPOS_OFFSET);
Lightvalve 67:c2812cf26c38 876 // ENC_SET_ZERO();
Lightvalve 29:69f3f5445d6d 877 INIT_REF_POS = HOMEPOS_OFFSET;
Lightvalve 29:69f3f5445d6d 878 REF_POSITION = 0;
Lightvalve 29:69f3f5445d6d 879 REF_VELOCITY = 0;
Lightvalve 29:69f3f5445d6d 880 FINDHOME_POSITION = 0;
Lightvalve 29:69f3f5445d6d 881 FINDHOME_POSITION_OLD = 0;
Lightvalve 29:69f3f5445d6d 882 FINDHOME_VELOCITY = 0;
Lightvalve 29:69f3f5445d6d 883 cnt_findhome = 0;
Lightvalve 29:69f3f5445d6d 884 cnt_vel_findhome = 0;
Lightvalve 29:69f3f5445d6d 885 FINDHOME_STAGE = FINDHOME_ZEROPOSE;
Lightvalve 67:c2812cf26c38 886
Lightvalve 67:c2812cf26c38 887
Lightvalve 67:c2812cf26c38 888 cnt_findhome = 0;
Lightvalve 67:c2812cf26c38 889 pos.ref = 0.0f;
Lightvalve 67:c2812cf26c38 890 vel.ref = 0.0f;
Lightvalve 67:c2812cf26c38 891 pos.ref_home_pos = 0.0f;
Lightvalve 67:c2812cf26c38 892 vel.ref_home_pos = 0.0f;
Lightvalve 67:c2812cf26c38 893 //FINDHOME_STAGE = FINDHOME_INIT;
Lightvalve 67:c2812cf26c38 894 //CONTROL_UTILITY_MODE = MODE_JOINT_CONTROL;
Lightvalve 67:c2812cf26c38 895
Lightvalve 67:c2812cf26c38 896
Lightvalve 29:69f3f5445d6d 897 }
Lightvalve 29:69f3f5445d6d 898 } else if (FINDHOME_STAGE == FINDHOME_ZEROPOSE) {
Lightvalve 29:69f3f5445d6d 899 int T_move = 2*TMR_FREQ_5k;
Lightvalve 59:f308b1656d9c 900 pos.ref = (0.0f - (float)INIT_REF_POS)*0.5f*(1.0f - cos(3.14159f * (float)cnt_findhome / (float)T_move)) + (float)INIT_REF_POS;
Lightvalve 67:c2812cf26c38 901 //pos.ref = 0.0f;
Lightvalve 59:f308b1656d9c 902 vel.ref = 0.0f;
Lightvalve 67:c2812cf26c38 903
Lightvalve 29:69f3f5445d6d 904 // input for position control
Lightvalve 67:c2812cf26c38 905
Lightvalve 67:c2812cf26c38 906 // CONTROL_MODE = MODE_JOINT_CONTROL;
Lightvalve 67:c2812cf26c38 907 alpha_trans = 0.0f;
Lightvalve 61:bc8c8270f0ab 908
Lightvalve 67:c2812cf26c38 909 double torq_ref = 0.0f;
Lightvalve 67:c2812cf26c38 910 pos.err = (pos.ref - pos.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm]
Lightvalve 67:c2812cf26c38 911 vel.err = (0.0f - vel.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm/s]
Lightvalve 67:c2812cf26c38 912 pos.err_sum += pos.err/(float) TMR_FREQ_5k; //[mm]
Lightvalve 67:c2812cf26c38 913
Lightvalve 67:c2812cf26c38 914 if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) {
Lightvalve 67:c2812cf26c38 915
Lightvalve 67:c2812cf26c38 916 double I_REF_POS = 0.0f;
Lightvalve 67:c2812cf26c38 917 double I_REF_FORCE_FB = 0.0f; // I_REF by Force Feedback
Lightvalve 67:c2812cf26c38 918 double I_REF_VC = 0.0f; // I_REF for velocity compensation
Lightvalve 67:c2812cf26c38 919
Lightvalve 67:c2812cf26c38 920 double temp_vel_pos = 0.0f;
Lightvalve 67:c2812cf26c38 921 double temp_vel_torq = 0.0f;
Lightvalve 67:c2812cf26c38 922 double wn_Pos = 2.0f * PI * 5.0f; // f_cut : 5Hz Position Control
Lightvalve 67:c2812cf26c38 923
Lightvalve 67:c2812cf26c38 924 if ((OPERATING_MODE && 0x01) == 0) { // Rotary Mode
Lightvalve 67:c2812cf26c38 925 temp_vel_pos = (0.01f * (double) P_GAIN_JOINT_POSITION * wn_Pos * pos.err + 0.01f * (double) I_GAIN_JOINT_POSITION * wn_Pos * pos.err_sum + 0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / ENC_PULSE_PER_POSITION) * 3.14159f / 180.0f; // rad/s
Lightvalve 67:c2812cf26c38 926 // L when P-gain = 100, f_cut = 10Hz L feedforward velocity
Lightvalve 67:c2812cf26c38 927 } else if ((OPERATING_MODE && 0x01) == 1) {
Lightvalve 67:c2812cf26c38 928 temp_vel_pos = (0.01f * (double) P_GAIN_JOINT_POSITION * wn_Pos * pos.err + 0.01f * (double) I_GAIN_JOINT_POSITION * wn_Pos * pos.err_sum + 0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / ENC_PULSE_PER_POSITION); // mm/s
Lightvalve 67:c2812cf26c38 929 // L when P-gain = 100, f_cut = 10Hz L feedforward velocity
Lightvalve 67:c2812cf26c38 930 }
Lightvalve 67:c2812cf26c38 931 if (temp_vel_pos > 0.0f) I_REF_POS = temp_vel_pos * ((double) PISTON_AREA_A * 0.00006f / (K_v * sqrt(2.0f * alpha3 / (alpha3 + 1.0f))));
Lightvalve 67:c2812cf26c38 932 else I_REF_POS = temp_vel_pos * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f))));
Lightvalve 67:c2812cf26c38 933
Lightvalve 67:c2812cf26c38 934 I_REF = I_REF_POS;
Lightvalve 67:c2812cf26c38 935
Lightvalve 67:c2812cf26c38 936
Lightvalve 67:c2812cf26c38 937
Lightvalve 67:c2812cf26c38 938 } else {
Lightvalve 67:c2812cf26c38 939 float VALVE_POS_RAW_FORCE_FB = 0.0f;
Lightvalve 67:c2812cf26c38 940 VALVE_POS_RAW_FORCE_FB = DDV_JOINT_POS_FF(vel.sen) + (P_GAIN_JOINT_POSITION * 0.01f * pos.err + DDV_JOINT_POS_FF(vel.ref));
Lightvalve 67:c2812cf26c38 941
Lightvalve 67:c2812cf26c38 942 if (VALVE_POS_RAW_FORCE_FB >= 0) {
Lightvalve 67:c2812cf26c38 943 valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_PLUS;
Lightvalve 67:c2812cf26c38 944 } else {
Lightvalve 67:c2812cf26c38 945 valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_MINUS;
Lightvalve 67:c2812cf26c38 946 }
Lightvalve 67:c2812cf26c38 947
Lightvalve 67:c2812cf26c38 948 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 67:c2812cf26c38 949
Lightvalve 67:c2812cf26c38 950 V_out = (float) Vout.ref;
Lightvalve 67:c2812cf26c38 951
Lightvalve 67:c2812cf26c38 952 }
Lightvalve 67:c2812cf26c38 953
Lightvalve 67:c2812cf26c38 954
Lightvalve 67:c2812cf26c38 955
Lightvalve 67:c2812cf26c38 956
Lightvalve 59:f308b1656d9c 957 // pos.err = pos.ref - (float)pos.sen;
Lightvalve 59:f308b1656d9c 958 // float VALVE_POS_RAW_POS_FB = 0.0f;
Lightvalve 59:f308b1656d9c 959 // VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * 0.01f * pos.err/(float) ENC_PULSE_PER_POSITION;
Lightvalve 59:f308b1656d9c 960 // valve_pos.ref = VALVE_POS_RAW_POS_FB + (float) VALVE_CENTER;
Lightvalve 59:f308b1656d9c 961 // VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 29:69f3f5445d6d 962
Lightvalve 29:69f3f5445d6d 963 cnt_findhome++;
Lightvalve 29:69f3f5445d6d 964 if (cnt_findhome >= T_move) {
Lightvalve 29:69f3f5445d6d 965 //REFERENCE_MODE = MODE_REF_DIRECT;
Lightvalve 29:69f3f5445d6d 966 cnt_findhome = 0;
Lightvalve 30:8d561f16383b 967 pos.ref = 0.0f;
Lightvalve 30:8d561f16383b 968 vel.ref = 0.0f;
Lightvalve 30:8d561f16383b 969 pos.ref_home_pos = 0.0f;
Lightvalve 30:8d561f16383b 970 vel.ref_home_pos = 0.0f;
Lightvalve 29:69f3f5445d6d 971 FINDHOME_STAGE = FINDHOME_INIT;
Lightvalve 57:f4819de54e7a 972 CONTROL_UTILITY_MODE = MODE_JOINT_CONTROL;
Lightvalve 29:69f3f5445d6d 973 }
Lightvalve 13:747daba9cf59 974 }
Lightvalve 19:23b7c1ad8683 975
Lightvalve 13:747daba9cf59 976 break;
Lightvalve 13:747daba9cf59 977 }
Lightvalve 14:8e7590227d22 978
Lightvalve 50:3c630b5eba9f 979 // case MODE_VALVE_GAIN_SETTING: {
Lightvalve 50:3c630b5eba9f 980 // if (TMR3_COUNT_FLOWRATE == 0) {
Lightvalve 50:3c630b5eba9f 981 // if (pos_plus_end == pos_minus_end) need_enc_init = true;
Lightvalve 50:3c630b5eba9f 982 // else {
Lightvalve 50:3c630b5eba9f 983 // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 50:3c630b5eba9f 984 // temp_time = (int) (0.5f * (float) TMR_FREQ_5k);
Lightvalve 50:3c630b5eba9f 985 // }
Lightvalve 50:3c630b5eba9f 986 // }
Lightvalve 50:3c630b5eba9f 987 // if (need_enc_init) {
Lightvalve 50:3c630b5eba9f 988 // if (TMR3_COUNT_FLOWRATE < (int) (0.5f * (float) TMR_FREQ_5k)) {
Lightvalve 50:3c630b5eba9f 989 // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 50:3c630b5eba9f 990 // pos_plus_end = pos.sen;
Lightvalve 50:3c630b5eba9f 991 // } else if (TMR3_COUNT_FLOWRATE < TMR_FREQ_5k) {
Lightvalve 50:3c630b5eba9f 992 // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 50:3c630b5eba9f 993 // pos_minus_end = pos.sen;
Lightvalve 50:3c630b5eba9f 994 // } else if (TMR3_COUNT_FLOWRATE == TMR_FREQ_5k) {
Lightvalve 50:3c630b5eba9f 995 // need_enc_init = false;
Lightvalve 50:3c630b5eba9f 996 // check_vel_pos_init = (int) (0.9f * (float) (pos_plus_end - pos_minus_end));
Lightvalve 50:3c630b5eba9f 997 // check_vel_pos_fin = (int) (0.95f * (float) (pos_plus_end - pos_minus_end));
Lightvalve 50:3c630b5eba9f 998 // check_vel_pos_interv = check_vel_pos_fin - check_vel_pos_init;
Lightvalve 50:3c630b5eba9f 999 // }
Lightvalve 50:3c630b5eba9f 1000 // temp_time = TMR_FREQ_5k;
Lightvalve 50:3c630b5eba9f 1001 // }
Lightvalve 50:3c630b5eba9f 1002 // TMR3_COUNT_FLOWRATE++;
Lightvalve 50:3c630b5eba9f 1003 // if (TMR3_COUNT_FLOWRATE > temp_time) {
Lightvalve 50:3c630b5eba9f 1004 // if (flag_flowrate % 2 == 0) { // (+)
Lightvalve 50:3c630b5eba9f 1005 // VALVE_VOLTAGE = 1000.0f * (float) (flag_flowrate / 2 + 1);
Lightvalve 50:3c630b5eba9f 1006 // V_out = VALVE_VOLTAGE;
Lightvalve 50:3c630b5eba9f 1007 // if (pos.sen > (pos_minus_end + check_vel_pos_init) && pos.sen < (pos_minus_end + check_vel_pos_fin)) {
Lightvalve 50:3c630b5eba9f 1008 // fl_temp_cnt++;
Lightvalve 50:3c630b5eba9f 1009 // } else if (pos.sen >= (pos_minus_end + check_vel_pos_fin) && CUR_VELOCITY == 0) {
Lightvalve 50:3c630b5eba9f 1010 // VALVE_GAIN_LPM_PER_V[flag_flowrate] = 0.95873f * 0.5757f * (float) TMR_FREQ_5k / 10000.0 * (float) check_vel_pos_interv / (float) fl_temp_cnt / VALVE_VOLTAGE; // 0.9587=6*pi/65536*10000 0.5757=0.02525*0.02*0.0095*2*60*1000
Lightvalve 50:3c630b5eba9f 1011 // // VALVE_GAIN_LPM_PER_V[flag_flowrate] = (float) TMR_FREQ_10k * (float) check_vel_pos_interv / (float) fl_temp_cnt / VALVE_VOLTAGE; // PULSE/sec
Lightvalve 50:3c630b5eba9f 1012 // fl_temp_cnt2++;
Lightvalve 50:3c630b5eba9f 1013 // }
Lightvalve 50:3c630b5eba9f 1014 // } else if (flag_flowrate % 2 == 1) { // (-)
Lightvalve 50:3c630b5eba9f 1015 // VALVE_VOLTAGE = -1. * (float) (flag_flowrate / 2 + 1);
Lightvalve 50:3c630b5eba9f 1016 // V_out = VALVE_VOLTAGE;
Lightvalve 50:3c630b5eba9f 1017 // if (pos.sen < (pos_plus_end - check_vel_pos_init) && pos.sen > (pos_plus_end - check_vel_pos_fin)) {
Lightvalve 50:3c630b5eba9f 1018 // fl_temp_cnt++;
Lightvalve 50:3c630b5eba9f 1019 // } else if (pos.sen <= (pos_plus_end - check_vel_pos_fin) && CUR_VELOCITY == 0) {
Lightvalve 50:3c630b5eba9f 1020 // VALVE_GAIN_LPM_PER_V[flag_flowrate] = 0.95873f * 0.5757f * (float) TMR_FREQ_5k / 10000.0f * (float) check_vel_pos_interv / (float) fl_temp_cnt / (-VALVE_VOLTAGE);
Lightvalve 50:3c630b5eba9f 1021 // // VALVE_GAIN_LPM_PER_V[flag_flowrate] = (float) TMR_FREQ_10k * (float) check_vel_pos_interv / (float) fl_temp_cnt / (-VALVE_VOLTAGE); // PULSE/sec
Lightvalve 50:3c630b5eba9f 1022 // fl_temp_cnt2++;
Lightvalve 50:3c630b5eba9f 1023 // }
Lightvalve 50:3c630b5eba9f 1024 // }
Lightvalve 50:3c630b5eba9f 1025 // if (fl_temp_cnt2 == 100) {
Lightvalve 50:3c630b5eba9f 1026 //
Lightvalve 50:3c630b5eba9f 1027 // ROM_RESET_DATA();
Lightvalve 50:3c630b5eba9f 1028 //
Lightvalve 50:3c630b5eba9f 1029 // //spi_eeprom_write(RID_VALVE_GAIN_PLUS_1 + flag_flowrate, (int16_t) (VALVE_GAIN_LPM_PER_V[flag_flowrate] * 100.0f));
Lightvalve 50:3c630b5eba9f 1030 // cur_vel_sum = 0;
Lightvalve 50:3c630b5eba9f 1031 // fl_temp_cnt = 0;
Lightvalve 50:3c630b5eba9f 1032 // fl_temp_cnt2 = 0;
Lightvalve 50:3c630b5eba9f 1033 // flag_flowrate++;
Lightvalve 50:3c630b5eba9f 1034 // }
Lightvalve 50:3c630b5eba9f 1035 // if (flag_flowrate == 10) {
Lightvalve 50:3c630b5eba9f 1036 // V_out = 0;
Lightvalve 50:3c630b5eba9f 1037 // flag_flowrate = 0;
Lightvalve 50:3c630b5eba9f 1038 // TMR3_COUNT_FLOWRATE = 0;
Lightvalve 50:3c630b5eba9f 1039 // valve_gain_repeat_cnt++;
Lightvalve 50:3c630b5eba9f 1040 // if (valve_gain_repeat_cnt >= 1) {
Lightvalve 50:3c630b5eba9f 1041 // CONTROL_MODE = MODE_NO_ACT;
Lightvalve 50:3c630b5eba9f 1042 // valve_gain_repeat_cnt = 0;
Lightvalve 50:3c630b5eba9f 1043 // }
Lightvalve 50:3c630b5eba9f 1044 //
Lightvalve 50:3c630b5eba9f 1045 // }
Lightvalve 50:3c630b5eba9f 1046 // break;
Lightvalve 50:3c630b5eba9f 1047 // }
Lightvalve 50:3c630b5eba9f 1048 //
Lightvalve 50:3c630b5eba9f 1049 // }
Lightvalve 14:8e7590227d22 1050 case MODE_PRESSURE_SENSOR_NULLING: {
Lightvalve 13:747daba9cf59 1051 // DAC Voltage reference set
Lightvalve 14:8e7590227d22 1052 if (TMR3_COUNT_PRES_NULL < TMR_FREQ_5k * 2) {
Lightvalve 14:8e7590227d22 1053 CUR_PRES_A_sum += pres_A.sen;
Lightvalve 14:8e7590227d22 1054 CUR_PRES_B_sum += pres_B.sen;
Lightvalve 14:8e7590227d22 1055
Lightvalve 14:8e7590227d22 1056 if (TMR3_COUNT_PRES_NULL % 10 == 0) {
Lightvalve 30:8d561f16383b 1057 CUR_PRES_A_mean = CUR_PRES_A_sum / 10.0f;
Lightvalve 30:8d561f16383b 1058 CUR_PRES_B_mean = CUR_PRES_B_sum / 10.0f;
Lightvalve 13:747daba9cf59 1059 CUR_PRES_A_sum = 0;
Lightvalve 13:747daba9cf59 1060 CUR_PRES_B_sum = 0;
Lightvalve 14:8e7590227d22 1061
Lightvalve 38:118df027d851 1062 float VREF_NullingGain = 0.0003f;
Lightvalve 58:2eade98630e2 1063 PRES_A_VREF = PRES_A_VREF + VREF_NullingGain * CUR_PRES_A_mean;
Lightvalve 58:2eade98630e2 1064 PRES_B_VREF = PRES_B_VREF + VREF_NullingGain * CUR_PRES_B_mean;
Lightvalve 14:8e7590227d22 1065
Lightvalve 30:8d561f16383b 1066 if (PRES_A_VREF > 3.3f) PRES_A_VREF = 3.3f;
Lightvalve 30:8d561f16383b 1067 if (PRES_A_VREF < 0.0f) PRES_A_VREF = 0.0f;
Lightvalve 30:8d561f16383b 1068 if (PRES_B_VREF > 3.3f) PRES_B_VREF = 3.3f;
Lightvalve 30:8d561f16383b 1069 if (PRES_B_VREF < 0.0f) PRES_B_VREF = 0.0f;
Lightvalve 19:23b7c1ad8683 1070
Lightvalve 30:8d561f16383b 1071 dac_1 = PRES_A_VREF / 3.3f;
Lightvalve 30:8d561f16383b 1072 dac_2 = PRES_B_VREF / 3.3f;
Lightvalve 13:747daba9cf59 1073 }
Lightvalve 13:747daba9cf59 1074 } else {
Lightvalve 57:f4819de54e7a 1075 CONTROL_UTILITY_MODE = MODE_NO_ACT;
Lightvalve 14:8e7590227d22 1076 TMR3_COUNT_PRES_NULL = 0;
Lightvalve 13:747daba9cf59 1077 CUR_PRES_A_sum = 0;
Lightvalve 13:747daba9cf59 1078 CUR_PRES_B_sum = 0;
Lightvalve 13:747daba9cf59 1079 CUR_PRES_A_mean = 0;
Lightvalve 13:747daba9cf59 1080 CUR_PRES_B_mean = 0;
Lightvalve 14:8e7590227d22 1081
Lightvalve 16:903b5a4433b4 1082 ROM_RESET_DATA();
Lightvalve 19:23b7c1ad8683 1083
Lightvalve 30:8d561f16383b 1084 dac_1 = PRES_A_VREF / 3.3f;
Lightvalve 30:8d561f16383b 1085 dac_2 = PRES_B_VREF / 3.3f;
Lightvalve 17:1865016ca2e7 1086 //pc.printf("nulling end");
Lightvalve 13:747daba9cf59 1087 }
Lightvalve 14:8e7590227d22 1088 TMR3_COUNT_PRES_NULL++;
Lightvalve 13:747daba9cf59 1089 break;
Lightvalve 13:747daba9cf59 1090 }
Lightvalve 14:8e7590227d22 1091
Lightvalve 50:3c630b5eba9f 1092 // case MODE_PRESSURE_SENSOR_CALIB: {
Lightvalve 50:3c630b5eba9f 1093 // if (TMR3_COUNT_PRES_CALIB < 2 * TMR_FREQ_5k) {
Lightvalve 50:3c630b5eba9f 1094 // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 50:3c630b5eba9f 1095 // if (TMR3_COUNT_PRES_CALIB >= TMR_FREQ_5k) {
Lightvalve 50:3c630b5eba9f 1096 // CUR_PRES_A_sum += CUR_PRES_A;
Lightvalve 50:3c630b5eba9f 1097 // }
Lightvalve 50:3c630b5eba9f 1098 // } else if (TMR3_COUNT_PRES_CALIB < 4 * TMR_FREQ_5k) {
Lightvalve 50:3c630b5eba9f 1099 // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 50:3c630b5eba9f 1100 // if (TMR3_COUNT_PRES_CALIB >= 3 * TMR_FREQ_5k) {
Lightvalve 50:3c630b5eba9f 1101 // CUR_PRES_B_sum += CUR_PRES_B;
Lightvalve 50:3c630b5eba9f 1102 // }
Lightvalve 50:3c630b5eba9f 1103 // } else {
Lightvalve 50:3c630b5eba9f 1104 // CONTROL_MODE = MODE_NO_ACT;
Lightvalve 50:3c630b5eba9f 1105 // TMR3_COUNT_PRES_CALIB = 0;
Lightvalve 50:3c630b5eba9f 1106 // V_out = 0;
Lightvalve 50:3c630b5eba9f 1107 // PRES_SENSOR_A_PULSE_PER_BAR = CUR_PRES_A_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_A_NULL;
Lightvalve 50:3c630b5eba9f 1108 // PRES_SENSOR_A_PULSE_PER_BAR = PRES_SENSOR_A_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f);
Lightvalve 50:3c630b5eba9f 1109 // PRES_SENSOR_B_PULSE_PER_BAR = CUR_PRES_B_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_B_NULL;
Lightvalve 50:3c630b5eba9f 1110 // PRES_SENSOR_B_PULSE_PER_BAR = PRES_SENSOR_B_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f);
Lightvalve 50:3c630b5eba9f 1111 // CUR_PRES_A_sum = 0;
Lightvalve 50:3c630b5eba9f 1112 // CUR_PRES_B_sum = 0;
Lightvalve 50:3c630b5eba9f 1113 // CUR_PRES_A_mean = 0;
Lightvalve 50:3c630b5eba9f 1114 // CUR_PRES_B_mean = 0;
Lightvalve 50:3c630b5eba9f 1115 //
Lightvalve 50:3c630b5eba9f 1116 // ROM_RESET_DATA();
Lightvalve 50:3c630b5eba9f 1117 //
Lightvalve 50:3c630b5eba9f 1118 // //spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f));
Lightvalve 50:3c630b5eba9f 1119 // //spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f));
Lightvalve 50:3c630b5eba9f 1120 // }
Lightvalve 50:3c630b5eba9f 1121 // TMR3_COUNT_PRES_CALIB++;
Lightvalve 50:3c630b5eba9f 1122 // break;
Lightvalve 50:3c630b5eba9f 1123 // }
Lightvalve 19:23b7c1ad8683 1124
Lightvalve 50:3c630b5eba9f 1125 // case MODE_ROTARY_FRICTION_TUNING: {
Lightvalve 50:3c630b5eba9f 1126 // if (TMR3_COUNT_ROTARY_FRIC_TUNE % (5 * TMR_FREQ_5k) == 0) freq_fric_tune = 4.0f + 3.0f * sin(2 * 3.14159f * 0.5f * TMR3_COUNT_ROTARY_FRIC_TUNE * 0.0001f * 0.05f);
Lightvalve 50:3c630b5eba9f 1127 // V_out = PWM_out * sin(2 * 3.14159f * freq_fric_tune * TMR3_COUNT_ROTARY_FRIC_TUNE * 0.0001f);
Lightvalve 50:3c630b5eba9f 1128 // if (V_out > 0) V_out = VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 50:3c630b5eba9f 1129 // else V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 50:3c630b5eba9f 1130 // TMR3_COUNT_ROTARY_FRIC_TUNE++;
Lightvalve 50:3c630b5eba9f 1131 // if (TMR3_COUNT_ROTARY_FRIC_TUNE > TUNING_TIME * TMR_FREQ_5k) {
Lightvalve 50:3c630b5eba9f 1132 // TMR3_COUNT_ROTARY_FRIC_TUNE = 0;
Lightvalve 50:3c630b5eba9f 1133 // V_out = 0.0f;
Lightvalve 50:3c630b5eba9f 1134 // CONTROL_MODE = MODE_NO_ACT;
Lightvalve 50:3c630b5eba9f 1135 // }
Lightvalve 50:3c630b5eba9f 1136 // break;
Lightvalve 50:3c630b5eba9f 1137 // }
Lightvalve 14:8e7590227d22 1138
Lightvalve 14:8e7590227d22 1139 case MODE_DDV_POS_VS_PWM_ID: {
Lightvalve 59:f308b1656d9c 1140 CONTROL_MODE = MODE_VALVE_OPEN_LOOP;
Lightvalve 13:747daba9cf59 1141 VALVE_ID_timer = VALVE_ID_timer + 1;
Lightvalve 14:8e7590227d22 1142
Lightvalve 14:8e7590227d22 1143 if(VALVE_ID_timer < TMR_FREQ_5k*1) {
Lightvalve 60:64181f1d3e60 1144 Vout.ref = 3000.0f * sin(2.0f*3.14f*VALVE_ID_timer/TMR_FREQ_5k * 100.0f);
Lightvalve 14:8e7590227d22 1145 } else if(VALVE_ID_timer < TMR_FREQ_5k*2) {
Lightvalve 59:f308b1656d9c 1146 Vout.ref = 1000.0f*(ID_index_array[ID_index]);
Lightvalve 14:8e7590227d22 1147 } else if(VALVE_ID_timer == TMR_FREQ_5k*2) {
Lightvalve 13:747daba9cf59 1148 VALVE_POS_TMP = 0;
Lightvalve 13:747daba9cf59 1149 data_num = 0;
Lightvalve 14:8e7590227d22 1150 } else if(VALVE_ID_timer < TMR_FREQ_5k*3) {
Lightvalve 13:747daba9cf59 1151 data_num = data_num + 1;
Lightvalve 13:747daba9cf59 1152 VALVE_POS_TMP = VALVE_POS_TMP + value;
Lightvalve 14:8e7590227d22 1153 } else if(VALVE_ID_timer == TMR_FREQ_5k*3) {
Lightvalve 59:f308b1656d9c 1154 Vout.ref = 0.0f;
Lightvalve 59:f308b1656d9c 1155 } else {
Lightvalve 13:747daba9cf59 1156 VALVE_POS_AVG[ID_index] = VALVE_POS_TMP / data_num;
Lightvalve 13:747daba9cf59 1157 VALVE_ID_timer = 0;
Lightvalve 13:747daba9cf59 1158 ID_index= ID_index +1;
Lightvalve 13:747daba9cf59 1159 }
Lightvalve 14:8e7590227d22 1160
Lightvalve 17:1865016ca2e7 1161 if(ID_index>=25) {
Lightvalve 13:747daba9cf59 1162 int i;
Lightvalve 13:747daba9cf59 1163 VALVE_POS_AVG_OLD = VALVE_POS_AVG[0];
Lightvalve 17:1865016ca2e7 1164 for(i=0; i<25; i++) {
Lightvalve 13:747daba9cf59 1165 VALVE_POS_VS_PWM[i] = (int16_t) (VALVE_POS_AVG[i]);
Lightvalve 14:8e7590227d22 1166 if(VALVE_POS_AVG[i] > VALVE_POS_AVG_OLD) {
Lightvalve 13:747daba9cf59 1167 VALVE_MAX_POS = VALVE_POS_AVG[i];
Lightvalve 13:747daba9cf59 1168 VALVE_POS_AVG_OLD = VALVE_MAX_POS;
Lightvalve 14:8e7590227d22 1169 } else if(VALVE_POS_AVG[i] < VALVE_POS_AVG_OLD) {
Lightvalve 13:747daba9cf59 1170 VALVE_MIN_POS = VALVE_POS_AVG[i];
Lightvalve 13:747daba9cf59 1171 VALVE_POS_AVG_OLD = VALVE_MIN_POS;
Lightvalve 13:747daba9cf59 1172 }
Lightvalve 13:747daba9cf59 1173 }
Lightvalve 59:f308b1656d9c 1174 ROM_RESET_DATA();
Lightvalve 13:747daba9cf59 1175 ID_index = 0;
Lightvalve 57:f4819de54e7a 1176 CONTROL_UTILITY_MODE = MODE_NO_ACT;
Lightvalve 13:747daba9cf59 1177 }
Lightvalve 14:8e7590227d22 1178
Lightvalve 14:8e7590227d22 1179
Lightvalve 13:747daba9cf59 1180 break;
Lightvalve 13:747daba9cf59 1181 }
Lightvalve 14:8e7590227d22 1182
Lightvalve 14:8e7590227d22 1183 case MODE_DDV_DEADZONE_AND_CENTER: {
Lightvalve 59:f308b1656d9c 1184 CONTROL_MODE = MODE_VALVE_OPEN_LOOP;
Lightvalve 13:747daba9cf59 1185 VALVE_DZ_timer = VALVE_DZ_timer + 1;
Lightvalve 14:8e7590227d22 1186 if(first_check == 0) {
Lightvalve 30:8d561f16383b 1187 if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1188 Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 30:8d561f16383b 1189 } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1190 Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 14:8e7590227d22 1191 pos_plus_end = pos.sen;
Lightvalve 30:8d561f16383b 1192 } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1193 Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 30:8d561f16383b 1194 } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1195 Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 14:8e7590227d22 1196 pos_minus_end = pos.sen;
Lightvalve 30:8d561f16383b 1197 } else if(VALVE_DZ_timer < (int) (3.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1198 Vout.ref = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen)/(float) ENC_PULSE_PER_POSITION;
Lightvalve 30:8d561f16383b 1199 } else if(VALVE_DZ_timer < (int) (4.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1200 Vout.ref = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen)/(float) ENC_PULSE_PER_POSITION;
Lightvalve 13:747daba9cf59 1201 data_num = data_num + 1;
Lightvalve 13:747daba9cf59 1202 VALVE_POS_TMP = VALVE_POS_TMP + value;
Lightvalve 30:8d561f16383b 1203 } else if(VALVE_DZ_timer == (int) (4.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1204 Vout.ref = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen)/(float) ENC_PULSE_PER_POSITION;
Lightvalve 13:747daba9cf59 1205 DDV_POS_AVG = VALVE_POS_TMP / data_num;
Lightvalve 14:8e7590227d22 1206 START_POS = pos.sen;
Lightvalve 13:747daba9cf59 1207 VALVE_POS_TMP = 0;
Lightvalve 13:747daba9cf59 1208 data_num = 0;
Lightvalve 14:8e7590227d22 1209
Lightvalve 30:8d561f16383b 1210 } else if(VALVE_DZ_timer < (int) (5.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1211 valve_pos.ref = DDV_POS_AVG;
Lightvalve 14:8e7590227d22 1212 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 14:8e7590227d22 1213
Lightvalve 30:8d561f16383b 1214 } else if(VALVE_DZ_timer < (int) (6.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1215 valve_pos.ref = DDV_POS_AVG;
Lightvalve 14:8e7590227d22 1216 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 60:64181f1d3e60 1217
Lightvalve 30:8d561f16383b 1218 } else if(VALVE_DZ_timer == (int) (6.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1219 valve_pos.ref = DDV_POS_AVG;
Lightvalve 14:8e7590227d22 1220 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 14:8e7590227d22 1221 FINAL_POS = pos.sen;
Lightvalve 14:8e7590227d22 1222
Lightvalve 60:64181f1d3e60 1223 if((FINAL_POS - START_POS)>200) {
Lightvalve 13:747daba9cf59 1224 DZ_case = 1;
Lightvalve 60:64181f1d3e60 1225 } else if((FINAL_POS - START_POS)<-200) {
Lightvalve 13:747daba9cf59 1226 DZ_case = -1;
Lightvalve 14:8e7590227d22 1227 } else {
Lightvalve 13:747daba9cf59 1228 DZ_case = 0;
Lightvalve 13:747daba9cf59 1229 }
Lightvalve 61:bc8c8270f0ab 1230
Lightvalve 60:64181f1d3e60 1231 CAN_TX_PRES((int16_t) (DZ_case), (int16_t) (6));
Lightvalve 50:3c630b5eba9f 1232
Lightvalve 13:747daba9cf59 1233 first_check = 1;
Lightvalve 13:747daba9cf59 1234 DZ_DIRECTION = 1;
Lightvalve 13:747daba9cf59 1235 VALVE_DZ_timer = 0;
Lightvalve 13:747daba9cf59 1236 Ref_Valve_Pos_Old = DDV_POS_AVG;
Lightvalve 13:747daba9cf59 1237 DZ_NUM = 1;
Lightvalve 13:747daba9cf59 1238 DZ_index = 1;
Lightvalve 14:8e7590227d22 1239
Lightvalve 13:747daba9cf59 1240 }
Lightvalve 19:23b7c1ad8683 1241 } else {
Lightvalve 14:8e7590227d22 1242 if((DZ_case == -1 && DZ_NUM == 1) | (DZ_case == 1 && DZ_NUM == 1)) {
Lightvalve 30:8d561f16383b 1243 if(VALVE_DZ_timer < (int) (1.0 * (float) TMR_FREQ_5k)) {
Lightvalve 60:64181f1d3e60 1244 Vout.ref = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen)/(float) ENC_PULSE_PER_POSITION;
Lightvalve 60:64181f1d3e60 1245 //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end;
Lightvalve 60:64181f1d3e60 1246 //CONTROL_MODE = MODE_JOINT_CONTROL;
Lightvalve 30:8d561f16383b 1247 } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1248 START_POS = pos.sen;
Lightvalve 30:8d561f16383b 1249 } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1250 valve_pos.ref = Ref_Valve_Pos_Old - DZ_case * DZ_DIRECTION * 64 / DZ_index;
Lightvalve 14:8e7590227d22 1251 if(valve_pos.ref <= VALVE_MIN_POS) {
Lightvalve 14:8e7590227d22 1252 valve_pos.ref = VALVE_MIN_POS;
Lightvalve 14:8e7590227d22 1253 } else if(valve_pos.ref >= VALVE_MAX_POS) {
Lightvalve 14:8e7590227d22 1254 valve_pos.ref = VALVE_MAX_POS;
Lightvalve 13:747daba9cf59 1255 }
Lightvalve 14:8e7590227d22 1256 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 60:64181f1d3e60 1257
Lightvalve 30:8d561f16383b 1258 } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1259 Ref_Valve_Pos_Old = valve_pos.ref;
Lightvalve 14:8e7590227d22 1260 FINAL_POS = pos.sen;
Lightvalve 14:8e7590227d22 1261
Lightvalve 14:8e7590227d22 1262 if((FINAL_POS - START_POS)>100) {
Lightvalve 14:8e7590227d22 1263 DZ_DIRECTION = 1 * DZ_case;
Lightvalve 14:8e7590227d22 1264 } else if((FINAL_POS - START_POS)<-100) {
Lightvalve 14:8e7590227d22 1265 DZ_DIRECTION = -1 * DZ_case;
Lightvalve 14:8e7590227d22 1266 } else {
Lightvalve 13:747daba9cf59 1267 DZ_DIRECTION = 1 * DZ_case;
Lightvalve 13:747daba9cf59 1268 }
Lightvalve 14:8e7590227d22 1269
Lightvalve 13:747daba9cf59 1270 VALVE_DZ_timer = 0;
Lightvalve 13:747daba9cf59 1271 DZ_index= DZ_index *2;
Lightvalve 14:8e7590227d22 1272 if(DZ_index >= 128) {
Lightvalve 14:8e7590227d22 1273 FIRST_DZ = valve_pos.ref;
Lightvalve 13:747daba9cf59 1274 DZ_NUM = 2;
Lightvalve 13:747daba9cf59 1275 Ref_Valve_Pos_Old = FIRST_DZ;
Lightvalve 13:747daba9cf59 1276 DZ_index = 1;
Lightvalve 13:747daba9cf59 1277 DZ_DIRECTION = 1;
Lightvalve 13:747daba9cf59 1278 }
Lightvalve 13:747daba9cf59 1279 }
Lightvalve 14:8e7590227d22 1280 } else if((DZ_case == -1 && DZ_NUM == 2) | (DZ_case == 1 && DZ_NUM == 2)) {
Lightvalve 30:8d561f16383b 1281 if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 60:64181f1d3e60 1282 Vout.ref = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen)/(float) ENC_PULSE_PER_POSITION;
Lightvalve 60:64181f1d3e60 1283 //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end;
Lightvalve 60:64181f1d3e60 1284 //CONTROL_MODE = MODE_JOINT_CONTROL;
Lightvalve 30:8d561f16383b 1285 } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1286 START_POS = pos.sen;
Lightvalve 30:8d561f16383b 1287 } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 60:64181f1d3e60 1288 valve_pos.ref = Ref_Valve_Pos_Old - DZ_case * DZ_DIRECTION * 64 / DZ_index;
Lightvalve 14:8e7590227d22 1289 if(valve_pos.ref <= VALVE_MIN_POS) {
Lightvalve 14:8e7590227d22 1290 valve_pos.ref = VALVE_MIN_POS;
Lightvalve 14:8e7590227d22 1291 } else if(valve_pos.ref >= VALVE_MAX_POS) {
Lightvalve 14:8e7590227d22 1292 valve_pos.ref = VALVE_MAX_POS;
Lightvalve 13:747daba9cf59 1293 }
Lightvalve 14:8e7590227d22 1294 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 61:bc8c8270f0ab 1295
Lightvalve 30:8d561f16383b 1296 } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1297 Vout.ref = 0.0f;
Lightvalve 59:f308b1656d9c 1298 } else if(VALVE_DZ_timer > (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1299 Ref_Valve_Pos_Old = valve_pos.ref;
Lightvalve 14:8e7590227d22 1300 FINAL_POS = pos.sen;
Lightvalve 14:8e7590227d22 1301
Lightvalve 14:8e7590227d22 1302 if((FINAL_POS - START_POS)>100) {
Lightvalve 60:64181f1d3e60 1303 DZ_DIRECTION = 1 * DZ_case;
Lightvalve 14:8e7590227d22 1304 } else if((FINAL_POS - START_POS)<-100) {
Lightvalve 60:64181f1d3e60 1305 DZ_DIRECTION = -1 * DZ_case;
Lightvalve 14:8e7590227d22 1306 } else {
Lightvalve 60:64181f1d3e60 1307 DZ_DIRECTION = -1 * DZ_case;
Lightvalve 13:747daba9cf59 1308 }
Lightvalve 14:8e7590227d22 1309
Lightvalve 13:747daba9cf59 1310 VALVE_DZ_timer = 0;
Lightvalve 60:64181f1d3e60 1311 DZ_index= DZ_index * 2;
Lightvalve 14:8e7590227d22 1312 if(DZ_index >= 128) {
Lightvalve 14:8e7590227d22 1313 SECOND_DZ = valve_pos.ref;
Lightvalve 57:f4819de54e7a 1314 VALVE_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ));
Lightvalve 13:747daba9cf59 1315 first_check = 0;
Lightvalve 33:91b17819ec30 1316 VALVE_DEADZONE_MINUS = (float) FIRST_DZ;
Lightvalve 33:91b17819ec30 1317 VALVE_DEADZONE_PLUS = (float) SECOND_DZ;
Lightvalve 19:23b7c1ad8683 1318
Lightvalve 16:903b5a4433b4 1319 ROM_RESET_DATA();
Lightvalve 34:bb2ca2fc2a8e 1320
Lightvalve 60:64181f1d3e60 1321 CONTROL_UTILITY_MODE = MODE_NO_ACT;
Lightvalve 13:747daba9cf59 1322 DZ_index = 1;
Lightvalve 13:747daba9cf59 1323 }
Lightvalve 13:747daba9cf59 1324 }
Lightvalve 14:8e7590227d22 1325 } else if(DZ_case == 0 && DZ_NUM ==1) {
Lightvalve 30:8d561f16383b 1326 if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 60:64181f1d3e60 1327 Vout.ref = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen)/(float) ENC_PULSE_PER_POSITION;
Lightvalve 60:64181f1d3e60 1328 //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end;
Lightvalve 60:64181f1d3e60 1329 //CONTROL_MODE = MODE_JOINT_CONTROL;
Lightvalve 30:8d561f16383b 1330 } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1331 START_POS = pos.sen;
Lightvalve 30:8d561f16383b 1332 } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1333 valve_pos.ref = Ref_Valve_Pos_Old - DZ_DIRECTION * 64 / DZ_index;
Lightvalve 14:8e7590227d22 1334 if(valve_pos.ref <= VALVE_MIN_POS) {
Lightvalve 14:8e7590227d22 1335 valve_pos.ref = VALVE_MIN_POS;
Lightvalve 14:8e7590227d22 1336 } else if(valve_pos.ref >= VALVE_MAX_POS) {
Lightvalve 14:8e7590227d22 1337 valve_pos.ref = VALVE_MAX_POS;
Lightvalve 13:747daba9cf59 1338 }
Lightvalve 14:8e7590227d22 1339 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 61:bc8c8270f0ab 1340
Lightvalve 30:8d561f16383b 1341 } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1342 Ref_Valve_Pos_Old = valve_pos.ref;
Lightvalve 14:8e7590227d22 1343 FINAL_POS = pos.sen;
Lightvalve 14:8e7590227d22 1344
Lightvalve 14:8e7590227d22 1345 if((FINAL_POS - START_POS)>100) {
Lightvalve 14:8e7590227d22 1346 DZ_DIRECTION = 1;
Lightvalve 14:8e7590227d22 1347 } else if((FINAL_POS - START_POS)<-100) {
Lightvalve 14:8e7590227d22 1348 DZ_DIRECTION = -1;
Lightvalve 14:8e7590227d22 1349 } else {
Lightvalve 13:747daba9cf59 1350 DZ_DIRECTION = 1;
Lightvalve 13:747daba9cf59 1351 }
Lightvalve 13:747daba9cf59 1352 VALVE_DZ_timer = 0;
Lightvalve 13:747daba9cf59 1353 DZ_index= DZ_index *2;
Lightvalve 14:8e7590227d22 1354 if(DZ_index >= 128) {
Lightvalve 14:8e7590227d22 1355 FIRST_DZ = valve_pos.ref;
Lightvalve 13:747daba9cf59 1356 DZ_NUM = 2;
Lightvalve 13:747daba9cf59 1357 Ref_Valve_Pos_Old = FIRST_DZ;
Lightvalve 13:747daba9cf59 1358 DZ_index = 1;
Lightvalve 13:747daba9cf59 1359 DZ_DIRECTION = 1;
Lightvalve 13:747daba9cf59 1360 }
Lightvalve 13:747daba9cf59 1361 }
Lightvalve 14:8e7590227d22 1362 } else {
Lightvalve 30:8d561f16383b 1363 if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 60:64181f1d3e60 1364 Vout.ref = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen)/(float) ENC_PULSE_PER_POSITION;
Lightvalve 60:64181f1d3e60 1365 //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end;
Lightvalve 60:64181f1d3e60 1366 //CONTROL_MODE = MODE_JOINT_CONTROL;
Lightvalve 30:8d561f16383b 1367 } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1368 START_POS = pos.sen;
Lightvalve 30:8d561f16383b 1369 } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1370 valve_pos.ref = Ref_Valve_Pos_Old + DZ_DIRECTION * 64 / DZ_index;
Lightvalve 14:8e7590227d22 1371 if(valve_pos.ref <= VALVE_MIN_POS) {
Lightvalve 14:8e7590227d22 1372 valve_pos.ref = VALVE_MIN_POS;
Lightvalve 14:8e7590227d22 1373 } else if(valve_pos.ref > VALVE_MAX_POS) {
Lightvalve 14:8e7590227d22 1374 valve_pos.ref = VALVE_MAX_POS - 1;
Lightvalve 13:747daba9cf59 1375 }
Lightvalve 14:8e7590227d22 1376 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 60:64181f1d3e60 1377
Lightvalve 30:8d561f16383b 1378 } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1379 Vout.ref = 0.0f;
Lightvalve 59:f308b1656d9c 1380 } else if(VALVE_DZ_timer > (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1381 Ref_Valve_Pos_Old = valve_pos.ref;
Lightvalve 14:8e7590227d22 1382 FINAL_POS = pos.sen;
Lightvalve 61:bc8c8270f0ab 1383
Lightvalve 60:64181f1d3e60 1384 if((FINAL_POS - START_POS)>100) {
Lightvalve 13:747daba9cf59 1385 DZ_DIRECTION = 1;
Lightvalve 60:64181f1d3e60 1386 } else if((FINAL_POS - START_POS)<-100) {
Lightvalve 60:64181f1d3e60 1387 DZ_DIRECTION = -1;
Lightvalve 60:64181f1d3e60 1388 } else {
Lightvalve 13:747daba9cf59 1389 DZ_DIRECTION = 1;
Lightvalve 60:64181f1d3e60 1390 }
Lightvalve 14:8e7590227d22 1391
Lightvalve 13:747daba9cf59 1392 VALVE_DZ_timer = 0;
Lightvalve 13:747daba9cf59 1393 DZ_index= DZ_index *2;
Lightvalve 14:8e7590227d22 1394 if(DZ_index >= 128) {
Lightvalve 14:8e7590227d22 1395 SECOND_DZ = valve_pos.ref;
Lightvalve 57:f4819de54e7a 1396 VALVE_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ));
Lightvalve 13:747daba9cf59 1397 first_check = 0;
Lightvalve 33:91b17819ec30 1398 VALVE_DEADZONE_MINUS = (float) FIRST_DZ;
Lightvalve 33:91b17819ec30 1399 VALVE_DEADZONE_PLUS = (float) SECOND_DZ;
Lightvalve 61:bc8c8270f0ab 1400
Lightvalve 59:f308b1656d9c 1401 ROM_RESET_DATA();
Lightvalve 34:bb2ca2fc2a8e 1402
Lightvalve 57:f4819de54e7a 1403 CONTROL_UTILITY_MODE = MODE_NO_ACT;
Lightvalve 13:747daba9cf59 1404 DZ_index = 1;
Lightvalve 13:747daba9cf59 1405 }
Lightvalve 13:747daba9cf59 1406 }
Lightvalve 13:747daba9cf59 1407 }
Lightvalve 14:8e7590227d22 1408 }
Lightvalve 13:747daba9cf59 1409 break;
Lightvalve 13:747daba9cf59 1410 }
Lightvalve 14:8e7590227d22 1411
Lightvalve 14:8e7590227d22 1412 case MODE_DDV_POS_VS_FLOWRATE: {
Lightvalve 59:f308b1656d9c 1413 CONTROL_MODE = MODE_VALVE_OPEN_LOOP;
Lightvalve 13:747daba9cf59 1414 VALVE_FR_timer = VALVE_FR_timer + 1;
Lightvalve 14:8e7590227d22 1415 if(first_check == 0) {
Lightvalve 30:8d561f16383b 1416 if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1417 Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 23:59218d4a256d 1418 //CAN_TX_PRES((int16_t) (VALVE_FR_timer), (int16_t) (6));
Lightvalve 30:8d561f16383b 1419 } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1420 Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 14:8e7590227d22 1421 pos_plus_end = pos.sen;
Lightvalve 14:8e7590227d22 1422 // CAN_TX_PRES((int16_t) (V_out), (int16_t) (7));
Lightvalve 30:8d561f16383b 1423 } else if(VALVE_FR_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1424 Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 30:8d561f16383b 1425 } else if(VALVE_FR_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1426 // CAN_TX_PRES((int16_t) (V_out), (int16_t) (8));
Lightvalve 59:f308b1656d9c 1427 Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f;
Lightvalve 14:8e7590227d22 1428 pos_minus_end = pos.sen;
Lightvalve 13:747daba9cf59 1429 first_check = 1;
Lightvalve 13:747daba9cf59 1430 VALVE_FR_timer = 0;
Lightvalve 57:f4819de54e7a 1431 valve_pos.ref = (float) VALVE_CENTER;
Lightvalve 13:747daba9cf59 1432 ID_index = 0;
Lightvalve 13:747daba9cf59 1433 max_check = 0;
Lightvalve 13:747daba9cf59 1434 min_check = 0;
Lightvalve 13:747daba9cf59 1435 }
Lightvalve 14:8e7590227d22 1436 } else {
Lightvalve 30:8d561f16383b 1437 if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 59:f308b1656d9c 1438 //V_out = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen)/(float) ENC_PULSE_PER_POSITION;
Lightvalve 59:f308b1656d9c 1439 pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end;
Lightvalve 59:f308b1656d9c 1440 CONTROL_MODE = MODE_JOINT_CONTROL;
Lightvalve 30:8d561f16383b 1441 } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
Lightvalve 13:747daba9cf59 1442 data_num = 0;
Lightvalve 57:f4819de54e7a 1443 valve_pos.ref = 10.0f*((float) ID_index_array[ID_index]) + (float) VALVE_CENTER;
Lightvalve 14:8e7590227d22 1444
Lightvalve 14:8e7590227d22 1445 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 14:8e7590227d22 1446 START_POS = pos.sen;
Lightvalve 30:8d561f16383b 1447 } else if(VALVE_FR_timer < (int) (5.0f * (float) TMR_FREQ_5k)) {
Lightvalve 57:f4819de54e7a 1448 valve_pos.ref = 10.0f*((float) ID_index_array[ID_index]) + (float) VALVE_CENTER;
Lightvalve 14:8e7590227d22 1449 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 13:747daba9cf59 1450 data_num = data_num + 1;
Lightvalve 30:8d561f16383b 1451 if(abs(0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen) > 20000.0f) {
Lightvalve 14:8e7590227d22 1452 FINAL_POS = pos.sen;
Lightvalve 14:8e7590227d22 1453 one_period_end = 1;
Lightvalve 13:747daba9cf59 1454 }
Lightvalve 30:8d561f16383b 1455 } else if(VALVE_FR_timer == (int) (5.0f * (float) TMR_FREQ_5k)) {
Lightvalve 14:8e7590227d22 1456 FINAL_POS = pos.sen;
Lightvalve 13:747daba9cf59 1457 one_period_end = 1;
Lightvalve 59:f308b1656d9c 1458 V_out = 0.0f;
Lightvalve 13:747daba9cf59 1459 }
Lightvalve 14:8e7590227d22 1460
Lightvalve 14:8e7590227d22 1461 if(one_period_end == 1) {
Lightvalve 14:8e7590227d22 1462 if(valve_pos.ref > VALVE_MAX_POS) {
Lightvalve 13:747daba9cf59 1463 max_check = 1;
Lightvalve 14:8e7590227d22 1464 } else if(valve_pos.ref < VALVE_MIN_POS) {
Lightvalve 13:747daba9cf59 1465 min_check = 1;
Lightvalve 13:747daba9cf59 1466 }
Lightvalve 13:747daba9cf59 1467 JOINT_VEL[ID_index] = (FINAL_POS - START_POS) / data_num * TMR_FREQ_5k; // pulse/sec
Lightvalve 19:23b7c1ad8683 1468
Lightvalve 13:747daba9cf59 1469 VALVE_FR_timer = 0;
Lightvalve 13:747daba9cf59 1470 one_period_end = 0;
Lightvalve 13:747daba9cf59 1471 ID_index= ID_index +1;
Lightvalve 30:8d561f16383b 1472 V_out = 0.0f;
Lightvalve 13:747daba9cf59 1473 }
Lightvalve 14:8e7590227d22 1474
Lightvalve 14:8e7590227d22 1475 if(max_check == 1 && min_check == 1) {
Lightvalve 19:23b7c1ad8683 1476
Lightvalve 13:747daba9cf59 1477 VALVE_POS_NUM = ID_index;
Lightvalve 59:f308b1656d9c 1478 ROM_RESET_DATA();
Lightvalve 13:747daba9cf59 1479 ID_index = 0;
Lightvalve 13:747daba9cf59 1480 first_check = 0;
Lightvalve 13:747daba9cf59 1481 VALVE_FR_timer = 0;
Lightvalve 57:f4819de54e7a 1482 CONTROL_UTILITY_MODE = MODE_NO_ACT;
Lightvalve 49:e7bcfc244d40 1483 // CAN_TX_PRES((int16_t) (VALVE_FR_timer), (int16_t) (6));
Lightvalve 13:747daba9cf59 1484 }
Lightvalve 13:747daba9cf59 1485 }
Lightvalve 13:747daba9cf59 1486 break;
Lightvalve 13:747daba9cf59 1487 }
Lightvalve 58:2eade98630e2 1488
Lightvalve 57:f4819de54e7a 1489 case MODE_SYSTEM_ID: {
Lightvalve 57:f4819de54e7a 1490 freq_sysid_Iref = (double) cnt_sysid * DT_TMR3 * 3.;
Lightvalve 57:f4819de54e7a 1491 valve_pos.ref = 2500.0f * sin(2.0f * 3.14159f * freq_sysid_Iref * (double) cnt_sysid * DT_TMR3);
Lightvalve 57:f4819de54e7a 1492 CONTROL_MODE = MODE_VALVE_OPEN_LOOP;
Lightvalve 57:f4819de54e7a 1493 cnt_sysid++;
Lightvalve 57:f4819de54e7a 1494 if (freq_sysid_Iref >= 300) {
Lightvalve 57:f4819de54e7a 1495 cnt_sysid = 0;
Lightvalve 57:f4819de54e7a 1496 CONTROL_UTILITY_MODE = MODE_NO_ACT;
Lightvalve 57:f4819de54e7a 1497 }
Lightvalve 57:f4819de54e7a 1498 break;
Lightvalve 57:f4819de54e7a 1499 }
Lightvalve 58:2eade98630e2 1500
Lightvalve 58:2eade98630e2 1501
Lightvalve 57:f4819de54e7a 1502
Lightvalve 57:f4819de54e7a 1503 default:
Lightvalve 57:f4819de54e7a 1504 break;
Lightvalve 57:f4819de54e7a 1505 }
Lightvalve 57:f4819de54e7a 1506
Lightvalve 57:f4819de54e7a 1507 // CONTROL MODE ------------------------------------------------------------
Lightvalve 57:f4819de54e7a 1508
Lightvalve 57:f4819de54e7a 1509 switch (CONTROL_MODE) {
Lightvalve 57:f4819de54e7a 1510 case MODE_NO_ACT: {
Lightvalve 57:f4819de54e7a 1511 V_out = 0.0f;
Lightvalve 57:f4819de54e7a 1512 break;
Lightvalve 57:f4819de54e7a 1513 }
Lightvalve 57:f4819de54e7a 1514
Lightvalve 57:f4819de54e7a 1515 case MODE_VALVE_POSITION_CONTROL: {
Lightvalve 67:c2812cf26c38 1516 if (OPERATING_MODE == 5) { //SW Valve
Lightvalve 57:f4819de54e7a 1517 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 59:f308b1656d9c 1518 V_out = Vout.ref;
Lightvalve 67:c2812cf26c38 1519 } else if (CURRENT_CONTROL_MODE == 0) { //PWM
Lightvalve 67:c2812cf26c38 1520 V_out = valve_pos.ref;
Lightvalve 67:c2812cf26c38 1521 } else {
Lightvalve 67:c2812cf26c38 1522 I_REF = valve_pos.ref * 0.001f;
Lightvalve 57:f4819de54e7a 1523 }
Lightvalve 58:2eade98630e2 1524
Lightvalve 57:f4819de54e7a 1525 break;
Lightvalve 57:f4819de54e7a 1526 }
Lightvalve 57:f4819de54e7a 1527
Lightvalve 57:f4819de54e7a 1528 case MODE_JOINT_CONTROL: {
Lightvalve 57:f4819de54e7a 1529 double torq_ref = 0.0f;
Lightvalve 57:f4819de54e7a 1530 pos.err = (pos.ref - pos.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm]
Lightvalve 67:c2812cf26c38 1531 vel.err = (0.0f - vel.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm/s]
Lightvalve 57:f4819de54e7a 1532 pos.err_sum += pos.err/(float) TMR_FREQ_5k; //[mm]
Lightvalve 67:c2812cf26c38 1533
Lightvalve 67:c2812cf26c38 1534 //K & D Low Pass Filter
Lightvalve 67:c2812cf26c38 1535 float alpha_K_D = 1.0f/(1.0f + 5000.0f/(2.0f*3.14f*30.0f)); // f_cutoff : 30Hz
Lightvalve 67:c2812cf26c38 1536 K_LPF = K_LPF*(1.0f-alpha_K_D)+K_SPRING*(alpha_K_D);
Lightvalve 67:c2812cf26c38 1537 D_LPF = D_LPF*(1.0f-alpha_K_D)+D_DAMPER*(alpha_K_D);
Lightvalve 67:c2812cf26c38 1538
Lightvalve 67:c2812cf26c38 1539 torq_ref = torq.ref + K_LPF * pos.err - D_LPF * vel.sen / ENC_PULSE_PER_POSITION; //[N]
Lightvalve 57:f4819de54e7a 1540
Lightvalve 57:f4819de54e7a 1541 // torque feedback
Lightvalve 67:c2812cf26c38 1542 torq.err = torq_ref - torq.sen; //[N]
Lightvalve 57:f4819de54e7a 1543 torq.err_sum += torq.err/(float) TMR_FREQ_5k; //[N]
Lightvalve 57:f4819de54e7a 1544
Lightvalve 57:f4819de54e7a 1545 if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) {
Lightvalve 58:2eade98630e2 1546
Lightvalve 57:f4819de54e7a 1547 double I_REF_POS = 0.0f;
Lightvalve 57:f4819de54e7a 1548 double I_REF_FORCE_FB = 0.0f; // I_REF by Force Feedback
Lightvalve 57:f4819de54e7a 1549 double I_REF_VC = 0.0f; // I_REF for velocity compensation
Lightvalve 57:f4819de54e7a 1550
Lightvalve 57:f4819de54e7a 1551 double temp_vel_pos = 0.0f;
Lightvalve 57:f4819de54e7a 1552 double temp_vel_torq = 0.0f;
Lightvalve 57:f4819de54e7a 1553 double wn_Pos = 2.0f * PI * 5.0f; // f_cut : 5Hz Position Control
Lightvalve 58:2eade98630e2 1554
Lightvalve 57:f4819de54e7a 1555 if ((OPERATING_MODE && 0x01) == 0) { // Rotary Mode
Lightvalve 57:f4819de54e7a 1556 temp_vel_pos = (0.01f * (double) P_GAIN_JOINT_POSITION * wn_Pos * pos.err + 0.01f * (double) I_GAIN_JOINT_POSITION * wn_Pos * pos.err_sum + 0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / ENC_PULSE_PER_POSITION) * PI / 180.0f; // rad/s
Lightvalve 57:f4819de54e7a 1557 // L when P-gain = 100, f_cut = 10Hz L feedforward velocity
Lightvalve 57:f4819de54e7a 1558 } else if ((OPERATING_MODE && 0x01) == 1) {
Lightvalve 57:f4819de54e7a 1559 temp_vel_pos = (0.01f * (double) P_GAIN_JOINT_POSITION * wn_Pos * pos.err + 0.01f * (double) I_GAIN_JOINT_POSITION * wn_Pos * pos.err_sum + 0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / ENC_PULSE_PER_POSITION); // mm/s
Lightvalve 57:f4819de54e7a 1560 // L when P-gain = 100, f_cut = 10Hz L feedforward velocity
Lightvalve 57:f4819de54e7a 1561 }
Lightvalve 57:f4819de54e7a 1562 if (temp_vel_pos > 0.0f) I_REF_POS = temp_vel_pos * ((double) PISTON_AREA_A * 0.00006f / (K_v * sqrt(2.0f * alpha3 / (alpha3 + 1.0f))));
Lightvalve 57:f4819de54e7a 1563 else I_REF_POS = temp_vel_pos * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f))));
Lightvalve 57:f4819de54e7a 1564
Lightvalve 57:f4819de54e7a 1565 // velocity compensation for torque control
Lightvalve 57:f4819de54e7a 1566 if ((OPERATING_MODE && 0x01) == 0) { // Rotary Mode
Lightvalve 57:f4819de54e7a 1567 I_REF_FORCE_FB = 0.001f * ((double) P_GAIN_JOINT_TORQUE * torq.err + (double) I_GAIN_JOINT_TORQUE * torq.err_sum);
Lightvalve 57:f4819de54e7a 1568 // temp_vel_torq = (0.01 * (double) VELOCITY_COMP_GAIN * (double) CUR_VELOCITY / (double) ENC_PULSE_PER_POSITION) * PI / 180.0; // rad/s
Lightvalve 57:f4819de54e7a 1569 temp_vel_torq = (0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / (double) ENC_PULSE_PER_POSITION) * PI / 180.0f; // rad/s
Lightvalve 57:f4819de54e7a 1570 // L feedforward velocity
Lightvalve 57:f4819de54e7a 1571 } else if ((OPERATING_MODE && 0x01) == 1) {
Lightvalve 57:f4819de54e7a 1572 I_REF_FORCE_FB = 0.001f * 0.01f*((double) P_GAIN_JOINT_TORQUE * torq.err + (double) I_GAIN_JOINT_TORQUE * torq.err_sum); // Linear Actuators are more sensitive.
Lightvalve 57:f4819de54e7a 1573 // temp_vel_torq = (0.01 * (double) VELOCITY_COMP_GAIN * (double) CUR_VELOCITY / (double) ENC_PULSE_PER_POSITION); // mm/s
Lightvalve 57:f4819de54e7a 1574 temp_vel_torq = (0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / (double) ENC_PULSE_PER_POSITION); // mm/s
Lightvalve 57:f4819de54e7a 1575 // L feedforward velocity
Lightvalve 57:f4819de54e7a 1576 }
Lightvalve 57:f4819de54e7a 1577 if (temp_vel_torq > 0.0f) I_REF_VC = temp_vel_torq * ((double) PISTON_AREA_A * 0.00006f / (K_v * sqrt(2.0f * alpha3 / (alpha3 + 1.0f))));
Lightvalve 57:f4819de54e7a 1578 else I_REF_VC = temp_vel_torq * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f))));
Lightvalve 57:f4819de54e7a 1579 // L velocity(rad/s or mm/s) >> I_ref(mA)
Lightvalve 57:f4819de54e7a 1580 // Ref_Joint_FT_dot = (Ref_Joint_FT_Nm - Ref_Joint_FT_Nm_old) / TMR_DT_5k;
Lightvalve 57:f4819de54e7a 1581 // Ref_Joint_FT_Nm_old = Ref_Joint_FT_Nm;
Lightvalve 57:f4819de54e7a 1582
Lightvalve 57:f4819de54e7a 1583 I_REF = (1.0f - alpha_trans) * I_REF_POS + alpha_trans * (I_REF_VC + I_REF_FORCE_FB);
Lightvalve 67:c2812cf26c38 1584
Lightvalve 67:c2812cf26c38 1585 // Anti-windup for FT
Lightvalve 67:c2812cf26c38 1586 if (I_GAIN_JOINT_TORQUE != 0) {
Lightvalve 67:c2812cf26c38 1587 double I_MAX = 10.0f; // Maximum Current : 10mV
Lightvalve 67:c2812cf26c38 1588 double Ka = 2.0f / ((double) I_GAIN_JOINT_TORQUE * 0.001f);
Lightvalve 67:c2812cf26c38 1589 if (I_REF > I_MAX) {
Lightvalve 67:c2812cf26c38 1590 double I_rem = I_REF - I_MAX;
Lightvalve 67:c2812cf26c38 1591 I_rem = Ka*I_rem;
Lightvalve 67:c2812cf26c38 1592 I_REF = I_MAX;
Lightvalve 67:c2812cf26c38 1593 torq.err_sum = torq.err_sum - I_rem /(float) TMR_FREQ_5k;
Lightvalve 67:c2812cf26c38 1594 } else if (I_REF < -I_MAX) {
Lightvalve 67:c2812cf26c38 1595 double I_rem = I_REF - (-I_MAX);
Lightvalve 67:c2812cf26c38 1596 I_rem = Ka*I_rem;
Lightvalve 67:c2812cf26c38 1597 I_REF = -I_MAX;
Lightvalve 67:c2812cf26c38 1598 torq.err_sum = torq.err_sum - I_rem /(float) TMR_FREQ_5k;
Lightvalve 67:c2812cf26c38 1599 }
Lightvalve 67:c2812cf26c38 1600 }
Lightvalve 57:f4819de54e7a 1601
Lightvalve 57:f4819de54e7a 1602 } else {
Lightvalve 57:f4819de54e7a 1603 float VALVE_POS_RAW_FORCE_FB = 0.0f;
Lightvalve 57:f4819de54e7a 1604
Lightvalve 57:f4819de54e7a 1605 VALVE_POS_RAW_FORCE_FB = alpha_trans*(((float) P_GAIN_JOINT_TORQUE * torq.err + (float) I_GAIN_JOINT_TORQUE * torq.err_sum) * 0.01f
Lightvalve 57:f4819de54e7a 1606 + DDV_JOINT_POS_FF(vel.sen))+ (1.0f-alpha_trans) * (P_GAIN_JOINT_POSITION * 0.01f * pos.err + DDV_JOINT_POS_FF(vel.ref));
Lightvalve 57:f4819de54e7a 1607
Lightvalve 57:f4819de54e7a 1608 if (VALVE_POS_RAW_FORCE_FB >= 0) {
Lightvalve 57:f4819de54e7a 1609 valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_PLUS;
Lightvalve 57:f4819de54e7a 1610 } else {
Lightvalve 57:f4819de54e7a 1611 valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_MINUS;
Lightvalve 57:f4819de54e7a 1612 }
Lightvalve 57:f4819de54e7a 1613
Lightvalve 57:f4819de54e7a 1614 if(I_GAIN_JOINT_TORQUE != 0) {
Lightvalve 57:f4819de54e7a 1615 double Ka = 1.0f / (double) I_GAIN_JOINT_TORQUE * 100.0f;
Lightvalve 57:f4819de54e7a 1616 if(valve_pos.ref>VALVE_MAX_POS) {
Lightvalve 57:f4819de54e7a 1617 double valve_pos_rem = valve_pos.ref - VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1618 valve_pos_rem = valve_pos_rem * Ka;
Lightvalve 57:f4819de54e7a 1619 valve_pos.ref = VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1620 torq.err_sum = torq.err_sum - valve_pos_rem/(float) TMR_FREQ_5k;
Lightvalve 57:f4819de54e7a 1621 } else if(valve_pos.ref < VALVE_MIN_POS) {
Lightvalve 57:f4819de54e7a 1622 double valve_pos_rem = valve_pos.ref - VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1623 valve_pos_rem = valve_pos_rem * Ka;
Lightvalve 57:f4819de54e7a 1624 valve_pos.ref = VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1625 torq.err_sum = torq.err_sum - valve_pos_rem/(float) TMR_FREQ_5k;
Lightvalve 57:f4819de54e7a 1626 }
Lightvalve 57:f4819de54e7a 1627 }
Lightvalve 61:bc8c8270f0ab 1628
Lightvalve 57:f4819de54e7a 1629 VALVE_POS_CONTROL(valve_pos.ref);
Lightvalve 61:bc8c8270f0ab 1630
Lightvalve 67:c2812cf26c38 1631 // Vout.ref = (float) P_GAIN_JOINT_POSITION * 0.01f * ((float) pos.err);
Lightvalve 60:64181f1d3e60 1632 V_out = (float) Vout.ref;
Lightvalve 57:f4819de54e7a 1633
Lightvalve 57:f4819de54e7a 1634 }
Lightvalve 58:2eade98630e2 1635
Lightvalve 57:f4819de54e7a 1636 break;
Lightvalve 57:f4819de54e7a 1637 }
Lightvalve 58:2eade98630e2 1638
Lightvalve 57:f4819de54e7a 1639 case MODE_VALVE_OPEN_LOOP: {
Lightvalve 57:f4819de54e7a 1640 V_out = (float) Vout.ref;
Lightvalve 57:f4819de54e7a 1641 break;
Lightvalve 57:f4819de54e7a 1642 }
Lightvalve 14:8e7590227d22 1643
Lightvalve 12:6f2531038ea4 1644 default:
Lightvalve 12:6f2531038ea4 1645 break;
Lightvalve 12:6f2531038ea4 1646 }
Lightvalve 14:8e7590227d22 1647
Lightvalve 57:f4819de54e7a 1648
Lightvalve 57:f4819de54e7a 1649 if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) { //Moog Valve or KNR Valve
Lightvalve 58:2eade98630e2 1650
Lightvalve 57:f4819de54e7a 1651 ////////////////////////////////////////////////////////////////////////////
Lightvalve 57:f4819de54e7a 1652 //////////////////////////// CURRENT CONTROL //////////////////////////////
Lightvalve 57:f4819de54e7a 1653 ////////////////////////////////////////////////////////////////////////////
Lightvalve 57:f4819de54e7a 1654 if (CURRENT_CONTROL_MODE) {
Lightvalve 67:c2812cf26c38 1655 double alpha_update_Iref = 1.0f / (1.0f + 5000.0f / (2.0f * 3.14f * 300.0f)); // f_cutoff : 500Hz
Lightvalve 57:f4819de54e7a 1656 I_REF_fil = (1.0f - alpha_update_Iref) * I_REF_fil + alpha_update_Iref*I_REF;
Lightvalve 57:f4819de54e7a 1657
Lightvalve 57:f4819de54e7a 1658 I_ERR = I_REF_fil - cur.sen;
Lightvalve 67:c2812cf26c38 1659 I_ERR_INT = I_ERR_INT + (I_ERR) * 0.0002f;
Lightvalve 57:f4819de54e7a 1660
Lightvalve 57:f4819de54e7a 1661
Lightvalve 57:f4819de54e7a 1662 // Moog Valve Current Control Gain
Lightvalve 67:c2812cf26c38 1663 double R_model = 500.0f; // ohm
Lightvalve 57:f4819de54e7a 1664 double L_model = 1.2f;
Lightvalve 57:f4819de54e7a 1665 double w0 = 2.0f * 3.14f * 150.0f;
Lightvalve 57:f4819de54e7a 1666 double KP_I = 0.1f * L_model*w0;
Lightvalve 57:f4819de54e7a 1667 double KI_I = 0.1f * R_model*w0;
Lightvalve 57:f4819de54e7a 1668
Lightvalve 57:f4819de54e7a 1669 // KNR Valve Current Control Gain
Lightvalve 57:f4819de54e7a 1670 if (((OPERATING_MODE & 0b110)>>1) == 1) { // KNR Valve
Lightvalve 57:f4819de54e7a 1671 R_model = 163.0f; // ohm
Lightvalve 57:f4819de54e7a 1672 L_model = 1.0f;
Lightvalve 57:f4819de54e7a 1673 w0 = 2.0f * 3.14f * 80.0f;
Lightvalve 57:f4819de54e7a 1674 KP_I = 1.0f * L_model*w0;
Lightvalve 57:f4819de54e7a 1675 KI_I = 0.08f * R_model*w0;
Lightvalve 57:f4819de54e7a 1676 }
Lightvalve 57:f4819de54e7a 1677
Lightvalve 57:f4819de54e7a 1678 double FF_gain = 1.0f;
Lightvalve 57:f4819de54e7a 1679
Lightvalve 67:c2812cf26c38 1680 VALVE_PWM_RAW = KP_I * 2.0f * I_ERR + KI_I * 2.0f* I_ERR_INT;
Lightvalve 57:f4819de54e7a 1681 // VALVE_PWM_RAW = VALVE_PWM_RAW + FF_gain * (R_model*I_REF); // Unit : mV
Lightvalve 57:f4819de54e7a 1682 I_REF_fil_diff = I_REF_fil - I_REF_fil_old;
Lightvalve 57:f4819de54e7a 1683 I_REF_fil_old = I_REF_fil;
Lightvalve 67:c2812cf26c38 1684 // VALVE_PWM_RAW = VALVE_PWM_RAW + FF_gain * (R_model * I_REF_fil + L_model * I_REF_fil_diff * 5000.0f); // Unit : mV
Lightvalve 67:c2812cf26c38 1685 VALVE_PWM_RAW = VALVE_PWM_RAW + FF_gain * (R_model * I_REF_fil); // Unit : mV
Lightvalve 67:c2812cf26c38 1686 double V_MAX = 12000.0f; // Maximum Voltage : 12V = 12000mV
Lightvalve 57:f4819de54e7a 1687
Lightvalve 57:f4819de54e7a 1688 double Ka = 3.0f / KP_I;
Lightvalve 57:f4819de54e7a 1689 if (VALVE_PWM_RAW > V_MAX) {
Lightvalve 57:f4819de54e7a 1690 V_rem = VALVE_PWM_RAW - V_MAX;
Lightvalve 57:f4819de54e7a 1691 V_rem = Ka*V_rem;
Lightvalve 57:f4819de54e7a 1692 VALVE_PWM_RAW = V_MAX;
Lightvalve 67:c2812cf26c38 1693 I_ERR_INT = I_ERR_INT - V_rem * 0.0002f;
Lightvalve 57:f4819de54e7a 1694 } else if (VALVE_PWM_RAW < -V_MAX) {
Lightvalve 57:f4819de54e7a 1695 V_rem = VALVE_PWM_RAW - (-V_MAX);
Lightvalve 57:f4819de54e7a 1696 V_rem = Ka*V_rem;
Lightvalve 57:f4819de54e7a 1697 VALVE_PWM_RAW = -V_MAX;
Lightvalve 67:c2812cf26c38 1698 I_ERR_INT = I_ERR_INT - V_rem * 0.0002f;
Lightvalve 57:f4819de54e7a 1699 }
Lightvalve 57:f4819de54e7a 1700 Cur_Valve_Open_pulse = cur.sen / mA_PER_pulse;
Lightvalve 57:f4819de54e7a 1701 } else {
Lightvalve 57:f4819de54e7a 1702 VALVE_PWM_RAW = I_REF * mV_PER_mA;
Lightvalve 57:f4819de54e7a 1703 Cur_Valve_Open_pulse = I_REF / mA_PER_pulse;
Lightvalve 57:f4819de54e7a 1704 }
Lightvalve 57:f4819de54e7a 1705
Lightvalve 57:f4819de54e7a 1706 ////////////////////////////////////////////////////////////////////////////
Lightvalve 57:f4819de54e7a 1707 ///////////////// Dead Zone Cancellation & Linearization //////////////////
Lightvalve 57:f4819de54e7a 1708 ////////////////////////////////////////////////////////////////////////////
Lightvalve 57:f4819de54e7a 1709 // Dead Zone Cancellation (Mechanical Valve dead-zone)
Lightvalve 57:f4819de54e7a 1710 if (FLAG_VALVE_DEADZONE) {
Lightvalve 57:f4819de54e7a 1711 if (VALVE_PWM_RAW > 0) VALVE_PWM_RAW = VALVE_PWM_RAW + VALVE_DEADZONE_PLUS * mV_PER_pulse; // unit: mV
Lightvalve 57:f4819de54e7a 1712 else if (VALVE_PWM_RAW < 0) VALVE_PWM_RAW = VALVE_PWM_RAW + VALVE_DEADZONE_MINUS * mV_PER_pulse; // unit: mV
Lightvalve 57:f4819de54e7a 1713
Lightvalve 57:f4819de54e7a 1714 VALVE_PWM_VALVE_DZ = VALVE_PWM_RAW + (double)VALVE_CENTER * mV_PER_pulse; // unit: mV
Lightvalve 57:f4819de54e7a 1715
Lightvalve 57:f4819de54e7a 1716 } else {
Lightvalve 57:f4819de54e7a 1717 VALVE_PWM_VALVE_DZ = VALVE_PWM_RAW;
Lightvalve 57:f4819de54e7a 1718 }
Lightvalve 57:f4819de54e7a 1719
Lightvalve 57:f4819de54e7a 1720 // Output Voltage Linearization
Lightvalve 57:f4819de54e7a 1721 double CUR_PWM_nonlin = VALVE_PWM_VALVE_DZ; // Unit : mV
Lightvalve 67:c2812cf26c38 1722 double CUR_PWM_lin = PWM_duty_byLT(CUR_PWM_nonlin); // -8000~8000
Lightvalve 57:f4819de54e7a 1723
Lightvalve 57:f4819de54e7a 1724 // Dead Zone Cancellation (Electrical dead-zone)
Lightvalve 67:c2812cf26c38 1725 if (CUR_PWM_lin > 0) V_out = (float) (CUR_PWM_lin + 169.0f);
Lightvalve 67:c2812cf26c38 1726 else if (CUR_PWM_lin < 0) V_out = (float) (CUR_PWM_lin - 174.0f);
Lightvalve 67:c2812cf26c38 1727 else V_out = (float) (CUR_PWM_lin);
Lightvalve 57:f4819de54e7a 1728 }
Lightvalve 67:c2812cf26c38 1729
Lightvalve 67:c2812cf26c38 1730 // if(V_out > 0.0f) V_out = (float) (V_out + 169.0f);
Lightvalve 67:c2812cf26c38 1731 // else if(V_out < 0.0f) V_out = (float) (V_out - 174.0f);
Lightvalve 67:c2812cf26c38 1732 // else V_out = V_out;
Lightvalve 67:c2812cf26c38 1733
jobuuu 7:e9086c72bb22 1734 /*******************************************************
jobuuu 7:e9086c72bb22 1735 *** PWM
jobuuu 7:e9086c72bb22 1736 ********************************************************/
Lightvalve 67:c2812cf26c38 1737 if(DIR_VALVE<0){
Lightvalve 67:c2812cf26c38 1738 V_out = -V_out;
Lightvalve 67:c2812cf26c38 1739 }
Lightvalve 67:c2812cf26c38 1740
Lightvalve 49:e7bcfc244d40 1741 if (V_out >= VALVE_VOLTAGE_LIMIT*1000.0f) {
Lightvalve 49:e7bcfc244d40 1742 V_out = VALVE_VOLTAGE_LIMIT*1000.0f;
Lightvalve 49:e7bcfc244d40 1743 } else if(V_out<=-VALVE_VOLTAGE_LIMIT*1000.0f) {
Lightvalve 49:e7bcfc244d40 1744 V_out = -VALVE_VOLTAGE_LIMIT*1000.0f;
Lightvalve 27:a2254a485f23 1745 }
Lightvalve 49:e7bcfc244d40 1746 PWM_out= V_out/(SUPPLY_VOLTAGE*1000.0f); // Full duty : 12000.0mV
Lightvalve 13:747daba9cf59 1747
Lightvalve 19:23b7c1ad8683 1748 // Saturation of output voltage to 12.0V
Lightvalve 30:8d561f16383b 1749 if(PWM_out > 1.0f) PWM_out=1.0f;
Lightvalve 30:8d561f16383b 1750 else if (PWM_out < -1.0f) PWM_out=-1.0f;
Lightvalve 13:747daba9cf59 1751
Lightvalve 30:8d561f16383b 1752 if (PWM_out>0.0f) {
Lightvalve 30:8d561f16383b 1753 dtc_v=0.0f;
jobuuu 1:e04e563be5ce 1754 dtc_w=PWM_out;
jobuuu 1:e04e563be5ce 1755 } else {
jobuuu 2:a1c0a37df760 1756 dtc_v=-PWM_out;
Lightvalve 30:8d561f16383b 1757 dtc_w=0.0f;
jobuuu 1:e04e563be5ce 1758 }
Lightvalve 13:747daba9cf59 1759
jobuuu 1:e04e563be5ce 1760 //pwm
Lightvalve 30:8d561f16383b 1761 TIM4->CCR2 = (PWM_ARR)*(1.0f-dtc_v);
Lightvalve 30:8d561f16383b 1762 TIM4->CCR1 = (PWM_ARR)*(1.0f-dtc_w);
Lightvalve 67:c2812cf26c38 1763
Lightvalve 61:bc8c8270f0ab 1764
Lightvalve 57:f4819de54e7a 1765 if (TMR2_COUNT_CAN_TX % (int) ((int) TMR_FREQ_5k/CAN_FREQ) == 0) {
Lightvalve 20:806196fda269 1766
Lightvalve 54:647072f5307a 1767 // Position, Velocity, and Torque (ID:1200)
Lightvalve 56:6f50d9d3bfee 1768 if (flag_data_request[0] == HIGH) {
Lightvalve 57:f4819de54e7a 1769 if ((OPERATING_MODE & 0b01) == 0) { // Rotary Actuator
Lightvalve 54:647072f5307a 1770 if (SENSING_MODE == 0) {
Lightvalve 67:c2812cf26c38 1771 CAN_TX_POSITION_FT((int16_t) (pos.sen), (int16_t) (vel.sen/10.0f), (int16_t) (torq.sen*10.0f));
Lightvalve 54:647072f5307a 1772 } else if (SENSING_MODE == 1) {
Lightvalve 58:2eade98630e2 1773 CAN_TX_POSITION_PRESSURE((int16_t) (pos.sen), (int16_t) (vel.sen/10.0f), (int16_t) ((pres_A.sen)*5.0f), (int16_t) ((pres_B.sen)*5.0f));
Lightvalve 54:647072f5307a 1774 }
Lightvalve 57:f4819de54e7a 1775 } else if ((OPERATING_MODE & 0b01) == 1) { // Linear Actuator
Lightvalve 54:647072f5307a 1776 if (SENSING_MODE == 0) {
Lightvalve 67:c2812cf26c38 1777 CAN_TX_POSITION_FT((int16_t) (pos.sen/10.0f), (int16_t) (vel.sen/256.0f), (int16_t) (torq.sen * 10.0f * (float)(TORQUE_SENSOR_PULSE_PER_TORQUE)));
Lightvalve 54:647072f5307a 1778 } else if (SENSING_MODE == 1) {
Lightvalve 67:c2812cf26c38 1779 CAN_TX_POSITION_PRESSURE((int16_t) (pos.sen/10.0f), (int16_t) (vel.sen/256.0f), (int16_t) ((pres_A.sen)*5.0f), (int16_t) ((pres_B.sen)*5.0f));
Lightvalve 54:647072f5307a 1780 }
Lightvalve 52:8ea76864368a 1781 }
Lightvalve 52:8ea76864368a 1782 }
Lightvalve 56:6f50d9d3bfee 1783 if (flag_data_request[1] == HIGH) {
Lightvalve 54:647072f5307a 1784 //valve position
Lightvalve 54:647072f5307a 1785 double t_value = 0;
Lightvalve 67:c2812cf26c38 1786 if(valve_pos.ref>=(float) VALVE_CENTER) {
Lightvalve 67:c2812cf26c38 1787 t_value = 10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER);
Lightvalve 67:c2812cf26c38 1788 } else {
Lightvalve 67:c2812cf26c38 1789 t_value = -10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER);
Lightvalve 67:c2812cf26c38 1790 }
Lightvalve 67:c2812cf26c38 1791 // if(OPERATING_MODE==5) {
Lightvalve 67:c2812cf26c38 1792 // t_value = (double) value;
Lightvalve 67:c2812cf26c38 1793 // } else if(CURRENT_CONTROL_MODE==1) {
Lightvalve 67:c2812cf26c38 1794 // t_value = cur.sen;
Lightvalve 57:f4819de54e7a 1795 // } else {
Lightvalve 67:c2812cf26c38 1796 // t_value = V_out;
Lightvalve 67:c2812cf26c38 1797 // }
Lightvalve 67:c2812cf26c38 1798 CAN_TX_TORQUE((int16_t) (t_value)); //1300
Lightvalve 67:c2812cf26c38 1799 //CAN_TX_TORQUE((int16_t) (cur.sen * 1000.0f)); //1300
Lightvalve 67:c2812cf26c38 1800 //CAN_TX_TORQUE((int16_t) (I_REF * 1000.0f)); //1300
Lightvalve 54:647072f5307a 1801 }
Lightvalve 58:2eade98630e2 1802
Lightvalve 58:2eade98630e2 1803
Lightvalve 56:6f50d9d3bfee 1804 if (flag_data_request[2] == HIGH) {
Lightvalve 56:6f50d9d3bfee 1805 //pressure A and B
Lightvalve 57:f4819de54e7a 1806 CAN_TX_PRES((int16_t) (pres_A.sen), (int16_t) (pres_B.sen)); // CUR_PRES_X : 0(0bar)~4096(210bar) //1400
Lightvalve 55:b25725257569 1807 }
Lightvalve 58:2eade98630e2 1808
Lightvalve 57:f4819de54e7a 1809 //If it doesn't rest, below can can not work.
Lightvalve 57:f4819de54e7a 1810 for (can_rest = 0; can_rest < 10000; can_rest++) {
Lightvalve 57:f4819de54e7a 1811 ;
Lightvalve 57:f4819de54e7a 1812 }
Lightvalve 58:2eade98630e2 1813
Lightvalve 56:6f50d9d3bfee 1814 if (flag_data_request[3] == HIGH) {
Lightvalve 54:647072f5307a 1815 //PWM
Lightvalve 67:c2812cf26c38 1816 CAN_TX_PWM((int16_t) value); //1500
Lightvalve 54:647072f5307a 1817 }
Lightvalve 57:f4819de54e7a 1818 //for (i = 0; i < 10000; i++) {
Lightvalve 57:f4819de54e7a 1819 // ;
Lightvalve 57:f4819de54e7a 1820 // }
Lightvalve 56:6f50d9d3bfee 1821 if (flag_data_request[4] == HIGH) {
Lightvalve 54:647072f5307a 1822 //valve position
Lightvalve 57:f4819de54e7a 1823 CAN_TX_VALVE_POSITION((int16_t) (CAN_FREQ), (int16_t) (D_DAMPER), (int16_t) OPERATING_MODE); //1600
Lightvalve 54:647072f5307a 1824 }
Lightvalve 20:806196fda269 1825
Lightvalve 54:647072f5307a 1826 // Others : Reference position, Reference FT, PWM, Current (ID:1300)
Lightvalve 52:8ea76864368a 1827 // if (flag_data_request[1] == HIGH) {
Lightvalve 52:8ea76864368a 1828 // CAN_TX_SOMETHING((int) (FORCE_VREF), (int16_t) (1), (int16_t) (2), (int16_t) (3));
Lightvalve 52:8ea76864368a 1829 // }
Lightvalve 54:647072f5307a 1830 //if (flag_delay_test == 1){
Lightvalve 58:2eade98630e2 1831 //CAN_TX_PRES((int16_t) (0),(int16_t) torq_ref);
Lightvalve 54:647072f5307a 1832 //}
Lightvalve 52:8ea76864368a 1833
Lightvalve 54:647072f5307a 1834 TMR2_COUNT_CAN_TX = 0;
Lightvalve 54:647072f5307a 1835 }
Lightvalve 54:647072f5307a 1836 TMR2_COUNT_CAN_TX++;
Lightvalve 52:8ea76864368a 1837
Lightvalve 20:806196fda269 1838 }
Lightvalve 52:8ea76864368a 1839 TIM3->SR = 0x0; // reset the status register
Lightvalve 52:8ea76864368a 1840
Lightvalve 58:2eade98630e2 1841 }