![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
for learning
main.cpp@89:a7b45368ea0f, 2020-07-28 (annotated)
- Committer:
- Lightvalve
- Date:
- Tue Jul 28 00:43:11 2020 +0000
- Revision:
- 89:a7b45368ea0f
- Parent:
- 88:d6e591bece22
- Child:
- 90:a6cfef34bdce
200728-1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lightvalve | 89:a7b45368ea0f | 1 | //200728-1 |
GiJeongKim | 0:51c43836c1d7 | 2 | #include "mbed.h" |
GiJeongKim | 0:51c43836c1d7 | 3 | #include "FastPWM.h" |
GiJeongKim | 0:51c43836c1d7 | 4 | #include "INIT_HW.h" |
jobuuu | 2:a1c0a37df760 | 5 | #include "function_CAN.h" |
GiJeongKim | 0:51c43836c1d7 | 6 | #include "SPI_EEP_ENC.h" |
GiJeongKim | 0:51c43836c1d7 | 7 | #include "I2C_AS5510.h" |
GiJeongKim | 0:51c43836c1d7 | 8 | #include "setting.h" |
Lightvalve | 11:82d8768d7351 | 9 | #include "function_utilities.h" |
Lightvalve | 16:903b5a4433b4 | 10 | #include "stm32f4xx_flash.h" |
Lightvalve | 65:a2d7c63419c2 | 11 | #include "FlashWriter.h" |
Lightvalve | 61:bc8c8270f0ab | 12 | |
Lightvalve | 61:bc8c8270f0ab | 13 | using namespace std; |
Lightvalve | 61:bc8c8270f0ab | 14 | Timer t; |
GiJeongKim | 0:51c43836c1d7 | 15 | |
Lightvalve | 31:66738bfecec5 | 16 | ///191008//// |
Lightvalve | 31:66738bfecec5 | 17 | |
jobuuu | 7:e9086c72bb22 | 18 | // dac & check /////////////////////////////////////////// |
GiJeongKim | 0:51c43836c1d7 | 19 | DigitalOut check(PC_2); |
GiJeongKim | 0:51c43836c1d7 | 20 | DigitalOut check_2(PC_3); |
GiJeongKim | 0:51c43836c1d7 | 21 | AnalogOut dac_1(PA_4); |
GiJeongKim | 0:51c43836c1d7 | 22 | AnalogOut dac_2(PA_5); |
Lightvalve | 14:8e7590227d22 | 23 | AnalogIn adc1(PC_4); //pressure_1 |
Lightvalve | 14:8e7590227d22 | 24 | AnalogIn adc2(PB_0); //pressure_2 |
Lightvalve | 14:8e7590227d22 | 25 | AnalogIn adc3(PC_1); //current |
GiJeongKim | 0:51c43836c1d7 | 26 | |
Lightvalve | 24:ef6e1092e9e6 | 27 | |
jobuuu | 7:e9086c72bb22 | 28 | // PWM /////////////////////////////////////////// |
Lightvalve | 30:8d561f16383b | 29 | float dtc_v=0.0f; |
Lightvalve | 30:8d561f16383b | 30 | float dtc_w=0.0f; |
GiJeongKim | 0:51c43836c1d7 | 31 | |
jobuuu | 7:e9086c72bb22 | 32 | // I2C /////////////////////////////////////////// |
GiJeongKim | 0:51c43836c1d7 | 33 | I2C i2c(PC_9,PA_8); // SDA, SCL (for K22F) |
GiJeongKim | 0:51c43836c1d7 | 34 | const int i2c_slave_addr1 = 0x56; |
GiJeongKim | 0:51c43836c1d7 | 35 | unsigned int value; // 10bit output of reading sensor AS5510 |
GiJeongKim | 0:51c43836c1d7 | 36 | |
jobuuu | 7:e9086c72bb22 | 37 | // SPI /////////////////////////////////////////// |
Lightvalve | 16:903b5a4433b4 | 38 | //SPI eeprom(PB_15, PB_14, PB_13); // EEPROM //(SPI_MOSI, SPI_MISO, SPI_SCK); |
Lightvalve | 16:903b5a4433b4 | 39 | //DigitalOut eeprom_cs(PB_12); |
Lightvalve | 16:903b5a4433b4 | 40 | //FlashWriter writer(6);//2부터 7까지 되는듯 아마 sector |
GiJeongKim | 0:51c43836c1d7 | 41 | SPI enc(PC_12,PC_11,PC_10); |
GiJeongKim | 0:51c43836c1d7 | 42 | DigitalOut enc_cs(PD_2); |
Lightvalve | 11:82d8768d7351 | 43 | DigitalOut LED(PA_15); |
GiJeongKim | 0:51c43836c1d7 | 44 | |
jobuuu | 7:e9086c72bb22 | 45 | // UART /////////////////////////////////////////// |
GiJeongKim | 0:51c43836c1d7 | 46 | Serial pc(PA_9,PA_10); // _ UART |
GiJeongKim | 0:51c43836c1d7 | 47 | |
jobuuu | 7:e9086c72bb22 | 48 | // CAN /////////////////////////////////////////// |
GiJeongKim | 0:51c43836c1d7 | 49 | CAN can(PB_8, PB_9, 1000000); |
GiJeongKim | 0:51c43836c1d7 | 50 | CANMessage msg; |
Lightvalve | 11:82d8768d7351 | 51 | void onMsgReceived() |
Lightvalve | 11:82d8768d7351 | 52 | { |
Lightvalve | 11:82d8768d7351 | 53 | CAN_RX_HANDLER(); |
Lightvalve | 11:82d8768d7351 | 54 | } |
jobuuu | 2:a1c0a37df760 | 55 | |
jobuuu | 7:e9086c72bb22 | 56 | // Variables /////////////////////////////////////////// |
jobuuu | 7:e9086c72bb22 | 57 | State pos; |
jobuuu | 7:e9086c72bb22 | 58 | State vel; |
jobuuu | 7:e9086c72bb22 | 59 | State Vout; |
jobuuu | 7:e9086c72bb22 | 60 | State torq; |
jobuuu | 7:e9086c72bb22 | 61 | State pres_A; |
jobuuu | 7:e9086c72bb22 | 62 | State pres_B; |
jobuuu | 7:e9086c72bb22 | 63 | State cur; |
Lightvalve | 14:8e7590227d22 | 64 | State valve_pos; |
Lightvalve | 14:8e7590227d22 | 65 | |
Lightvalve | 14:8e7590227d22 | 66 | State INIT_Vout; |
Lightvalve | 14:8e7590227d22 | 67 | State INIT_Valve_Pos; |
Lightvalve | 14:8e7590227d22 | 68 | State INIT_Pos; |
Lightvalve | 14:8e7590227d22 | 69 | State INIT_torq; |
jobuuu | 5:a4319f79457b | 70 | |
Lightvalve | 19:23b7c1ad8683 | 71 | extern int CID_RX_CMD; |
Lightvalve | 19:23b7c1ad8683 | 72 | extern int CID_RX_REF_POSITION; |
Lightvalve | 49:e7bcfc244d40 | 73 | extern int CID_RX_REF_VALVE_POS; |
Lightvalve | 45:35fa6884d0c6 | 74 | extern int CID_RX_REF_PWM; |
Lightvalve | 19:23b7c1ad8683 | 75 | |
Lightvalve | 19:23b7c1ad8683 | 76 | extern int CID_TX_INFO; |
Lightvalve | 19:23b7c1ad8683 | 77 | extern int CID_TX_POSITION; |
Lightvalve | 19:23b7c1ad8683 | 78 | extern int CID_TX_TORQUE; |
Lightvalve | 19:23b7c1ad8683 | 79 | extern int CID_TX_PRES; |
Lightvalve | 19:23b7c1ad8683 | 80 | extern int CID_TX_VOUT; |
Lightvalve | 19:23b7c1ad8683 | 81 | extern int CID_TX_VALVE_POSITION; |
Lightvalve | 19:23b7c1ad8683 | 82 | |
Lightvalve | 61:bc8c8270f0ab | 83 | |
Lightvalve | 61:bc8c8270f0ab | 84 | |
Lightvalve | 61:bc8c8270f0ab | 85 | |
jobuuu | 7:e9086c72bb22 | 86 | // ============================================================================= |
jobuuu | 7:e9086c72bb22 | 87 | // ============================================================================= |
jobuuu | 7:e9086c72bb22 | 88 | // ============================================================================= |
jobuuu | 7:e9086c72bb22 | 89 | |
Lightvalve | 12:6f2531038ea4 | 90 | /******************************************************************************* |
Lightvalve | 12:6f2531038ea4 | 91 | * REFERENCE MODE |
Lightvalve | 12:6f2531038ea4 | 92 | ******************************************************************************/ |
Lightvalve | 13:747daba9cf59 | 93 | enum _REFERENCE_MODE { |
Lightvalve | 13:747daba9cf59 | 94 | MODE_REF_NO_ACT = 0, //0 |
Lightvalve | 12:6f2531038ea4 | 95 | MODE_REF_DIRECT, //1 |
Lightvalve | 12:6f2531038ea4 | 96 | MODE_REF_COS_INC, //2 |
Lightvalve | 12:6f2531038ea4 | 97 | MODE_REF_LINE_INC, //3 |
Lightvalve | 12:6f2531038ea4 | 98 | MODE_REF_SIN_WAVE, //4 |
Lightvalve | 12:6f2531038ea4 | 99 | MODE_REF_SQUARE_WAVE, //5 |
Lightvalve | 12:6f2531038ea4 | 100 | }; |
Lightvalve | 12:6f2531038ea4 | 101 | |
Lightvalve | 12:6f2531038ea4 | 102 | /******************************************************************************* |
Lightvalve | 12:6f2531038ea4 | 103 | * CONTROL MODE |
Lightvalve | 12:6f2531038ea4 | 104 | ******************************************************************************/ |
Lightvalve | 13:747daba9cf59 | 105 | enum _CONTROL_MODE { |
Lightvalve | 12:6f2531038ea4 | 106 | //control mode |
Lightvalve | 12:6f2531038ea4 | 107 | MODE_NO_ACT = 0, //0 |
Lightvalve | 47:fdcb8bd86fd6 | 108 | MODE_VALVE_POSITION_CONTROL, //1 |
Lightvalve | 47:fdcb8bd86fd6 | 109 | MODE_JOINT_CONTROL, //2 |
Lightvalve | 50:3c630b5eba9f | 110 | |
Lightvalve | 47:fdcb8bd86fd6 | 111 | MODE_VALVE_OPEN_LOOP, //3 |
Lightvalve | 12:6f2531038ea4 | 112 | MODE_JOINT_POSITION_TORQUE_CONTROL_VALVE_POSITION, //4 |
Lightvalve | 12:6f2531038ea4 | 113 | MODE_VALVE_POSITION_TORQUE_CONTROL_LEARNING, //5 |
Lightvalve | 13:747daba9cf59 | 114 | |
Lightvalve | 12:6f2531038ea4 | 115 | MODE_JOINT_POSITION_PRES_CONTROL_PWM, //6 |
Lightvalve | 12:6f2531038ea4 | 116 | MODE_JOINT_POSITION_PRES_CONTROL_VALVE_POSITION, //7 |
Lightvalve | 12:6f2531038ea4 | 117 | MODE_VALVE_POSITION_PRES_CONTROL_LEARNING, //8 |
Lightvalve | 13:747daba9cf59 | 118 | |
Lightvalve | 12:6f2531038ea4 | 119 | MODE_TEST_CURRENT_CONTROL, //9 |
Lightvalve | 12:6f2531038ea4 | 120 | MODE_TEST_PWM_CONTROL, //10 |
Lightvalve | 21:e5f1a43ea6f9 | 121 | |
Lightvalve | 14:8e7590227d22 | 122 | MODE_CURRENT_CONTROL, //11 |
Lightvalve | 14:8e7590227d22 | 123 | MODE_JOINT_POSITION_TORQUE_CONTROL_CURRENT, //12 |
Lightvalve | 14:8e7590227d22 | 124 | MODE_JOINT_POSITION_PRES_CONTROL_CURRENT, //13 |
Lightvalve | 13:747daba9cf59 | 125 | |
Lightvalve | 12:6f2531038ea4 | 126 | //utility |
Lightvalve | 12:6f2531038ea4 | 127 | MODE_TORQUE_SENSOR_NULLING = 20, //20 |
Lightvalve | 12:6f2531038ea4 | 128 | MODE_VALVE_NULLING_AND_DEADZONE_SETTING, //21 |
Lightvalve | 12:6f2531038ea4 | 129 | MODE_FIND_HOME, //22 |
Lightvalve | 57:f4819de54e7a | 130 | MODE_VALVE_GAIN_SETTING, //23 |
Lightvalve | 12:6f2531038ea4 | 131 | MODE_PRESSURE_SENSOR_NULLING, //24 |
Lightvalve | 12:6f2531038ea4 | 132 | MODE_PRESSURE_SENSOR_CALIB, //25 |
Lightvalve | 12:6f2531038ea4 | 133 | MODE_ROTARY_FRICTION_TUNING, //26 |
Lightvalve | 13:747daba9cf59 | 134 | |
Lightvalve | 12:6f2531038ea4 | 135 | MODE_DDV_POS_VS_PWM_ID = 30, //30 |
Lightvalve | 12:6f2531038ea4 | 136 | MODE_DDV_DEADZONE_AND_CENTER, //31 |
Lightvalve | 12:6f2531038ea4 | 137 | MODE_DDV_POS_VS_FLOWRATE, //32 |
Lightvalve | 57:f4819de54e7a | 138 | MODE_SYSTEM_ID, //33 |
Lightvalve | 12:6f2531038ea4 | 139 | }; |
Lightvalve | 12:6f2531038ea4 | 140 | |
Lightvalve | 65:a2d7c63419c2 | 141 | void SystemClock_Config(void) |
Lightvalve | 65:a2d7c63419c2 | 142 | { |
Lightvalve | 65:a2d7c63419c2 | 143 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
Lightvalve | 65:a2d7c63419c2 | 144 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
Lightvalve | 65:a2d7c63419c2 | 145 | |
Lightvalve | 65:a2d7c63419c2 | 146 | /** Configure the main internal regulator output voltage |
Lightvalve | 65:a2d7c63419c2 | 147 | */ |
Lightvalve | 65:a2d7c63419c2 | 148 | __HAL_RCC_PWR_CLK_ENABLE(); |
Lightvalve | 65:a2d7c63419c2 | 149 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
Lightvalve | 65:a2d7c63419c2 | 150 | /** Initializes the CPU, AHB and APB busses clocks |
Lightvalve | 65:a2d7c63419c2 | 151 | */ |
Lightvalve | 65:a2d7c63419c2 | 152 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
Lightvalve | 65:a2d7c63419c2 | 153 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
Lightvalve | 65:a2d7c63419c2 | 154 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
Lightvalve | 65:a2d7c63419c2 | 155 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
Lightvalve | 65:a2d7c63419c2 | 156 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
Lightvalve | 65:a2d7c63419c2 | 157 | RCC_OscInitStruct.PLL.PLLM = 8;//8 |
Lightvalve | 65:a2d7c63419c2 | 158 | RCC_OscInitStruct.PLL.PLLN = 180; //180 |
Lightvalve | 65:a2d7c63419c2 | 159 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; |
Lightvalve | 65:a2d7c63419c2 | 160 | RCC_OscInitStruct.PLL.PLLQ = 2; |
Lightvalve | 65:a2d7c63419c2 | 161 | RCC_OscInitStruct.PLL.PLLR = 2; |
Lightvalve | 65:a2d7c63419c2 | 162 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
Lightvalve | 65:a2d7c63419c2 | 163 | { |
Lightvalve | 65:a2d7c63419c2 | 164 | //Error_Handler(); |
Lightvalve | 65:a2d7c63419c2 | 165 | } |
Lightvalve | 65:a2d7c63419c2 | 166 | /** Activate the Over-Drive mode |
Lightvalve | 65:a2d7c63419c2 | 167 | */ |
Lightvalve | 65:a2d7c63419c2 | 168 | if (HAL_PWREx_EnableOverDrive() != HAL_OK) |
Lightvalve | 65:a2d7c63419c2 | 169 | { |
Lightvalve | 65:a2d7c63419c2 | 170 | //Error_Handler(); |
Lightvalve | 65:a2d7c63419c2 | 171 | } |
Lightvalve | 65:a2d7c63419c2 | 172 | /** Initializes the CPU, AHB and APB busses clocks |
Lightvalve | 65:a2d7c63419c2 | 173 | */ |
Lightvalve | 65:a2d7c63419c2 | 174 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
Lightvalve | 65:a2d7c63419c2 | 175 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
Lightvalve | 65:a2d7c63419c2 | 176 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
Lightvalve | 65:a2d7c63419c2 | 177 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
Lightvalve | 65:a2d7c63419c2 | 178 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; |
Lightvalve | 65:a2d7c63419c2 | 179 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; |
Lightvalve | 65:a2d7c63419c2 | 180 | |
Lightvalve | 65:a2d7c63419c2 | 181 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) |
Lightvalve | 65:a2d7c63419c2 | 182 | { |
Lightvalve | 65:a2d7c63419c2 | 183 | //Error_Handler(); |
Lightvalve | 65:a2d7c63419c2 | 184 | } |
Lightvalve | 65:a2d7c63419c2 | 185 | } |
Lightvalve | 65:a2d7c63419c2 | 186 | |
Lightvalve | 65:a2d7c63419c2 | 187 | |
Lightvalve | 68:328e1be06f5d | 188 | float x_past[num_array_x_past] = {0.0f}; |
Lightvalve | 85:a3b46118b5cd | 189 | float x_future[num_array_x_future] = {0.0f}; |
Lightvalve | 68:328e1be06f5d | 190 | float f_past[num_array_f_past] = {0.0f}; |
Lightvalve | 68:328e1be06f5d | 191 | float f_future[num_array_f_future] = {0.0f}; |
Lightvalve | 66:a8e6799dbce3 | 192 | |
Lightvalve | 73:f80dc3970c99 | 193 | float input_NN[num_input] = { 0.0f }; |
Lightvalve | 65:a2d7c63419c2 | 194 | |
Lightvalve | 89:a7b45368ea0f | 195 | const float h1[num_input][32] = { |
Lightvalve | 89:a7b45368ea0f | 196 | {-1.6120201349258423f,1.0650807619094849f,0.10589459538459778f,-0.33597394824028015f,-2.401294708251953f,-0.303094744682312f,-0.6049969792366028f,0.8231816291809082f,0.64059978723526f,-0.47648805379867554f,-0.22159487009048462f,-0.12132000178098679f,-0.19318288564682007f,0.21215307712554932f,-0.21103838086128235f,-1.2288156747817993f,0.6063412427902222f,0.24935457110404968f,0.734065592288971f,1.0331326723098755f,-0.33476194739341736f,0.10696089267730713f,-0.3326931595802307f,-0.0792258083820343f,-0.14849676191806793f,0.18374285101890564f,-0.1767144799232483f,-1.2645845413208008f,-0.21902410686016083f,-0.18794111907482147f,-1.9297771453857422f,0.44305622577667236f}, |
Lightvalve | 89:a7b45368ea0f | 197 | {-1.1207491159439087f,0.5761895179748535f,0.29864487051963806f,-0.43265143036842346f,-1.4888489246368408f,-0.17376138269901276f,-0.11488400399684906f,0.40625444054603577f,0.24788768589496613f,-0.06643147021532059f,-0.3124499022960663f,-0.3919813334941864f,0.021212786436080933f,0.13858725130558014f,0.045876264572143555f,-0.8044695854187012f,0.2339925765991211f,0.06295260787010193f,0.7903832197189331f,0.7084060311317444f,-0.03096979856491089f,-0.12077532708644867f,-0.09506890177726746f,0.27714261412620544f,-0.3909570872783661f,0.2936786115169525f,0.12686115503311157f,-0.40915700793266296f,-0.4260590970516205f,0.09809011220932007f,-1.4230859279632568f,0.2934163510799408f}, |
Lightvalve | 89:a7b45368ea0f | 198 | {-0.3573513329029083f,0.434440553188324f,-0.0042223334312438965f,0.10765819251537323f,-0.9994243383407593f,-0.18276168406009674f,-0.15929634869098663f,0.22509628534317017f,0.32423192262649536f,0.01762457564473152f,0.25851523876190186f,-0.2185339778661728f,-0.03282937407493591f,0.1540619432926178f,-0.31718650460243225f,-0.9658282995223999f,0.6396885514259338f,-0.2658354640007019f,0.556288480758667f,0.5571556091308594f,0.22159990668296814f,-0.15311938524246216f,0.13552400469779968f,-0.24659553170204163f,-0.33682775497436523f,0.14537742733955383f,-0.15514154732227325f,-0.42652565240859985f,-0.40720629692077637f,0.302763432264328f,-1.3403044939041138f,-0.14417313039302826f}, |
Lightvalve | 89:a7b45368ea0f | 199 | {-0.1856374442577362f,0.2553187608718872f,-0.20532599091529846f,-0.6329777240753174f,-0.9888362884521484f,0.054618243128061295f,-0.13591986894607544f,-0.04281715676188469f,0.6310384273529053f,0.10263294726610184f,0.09619598090648651f,0.19032952189445496f,-0.11809042096138f,0.2916359603404999f,-0.12817290425300598f,-1.349012851715088f,0.2070746272802353f,-0.23756909370422363f,0.22165082395076752f,0.3439677059650421f,-0.24942269921302795f,-0.08793863654136658f,-0.14710915088653564f,-0.29148542881011963f,-0.17284530401229858f,0.14159366488456726f,0.13380053639411926f,-0.8715218901634216f,0.2121921181678772f,0.1323157548904419f,-0.8826896548271179f,0.08530819416046143f}, |
Lightvalve | 89:a7b45368ea0f | 200 | {0.7076958417892456f,-0.011784130707383156f,0.08410122990608215f,-0.1790498048067093f,-0.047825515270233154f,0.12502601742744446f,-0.12781423330307007f,-0.6459188461303711f,-0.44403040409088135f,0.566622793674469f,-0.27170997858047485f,-0.17462749779224396f,0.211430162191391f,0.17245565354824066f,-0.25075238943099976f,-1.129048228263855f,-0.29245424270629883f,-0.18436601758003235f,-0.031988393515348434f,-0.4536682367324829f,0.1375632882118225f,0.23587647080421448f,-0.24541926383972168f,-0.07457953691482544f,-0.5412957072257996f,-0.34256690740585327f,0.04057341814041138f,-0.7414973378181458f,0.34006574749946594f,-0.16320037841796875f,-0.002243728144094348f,-0.24738875031471252f}, |
Lightvalve | 89:a7b45368ea0f | 201 | {2.7830452919006348f,-2.1286120414733887f,0.30513831973075867f,1.9285629987716675f,1.905887246131897f,0.314697802066803f,-0.05796601623296738f,-1.917033314704895f,-2.3627591133117676f,0.7325804829597473f,0.2581515312194824f,-2.0754995346069336f,-0.03144201636314392f,-0.005068972706794739f,0.21901831030845642f,0.13221438229084015f,-1.4217417240142822f,-0.3195672333240509f,-2.6085214614868164f,-2.259031295776367f,0.13521116971969604f,-0.009676039218902588f,0.12587067484855652f,0.3309326469898224f,-2.081035614013672f,0.20814630389213562f,-0.2925715744495392f,1.7804770469665527f,0.3318169116973877f,-0.0013132691383361816f,1.5528967380523682f,-0.5669023394584656f}, |
Lightvalve | 89:a7b45368ea0f | 202 | {-0.0035349533427506685f,-0.1737985759973526f,0.16288265585899353f,-0.4572395384311676f,0.6176647543907166f,-0.02229202166199684f,-0.24911771714687347f,-0.0452004075050354f,-0.09992233663797379f,-0.166379913687706f,-0.11600276082754135f,-0.020616959780454636f,0.098605215549469f,-0.08617053925991058f,-0.18274356424808502f,0.9346072673797607f,-0.39059263467788696f,-0.08166468143463135f,0.7394335269927979f,0.05463321879506111f,-0.16223669052124023f,-0.1771286129951477f,-0.2626192569732666f,-0.24521145224571228f,0.2686273455619812f,-0.15535086393356323f,-0.1126367449760437f,0.7214518785476685f,-0.29785194993019104f,-0.03486502170562744f,0.5153166055679321f,0.009956101886928082f}, |
Lightvalve | 89:a7b45368ea0f | 203 | {0.75728839635849f,-0.14384029805660248f,0.16644713282585144f,0.04243979975581169f,0.7297391295433044f,-0.19591183960437775f,0.04227929562330246f,0.6254672408103943f,0.59623122215271f,0.037059180438518524f,-0.2557741701602936f,0.15746647119522095f,0.10806858539581299f,-0.12285306304693222f,0.054826945066452026f,1.7329609394073486f,0.07655717432498932f,-0.28619682788848877f,-0.5128512382507324f,0.03707432374358177f,-0.07430306077003479f,0.022674113512039185f,-0.12776102125644684f,-0.02844339609146118f,0.668587327003479f,0.0177537202835083f,-0.341458797454834f,0.9069352149963379f,-0.24441032111644745f,0.004316955804824829f,0.3377096354961395f,0.13890790939331055f}, |
Lightvalve | 89:a7b45368ea0f | 204 | {0.7074934244155884f,-0.4367210268974304f,0.13710039854049683f,0.31351205706596375f,0.4301673471927643f,-0.2533905506134033f,0.002942651743069291f,0.3325767517089844f,0.15748921036720276f,0.0747724324464798f,-0.31654277443885803f,0.6694631576538086f,0.11499327421188354f,0.22416141629219055f,0.24149659276008606f,1.6183996200561523f,0.007222022395581007f,0.06021764874458313f,-0.4668867588043213f,-0.3139956295490265f,-0.30298954248428345f,-0.022329479455947876f,-0.2963099479675293f,0.08446213603019714f,-0.08272957801818848f,-0.08218517899513245f,-0.08906334638595581f,1.300410509109497f,0.22126758098602295f,-0.11924156546592712f,0.08612995594739914f,-0.028056150302290916f}, |
Lightvalve | 89:a7b45368ea0f | 205 | {-0.08904407918453217f,-0.0344250425696373f,-0.24446426331996918f,0.36650365591049194f,0.6229566931724548f,-0.18743768334388733f,0.2456464171409607f,0.012134413234889507f,-0.15730206668376923f,-0.07979966700077057f,-0.37487393617630005f,0.5054458379745483f,0.08400186896324158f,0.10258787125349045f,-0.26784712076187134f,0.21161137521266937f,0.2236565798521042f,0.3319900929927826f,-0.5802162289619446f,-0.342804491519928f,-0.20100386440753937f,0.1638341248035431f,-0.11680193245410919f,-0.321638286113739f,0.12570004165172577f,0.05633258819580078f,0.13587942719459534f,1.2056348323822021f,0.11766253411769867f,0.30370619893074036f,0.3579072952270508f,0.1400863379240036f}, |
Lightvalve | 89:a7b45368ea0f | 206 | {-0.4138205945491791f,-0.2879457473754883f,-0.06658771634101868f,0.1737249493598938f,-0.027317969128489494f,-0.29802611470222473f,0.13119368255138397f,0.10418662428855896f,-0.2507239282131195f,-0.3831457495689392f,-0.36356019973754883f,-0.2426604926586151f,-0.1789563000202179f,0.2538357675075531f,0.017138004302978516f,0.23985646665096283f,-0.3834385871887207f,-0.24391496181488037f,-0.2302887737751007f,-0.4092941880226135f,0.16973629593849182f,-0.25340327620506287f,0.23975160717964172f,0.011333763599395752f,0.1096729189157486f,0.10268864035606384f,0.08055207133293152f,0.526046872138977f,0.04578748717904091f,0.029612571001052856f,0.29169538617134094f,0.1906040608882904f}, |
Lightvalve | 89:a7b45368ea0f | 207 | {-0.3148506283760071f,0.188726544380188f,-0.3080642819404602f,-0.2519609034061432f,-0.32783371210098267f,-0.5718503594398499f,-0.14704209566116333f,-0.05906349793076515f,-0.16883498430252075f,0.13223543763160706f,0.2747022211551666f,-0.19546236097812653f,-0.03757423162460327f,-0.18436194956302643f,-0.2992876172065735f,0.5082010626792908f,-0.08603760600090027f,-0.1821068376302719f,-0.26429253816604614f,-0.24194110929965973f,0.29002442955970764f,0.2275833785533905f,-0.23374228179454803f,0.3280802071094513f,-0.34091559052467346f,0.2108195722103119f,0.33828380703926086f,0.4916119873523712f,0.0688796192407608f,0.1480078399181366f,0.3437769412994385f,0.021540023386478424f}, |
Lightvalve | 89:a7b45368ea0f | 208 | {-0.22568830847740173f,-0.6859229803085327f,0.19288143515586853f,0.13860811293125153f,0.18111830949783325f,-0.225493386387825f,-0.24846182763576508f,-0.17090129852294922f,-0.2145383656024933f,0.21681338548660278f,-0.16550719738006592f,-0.037777580320835114f,-0.2720222473144531f,-0.3758172392845154f,0.06489166617393494f,0.7701258063316345f,-0.4776385724544525f,0.21822473406791687f,0.033832818269729614f,-0.4730614721775055f,-0.25171342492103577f,0.027203470468521118f,0.012447118759155273f,-0.0029686689376831055f,-0.10113293677568436f,0.03022313117980957f,0.3424017131328583f,0.12006776034832001f,-0.14167943596839905f,-0.34525999426841736f,0.05221972241997719f,0.15499582886695862f}, |
Lightvalve | 89:a7b45368ea0f | 209 | {-0.4222172200679779f,-0.32232731580734253f,0.06283923983573914f,0.013110841624438763f,0.2942807674407959f,-0.09681101888418198f,0.3005536198616028f,-0.4829605221748352f,-0.15350064635276794f,0.2139381766319275f,0.27548399567604065f,-0.37094953656196594f,0.03354460000991821f,0.016582421958446503f,0.1072375476360321f,0.43602806329727173f,-0.4137570858001709f,0.08871319890022278f,-0.09770973771810532f,-0.12307005375623703f,-0.2227887064218521f,-0.01532900333404541f,0.11891454458236694f,-0.33143535256385803f,-0.1446414440870285f,-0.1485452950000763f,0.25882163643836975f,-0.5185427665710449f,0.07972928136587143f,0.24182012677192688f,0.20943428575992584f,0.2407083958387375f}, |
Lightvalve | 89:a7b45368ea0f | 210 | {-0.11078464984893799f,-0.41078031063079834f,0.25620588660240173f,-0.08749675750732422f,0.2765541076660156f,0.05456498637795448f,0.22176240384578705f,-0.26677849888801575f,-0.013202283531427383f,0.02105121687054634f,-0.06236919015645981f,-0.2578541338443756f,0.18931713700294495f,-0.3472287654876709f,0.03958520293235779f,0.510597288608551f,-0.30422690510749817f,-0.07219305634498596f,0.20912642776966095f,0.06666555255651474f,0.31619134545326233f,0.26330670714378357f,0.026431173086166382f,0.237522691488266f,-0.24718806147575378f,0.19442179799079895f,0.1992029845714569f,-0.9869797229766846f,-0.2638043463230133f,-0.10433453321456909f,0.26766809821128845f,-0.23253415524959564f}, |
Lightvalve | 89:a7b45368ea0f | 211 | {-0.5205278396606445f,-0.26201313734054565f,-0.13789941370487213f,0.1127040833234787f,0.44230926036834717f,0.09053512662649155f,-0.22319665551185608f,-0.3336256146430969f,-0.4325152337551117f,0.05464315041899681f,-0.3394671678543091f,-0.09083918482065201f,0.06288954615592957f,-0.24741607904434204f,0.28114965558052063f,0.15618471801280975f,-0.3191489279270172f,-0.14027439057826996f,-0.28128987550735474f,-0.33636051416397095f,0.18525317311286926f,0.07025247812271118f,-0.12988737225532532f,0.04382038116455078f,0.1064760684967041f,-0.12333536148071289f,-0.12442702054977417f,-0.7191746234893799f,-0.19731022417545319f,0.27953919768333435f,0.7405022382736206f,0.19558896124362946f}, |
Lightvalve | 89:a7b45368ea0f | 212 | {-0.30985045433044434f,-0.5093477964401245f,0.23826703429222107f,-0.31279444694519043f,0.6929596662521362f,-0.18644334375858307f,0.3340062201023102f,-0.7429453730583191f,0.11461938917636871f,0.2035832703113556f,-0.3640037178993225f,-0.3512752652168274f,0.012096136808395386f,-0.08958700299263f,-0.03951779007911682f,0.23769795894622803f,-0.40115103125572205f,0.2508954107761383f,0.2533111870288849f,-0.2269076704978943f,0.22447606921195984f,0.30379387736320496f,-0.006355375051498413f,-0.11041811108589172f,-0.286796510219574f,-0.28886765241622925f,-0.05783697962760925f,-1.098929762840271f,0.04438596963882446f,-0.1556464582681656f,0.1087159514427185f,-0.13151060044765472f}, |
Lightvalve | 65:a2d7c63419c2 | 213 | }; |
Lightvalve | 65:a2d7c63419c2 | 214 | |
Lightvalve | 89:a7b45368ea0f | 215 | const float h2[32][32] = { |
Lightvalve | 89:a7b45368ea0f | 216 | {-0.24884511530399323f,-0.10295046865940094f,-0.04925942420959473f,0.02707986906170845f,-0.15490937232971191f,0.20292437076568604f,-0.8661956191062927f,0.06396704912185669f,-0.30411389470100403f,-0.10008957982063293f,-0.165212020277977f,-0.48054441809654236f,-0.0620017908513546f,-1.0283846855163574f,-5.381174087524414f,-0.9529179334640503f,0.07803884148597717f,-0.21483641862869263f,-0.16163024306297302f,-0.004240690264850855f,-0.4911329448223114f,-0.5535577535629272f,-0.3101543188095093f,-0.22541601955890656f,-1.0648218393325806f,1.5496712923049927f,-1.1512086391448975f,-0.295734167098999f,0.23828622698783875f,-0.024554777890443802f,-0.2571799159049988f,-0.1919100433588028f}, |
Lightvalve | 89:a7b45368ea0f | 217 | {-0.2780533730983734f,0.002147972583770752f,-0.04321768879890442f,0.22762925922870636f,0.039372533559799194f,-0.06644093990325928f,-1.1625723838806152f,-0.05986310541629791f,0.24677053093910217f,0.048597872257232666f,0.10102655738592148f,-0.2066873461008072f,0.10818520188331604f,-0.7969831228256226f,1.0538548231124878f,0.8588414192199707f,0.056778669357299805f,-0.2737269401550293f,-0.35849297046661377f,0.20634029805660248f,-0.36483123898506165f,-0.07164712995290756f,-0.29076412320137024f,0.16093440353870392f,-0.15582610666751862f,0.7269571423530579f,-0.26210856437683105f,0.2585713565349579f,-0.28620439767837524f,-0.1940789669752121f,0.12557406723499298f,-0.024700647220015526f}, |
Lightvalve | 89:a7b45368ea0f | 218 | {-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 | 89:a7b45368ea0f | 219 | {-0.2461596429347992f,-0.01806354522705078f,-0.23058539628982544f,0.03521127626299858f,-0.27190759778022766f,-0.5067502856254578f,0.0804506167769432f,-0.06019878387451172f,-0.06944303214550018f,0.09271347522735596f,-0.22685247659683228f,-0.7380675077438354f,-0.29127371311187744f,0.5357500314712524f,-0.11913066357374191f,-0.6795149445533752f,0.10996055603027344f,0.24023392796516418f,-0.10359782725572586f,-0.2149972915649414f,-0.3025924861431122f,-0.48566338419914246f,-0.11944298446178436f,-0.3593066334724426f,-0.27389389276504517f,-0.19860105216503143f,-0.27698126435279846f,-0.3569595217704773f,-0.22396358847618103f,0.1187380850315094f,-0.08347906917333603f,-0.0007677236571907997f}, |
Lightvalve | 89:a7b45368ea0f | 220 | {-0.3100738525390625f,0.2506926953792572f,-0.0804666131734848f,0.061038803309202194f,0.02918580174446106f,-0.5375155806541443f,-1.5650798082351685f,-0.14490489661693573f,0.043158918619155884f,-0.2690317630767822f,-1.8862931728363037f,-0.5884978175163269f,-0.4069013297557831f,-0.4935837388038635f,-0.9080424904823303f,-0.34340202808380127f,-0.10307048261165619f,0.15626338124275208f,-0.3583506941795349f,0.0058685410767793655f,-0.015140853822231293f,-0.149311363697052f,0.02121141366660595f,-0.40197017788887024f,-1.6539796590805054f,-2.762812376022339f,-2.6964528560638428f,0.12341205030679703f,0.2695164978504181f,-0.321733683347702f,-0.12418606132268906f,-0.32664018869400024f}, |
Lightvalve | 89:a7b45368ea0f | 221 | {-0.19158349931240082f,-0.004258692264556885f,0.032371193170547485f,-0.2938489317893982f,-0.023485273122787476f,0.2851887047290802f,-0.09775897115468979f,-0.14440131187438965f,-0.03548547625541687f,0.08825305104255676f,-0.21583324670791626f,0.1738855540752411f,-0.2578849494457245f,-0.07232409715652466f,-0.13833220303058624f,0.0032729320228099823f,0.2371552288532257f,0.24713221192359924f,0.19205603003501892f,0.15854741632938385f,-0.16550931334495544f,0.11437536776065826f,-0.1307595670223236f,-0.076647087931633f,0.08997642248868942f,-0.3786443769931793f,0.06452243030071259f,-0.1354997605085373f,0.05800282955169678f,-0.40722623467445374f,0.17187702655792236f,0.14475803077220917f}, |
Lightvalve | 89:a7b45368ea0f | 222 | {-0.21433322131633759f,-0.1279313862323761f,-0.11171227693557739f,0.25136756896972656f,-0.26441383361816406f,0.2845393121242523f,0.041312653571367264f,-0.20844537019729614f,-0.26620519161224365f,0.17144301533699036f,-0.07957437634468079f,-0.2724485397338867f,0.29584869742393494f,-0.023175599053502083f,-0.12345022708177567f,0.08411633223295212f,-0.16153597831726074f,0.18742787837982178f,-0.20045162737369537f,0.059110552072525024f,-0.046937815845012665f,-0.005264040548354387f,-0.07988794147968292f,-0.17039190232753754f,-0.07056275755167007f,-0.4178033769130707f,0.19651268422603607f,-0.1967385858297348f,-0.11822041869163513f,0.19546762108802795f,-0.16657039523124695f,-0.000729912135284394f}, |
Lightvalve | 89:a7b45368ea0f | 223 | {0.18205103278160095f,0.11346611380577087f,0.04012581706047058f,0.004675532691180706f,0.22828009724617004f,-0.9748165011405945f,-1.5658994913101196f,-0.13317009806632996f,0.2864855229854584f,0.01006925106048584f,-1.7065072059631348f,-0.2900503873825073f,-0.2382865995168686f,-0.7094941735267639f,0.7180572748184204f,0.07947060465812683f,-0.2721019387245178f,0.2706601917743683f,-0.10587131977081299f,-0.14732545614242554f,0.04871872812509537f,-0.1827782392501831f,-0.3025624752044678f,0.07826858758926392f,-1.6559882164001465f,0.2867830693721771f,-1.4658112525939941f,-0.229370579123497f,-0.14135785400867462f,-0.0749492198228836f,0.037974074482917786f,-0.11222749203443527f}, |
Lightvalve | 89:a7b45368ea0f | 224 | {0.16382472217082977f,0.2890130579471588f,-0.021617114543914795f,0.10035208612680435f,0.29321715235710144f,-0.5941426753997803f,-0.9791392087936401f,-0.3692907691001892f,0.29470762610435486f,-0.06864601373672485f,-0.9347758889198303f,-0.3577685058116913f,0.10174375772476196f,-1.1892009973526f,1.5573197603225708f,0.5846696496009827f,0.046292245388031006f,0.06025278568267822f,-0.33354344964027405f,0.22304639220237732f,0.21487970650196075f,-0.3296683430671692f,0.16501928865909576f,-0.16466358304023743f,-1.7639918327331543f,-0.931217610836029f,-1.2150951623916626f,-0.02735067717730999f,0.2501918375492096f,-0.2835308313369751f,-0.35732853412628174f,-0.36441531777381897f}, |
Lightvalve | 89:a7b45368ea0f | 225 | {0.2615049183368683f,0.08643358945846558f,-0.29237738251686096f,-0.2463665008544922f,0.15896368026733398f,0.0016535647446289659f,1.0283740758895874f,-0.25379088521003723f,0.18755429983139038f,-0.07031691074371338f,0.6797151565551758f,-0.6807708740234375f,-0.010029126890003681f,0.5625613927841187f,-0.22179760038852692f,-0.8032732605934143f,-0.015168905258178711f,-0.2859399914741516f,-0.4330553412437439f,-0.23430761694908142f,0.04670058190822601f,-0.013992827385663986f,-0.2307620644569397f,0.1691003143787384f,-0.002764361444860697f,-0.5617508888244629f,1.016584038734436f,-0.043152157217264175f,0.2113950550556183f,-0.054945893585681915f,-0.0010054409503936768f,-0.1481325328350067f}, |
Lightvalve | 89:a7b45368ea0f | 226 | {0.19981321692466736f,0.1956864297389984f,-0.033508092164993286f,-0.22838544845581055f,-0.12505969405174255f,0.026693344116210938f,0.0776548832654953f,0.14285165071487427f,-0.17670965194702148f,0.17403557896614075f,-0.18919339776039124f,0.10912971198558807f,-0.1060299277305603f,-0.004234084393829107f,-0.16190937161445618f,0.06031673774123192f,0.03990337252616882f,0.0716913640499115f,0.15350449085235596f,-0.09222009032964706f,0.25596585869789124f,0.09463635087013245f,0.07470300793647766f,0.3015579879283905f,0.05757787823677063f,0.061355363577604294f,-0.000344813393894583f,-0.2524169087409973f,0.13817378878593445f,0.17853263020515442f,-0.009185433387756348f,-0.02081478014588356f}, |
Lightvalve | 89:a7b45368ea0f | 227 | {-0.37253594398498535f,-0.09556084871292114f,0.12328919768333435f,0.07122714817523956f,-0.258735328912735f,-0.2757439911365509f,-1.4993038177490234f,-0.2444004863500595f,0.17735600471496582f,0.009893029928207397f,-0.05616951361298561f,-0.30972567200660706f,-0.2326023131608963f,-2.8106157779693604f,0.7795978784561157f,0.8158812522888184f,0.009990394115447998f,0.10842388868331909f,-0.0015612695133313537f,0.1710408478975296f,-0.1640889197587967f,-0.3869341015815735f,-0.1491391360759735f,-0.07571160793304443f,-2.2670748233795166f,-1.2573970556259155f,-0.7933836579322815f,0.11647215485572815f,-0.288028746843338f,-0.38098666071891785f,0.049322400242090225f,0.1433139145374298f}, |
Lightvalve | 89:a7b45368ea0f | 228 | {-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 | 89:a7b45368ea0f | 229 | {0.14700931310653687f,0.1833711564540863f,-0.0858893096446991f,0.059287380427122116f,-0.25116482377052307f,0.2733006179332733f,0.1710028052330017f,-0.16134384274482727f,0.000652611255645752f,-0.22920364141464233f,0.21644526720046997f,-0.36634811758995056f,0.26723334193229675f,0.40844377875328064f,-0.18742600083351135f,-0.4884636700153351f,-0.07963520288467407f,0.14483880996704102f,-0.2811259925365448f,-0.21284618973731995f,-0.09455670416355133f,0.20116078853607178f,-0.2228696048259735f,0.22894902527332306f,0.06873877346515656f,-0.08788177371025085f,0.06689995527267456f,0.10385961830615997f,-0.011228948831558228f,0.26896968483924866f,-0.28556761145591736f,0.02100294455885887f}, |
Lightvalve | 89:a7b45368ea0f | 230 | {-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 | 89:a7b45368ea0f | 231 | {-0.15892109274864197f,0.1317739188671112f,0.03260180354118347f,-0.1927446722984314f,-0.05160003900527954f,-0.534025251865387f,-0.21370860934257507f,-0.03364188224077225f,0.05445769429206848f,0.07657262682914734f,-0.4512843191623688f,-0.517540454864502f,0.08404679596424103f,-0.1785459816455841f,-0.12632714211940765f,-1.0249115228652954f,-0.25386664271354675f,-0.18997573852539062f,-0.36189472675323486f,-0.26924318075180054f,-0.1672324687242508f,-0.2426733523607254f,-0.730017364025116f,0.09599462151527405f,-0.3474728763103485f,-2.3507585525512695f,-0.47989511489868164f,-0.4416758120059967f,-0.0006675124168395996f,-0.35991936922073364f,-0.17363247275352478f,0.1250540018081665f}, |
Lightvalve | 89:a7b45368ea0f | 232 | {0.036086976528167725f,-0.062024205923080444f,0.10704237222671509f,-0.16218894720077515f,-0.04875987768173218f,-0.5561403036117554f,-0.05187790095806122f,0.13977529108524323f,-0.23304778337478638f,-0.035415440797805786f,-0.9932711124420166f,-0.0830407589673996f,0.03618334233760834f,-0.09362911432981491f,0.3184598982334137f,-0.08273540437221527f,-0.027234435081481934f,0.19620582461357117f,0.01967497356235981f,-0.2715267837047577f,0.001052129315212369f,-0.1183658167719841f,-0.2635014057159424f,-0.42729949951171875f,-0.9877696633338928f,0.3225666880607605f,-0.5459384322166443f,0.1087341234087944f,-0.2531542181968689f,0.09848026931285858f,-0.29045569896698f,-0.3233194351196289f}, |
Lightvalve | 89:a7b45368ea0f | 233 | {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 | 89:a7b45368ea0f | 234 | {-0.017657099291682243f,0.2841971218585968f,-0.0814327746629715f,-0.021704204380512238f,-0.017610490322113037f,-0.034884437918663025f,-1.2548327445983887f,0.11265848577022552f,-0.2925014793872833f,0.022429823875427246f,-1.0905170440673828f,-0.24021278321743011f,-0.2615266442298889f,-1.57011079788208f,0.9651749730110168f,2.436189651489258f,0.1296386420726776f,0.027322769165039062f,0.04849059879779816f,-0.03877267986536026f,0.020655816420912743f,-0.2378704696893692f,-0.08734534680843353f,0.06631384789943695f,-1.9399195909500122f,-2.259996175765991f,-1.4060866832733154f,-0.16243590414524078f,0.14345040917396545f,-0.2618231177330017f,-0.23102368414402008f,0.05394546687602997f}, |
Lightvalve | 89:a7b45368ea0f | 235 | {-0.26263561844825745f,0.29651907086372375f,0.02990397810935974f,-0.05575937032699585f,0.1826970875263214f,-0.3982952833175659f,-0.6370453238487244f,0.26979032158851624f,-0.2325194776058197f,-0.2458522766828537f,-0.007418768014758825f,-0.3996718227863312f,-0.3503566086292267f,-0.7228636145591736f,1.0390828847885132f,0.9585302472114563f,0.2577105462551117f,0.11064860224723816f,-0.31864234805107117f,-0.023358142003417015f,-0.0016425023786723614f,-0.6196765303611755f,-0.1119745597243309f,-0.09912597388029099f,-0.2200295776128769f,-0.08841383457183838f,-0.5124247670173645f,0.2643086314201355f,-0.2205982804298401f,0.14076603949069977f,-0.1757250279188156f,0.023216821253299713f}, |
Lightvalve | 89:a7b45368ea0f | 236 | {0.2703488767147064f,-0.16041381657123566f,0.12738299369812012f,-0.03611093759536743f,0.1169431209564209f,0.1861400008201599f,-0.1765512377023697f,0.28177282214164734f,0.1474648416042328f,-0.23766008019447327f,-0.005803406238555908f,0.08728843927383423f,0.09594401717185974f,-0.17028304934501648f,-0.16805587708950043f,-0.058941617608070374f,-0.22846683859825134f,0.08700510859489441f,-0.2656046748161316f,0.07154610753059387f,-0.1559111475944519f,0.22832396626472473f,-0.18301571905612946f,-0.17816279828548431f,-0.04200500249862671f,0.2835671007633209f,0.1830621361732483f,-0.26011598110198975f,0.08541131019592285f,0.08213254809379578f,-0.29332536458969116f,0.08477649092674255f}, |
Lightvalve | 89:a7b45368ea0f | 237 | {-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 | 89:a7b45368ea0f | 238 | {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 | 89:a7b45368ea0f | 239 | {-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 | 89:a7b45368ea0f | 240 | {-0.12992967665195465f,-0.25281068682670593f,-0.10565309226512909f,-0.07918522506952286f,0.2702934443950653f,-0.5060265064239502f,-2.2521328926086426f,-0.33907046914100647f,-0.06814777851104736f,-0.24531681835651398f,-1.3586469888687134f,-0.32010430097579956f,-0.1653079390525818f,-7.5781402587890625f,0.9042810201644897f,1.9208794832229614f,0.2015441358089447f,0.04417389631271362f,-0.03381158038973808f,0.09063783288002014f,0.003683165181428194f,-0.2655920088291168f,-0.5420690178871155f,0.13454720377922058f,-3.71278977394104f,-4.804920673370361f,-2.438314199447632f,-0.1479518711566925f,-0.18211489915847778f,-0.30876263976097107f,0.07066735625267029f,0.13299095630645752f}, |
Lightvalve | 89:a7b45368ea0f | 241 | {-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 | 89:a7b45368ea0f | 242 | {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 | 89:a7b45368ea0f | 243 | {0.1872251182794571f,-0.11652402579784393f,0.24921879172325134f,0.1870449334383011f,-0.2817712128162384f,-0.471887469291687f,-0.570704460144043f,-0.22949419915676117f,0.23963233828544617f,0.21321198344230652f,-0.22998826205730438f,-0.19151856005191803f,-0.3084449768066406f,-0.06819570064544678f,-0.16640815138816833f,-1.2870584726333618f,-0.19791248440742493f,0.2487291395664215f,-0.4555669128894806f,-0.30103084444999695f,-0.2687109112739563f,-0.17608027160167694f,-0.5496065020561218f,-0.3722294867038727f,0.12690000236034393f,4.395594120025635f,-0.1391826868057251f,-0.20867836475372314f,-0.03476092219352722f,0.1356719732284546f,-0.09322817623615265f,-0.16395188868045807f}, |
Lightvalve | 89:a7b45368ea0f | 244 | {-0.17075178027153015f,0.009595632553100586f,0.2466227114200592f,0.05338657647371292f,-0.29828932881355286f,-0.2819134294986725f,-0.08217992633581161f,-0.15331926941871643f,-0.2516406178474426f,0.012286126613616943f,0.1951085329055786f,-0.34216028451919556f,-0.09437626600265503f,-0.01486560981720686f,-0.033015795052051544f,-0.026025136932730675f,-0.24087269604206085f,-0.048499464988708496f,-0.3224903643131256f,0.008257976733148098f,-0.27921897172927856f,-0.26612040400505066f,-0.031352698802948f,0.2829146385192871f,-0.04500345513224602f,-0.27047377824783325f,-0.4029959440231323f,0.26659882068634033f,-0.07090267539024353f,-0.23986908793449402f,-0.2543276250362396f,0.01611592434346676f}, |
Lightvalve | 89:a7b45368ea0f | 245 | {-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 | 89:a7b45368ea0f | 246 | {-0.30146604776382446f,-0.17203155159950256f,0.0620841383934021f,-0.026889100670814514f,-0.07396678626537323f,-1.0299530029296875f,-2.8012266159057617f,0.02751191519200802f,-0.21029016375541687f,0.2210421860218048f,-0.3981570303440094f,-0.11896248161792755f,-0.20211905241012573f,-0.17902104556560516f,-1.1087616682052612f,-0.42965641617774963f,0.10771593451499939f,-0.29308468103408813f,-0.29877009987831116f,-0.1888214647769928f,-0.1405947506427765f,-0.40318942070007324f,-0.370537668466568f,0.028905242681503296f,-1.7976940870285034f,-2.0812807083129883f,-4.568117618560791f,-0.032483071088790894f,0.17976179718971252f,-0.22928372025489807f,0.1545799821615219f,-0.0419585220515728f}, |
Lightvalve | 89:a7b45368ea0f | 247 | {-0.09888127446174622f,-0.22750279307365417f,-0.22503364086151123f,-0.030222373083233833f,-0.012498408555984497f,-0.24329537153244019f,-0.09181441366672516f,0.08175003528594971f,-0.016126900911331177f,0.06972584128379822f,0.41604337096214294f,0.13558582961559296f,-0.031845152378082275f,-0.34389445185661316f,0.5235684514045715f,0.215203657746315f,-0.09216172993183136f,0.04617339372634888f,-0.1526023894548416f,-0.13339459896087646f,0.6752443909645081f,-0.31539809703826904f,-0.06047184765338898f,-0.30429452657699585f,-0.3479069471359253f,-0.9104090332984924f,0.8691915273666382f,-0.31245481967926025f,-0.16326025128364563f,0.01193301472812891f,-0.02675291895866394f,0.17420369386672974f}, |
Lightvalve | 65:a2d7c63419c2 | 248 | }; |
Lightvalve | 65:a2d7c63419c2 | 249 | |
Lightvalve | 89:a7b45368ea0f | 250 | const float h3[32][32] = { |
Lightvalve | 89:a7b45368ea0f | 251 | {-0.2551194727420807f,-0.09101890027523041f,-0.026477575302124023f,-0.24469062685966492f,0.028834380209445953f,-0.11549980193376541f,0.23563924431800842f,0.21467849612236023f,-0.17011712491512299f,0.034586966037750244f,-0.08393588662147522f,0.28293344378471375f,0.045914679765701294f,0.1892293095588684f,-0.2476848065853119f,0.13452908396720886f,0.033751994371414185f,0.2061004936695099f,0.0946265459060669f,-0.10083381831645966f,-0.11890523135662079f,0.024368882179260254f,-0.22618433833122253f,0.044178664684295654f,0.25393906235694885f,-0.1258748173713684f,0.2930828630924225f,-0.09901801496744156f,-0.030303647741675377f,0.2922307550907135f,-0.21407078206539154f,-0.3020341694355011f}, |
Lightvalve | 89:a7b45368ea0f | 252 | {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 | 89:a7b45368ea0f | 253 | {-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 | 89:a7b45368ea0f | 254 | {0.2906629145145416f,0.19203472137451172f,-0.2048129439353943f,0.2633720338344574f,0.10351300984621048f,-0.06133239343762398f,-0.061309605836868286f,-0.17915479838848114f,-0.02033988945186138f,-0.044261813163757324f,-0.09506386518478394f,0.24970653653144836f,0.15105298161506653f,0.06916186213493347f,0.22106656432151794f,-0.23978039622306824f,-0.28915077447891235f,0.030949801206588745f,-0.27313676476478577f,0.1836264431476593f,0.24285662174224854f,-0.0373874306678772f,-0.16296987235546112f,-0.27595841884613037f,0.19668178260326385f,-0.11024686694145203f,-0.09994620084762573f,0.00232623890042305f,-0.19564327597618103f,-0.25852420926094055f,0.05653107166290283f,0.0037463903427124023f}, |
Lightvalve | 89:a7b45368ea0f | 255 | {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 | 89:a7b45368ea0f | 256 | {0.10931676626205444f,0.09901993721723557f,0.12925085425376892f,-0.06346556544303894f,-0.31038108468055725f,0.3142895996570587f,-0.061815500259399414f,0.04091137647628784f,-0.18566812574863434f,-0.15699732303619385f,0.04343574866652489f,-0.21529507637023926f,1.0960476398468018f,0.4208458960056305f,0.2971965968608856f,0.25175121426582336f,-0.2889891266822815f,-0.13035915791988373f,0.25247663259506226f,0.7784700989723206f,-0.3849126994609833f,0.2185358703136444f,0.023232191801071167f,0.27409639954566956f,0.35451456904411316f,-0.18302330374717712f,0.09057381749153137f,-0.3630118668079376f,-0.5228159427642822f,-0.29547566175460815f,-0.25800079107284546f,0.27328526973724365f}, |
Lightvalve | 89:a7b45368ea0f | 257 | {-0.21155381202697754f,0.24320489168167114f,-0.24049416184425354f,0.38925015926361084f,-0.13059227168560028f,1.2946875095367432f,-0.10846608132123947f,0.2444917857646942f,-0.6105182766914368f,-0.32602089643478394f,0.5678800940513611f,-0.3907425105571747f,0.059721797704696655f,0.42207664251327515f,0.25543639063835144f,-0.1192857176065445f,-0.18917083740234375f,0.011466026306152344f,1.308021903038025f,-0.07634314894676208f,-0.9140365123748779f,0.8853653073310852f,-0.26710981130599976f,-0.2255190908908844f,0.7980838418006897f,-0.2910519242286682f,-0.30968034267425537f,-1.6649792194366455f,-2.0920190811157227f,-0.09532724320888519f,0.14420299232006073f,0.263065904378891f}, |
Lightvalve | 89:a7b45368ea0f | 258 | {-0.01093912124633789f,-0.23583689332008362f,0.28153905272483826f,0.2877257764339447f,0.09408318996429443f,-0.2994205355644226f,0.036741942167282104f,-0.0059101879596710205f,-0.23830170929431915f,-0.27182313799858093f,0.09319102764129639f,-0.08139897882938385f,0.19774547219276428f,-0.038983892649412155f,0.0685860812664032f,-0.29903873801231384f,0.1317853033542633f,0.20550194382667542f,-0.12251400947570801f,-0.2671976387500763f,0.24989311397075653f,0.10190683603286743f,0.0343703031539917f,0.12564969062805176f,0.006905830465257168f,0.23886635899543762f,-0.2778390347957611f,0.1619493067264557f,0.249174565076828f,0.17161712050437927f,-0.017215043306350708f,-0.07319892197847366f}, |
Lightvalve | 89:a7b45368ea0f | 259 | {-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 | 89:a7b45368ea0f | 260 | {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 | 89:a7b45368ea0f | 261 | {-0.023678362369537354f,0.25627627968788147f,-0.2606240510940552f,0.027978017926216125f,0.15899628400802612f,0.6595502495765686f,-0.0036431346088647842f,0.196751207113266f,-0.5179072618484497f,0.20499464869499207f,0.9699771404266357f,-0.06168833374977112f,-0.2220895141363144f,0.47917166352272034f,0.080221027135849f,-0.2471318244934082f,0.026521950960159302f,0.28880444169044495f,0.05281196907162666f,-0.39944612979888916f,-0.5933054089546204f,0.5928339958190918f,0.04898126795887947f,0.2614522874355316f,0.7622845768928528f,-0.25962090492248535f,-0.037509460002183914f,-0.4053201377391815f,0.1844288557767868f,-0.2912617325782776f,-0.3931782841682434f,-0.4292046129703522f}, |
Lightvalve | 89:a7b45368ea0f | 262 | {0.2680447995662689f,0.08889183402061462f,-0.34841927886009216f,-0.12294139713048935f,-0.006906433962285519f,0.18842726945877075f,0.1912839114665985f,-0.17794576287269592f,0.29124289751052856f,-0.3118562698364258f,-0.3657170534133911f,0.2547462284564972f,0.2927215099334717f,0.014082422479987144f,0.23152390122413635f,-0.07731422781944275f,0.21101722121238708f,-0.15284278988838196f,0.18169839680194855f,0.09024403244256973f,0.14264146983623505f,0.17841528356075287f,-0.27908316254615784f,0.12623250484466553f,-0.43558114767074585f,0.18312275409698486f,-0.2869618535041809f,0.39280518889427185f,0.24194808304309845f,-0.1739533692598343f,-0.3423449695110321f,-0.2080104500055313f}, |
Lightvalve | 89:a7b45368ea0f | 263 | {0.10771462321281433f,0.1270637810230255f,-0.1647956818342209f,-0.00161704421043396f,0.22193093597888947f,0.03871941566467285f,-0.2502448558807373f,-0.05063694715499878f,-0.1898418813943863f,-0.11501708626747131f,0.11628510057926178f,0.11519002914428711f,-0.1879904866218567f,-0.05469268187880516f,-0.0055807530879974365f,0.05870962142944336f,-0.0561012327671051f,-0.1419317126274109f,-0.12008143961429596f,0.001279879012145102f,-0.11299116909503937f,-0.3814079761505127f,0.2986377775669098f,-0.2888573110103607f,-0.2871626615524292f,-0.03866580128669739f,0.09892630577087402f,0.3167524039745331f,-0.015963073819875717f,0.024399906396865845f,-0.264041006565094f,-0.11027073860168457f}, |
Lightvalve | 89:a7b45368ea0f | 264 | {0.07240793108940125f,-0.09338265657424927f,-0.06903354823589325f,0.015366114675998688f,-0.2661875784397125f,1.5422624349594116f,0.15137922763824463f,-0.09019742906093597f,-0.5131413340568542f,-0.6012843251228333f,-0.11048789322376251f,-0.12352582067251205f,-2.6593611240386963f,0.6466706991195679f,0.13272255659103394f,-0.0684008002281189f,-0.13351139426231384f,0.2471931278705597f,0.031969256699085236f,1.09149968624115f,-0.9428436160087585f,0.19677256047725677f,-0.08138792216777802f,0.28785380721092224f,1.0912519693374634f,-0.1976800560951233f,-0.28017786145210266f,0.11125613003969193f,0.3943520188331604f,-0.29330405592918396f,-0.12236892431974411f,2.205066204071045f}, |
Lightvalve | 89:a7b45368ea0f | 265 | {-0.27890223264694214f,-0.07800088077783585f,-0.12371830642223358f,-1.2700937986373901f,-1.0912457704544067f,0.9797009229660034f,-0.2505151033401489f,-0.2674597501754761f,-0.16105304658412933f,-0.20609107613563538f,-1.0739810466766357f,-0.10769722610712051f,-0.8888100981712341f,-0.2861039340496063f,-0.02410009503364563f,0.10129088163375854f,0.22686699032783508f,-0.30486053228378296f,0.86100172996521f,-3.4880826473236084f,-0.36854830384254456f,0.26552632451057434f,-0.14972762763500214f,0.11354613304138184f,-0.013822424225509167f,-0.18427850306034088f,-0.19968591630458832f,-0.36554718017578125f,-0.7460378408432007f,0.06508117914199829f,-0.04379427433013916f,-0.5686119198799133f}, |
Lightvalve | 89:a7b45368ea0f | 266 | {0.3047083914279938f,-0.05296872928738594f,-0.3443875312805176f,-1.3551783561706543f,1.0348049402236938f,-1.132575511932373f,-0.20920369029045105f,-0.25786101818084717f,-0.2481493502855301f,-0.3406773507595062f,-0.7330422401428223f,-0.11543221771717072f,1.4418936967849731f,-2.2486696243286133f,0.062144935131073f,-0.28920799493789673f,0.03473195433616638f,-0.0016761720180511475f,0.594510018825531f,-5.295821666717529f,-0.4134751260280609f,-1.7540544271469116f,0.08548198640346527f,-0.10900285840034485f,-2.413933515548706f,-0.18968722224235535f,-0.3918294906616211f,0.2870296239852905f,-1.4750810861587524f,0.017086774110794067f,-0.22334833443164825f,-0.29180970788002014f}, |
Lightvalve | 89:a7b45368ea0f | 267 | {-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 | 89:a7b45368ea0f | 268 | {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 | 89:a7b45368ea0f | 269 | {-0.16101892292499542f,0.0549481138586998f,0.26537272334098816f,0.14797939360141754f,-0.08496929705142975f,-0.20862935483455658f,0.1589156985282898f,-0.17396175861358643f,0.24158169329166412f,-0.12575815618038177f,0.3032090365886688f,-0.04377517104148865f,-0.09723557531833649f,-0.004979115445166826f,-0.2592318058013916f,0.1978430449962616f,0.18047624826431274f,0.2863751947879791f,-0.21538209915161133f,-0.02161381021142006f,-0.1044420450925827f,0.13378354907035828f,0.25320637226104736f,0.13123968243598938f,-0.06181655451655388f,-0.28873488306999207f,-0.09778036177158356f,0.23691287636756897f,0.21785739064216614f,0.18439257144927979f,0.17250561714172363f,0.17694389820098877f}, |
Lightvalve | 89:a7b45368ea0f | 270 | {0.261911004781723f,-0.28497835993766785f,-0.2993849217891693f,-0.02090282365679741f,0.0802551805973053f,0.04678889364004135f,-0.06670857965946198f,-0.030254334211349487f,-0.2704773545265198f,0.1197996437549591f,0.01667046546936035f,-0.2924177646636963f,0.20017656683921814f,-0.1378343403339386f,-0.20773646235466003f,-0.10781967639923096f,-0.15712574124336243f,0.16112294793128967f,0.23735012114048004f,0.18995007872581482f,0.20655642449855804f,0.11912650614976883f,-0.2746070921421051f,0.14906415343284607f,0.1447516828775406f,0.0025720298290252686f,-0.08664152026176453f,-0.20831836760044098f,0.07929258048534393f,0.21125611662864685f,-0.05751854181289673f,-0.22727590799331665f}, |
Lightvalve | 89:a7b45368ea0f | 271 | {0.14277681708335876f,-0.21723729372024536f,0.0499022975564003f,-0.22327251732349396f,-0.0364639014005661f,-0.07534641027450562f,0.1624150574207306f,-0.27022814750671387f,-0.033554524183273315f,-0.43515852093696594f,-0.19478121399879456f,0.032551031559705734f,-0.012572181411087513f,0.006577334366738796f,-0.03100520372390747f,-0.2484396994113922f,0.06366744637489319f,-0.2764144539833069f,0.06228047236800194f,0.20165595412254333f,-0.27491843700408936f,0.1637345552444458f,0.22071760892868042f,-0.0716068297624588f,-0.24483560025691986f,-0.19159743189811707f,0.1727093905210495f,-0.25190210342407227f,0.13014718890190125f,-0.10488687455654144f,-0.21563708782196045f,-0.220583975315094f}, |
Lightvalve | 89:a7b45368ea0f | 272 | {0.29069945216178894f,-0.23835359513759613f,0.019009560346603394f,-0.30957385897636414f,-0.06500361114740372f,-0.23950506746768951f,0.045349299907684326f,-0.17138783633708954f,-0.14764569699764252f,0.028545528650283813f,-0.16238126158714294f,-0.15074089169502258f,-0.29816436767578125f,-0.23938924074172974f,0.09875330328941345f,0.08164769411087036f,0.2294725477695465f,0.10683679580688477f,-0.27405375242233276f,-0.0006060161394998431f,0.17440509796142578f,0.2672456204891205f,0.16651621460914612f,-0.15362010896205902f,0.25261634588241577f,0.023651927709579468f,-0.1729920208454132f,0.31404948234558105f,0.10934463143348694f,0.19045329093933105f,0.02994692325592041f,0.02890726737678051f}, |
Lightvalve | 89:a7b45368ea0f | 273 | {0.1991647183895111f,0.12534403800964355f,-0.04112154245376587f,0.23123982548713684f,-0.08205600827932358f,-0.28823745250701904f,-0.1610087752342224f,-0.031804412603378296f,0.10274738073348999f,-0.25018924474716187f,0.15975651144981384f,-0.057292819023132324f,0.11819945275783539f,-0.028415275737643242f,0.2151305377483368f,0.2952744662761688f,-0.21319252252578735f,0.04970458149909973f,0.31859418749809265f,0.3050673305988312f,0.21167120337486267f,-0.07602974027395248f,0.13887640833854675f,0.25299301743507385f,-0.44058921933174133f,-0.07015113532543182f,-0.287551611661911f,-0.10459110885858536f,-0.09004730731248856f,-0.24420931935310364f,0.015819430351257324f,-0.11104980111122131f}, |
Lightvalve | 89:a7b45368ea0f | 274 | {0.12202468514442444f,0.15165209770202637f,-0.10034829378128052f,-0.32564064860343933f,0.19685158133506775f,0.14437249302864075f,-0.06113804876804352f,-0.11568751931190491f,0.32051777839660645f,-0.3136619031429291f,-0.06917986273765564f,-0.11160935461521149f,-0.09922535717487335f,-0.2136005163192749f,-0.06735922396183014f,0.05864924192428589f,-0.25733181834220886f,-0.17565661668777466f,0.0016648777527734637f,-0.11804971843957901f,-0.2269780933856964f,0.15428996086120605f,0.14481176435947418f,-0.05681343376636505f,0.20978398621082306f,0.1795230209827423f,0.19069638848304749f,-0.020621083676815033f,-0.14379416406154633f,0.2425754964351654f,-0.22172409296035767f,-0.009572982788085938f}, |
Lightvalve | 89:a7b45368ea0f | 275 | {-0.3055141270160675f,-0.25092458724975586f,-0.19300995767116547f,0.7325661778450012f,-0.8033947348594666f,-1.040702223777771f,0.04595213010907173f,0.21086838841438293f,-0.0748712420463562f,-0.31109288334846497f,-0.5775437355041504f,-0.15827980637550354f,-0.26629605889320374f,0.04673107713460922f,-0.023131370544433594f,0.036719828844070435f,0.16260939836502075f,0.05286213755607605f,1.6439915895462036f,-1.9019787311553955f,-0.2704979181289673f,-0.6358916163444519f,0.10412012040615082f,0.19191309809684753f,-0.7669793963432312f,-0.02825927734375f,-0.20535290241241455f,-1.277054786682129f,0.2577309310436249f,0.1865309774875641f,0.10359535366296768f,0.3297824561595917f}, |
Lightvalve | 89:a7b45368ea0f | 276 | {0.1782623827457428f,-0.03855970501899719f,-0.4635035991668701f,0.29705339670181274f,0.29944854974746704f,0.572848916053772f,-0.36316245794296265f,0.1475539207458496f,-0.17366336286067963f,-0.29410749673843384f,-0.11954933404922485f,-0.3833993077278137f,0.7884312868118286f,1.1966091394424438f,-0.2527656555175781f,-0.3049176335334778f,0.032145023345947266f,-0.25376296043395996f,0.5861251354217529f,-1.4569975137710571f,-0.2457541525363922f,0.18761852383613586f,-0.05961836501955986f,0.05391114950180054f,0.6069787740707397f,-0.058409590274095535f,-0.06608664989471436f,-1.4693738222122192f,0.8979771733283997f,0.1616479754447937f,-0.26603591442108154f,1.185694694519043f}, |
Lightvalve | 89:a7b45368ea0f | 277 | {-0.17396044731140137f,-0.12593205273151398f,-0.19672991335391998f,0.05691675841808319f,0.1397278606891632f,0.21612973511219025f,-0.16139104962348938f,-0.1761629432439804f,-0.6402992010116577f,-0.32974573969841003f,1.1390248537063599f,-0.26317694783210754f,0.2519507110118866f,0.9231234788894653f,-0.19851773977279663f,-0.10762731730937958f,0.14198419451713562f,0.10370296239852905f,0.5022594928741455f,-0.6512249708175659f,-0.7421490550041199f,0.7806501984596252f,0.14419947564601898f,-0.19857197999954224f,1.0913468599319458f,-0.2665709853172302f,0.19562599062919617f,-0.340131014585495f,-0.5099549293518066f,-0.1200934648513794f,-0.1742367148399353f,0.5318814516067505f}, |
Lightvalve | 89:a7b45368ea0f | 278 | {-0.12546227872371674f,-0.046350039541721344f,-0.08090300858020782f,0.13400159776210785f,-0.15044839680194855f,-0.3213222324848175f,-0.28310835361480713f,-0.020981580018997192f,0.04249835014343262f,-0.1450422704219818f,-0.19499319791793823f,0.046816736459732056f,-0.04238327220082283f,-0.1563507467508316f,-0.0649729073047638f,0.2468220293521881f,0.060016900300979614f,-0.16779978573322296f,0.19903524219989777f,0.08180815726518631f,-0.11929178237915039f,0.04381689429283142f,-0.3016570210456848f,0.22389158606529236f,-0.06335359811782837f,0.020356476306915283f,-0.2721233367919922f,0.2845783233642578f,0.03800060600042343f,-0.000007510185241699219f,0.094448983669281f,-0.08897853642702103f}, |
Lightvalve | 89:a7b45368ea0f | 279 | {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 | 89:a7b45368ea0f | 280 | {0.06582912802696228f,0.2796666920185089f,-0.2556927502155304f,0.0023079216480255127f,0.32987985014915466f,0.008925902657210827f,0.06556430459022522f,0.29767414927482605f,0.3899354934692383f,-0.16670267283916473f,-0.07468277961015701f,-0.06570860743522644f,-0.015925198793411255f,0.050778210163116455f,-0.014884740114212036f,-0.05300724506378174f,0.26490333676338196f,0.15243005752563477f,0.07542221993207932f,0.35540080070495605f,0.35460686683654785f,0.036047618836164474f,-0.04174882173538208f,-0.11559568345546722f,-0.19164401292800903f,0.21069613099098206f,-0.19532959163188934f,-0.11914381384849548f,0.032513976097106934f,-0.2712400257587433f,-0.19435247778892517f,-0.23200613260269165f}, |
Lightvalve | 89:a7b45368ea0f | 281 | {-0.1299392580986023f,-0.06208275258541107f,-0.18067686259746552f,0.062329649925231934f,-0.18659290671348572f,-0.17816488444805145f,-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.06991848349571228f,-0.19175665080547333f,0.28649166226387024f,0.016488296911120415f,-0.27260470390319824f,-0.025072306394577026f,0.2722422182559967f,-0.007939159870147705f,-0.22979341447353363f,0.18354694545269012f,0.1298319399356842f,0.18135693669319153f,-0.008151531219482422f,0.06563670933246613f}, |
Lightvalve | 89:a7b45368ea0f | 282 | {0.07638216018676758f,0.05416220799088478f,-0.3668074607849121f,-0.27526140213012695f,0.14193227887153625f,-0.03358025848865509f,0.2795381247997284f,-0.25668495893478394f,-0.06847190111875534f,0.10313618183135986f,0.06818969547748566f,0.02524423599243164f,0.12337286025285721f,0.24906043708324432f,-0.029521822929382324f,-0.19500072300434113f,0.06506577134132385f,-0.011876672506332397f,0.13714706897735596f,0.241392120718956f,0.15146386623382568f,-0.03257722035050392f,-0.19373025000095367f,-0.17324526607990265f,0.18035846948623657f,0.1901901364326477f,-0.2794223725795746f,-0.0292219091206789f,-0.143522247672081f,0.22636333107948303f,-0.3317090570926666f,0.16370397806167603f}, |
Lightvalve | 66:a8e6799dbce3 | 283 | }; |
Lightvalve | 65:a2d7c63419c2 | 284 | |
Lightvalve | 89:a7b45368ea0f | 285 | const float hout[32] = { 0.3285340666770935f,0.20001740753650665f,-0.34911248087882996f,0.7785994410514832f,-0.3811017870903015f,0.192925363779068f,0.11950510740280151f,0.1081397533416748f,0.05394027382135391f,-0.08027924597263336f,0.3785701394081116f,-0.11859139055013657f,-0.06000533699989319f,0.5311194062232971f,0.2356991171836853f,-0.1462659239768982f,0.09851181507110596f,-0.21499931812286377f,-0.2335696816444397f,0.5094234943389893f,-0.02162783592939377f,-0.07713251560926437f,-0.16340212523937225f,-0.175692617893219f,-0.5511316657066345f,0.0982658639550209f,-0.19307535886764526f,0.005460194777697325f,0.03202202543616295f,-0.3257754445075989f,-0.31206440925598145f,0.38066837191581726f }; |
Lightvalve | 66:a8e6799dbce3 | 286 | |
Lightvalve | 89:a7b45368ea0f | 287 | const float b1[32] = { 0.4585856795310974f,1.5599967241287231f,-1.7145336866378784f,-0.5815920829772949f,1.7490010261535645f,0.693375289440155f,-0.12202438712120056f,1.839867115020752f,1.4444961547851562f,-1.156732439994812f,0.5561704039573669f,2.925478458404541f,-0.3425353467464447f,-0.9403132796287537f,-1.087764859199524f,1.6783026456832886f,0.7627432346343994f,-0.26377663016319275f,0.9854183793067932f,1.2830049991607666f,-0.284685879945755f,-1.1118980646133423f,-1.6770726442337036f,-1.2263047695159912f,3.647984266281128f,-2.0880801677703857f,-1.0489267110824585f,0.8671233654022217f,0.2414611577987671f,-1.0887231826782227f,2.1772990226745605f,-0.44598740339279175f }; |
Lightvalve | 87:471334725012 | 288 | |
Lightvalve | 89:a7b45368ea0f | 289 | const float b2[32] = { -0.22200508415699005f,-0.7642630338668823f,-1.4564176797866821f,-0.4980332851409912f,-0.6939148902893066f,-0.028987569734454155f,0.14226511120796204f,-0.4531817138195038f,-1.20063054561615f,-1.912178635597229f,0.01248383428901434f,0.14814351499080658f,-0.21863840520381927f,2.2132997512817383f,0.4528786838054657f,1.145101547241211f,-1.798204779624939f,-1.5844906568527222f,-0.08603224903345108f,-0.3332130014896393f,-0.0870656743645668f,-0.025959404185414314f,0.03327740728855133f,-1.189407467842102f,1.1251391172409058f,1.414678692817688f,0.012956145219504833f,-0.15001332759857178f,-0.6323830485343933f,-0.5580381155014038f,-1.2962936162948608f,-1.488829255104065f }; |
Lightvalve | 65:a2d7c63419c2 | 290 | |
Lightvalve | 89:a7b45368ea0f | 291 | const float b3[32] = { -1.963319182395935f,-0.5214390158653259f,-0.02191949263215065f,-0.8819749355316162f,-1.4401051998138428f,0.9515159726142883f,-0.5303202867507935f,-0.6562485098838806f,-0.0017350538400933146f,-0.04748106747865677f,-0.5597951412200928f,-0.10345426201820374f,-1.1365820169448853f,-0.029138414189219475f,-1.1428403854370117f,-0.3598397970199585f,-1.3594286441802979f,-1.0192245244979858f,-1.5457112789154053f,-0.15714126825332642f,-0.006691883783787489f,-0.8062649369239807f,-1.1899834871292114f,-0.8066051602363586f,-0.8363364338874817f,-0.5234388709068298f,-0.3238477408885956f,-1.4527530670166016f,-0.2316749542951584f,-2.3236680030822754f,-0.08294112235307693f,1.1520551443099976f }; |
Lightvalve | 87:471334725012 | 292 | |
Lightvalve | 89:a7b45368ea0f | 293 | const float bout[1] = { -0.029729647561907768f }; |
Lightvalve | 65:a2d7c63419c2 | 294 | |
Lightvalve | 66:a8e6799dbce3 | 295 | |
Lightvalve | 87:471334725012 | 296 | float VALVE_POS_RAW_NN = 0.0f; |
Lightvalve | 87:471334725012 | 297 | float DDV_JOINT_POS_FF(float REF_JOINT_VEL); |
Lightvalve | 61:bc8c8270f0ab | 298 | |
GiJeongKim | 0:51c43836c1d7 | 299 | int main() |
GiJeongKim | 0:51c43836c1d7 | 300 | { |
Lightvalve | 66:a8e6799dbce3 | 301 | |
Lightvalve | 65:a2d7c63419c2 | 302 | HAL_Init(); |
Lightvalve | 65:a2d7c63419c2 | 303 | SystemClock_Config(); |
Lightvalve | 65:a2d7c63419c2 | 304 | |
jobuuu | 6:df07d3491e3a | 305 | /********************************* |
jobuuu | 1:e04e563be5ce | 306 | *** Initialization |
jobuuu | 6:df07d3491e3a | 307 | *********************************/ |
Lightvalve | 69:3995ffeaa786 | 308 | LED = 0; |
Lightvalve | 61:bc8c8270f0ab | 309 | pc.baud(9600); |
Lightvalve | 21:e5f1a43ea6f9 | 310 | |
GiJeongKim | 0:51c43836c1d7 | 311 | // i2c init |
Lightvalve | 8:5d2eebdad025 | 312 | i2c.frequency(400 * 1000); // 0.4 mHz |
Lightvalve | 8:5d2eebdad025 | 313 | wait_ms(2); // Power Up wait |
Lightvalve | 8:5d2eebdad025 | 314 | look_for_hardware_i2c(); // Hardware present |
Lightvalve | 8:5d2eebdad025 | 315 | init_as5510(i2c_slave_addr1); |
Lightvalve | 11:82d8768d7351 | 316 | make_delay(); |
jobuuu | 2:a1c0a37df760 | 317 | |
GiJeongKim | 0:51c43836c1d7 | 318 | // // spi init |
Lightvalve | 16:903b5a4433b4 | 319 | //eeprom.format(8,3); |
Lightvalve | 16:903b5a4433b4 | 320 | //eeprom.frequency(5000000); //5M |
GiJeongKim | 0:51c43836c1d7 | 321 | enc.format(8,0); |
GiJeongKim | 0:51c43836c1d7 | 322 | enc.frequency(5000000); //5M |
Lightvalve | 11:82d8768d7351 | 323 | make_delay(); |
Lightvalve | 21:e5f1a43ea6f9 | 324 | |
Lightvalve | 16:903b5a4433b4 | 325 | //rom |
Lightvalve | 19:23b7c1ad8683 | 326 | ROM_CALL_DATA(); |
Lightvalve | 16:903b5a4433b4 | 327 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 328 | |
GiJeongKim | 0:51c43836c1d7 | 329 | // ADC init |
jobuuu | 5:a4319f79457b | 330 | Init_ADC(); |
Lightvalve | 11:82d8768d7351 | 331 | make_delay(); |
jobuuu | 2:a1c0a37df760 | 332 | |
GiJeongKim | 0:51c43836c1d7 | 333 | // Pwm init |
GiJeongKim | 0:51c43836c1d7 | 334 | Init_PWM(); |
GiJeongKim | 0:51c43836c1d7 | 335 | TIM4->CR1 ^= TIM_CR1_UDIS; |
Lightvalve | 11:82d8768d7351 | 336 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 337 | |
Lightvalve | 11:82d8768d7351 | 338 | // TMR3 init |
Lightvalve | 11:82d8768d7351 | 339 | Init_TMR3(); |
Lightvalve | 11:82d8768d7351 | 340 | TIM3->CR1 ^= TIM_CR1_UDIS; |
Lightvalve | 11:82d8768d7351 | 341 | make_delay(); |
Lightvalve | 21:e5f1a43ea6f9 | 342 | |
Lightvalve | 50:3c630b5eba9f | 343 | // TMR2 init |
Lightvalve | 56:6f50d9d3bfee | 344 | // Init_TMR2(); |
Lightvalve | 56:6f50d9d3bfee | 345 | // TIM2->CR1 ^= TIM_CR1_UDIS; |
Lightvalve | 56:6f50d9d3bfee | 346 | // make_delay(); |
Lightvalve | 21:e5f1a43ea6f9 | 347 | |
GiJeongKim | 0:51c43836c1d7 | 348 | // CAN |
jobuuu | 2:a1c0a37df760 | 349 | can.attach(&CAN_RX_HANDLER); |
Lightvalve | 11:82d8768d7351 | 350 | CAN_ID_INIT(); |
Lightvalve | 11:82d8768d7351 | 351 | make_delay(); |
Lightvalve | 34:bb2ca2fc2a8e | 352 | |
Lightvalve | 23:59218d4a256d | 353 | //Timer priority |
Lightvalve | 23:59218d4a256d | 354 | NVIC_SetPriority(TIM3_IRQn, 2); |
Lightvalve | 57:f4819de54e7a | 355 | //NVIC_SetPriority(TIM2_IRQn, 3); |
Lightvalve | 54:647072f5307a | 356 | NVIC_SetPriority(TIM4_IRQn, 3); |
Lightvalve | 34:bb2ca2fc2a8e | 357 | |
Lightvalve | 23:59218d4a256d | 358 | //can.reset(); |
Lightvalve | 19:23b7c1ad8683 | 359 | can.filter(msg.id, 0xFFFFF000, CANStandard); |
Lightvalve | 34:bb2ca2fc2a8e | 360 | |
GiJeongKim | 0:51c43836c1d7 | 361 | // spi _ enc |
GiJeongKim | 0:51c43836c1d7 | 362 | spi_enc_set_init(); |
Lightvalve | 11:82d8768d7351 | 363 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 364 | |
Lightvalve | 11:82d8768d7351 | 365 | //DAC init |
Lightvalve | 58:2eade98630e2 | 366 | if (SENSING_MODE == 0) { |
Lightvalve | 58:2eade98630e2 | 367 | dac_1 = TORQUE_VREF / 3.3f; |
Lightvalve | 58:2eade98630e2 | 368 | dac_2 = 0.0f; |
Lightvalve | 58:2eade98630e2 | 369 | } else if (SENSING_MODE == 1) { |
Lightvalve | 58:2eade98630e2 | 370 | dac_1 = PRES_A_VREF / 3.3f; |
Lightvalve | 58:2eade98630e2 | 371 | dac_2 = PRES_B_VREF / 3.3f; |
Lightvalve | 58:2eade98630e2 | 372 | } |
Lightvalve | 11:82d8768d7351 | 373 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 374 | |
Lightvalve | 19:23b7c1ad8683 | 375 | for (int i=0; i<50; i++) { |
Lightvalve | 11:82d8768d7351 | 376 | if(i%2==0) |
Lightvalve | 38:118df027d851 | 377 | ID_index_array[i] = - i * 0.5f; |
Lightvalve | 11:82d8768d7351 | 378 | else |
Lightvalve | 38:118df027d851 | 379 | ID_index_array[i] = (i+1) * 0.5f; |
Lightvalve | 11:82d8768d7351 | 380 | } |
Lightvalve | 61:bc8c8270f0ab | 381 | |
Lightvalve | 61:bc8c8270f0ab | 382 | |
jobuuu | 6:df07d3491e3a | 383 | /************************************ |
jobuuu | 1:e04e563be5ce | 384 | *** Program is operating! |
jobuuu | 6:df07d3491e3a | 385 | *************************************/ |
GiJeongKim | 0:51c43836c1d7 | 386 | while(1) { |
Lightvalve | 66:a8e6799dbce3 | 387 | // if(timer_while==1000 && OPERATING_MODE==5) { |
Lightvalve | 66:a8e6799dbce3 | 388 | //if(timer_while==1000) { |
Lightvalve | 65:a2d7c63419c2 | 389 | //i2c |
Lightvalve | 66:a8e6799dbce3 | 390 | |
Lightvalve | 65:a2d7c63419c2 | 391 | read_field(i2c_slave_addr1); |
Lightvalve | 65:a2d7c63419c2 | 392 | if(DIR_VALVE_ENC < 0) value = 1023 - value; |
Lightvalve | 65:a2d7c63419c2 | 393 | // if(LED==1) { |
Lightvalve | 65:a2d7c63419c2 | 394 | // LED=0; |
Lightvalve | 65:a2d7c63419c2 | 395 | // } else |
Lightvalve | 65:a2d7c63419c2 | 396 | // LED = 1; |
Lightvalve | 65:a2d7c63419c2 | 397 | timer_while = 0; |
Lightvalve | 66:a8e6799dbce3 | 398 | //} |
Lightvalve | 66:a8e6799dbce3 | 399 | |
Lightvalve | 66:a8e6799dbce3 | 400 | timer_while ++; |
Lightvalve | 66:a8e6799dbce3 | 401 | |
Lightvalve | 87:471334725012 | 402 | //LED = 0; |
Lightvalve | 87:471334725012 | 403 | |
Lightvalve | 73:f80dc3970c99 | 404 | if(NN_Control_Flag == 0) { |
Lightvalve | 73:f80dc3970c99 | 405 | LED = 0; |
Lightvalve | 73:f80dc3970c99 | 406 | } |
Lightvalve | 66:a8e6799dbce3 | 407 | |
Lightvalve | 73:f80dc3970c99 | 408 | else if(NN_Control_Flag == 1) { |
Lightvalve | 88:d6e591bece22 | 409 | float output1[16] = { 0.0f }; |
Lightvalve | 88:d6e591bece22 | 410 | float output2[16] = { 0.0f }; |
Lightvalve | 88:d6e591bece22 | 411 | float output3[16] = { 0.0f }; |
Lightvalve | 66:a8e6799dbce3 | 412 | float output = 0.0f; |
Lightvalve | 65:a2d7c63419c2 | 413 | |
Lightvalve | 88:d6e591bece22 | 414 | for (int index2 = 0; index2 < 16; index2++) { |
Lightvalve | 68:328e1be06f5d | 415 | for (int index1 = 0; index1 < num_input; index1++) { |
Lightvalve | 66:a8e6799dbce3 | 416 | output1[index2] = output1[index2] |
Lightvalve | 73:f80dc3970c99 | 417 | + h1[index1][index2] * input_NN[index1]; |
Lightvalve | 66:a8e6799dbce3 | 418 | } |
Lightvalve | 66:a8e6799dbce3 | 419 | output1[index2] = output1[index2] + b1[index2]; |
Lightvalve | 66:a8e6799dbce3 | 420 | if (output1[index2] < 0) { |
Lightvalve | 66:a8e6799dbce3 | 421 | output1[index2] = 0; |
Lightvalve | 66:a8e6799dbce3 | 422 | } |
Lightvalve | 66:a8e6799dbce3 | 423 | } |
Lightvalve | 65:a2d7c63419c2 | 424 | |
Lightvalve | 88:d6e591bece22 | 425 | for (int index2 = 0; index2 < 16; index2++) { |
Lightvalve | 88:d6e591bece22 | 426 | for (int index1 = 0; index1 < 16; index1++) { |
Lightvalve | 66:a8e6799dbce3 | 427 | output2[index2] = output2[index2] |
Lightvalve | 66:a8e6799dbce3 | 428 | + h2[index1][index2] * output1[index1]; |
Lightvalve | 66:a8e6799dbce3 | 429 | } |
Lightvalve | 66:a8e6799dbce3 | 430 | output2[index2] = output2[index2] + b2[index2]; |
Lightvalve | 66:a8e6799dbce3 | 431 | if (output2[index2] < 0) { |
Lightvalve | 66:a8e6799dbce3 | 432 | output2[index2] = 0; |
Lightvalve | 66:a8e6799dbce3 | 433 | } |
Lightvalve | 66:a8e6799dbce3 | 434 | } |
Lightvalve | 65:a2d7c63419c2 | 435 | |
Lightvalve | 88:d6e591bece22 | 436 | for (int index2 = 0; index2 < 16; index2++) { |
Lightvalve | 88:d6e591bece22 | 437 | for (int index1 = 0; index1 < 16; index1++) { |
Lightvalve | 66:a8e6799dbce3 | 438 | output3[index2] = output3[index2] |
Lightvalve | 66:a8e6799dbce3 | 439 | + h3[index1][index2] * output2[index1]; |
Lightvalve | 66:a8e6799dbce3 | 440 | } |
Lightvalve | 66:a8e6799dbce3 | 441 | output3[index2] = output3[index2] + b3[index2]; |
Lightvalve | 66:a8e6799dbce3 | 442 | if (output3[index2] < 0) { |
Lightvalve | 66:a8e6799dbce3 | 443 | output3[index2] = 0; |
Lightvalve | 66:a8e6799dbce3 | 444 | } |
Lightvalve | 65:a2d7c63419c2 | 445 | } |
Lightvalve | 66:a8e6799dbce3 | 446 | |
Lightvalve | 66:a8e6799dbce3 | 447 | for (int index2 = 0; index2 < 1; index2++) { |
Lightvalve | 88:d6e591bece22 | 448 | for (int index1 = 0; index1 < 16; index1++) { |
Lightvalve | 73:f80dc3970c99 | 449 | output = output + hout[index1] * output3[index1]; |
Lightvalve | 66:a8e6799dbce3 | 450 | } |
Lightvalve | 66:a8e6799dbce3 | 451 | output = output + bout[index2]; |
Lightvalve | 73:f80dc3970c99 | 452 | |
Lightvalve | 66:a8e6799dbce3 | 453 | } |
Lightvalve | 73:f80dc3970c99 | 454 | output = 1.0f/(1.0f+exp(-output)); |
Lightvalve | 68:328e1be06f5d | 455 | output = output * 20000.0f - 10000.0f; |
Lightvalve | 66:a8e6799dbce3 | 456 | if(output>=0) { |
Lightvalve | 66:a8e6799dbce3 | 457 | valve_pos.ref = output*0.0001f*((double)VALVE_MAX_POS - (double) VALVE_CENTER) + (double) VALVE_CENTER; |
Lightvalve | 66:a8e6799dbce3 | 458 | } else { |
Lightvalve | 66:a8e6799dbce3 | 459 | valve_pos.ref = -output*0.0001f*((double)VALVE_MIN_POS - (double) VALVE_CENTER) + (double) VALVE_CENTER; |
Lightvalve | 65:a2d7c63419c2 | 460 | } |
Lightvalve | 87:471334725012 | 461 | |
Lightvalve | 88:d6e591bece22 | 462 | // // torque feedback |
Lightvalve | 88:d6e591bece22 | 463 | // torq.err = f_past[0] - torq.sen; //[N] |
Lightvalve | 88:d6e591bece22 | 464 | //// torq.err_sum += torq.err/(float) TMR_FREQ_5k; //[N] |
Lightvalve | 88:d6e591bece22 | 465 | // torq.err_sum += torq.err/(float) 1500.0f; //[N] |
Lightvalve | 88:d6e591bece22 | 466 | // |
Lightvalve | 88:d6e591bece22 | 467 | // |
Lightvalve | 88:d6e591bece22 | 468 | // valve_pos.ref = ((float) P_GAIN_JOINT_TORQUE * torq.err + (float) I_GAIN_JOINT_TORQUE * torq.err_sum) * 0.01f + DDV_JOINT_POS_FF(vel.sen) + valve_pos.ref * 0.01f; |
Lightvalve | 88:d6e591bece22 | 469 | // |
Lightvalve | 88:d6e591bece22 | 470 | // if(I_GAIN_JOINT_TORQUE != 0) { |
Lightvalve | 88:d6e591bece22 | 471 | // double Ka = 1.0f / (double) I_GAIN_JOINT_TORQUE * 100.0f; |
Lightvalve | 88:d6e591bece22 | 472 | // if(valve_pos.ref>VALVE_MAX_POS) { |
Lightvalve | 88:d6e591bece22 | 473 | // double valve_pos_rem = valve_pos.ref - VALVE_MAX_POS; |
Lightvalve | 88:d6e591bece22 | 474 | // valve_pos_rem = valve_pos_rem * Ka; |
Lightvalve | 88:d6e591bece22 | 475 | // valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 88:d6e591bece22 | 476 | // torq.err_sum = torq.err_sum - valve_pos_rem/(float) 1500.0f; |
Lightvalve | 88:d6e591bece22 | 477 | // } else if(valve_pos.ref < VALVE_MIN_POS) { |
Lightvalve | 88:d6e591bece22 | 478 | // double valve_pos_rem = valve_pos.ref - VALVE_MIN_POS; |
Lightvalve | 88:d6e591bece22 | 479 | // valve_pos_rem = valve_pos_rem * Ka; |
Lightvalve | 88:d6e591bece22 | 480 | // valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 88:d6e591bece22 | 481 | // torq.err_sum = torq.err_sum - valve_pos_rem/(float) 1500.0f; |
Lightvalve | 88:d6e591bece22 | 482 | // } |
Lightvalve | 88:d6e591bece22 | 483 | // } |
Lightvalve | 87:471334725012 | 484 | |
Lightvalve | 69:3995ffeaa786 | 485 | |
Lightvalve | 69:3995ffeaa786 | 486 | if(LED==1) { |
Lightvalve | 69:3995ffeaa786 | 487 | LED=0; |
Lightvalve | 69:3995ffeaa786 | 488 | } else |
Lightvalve | 69:3995ffeaa786 | 489 | LED = 1; |
Lightvalve | 69:3995ffeaa786 | 490 | |
Lightvalve | 65:a2d7c63419c2 | 491 | } |
Lightvalve | 62:b5452adfb2cd | 492 | |
Lightvalve | 87:471334725012 | 493 | //LED = 1; |
Lightvalve | 69:3995ffeaa786 | 494 | |
Lightvalve | 66:a8e6799dbce3 | 495 | |
GiJeongKim | 0:51c43836c1d7 | 496 | } |
jobuuu | 1:e04e563be5ce | 497 | } |
jobuuu | 1:e04e563be5ce | 498 | |
Lightvalve | 33:91b17819ec30 | 499 | float DDV_JOINT_POS_FF(float REF_JOINT_VEL) |
Lightvalve | 14:8e7590227d22 | 500 | { |
Lightvalve | 14:8e7590227d22 | 501 | |
Lightvalve | 13:747daba9cf59 | 502 | int i = 0; |
Lightvalve | 48:889798ff9329 | 503 | float Ref_Valve_Pos_FF = 0.0f; |
Lightvalve | 14:8e7590227d22 | 504 | for(i=0; i<VALVE_POS_NUM; i++) { |
Lightvalve | 14:8e7590227d22 | 505 | 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 | 506 | if(i==0) { |
Lightvalve | 50:3c630b5eba9f | 507 | if(JOINT_VEL[i+1] == JOINT_VEL[i]) { |
Lightvalve | 57:f4819de54e7a | 508 | Ref_Valve_Pos_FF = (float) VALVE_CENTER; |
Lightvalve | 50:3c630b5eba9f | 509 | } else { |
Lightvalve | 57:f4819de54e7a | 510 | 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 | 511 | } |
Lightvalve | 14:8e7590227d22 | 512 | } else { |
Lightvalve | 50:3c630b5eba9f | 513 | if(JOINT_VEL[i+1] == JOINT_VEL[i-1]) { |
Lightvalve | 57:f4819de54e7a | 514 | Ref_Valve_Pos_FF = (float) VALVE_CENTER; |
Lightvalve | 50:3c630b5eba9f | 515 | } else { |
Lightvalve | 57:f4819de54e7a | 516 | 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 | 517 | } |
Lightvalve | 13:747daba9cf59 | 518 | } |
Lightvalve | 13:747daba9cf59 | 519 | break; |
Lightvalve | 13:747daba9cf59 | 520 | } |
Lightvalve | 13:747daba9cf59 | 521 | } |
Lightvalve | 14:8e7590227d22 | 522 | if(REF_JOINT_VEL > max(JOINT_VEL[VALVE_POS_NUM-1], JOINT_VEL[VALVE_POS_NUM-2])) { |
Lightvalve | 33:91b17819ec30 | 523 | Ref_Valve_Pos_FF = (float) VALVE_MAX_POS; |
Lightvalve | 14:8e7590227d22 | 524 | } else if(REF_JOINT_VEL < min(JOINT_VEL[VALVE_POS_NUM-1], JOINT_VEL[VALVE_POS_NUM-2])) { |
Lightvalve | 33:91b17819ec30 | 525 | Ref_Valve_Pos_FF = (float) VALVE_MIN_POS; |
Lightvalve | 13:747daba9cf59 | 526 | } |
Lightvalve | 36:a46e63505ed8 | 527 | |
Lightvalve | 57:f4819de54e7a | 528 | Ref_Valve_Pos_FF = (float) VELOCITY_COMP_GAIN * 0.01f * (float) (Ref_Valve_Pos_FF - (float) VALVE_CENTER); |
Lightvalve | 13:747daba9cf59 | 529 | return Ref_Valve_Pos_FF; |
Lightvalve | 50:3c630b5eba9f | 530 | |
Lightvalve | 13:747daba9cf59 | 531 | } |
jobuuu | 6:df07d3491e3a | 532 | |
jobuuu | 6:df07d3491e3a | 533 | |
Lightvalve | 30:8d561f16383b | 534 | void VALVE_POS_CONTROL(float REF_VALVE_POS) |
Lightvalve | 14:8e7590227d22 | 535 | { |
Lightvalve | 13:747daba9cf59 | 536 | int i = 0; |
Lightvalve | 13:747daba9cf59 | 537 | |
Lightvalve | 38:118df027d851 | 538 | if(REF_VALVE_POS > VALVE_MAX_POS) { |
Lightvalve | 38:118df027d851 | 539 | REF_VALVE_POS = VALVE_MAX_POS; |
Lightvalve | 38:118df027d851 | 540 | } else if(REF_VALVE_POS < VALVE_MIN_POS) { |
Lightvalve | 38:118df027d851 | 541 | REF_VALVE_POS = VALVE_MIN_POS; |
Lightvalve | 38:118df027d851 | 542 | } |
Lightvalve | 38:118df027d851 | 543 | |
Lightvalve | 89:a7b45368ea0f | 544 | valve_pos_err = (float) (REF_VALVE_POS - value); |
Lightvalve | 13:747daba9cf59 | 545 | valve_pos_err_diff = valve_pos_err - valve_pos_err_old; |
Lightvalve | 13:747daba9cf59 | 546 | valve_pos_err_old = valve_pos_err; |
Lightvalve | 13:747daba9cf59 | 547 | valve_pos_err_sum += valve_pos_err; |
Lightvalve | 89:a7b45368ea0f | 548 | if (valve_pos_err_sum > 1000.0f) valve_pos_err_sum = 1000.0f; |
Lightvalve | 89:a7b45368ea0f | 549 | if (valve_pos_err_sum<-1000.0f) valve_pos_err_sum = -1000.0f; |
Lightvalve | 13:747daba9cf59 | 550 | |
Lightvalve | 13:747daba9cf59 | 551 | 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 | 552 | |
Lightvalve | 18:b8adf1582ea3 | 553 | for(i=0; i<24; i++) { |
Lightvalve | 89:a7b45368ea0f | 554 | if(REF_VALVE_POS >= min(VALVE_POS_VS_PWM[i],VALVE_POS_VS_PWM[i+1]) && (float) REF_VALVE_POS <= max(VALVE_POS_VS_PWM[i],VALVE_POS_VS_PWM[i+1])) { |
Lightvalve | 14:8e7590227d22 | 555 | if(i==0) { |
Lightvalve | 48:889798ff9329 | 556 | 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 | 557 | } else { |
Lightvalve | 48:889798ff9329 | 558 | 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 | 559 | } |
Lightvalve | 13:747daba9cf59 | 560 | break; |
Lightvalve | 13:747daba9cf59 | 561 | } |
Lightvalve | 13:747daba9cf59 | 562 | } |
Lightvalve | 59:f308b1656d9c | 563 | Vout.ref = VALVE_PWM_RAW_FF + VALVE_PWM_RAW_FB; |
Lightvalve | 13:747daba9cf59 | 564 | } |
Lightvalve | 13:747daba9cf59 | 565 | |
Lightvalve | 14:8e7590227d22 | 566 | #define LT_MAX_IDX 57 |
Lightvalve | 30:8d561f16383b | 567 | 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 | 568 | -19.0f, -18.0f, -17.0f, -16.0f, -15.0f, -14.0f, -13.0f, -12.0f, -11.0f, -10.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 569 | -9.0f, -8.0f, -7.0f, -6.0f, -5.0f, -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 570 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 571 | 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 572 | 25.0f, 30.0f, 35.0f, 40.0f, 50.0f, 60.0f, 80.0f, 100.0f |
Lightvalve | 34:bb2ca2fc2a8e | 573 | }; // duty |
Lightvalve | 67:c2812cf26c38 | 574 | 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 | 575 | -150.0f, -145.0f, -145.0f, -145.0f, -135.0f, -135.0f, -135.0f, -127.5f, -127.5f, -115.0f, |
Lightvalve | 67:c2812cf26c38 | 576 | -115.0f, -115.0F, -100.0f, -100.0f, -100.0f, -60.0f, -60.0f, -10.0f, -5.0f, 0.0f, |
Lightvalve | 67:c2812cf26c38 | 577 | 7.5f, 14.0f, 14.0f, 14.0f, 42.5f, 42.5f, 42.5f, 80.0f, 80.0f, 105.0f, |
Lightvalve | 67:c2812cf26c38 | 578 | 105.0f, 105.0f, 120.0f, 120.0f, 120.0f, 131.0f, 131.0f, 140.0f, 140.0f, 140.0f, |
Lightvalve | 67:c2812cf26c38 | 579 | 155.0f, 160.0f, 170.0f, 174.0f, 182.0f, 191.0f, 212.0f, 230.0f |
Lightvalve | 34:bb2ca2fc2a8e | 580 | }; // mV |
Lightvalve | 13:747daba9cf59 | 581 | |
Lightvalve | 30:8d561f16383b | 582 | float PWM_duty_byLT(float Ref_V) |
Lightvalve | 14:8e7590227d22 | 583 | { |
Lightvalve | 30:8d561f16383b | 584 | float PWM_duty = 0.0f; |
Lightvalve | 13:747daba9cf59 | 585 | if(Ref_V<LT_Voltage_Output[0]) { |
Lightvalve | 30:8d561f16383b | 586 | PWM_duty = (Ref_V-LT_Voltage_Output[0])/1.5f+LT_PWM_duty[0]; |
Lightvalve | 13:747daba9cf59 | 587 | } else if (Ref_V>=LT_Voltage_Output[LT_MAX_IDX-1]) { |
Lightvalve | 30:8d561f16383b | 588 | PWM_duty = (Ref_V-LT_Voltage_Output[LT_MAX_IDX-1])/1.5f+LT_PWM_duty[LT_MAX_IDX-1]; |
Lightvalve | 13:747daba9cf59 | 589 | } else { |
Lightvalve | 13:747daba9cf59 | 590 | int idx = 0; |
Lightvalve | 13:747daba9cf59 | 591 | for(idx=0; idx<LT_MAX_IDX-1; idx++) { |
Lightvalve | 30:8d561f16383b | 592 | float ini_x = LT_Voltage_Output[idx]; |
Lightvalve | 30:8d561f16383b | 593 | float fin_x = LT_Voltage_Output[idx+1]; |
Lightvalve | 30:8d561f16383b | 594 | float ini_y = LT_PWM_duty[idx]; |
Lightvalve | 30:8d561f16383b | 595 | float fin_y = LT_PWM_duty[idx+1]; |
Lightvalve | 13:747daba9cf59 | 596 | if(Ref_V>=ini_x && Ref_V<fin_x) { |
Lightvalve | 13:747daba9cf59 | 597 | PWM_duty = (fin_y-ini_y)/(fin_x-ini_x)*(Ref_V-ini_x) + ini_y; |
Lightvalve | 13:747daba9cf59 | 598 | break; |
Lightvalve | 13:747daba9cf59 | 599 | } |
Lightvalve | 13:747daba9cf59 | 600 | } |
Lightvalve | 13:747daba9cf59 | 601 | } |
Lightvalve | 14:8e7590227d22 | 602 | |
Lightvalve | 13:747daba9cf59 | 603 | return PWM_duty; |
Lightvalve | 13:747daba9cf59 | 604 | } |
jobuuu | 6:df07d3491e3a | 605 | |
Lightvalve | 57:f4819de54e7a | 606 | |
Lightvalve | 57:f4819de54e7a | 607 | |
Lightvalve | 57:f4819de54e7a | 608 | |
Lightvalve | 57:f4819de54e7a | 609 | |
jobuuu | 2:a1c0a37df760 | 610 | /******************************************************************************* |
jobuuu | 2:a1c0a37df760 | 611 | TIMER INTERRUPT |
jobuuu | 2:a1c0a37df760 | 612 | *******************************************************************************/ |
jobuuu | 2:a1c0a37df760 | 613 | |
Lightvalve | 51:b46bed7fec80 | 614 | float FREQ_TMR4 = (float)FREQ_20k; |
Lightvalve | 51:b46bed7fec80 | 615 | float DT_TMR4 = (float)DT_20k; |
Lightvalve | 57:f4819de54e7a | 616 | long CNT_TMR4 = 0; |
Lightvalve | 57:f4819de54e7a | 617 | int TMR4_FREQ_10k = (int)FREQ_10k; |
jobuuu | 1:e04e563be5ce | 618 | extern "C" void TIM4_IRQHandler(void) |
jobuuu | 1:e04e563be5ce | 619 | { |
Lightvalve | 19:23b7c1ad8683 | 620 | if (TIM4->SR & TIM_SR_UIF ) { |
Lightvalve | 21:e5f1a43ea6f9 | 621 | |
Lightvalve | 21:e5f1a43ea6f9 | 622 | /******************************************************* |
Lightvalve | 21:e5f1a43ea6f9 | 623 | *** Sensor Read & Data Handling |
Lightvalve | 21:e5f1a43ea6f9 | 624 | ********************************************************/ |
Lightvalve | 13:747daba9cf59 | 625 | |
Lightvalve | 57:f4819de54e7a | 626 | //Encoder |
Lightvalve | 57:f4819de54e7a | 627 | if (CNT_TMR4 % (int) ((int) FREQ_TMR4/TMR4_FREQ_10k) == 0) { |
Lightvalve | 57:f4819de54e7a | 628 | ENC_UPDATE(); |
Lightvalve | 57:f4819de54e7a | 629 | } |
Lightvalve | 61:bc8c8270f0ab | 630 | |
Lightvalve | 61:bc8c8270f0ab | 631 | ADC1->CR2 |= 0x40000000; |
Lightvalve | 58:2eade98630e2 | 632 | if (SENSING_MODE == 0) { |
Lightvalve | 58:2eade98630e2 | 633 | // Torque Sensing (0~210)bar ============================================= |
Lightvalve | 58:2eade98630e2 | 634 | float pres_A_new = (((float) ADC1->DR) - 2047.5f); |
Lightvalve | 58:2eade98630e2 | 635 | double alpha_update_ft = 1.0f / (1.0f + FREQ_TMR4 / (2.0f * 3.14f * 100.0f)); // f_cutoff : 200Hz |
Lightvalve | 58:2eade98630e2 | 636 | pres_A.sen = (1.0f - alpha_update_ft) * pres_A.sen + alpha_update_ft * pres_A_new; |
Lightvalve | 67:c2812cf26c38 | 637 | torq.sen = -pres_A.sen / TORQUE_SENSOR_PULSE_PER_TORQUE; |
Lightvalve | 67:c2812cf26c38 | 638 | |
Lightvalve | 67:c2812cf26c38 | 639 | |
Lightvalve | 67:c2812cf26c38 | 640 | // float alpha_update_pres_A = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f)); |
Lightvalve | 67:c2812cf26c38 | 641 | //// float pres_A_new = ((float)ADC1->DR - PRES_A_NULL) / PRES_SENSOR_A_PULSE_PER_BAR; |
Lightvalve | 67:c2812cf26c38 | 642 | // float pres_A_new = ((float)ADC1->DR); |
Lightvalve | 67:c2812cf26c38 | 643 | // pres_A.sen = pres_A.sen*(1.0f-alpha_update_pres_A)+pres_A_new*(alpha_update_pres_A); |
Lightvalve | 67:c2812cf26c38 | 644 | // torq.sen = - (pres_A.sen-2048.0f); //pulse -2047~2047 |
Lightvalve | 67:c2812cf26c38 | 645 | |
Lightvalve | 17:1865016ca2e7 | 646 | |
Lightvalve | 58:2eade98630e2 | 647 | } else if (SENSING_MODE == 1) { |
Lightvalve | 58:2eade98630e2 | 648 | // Pressure Sensing (0~210)bar ============================================= |
Lightvalve | 58:2eade98630e2 | 649 | float pres_A_new = (((float)ADC1->DR) - PRES_A_NULL); |
Lightvalve | 58:2eade98630e2 | 650 | float pres_B_new = (((float)ADC2->DR) - PRES_B_NULL); |
Lightvalve | 58:2eade98630e2 | 651 | double alpha_update_pres = 1.0f / (1.0f + FREQ_TMR4 / (2.0f * 3.14f * 200.0f)); // f_cutoff : 500Hz |
Lightvalve | 58:2eade98630e2 | 652 | pres_A.sen = (1.0f - alpha_update_pres) * pres_A.sen + alpha_update_pres * pres_A_new; |
Lightvalve | 58:2eade98630e2 | 653 | pres_B.sen = (1.0f - alpha_update_pres) * pres_B.sen + alpha_update_pres * pres_B_new; |
Lightvalve | 58:2eade98630e2 | 654 | CUR_PRES_A_BAR = pres_A.sen / PRES_SENSOR_A_PULSE_PER_BAR; |
Lightvalve | 58:2eade98630e2 | 655 | CUR_PRES_B_BAR = pres_B.sen / PRES_SENSOR_B_PULSE_PER_BAR; |
Lightvalve | 50:3c630b5eba9f | 656 | |
Lightvalve | 58:2eade98630e2 | 657 | if ((OPERATING_MODE & 0x01) == 0) { // Rotary Actuator |
Lightvalve | 58:2eade98630e2 | 658 | 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 | 659 | } else if ((OPERATING_MODE & 0x01) == 1) { // Linear Actuator |
Lightvalve | 58:2eade98630e2 | 660 | 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 | 661 | } |
Lightvalve | 58:2eade98630e2 | 662 | } |
Lightvalve | 61:bc8c8270f0ab | 663 | |
Lightvalve | 58:2eade98630e2 | 664 | // //Pressure sensor A |
Lightvalve | 58:2eade98630e2 | 665 | // ADC1->CR2 |= 0x40000000; // adc _ 12bit |
Lightvalve | 58:2eade98630e2 | 666 | // //while((ADC1->SR & 0b10)); |
Lightvalve | 58:2eade98630e2 | 667 | // float alpha_update_pres_A = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f)); |
Lightvalve | 58:2eade98630e2 | 668 | // float pres_A_new = ((float)ADC1->DR); |
Lightvalve | 58:2eade98630e2 | 669 | // pres_A.sen = pres_A.sen*(1.0f-alpha_update_pres_A)+pres_A_new*(alpha_update_pres_A); |
Lightvalve | 58:2eade98630e2 | 670 | // 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 | 671 | // |
Lightvalve | 58:2eade98630e2 | 672 | // |
Lightvalve | 58:2eade98630e2 | 673 | // //Pressure sensor B |
Lightvalve | 58:2eade98630e2 | 674 | // float alpha_update_pres_B = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f)); |
Lightvalve | 58:2eade98630e2 | 675 | // float pres_B_new = ((float)ADC2->DR); |
Lightvalve | 58:2eade98630e2 | 676 | // pres_B.sen = pres_B.sen*(1.0f-alpha_update_pres_B)+pres_B_new*(alpha_update_pres_B); |
Lightvalve | 58:2eade98630e2 | 677 | // //torq.sen = pres_A.sen * (float) PISTON_AREA_A - pres_B.sen * (float) PISTON_AREA_B; |
Lightvalve | 17:1865016ca2e7 | 678 | |
Lightvalve | 17:1865016ca2e7 | 679 | |
Lightvalve | 21:e5f1a43ea6f9 | 680 | //Current |
Lightvalve | 21:e5f1a43ea6f9 | 681 | //ADC3->CR2 |= 0x40000000; // adc _ 12bit |
Lightvalve | 25:3e6b574cab5c | 682 | //int raw_cur = ADC3->DR; |
Lightvalve | 21:e5f1a43ea6f9 | 683 | //while((ADC3->SR & 0b10)); |
Lightvalve | 51:b46bed7fec80 | 684 | float alpha_update_cur = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*500.0f)); // f_cutoff : 500Hz |
Lightvalve | 30:8d561f16383b | 685 | float cur_new = ((float)ADC3->DR-2048.0f)*20.0f/4096.0f; // unit : mA |
Lightvalve | 30:8d561f16383b | 686 | cur.sen=cur.sen*(1.0f-alpha_update_cur)+cur_new*(alpha_update_cur); |
Lightvalve | 25:3e6b574cab5c | 687 | //cur.sen = raw_cur; |
Lightvalve | 58:2eade98630e2 | 688 | |
Lightvalve | 57:f4819de54e7a | 689 | CNT_TMR4++; |
Lightvalve | 21:e5f1a43ea6f9 | 690 | } |
Lightvalve | 11:82d8768d7351 | 691 | TIM4->SR = 0x0; // reset the status register |
Lightvalve | 11:82d8768d7351 | 692 | } |
Lightvalve | 19:23b7c1ad8683 | 693 | |
Lightvalve | 19:23b7c1ad8683 | 694 | |
Lightvalve | 18:b8adf1582ea3 | 695 | int j =0; |
Lightvalve | 54:647072f5307a | 696 | float FREQ_TMR3 = (float)FREQ_5k; |
Lightvalve | 48:889798ff9329 | 697 | float DT_TMR3 = (float)DT_5k; |
Lightvalve | 45:35fa6884d0c6 | 698 | int cnt_trans = 0; |
Lightvalve | 48:889798ff9329 | 699 | double VALVE_POS_RAW_FORCE_FB_LOGGING = 0.0f; |
Lightvalve | 57:f4819de54e7a | 700 | int can_rest =0; |
Lightvalve | 48:889798ff9329 | 701 | |
Lightvalve | 11:82d8768d7351 | 702 | extern "C" void TIM3_IRQHandler(void) |
Lightvalve | 21:e5f1a43ea6f9 | 703 | { |
Lightvalve | 19:23b7c1ad8683 | 704 | if (TIM3->SR & TIM_SR_UIF ) { |
Lightvalve | 57:f4819de54e7a | 705 | |
Lightvalve | 57:f4819de54e7a | 706 | if (((OPERATING_MODE&0b110)>>1) == 0) { |
Lightvalve | 57:f4819de54e7a | 707 | K_v = 0.4f; // Moog (LPM >> mA) , 100bar |
Lightvalve | 57:f4819de54e7a | 708 | mV_PER_mA = 500.0f; // 5000mV/10mA |
Lightvalve | 57:f4819de54e7a | 709 | mV_PER_pulse = 0.5f; // 5000mV/10000pulse |
Lightvalve | 57:f4819de54e7a | 710 | mA_PER_pulse = 0.001f; // 10mA/10000pulse |
Lightvalve | 57:f4819de54e7a | 711 | } else if (((OPERATING_MODE&0b110)>>1) == 1) { |
Lightvalve | 57:f4819de54e7a | 712 | K_v = 0.5f; // KNR (LPM >> mA) , 100bar |
Lightvalve | 57:f4819de54e7a | 713 | mV_PER_mA = 166.6666f; // 5000mV/30mA |
Lightvalve | 57:f4819de54e7a | 714 | mV_PER_pulse = 0.5f; // 5000mV/10000pulse |
Lightvalve | 57:f4819de54e7a | 715 | mA_PER_pulse = 0.003f; // 30mA/10000pulse |
Lightvalve | 57:f4819de54e7a | 716 | } |
Lightvalve | 50:3c630b5eba9f | 717 | |
Lightvalve | 50:3c630b5eba9f | 718 | if(MODE_POS_FT_TRANS == 1) { |
Lightvalve | 48:889798ff9329 | 719 | alpha_trans = (float)(1.0f - cos(3.141592f * (float)cnt_trans * DT_TMR3 /3.0f))/2.0f; |
Lightvalve | 45:35fa6884d0c6 | 720 | cnt_trans++; |
Lightvalve | 46:2694daea349b | 721 | torq.err_sum = 0; |
Lightvalve | 48:889798ff9329 | 722 | if((float)cnt_trans * DT_TMR3 > 3.0f) |
Lightvalve | 45:35fa6884d0c6 | 723 | MODE_POS_FT_TRANS = 2; |
Lightvalve | 50:3c630b5eba9f | 724 | } else if(MODE_POS_FT_TRANS == 3) { |
Lightvalve | 48:889798ff9329 | 725 | alpha_trans = (float)(1.0f + cos(3.141592f * (float)cnt_trans * DT_TMR3 /3.0f))/2.0f; |
Lightvalve | 45:35fa6884d0c6 | 726 | cnt_trans++; |
Lightvalve | 46:2694daea349b | 727 | torq.err_sum = 0; |
Lightvalve | 48:889798ff9329 | 728 | if((float) cnt_trans * DT_TMR3 > 3.0f ) |
Lightvalve | 45:35fa6884d0c6 | 729 | MODE_POS_FT_TRANS = 0; |
Lightvalve | 50:3c630b5eba9f | 730 | } else if(MODE_POS_FT_TRANS == 2) { |
Lightvalve | 58:2eade98630e2 | 731 | alpha_trans = 1.0f; |
Lightvalve | 45:35fa6884d0c6 | 732 | cnt_trans = 0; |
Lightvalve | 50:3c630b5eba9f | 733 | } else { |
Lightvalve | 58:2eade98630e2 | 734 | alpha_trans = 0.0f; |
Lightvalve | 45:35fa6884d0c6 | 735 | cnt_trans = 0; |
Lightvalve | 45:35fa6884d0c6 | 736 | } |
Lightvalve | 45:35fa6884d0c6 | 737 | |
Lightvalve | 50:3c630b5eba9f | 738 | |
Lightvalve | 57:f4819de54e7a | 739 | int UTILITY_MODE = 0; |
Lightvalve | 57:f4819de54e7a | 740 | int CONTROL_MODE = 0; |
Lightvalve | 58:2eade98630e2 | 741 | |
Lightvalve | 57:f4819de54e7a | 742 | if (CONTROL_UTILITY_MODE >= 20 || CONTROL_UTILITY_MODE == 0) { |
Lightvalve | 57:f4819de54e7a | 743 | UTILITY_MODE = CONTROL_UTILITY_MODE; |
Lightvalve | 57:f4819de54e7a | 744 | CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 57:f4819de54e7a | 745 | } else { |
Lightvalve | 57:f4819de54e7a | 746 | CONTROL_MODE = CONTROL_UTILITY_MODE; |
Lightvalve | 57:f4819de54e7a | 747 | UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 57:f4819de54e7a | 748 | } |
Lightvalve | 56:6f50d9d3bfee | 749 | |
Lightvalve | 56:6f50d9d3bfee | 750 | |
Lightvalve | 56:6f50d9d3bfee | 751 | |
Lightvalve | 57:f4819de54e7a | 752 | // UTILITY MODE ------------------------------------------------------------ |
Lightvalve | 56:6f50d9d3bfee | 753 | |
Lightvalve | 57:f4819de54e7a | 754 | switch (UTILITY_MODE) { |
Lightvalve | 57:f4819de54e7a | 755 | case MODE_NO_ACT: { |
Lightvalve | 13:747daba9cf59 | 756 | break; |
Lightvalve | 13:747daba9cf59 | 757 | } |
Lightvalve | 14:8e7590227d22 | 758 | |
Lightvalve | 14:8e7590227d22 | 759 | case MODE_TORQUE_SENSOR_NULLING: { |
Lightvalve | 13:747daba9cf59 | 760 | // DAC Voltage reference set |
Lightvalve | 14:8e7590227d22 | 761 | if (TMR3_COUNT_TORQUE_NULL < TMR_FREQ_5k * 2) { |
Lightvalve | 15:bd0d12728506 | 762 | CUR_TORQUE_sum += torq.sen; |
Lightvalve | 19:23b7c1ad8683 | 763 | |
Lightvalve | 14:8e7590227d22 | 764 | if (TMR3_COUNT_TORQUE_NULL % 10 == 0) { |
Lightvalve | 30:8d561f16383b | 765 | CUR_TORQUE_mean = CUR_TORQUE_sum / 10.0f; |
Lightvalve | 13:747daba9cf59 | 766 | CUR_TORQUE_sum = 0; |
Lightvalve | 14:8e7590227d22 | 767 | |
Lightvalve | 84:c355d3e52bf1 | 768 | TORQUE_VREF += 0.000003f * (0.0f - CUR_TORQUE_mean); |
Lightvalve | 19:23b7c1ad8683 | 769 | |
Lightvalve | 30:8d561f16383b | 770 | if (TORQUE_VREF > 3.3f) TORQUE_VREF = 3.3f; |
Lightvalve | 59:f308b1656d9c | 771 | if (TORQUE_VREF < 0.0f) TORQUE_VREF = 0.0f; |
Lightvalve | 50:3c630b5eba9f | 772 | |
Lightvalve | 16:903b5a4433b4 | 773 | //spi_eeprom_write(RID_TORQUE_SENSOR_VREF, (int16_t) (TORQUE_VREF * 1000.0)); |
Lightvalve | 30:8d561f16383b | 774 | dac_1 = TORQUE_VREF / 3.3f; |
Lightvalve | 13:747daba9cf59 | 775 | } |
Lightvalve | 13:747daba9cf59 | 776 | } else { |
Lightvalve | 58:2eade98630e2 | 777 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 14:8e7590227d22 | 778 | TMR3_COUNT_TORQUE_NULL = 0; |
Lightvalve | 13:747daba9cf59 | 779 | CUR_TORQUE_sum = 0; |
Lightvalve | 13:747daba9cf59 | 780 | CUR_TORQUE_mean = 0; |
Lightvalve | 19:23b7c1ad8683 | 781 | |
Lightvalve | 16:903b5a4433b4 | 782 | ROM_RESET_DATA(); |
Lightvalve | 19:23b7c1ad8683 | 783 | |
Lightvalve | 30:8d561f16383b | 784 | dac_1 = TORQUE_VREF / 3.3f; |
Lightvalve | 14:8e7590227d22 | 785 | |
Lightvalve | 13:747daba9cf59 | 786 | } |
Lightvalve | 14:8e7590227d22 | 787 | TMR3_COUNT_TORQUE_NULL++; |
Lightvalve | 13:747daba9cf59 | 788 | break; |
Lightvalve | 19:23b7c1ad8683 | 789 | } |
Lightvalve | 14:8e7590227d22 | 790 | |
Lightvalve | 50:3c630b5eba9f | 791 | // case MODE_VALVE_NULLING_AND_DEADZONE_SETTING: { |
Lightvalve | 50:3c630b5eba9f | 792 | // if (TMR3_COUNT_DEADZONE == 0) { |
Lightvalve | 50:3c630b5eba9f | 793 | // if (pos_plus_end == pos_minus_end) need_enc_init = true; |
Lightvalve | 50:3c630b5eba9f | 794 | // else temp_time = 0; |
Lightvalve | 50:3c630b5eba9f | 795 | // } |
Lightvalve | 50:3c630b5eba9f | 796 | // if (need_enc_init) { |
Lightvalve | 50:3c630b5eba9f | 797 | // if (TMR3_COUNT_DEADZONE < (int) (0.5f * (float) TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 798 | // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 799 | // pos_plus_end = pos.sen; |
Lightvalve | 50:3c630b5eba9f | 800 | // } else if (TMR3_COUNT_DEADZONE < TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 801 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 802 | // pos_minus_end = pos.sen; |
Lightvalve | 50:3c630b5eba9f | 803 | // } else if (TMR3_COUNT_DEADZONE == TMR_FREQ_5k) need_enc_init = false; |
Lightvalve | 50:3c630b5eba9f | 804 | // temp_time = TMR_FREQ_5k; |
Lightvalve | 50:3c630b5eba9f | 805 | // } |
Lightvalve | 50:3c630b5eba9f | 806 | // |
Lightvalve | 50:3c630b5eba9f | 807 | // if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 808 | // 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 | 809 | // VALVE_CENTER = VALVE_DEADZONE_PLUS = VALVE_DEADZONE_MINUS = 0; |
Lightvalve | 50:3c630b5eba9f | 810 | // |
Lightvalve | 50:3c630b5eba9f | 811 | // } else if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + (int) (1.9f * (float) TMR_FREQ_5k))) { |
Lightvalve | 50:3c630b5eba9f | 812 | // V_out = 0; |
Lightvalve | 50:3c630b5eba9f | 813 | // CUR_VELOCITY_sum += CUR_VELOCITY; |
Lightvalve | 50:3c630b5eba9f | 814 | // } else if (TMR3_COUNT_DEADZONE == (temp_time + 2 * TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 815 | // if (CUR_VELOCITY_sum == 0) DZ_dir = 1; |
Lightvalve | 50:3c630b5eba9f | 816 | // else if (CUR_VELOCITY_sum > 0) DZ_dir = 1; |
Lightvalve | 50:3c630b5eba9f | 817 | // else if (CUR_VELOCITY_sum < 0) DZ_dir = -1; |
Lightvalve | 50:3c630b5eba9f | 818 | // else DZ_temp_cnt2 = DZ_end; |
Lightvalve | 50:3c630b5eba9f | 819 | // CUR_VELOCITY_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 820 | // } else if (TMR3_COUNT_DEADZONE > (temp_time + 2 * TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 821 | // if (TMR3_COUNT_DEADZONE > (temp_time + 10 * TMR_FREQ_5k)) DZ_temp_cnt2 = DZ_end; |
Lightvalve | 50:3c630b5eba9f | 822 | // |
Lightvalve | 50:3c630b5eba9f | 823 | // // Position of Dead Zone |
Lightvalve | 50:3c630b5eba9f | 824 | // // (CUR_VELOCITY < 0) (CUR_VELOCITY == 0) (CUR_VELOCITY > 0) |
Lightvalve | 50:3c630b5eba9f | 825 | // // | / | / |/ |
Lightvalve | 50:3c630b5eba9f | 826 | // // | ______/ ___|___/ ______/| |
Lightvalve | 50:3c630b5eba9f | 827 | // // |/ / | / | |
Lightvalve | 50:3c630b5eba9f | 828 | // // /| / | / | |
Lightvalve | 50:3c630b5eba9f | 829 | // // 0V 0V 0V |
Lightvalve | 50:3c630b5eba9f | 830 | // |
Lightvalve | 50:3c630b5eba9f | 831 | // if (DZ_temp_cnt2 < DZ_end) { |
Lightvalve | 50:3c630b5eba9f | 832 | // if (TMR3_COUNT_DEADZONE % 20 != 0) { |
Lightvalve | 50:3c630b5eba9f | 833 | // CUR_VELOCITY_sum += CUR_VELOCITY; |
Lightvalve | 50:3c630b5eba9f | 834 | // } else { |
Lightvalve | 50:3c630b5eba9f | 835 | // V_out -= DZ_dir; |
Lightvalve | 50:3c630b5eba9f | 836 | // if (CUR_VELOCITY_sum * DZ_dir < 0) DZ_temp_cnt++; |
Lightvalve | 50:3c630b5eba9f | 837 | // CUR_VELOCITY_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 838 | // } |
Lightvalve | 50:3c630b5eba9f | 839 | // if (DZ_temp_cnt == 5) { |
Lightvalve | 50:3c630b5eba9f | 840 | // if (DZ_dir >= 0) VALVE_DEADZONE_MINUS = (int16_t) V_out; |
Lightvalve | 50:3c630b5eba9f | 841 | // else VALVE_DEADZONE_PLUS = (int16_t) V_out; |
Lightvalve | 50:3c630b5eba9f | 842 | // DZ_dir = -DZ_dir; |
Lightvalve | 50:3c630b5eba9f | 843 | // DZ_temp_cnt = 0; |
Lightvalve | 50:3c630b5eba9f | 844 | // DZ_temp_cnt2++; |
Lightvalve | 50:3c630b5eba9f | 845 | // } |
Lightvalve | 50:3c630b5eba9f | 846 | // } else { |
Lightvalve | 50:3c630b5eba9f | 847 | // TMR3_COUNT_DEADZONE = -1; |
Lightvalve | 50:3c630b5eba9f | 848 | // VALVE_CENTER = VALVE_DEADZONE_PLUS / 2 + VALVE_DEADZONE_MINUS / 2; |
Lightvalve | 50:3c630b5eba9f | 849 | // if (VALVE_DEADZONE_PLUS < VALVE_DEADZONE_MINUS) { |
Lightvalve | 50:3c630b5eba9f | 850 | // VALVE_DEADZONE_PLUS = VALVE_CENTER; |
Lightvalve | 50:3c630b5eba9f | 851 | // VALVE_DEADZONE_MINUS = VALVE_CENTER; |
Lightvalve | 50:3c630b5eba9f | 852 | // } |
Lightvalve | 50:3c630b5eba9f | 853 | // V_out = 0; |
Lightvalve | 50:3c630b5eba9f | 854 | // |
Lightvalve | 50:3c630b5eba9f | 855 | // ROM_RESET_DATA(); |
Lightvalve | 50:3c630b5eba9f | 856 | // |
Lightvalve | 50:3c630b5eba9f | 857 | // //spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, VALVE_DEADZONE_PLUS); |
Lightvalve | 50:3c630b5eba9f | 858 | // //spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, VALVE_DEADZONE_MINUS); |
Lightvalve | 50:3c630b5eba9f | 859 | // |
Lightvalve | 50:3c630b5eba9f | 860 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 50:3c630b5eba9f | 861 | // DZ_temp_cnt2 = 0; |
Lightvalve | 50:3c630b5eba9f | 862 | // } |
Lightvalve | 50:3c630b5eba9f | 863 | // } |
Lightvalve | 50:3c630b5eba9f | 864 | // TMR3_COUNT_DEADZONE++; |
Lightvalve | 50:3c630b5eba9f | 865 | // break; |
Lightvalve | 50:3c630b5eba9f | 866 | // } |
Lightvalve | 14:8e7590227d22 | 867 | |
Lightvalve | 14:8e7590227d22 | 868 | case MODE_FIND_HOME: { |
Lightvalve | 29:69f3f5445d6d | 869 | if (FINDHOME_STAGE == FINDHOME_INIT) { |
Lightvalve | 14:8e7590227d22 | 870 | cnt_findhome = 0; |
Lightvalve | 14:8e7590227d22 | 871 | cnt_vel_findhome = 0; |
Lightvalve | 14:8e7590227d22 | 872 | //REFERENCE_MODE = MODE_REF_NO_ACT; // Stop taking reference data from PODO |
Lightvalve | 59:f308b1656d9c | 873 | pos.ref = pos.sen; |
Lightvalve | 59:f308b1656d9c | 874 | vel.ref = 0.0f; |
Lightvalve | 29:69f3f5445d6d | 875 | FINDHOME_STAGE = FINDHOME_GOTOLIMIT; |
Lightvalve | 29:69f3f5445d6d | 876 | } else if (FINDHOME_STAGE == FINDHOME_GOTOLIMIT) { |
Lightvalve | 67:c2812cf26c38 | 877 | int cnt_check_enc = (TMR_FREQ_5k/20); |
Lightvalve | 29:69f3f5445d6d | 878 | if(cnt_findhome%cnt_check_enc == 0) { |
Lightvalve | 29:69f3f5445d6d | 879 | FINDHOME_POSITION = pos.sen; |
Lightvalve | 29:69f3f5445d6d | 880 | FINDHOME_VELOCITY = FINDHOME_POSITION - FINDHOME_POSITION_OLD; |
Lightvalve | 29:69f3f5445d6d | 881 | FINDHOME_POSITION_OLD = FINDHOME_POSITION; |
Lightvalve | 29:69f3f5445d6d | 882 | } |
Lightvalve | 29:69f3f5445d6d | 883 | cnt_findhome++; |
Lightvalve | 14:8e7590227d22 | 884 | |
Lightvalve | 29:69f3f5445d6d | 885 | if (abs(FINDHOME_VELOCITY) <= 1) { |
Lightvalve | 29:69f3f5445d6d | 886 | cnt_vel_findhome = cnt_vel_findhome + 1; |
Lightvalve | 29:69f3f5445d6d | 887 | } else { |
Lightvalve | 29:69f3f5445d6d | 888 | cnt_vel_findhome = 0; |
Lightvalve | 29:69f3f5445d6d | 889 | } |
Lightvalve | 19:23b7c1ad8683 | 890 | |
Lightvalve | 57:f4819de54e7a | 891 | if ((cnt_vel_findhome < 3*TMR_FREQ_5k) && cnt_findhome < 10*TMR_FREQ_5k) { // wait for 3sec |
Lightvalve | 29:69f3f5445d6d | 892 | //REFERENCE_MODE = MODE_REF_NO_ACT; |
Lightvalve | 67:c2812cf26c38 | 893 | if (HOMEPOS_OFFSET > 0) pos.ref = pos.ref + 12.0f; |
Lightvalve | 67:c2812cf26c38 | 894 | else pos.ref = pos.ref - 12.0f; |
Lightvalve | 61:bc8c8270f0ab | 895 | |
Lightvalve | 59:f308b1656d9c | 896 | // pos.err = pos.ref_home_pos - pos.sen; |
Lightvalve | 59:f308b1656d9c | 897 | // float VALVE_POS_RAW_POS_FB = 0.0f; |
Lightvalve | 59:f308b1656d9c | 898 | // VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * pos.err/(float) ENC_PULSE_PER_POSITION * 0.01f; |
Lightvalve | 59:f308b1656d9c | 899 | // valve_pos.ref = VALVE_POS_RAW_POS_FB + (float) VALVE_CENTER; |
Lightvalve | 59:f308b1656d9c | 900 | // VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 61:bc8c8270f0ab | 901 | |
Lightvalve | 59:f308b1656d9c | 902 | CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 59:f308b1656d9c | 903 | alpha_trans = 0.0f; |
Lightvalve | 61:bc8c8270f0ab | 904 | |
Lightvalve | 34:bb2ca2fc2a8e | 905 | |
Lightvalve | 29:69f3f5445d6d | 906 | } else { |
Lightvalve | 29:69f3f5445d6d | 907 | ENC_SET(HOMEPOS_OFFSET); |
Lightvalve | 67:c2812cf26c38 | 908 | // ENC_SET_ZERO(); |
Lightvalve | 29:69f3f5445d6d | 909 | INIT_REF_POS = HOMEPOS_OFFSET; |
Lightvalve | 29:69f3f5445d6d | 910 | REF_POSITION = 0; |
Lightvalve | 29:69f3f5445d6d | 911 | REF_VELOCITY = 0; |
Lightvalve | 29:69f3f5445d6d | 912 | FINDHOME_POSITION = 0; |
Lightvalve | 29:69f3f5445d6d | 913 | FINDHOME_POSITION_OLD = 0; |
Lightvalve | 29:69f3f5445d6d | 914 | FINDHOME_VELOCITY = 0; |
Lightvalve | 29:69f3f5445d6d | 915 | cnt_findhome = 0; |
Lightvalve | 29:69f3f5445d6d | 916 | cnt_vel_findhome = 0; |
Lightvalve | 29:69f3f5445d6d | 917 | FINDHOME_STAGE = FINDHOME_ZEROPOSE; |
Lightvalve | 67:c2812cf26c38 | 918 | |
Lightvalve | 67:c2812cf26c38 | 919 | |
Lightvalve | 67:c2812cf26c38 | 920 | cnt_findhome = 0; |
Lightvalve | 67:c2812cf26c38 | 921 | pos.ref = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 922 | vel.ref = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 923 | pos.ref_home_pos = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 924 | vel.ref_home_pos = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 925 | //FINDHOME_STAGE = FINDHOME_INIT; |
Lightvalve | 67:c2812cf26c38 | 926 | //CONTROL_UTILITY_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 67:c2812cf26c38 | 927 | |
Lightvalve | 67:c2812cf26c38 | 928 | |
Lightvalve | 29:69f3f5445d6d | 929 | } |
Lightvalve | 29:69f3f5445d6d | 930 | } else if (FINDHOME_STAGE == FINDHOME_ZEROPOSE) { |
Lightvalve | 29:69f3f5445d6d | 931 | int T_move = 2*TMR_FREQ_5k; |
Lightvalve | 59:f308b1656d9c | 932 | 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 | 933 | //pos.ref = 0.0f; |
Lightvalve | 59:f308b1656d9c | 934 | vel.ref = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 935 | |
Lightvalve | 29:69f3f5445d6d | 936 | // input for position control |
Lightvalve | 67:c2812cf26c38 | 937 | |
Lightvalve | 67:c2812cf26c38 | 938 | // CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 67:c2812cf26c38 | 939 | alpha_trans = 0.0f; |
Lightvalve | 61:bc8c8270f0ab | 940 | |
Lightvalve | 67:c2812cf26c38 | 941 | double torq_ref = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 942 | pos.err = (pos.ref - pos.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm] |
Lightvalve | 67:c2812cf26c38 | 943 | vel.err = (0.0f - vel.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm/s] |
Lightvalve | 67:c2812cf26c38 | 944 | pos.err_sum += pos.err/(float) TMR_FREQ_5k; //[mm] |
Lightvalve | 67:c2812cf26c38 | 945 | |
Lightvalve | 67:c2812cf26c38 | 946 | if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) { |
Lightvalve | 67:c2812cf26c38 | 947 | |
Lightvalve | 67:c2812cf26c38 | 948 | double I_REF_POS = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 949 | double I_REF_FORCE_FB = 0.0f; // I_REF by Force Feedback |
Lightvalve | 67:c2812cf26c38 | 950 | double I_REF_VC = 0.0f; // I_REF for velocity compensation |
Lightvalve | 67:c2812cf26c38 | 951 | |
Lightvalve | 67:c2812cf26c38 | 952 | double temp_vel_pos = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 953 | double temp_vel_torq = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 954 | double wn_Pos = 2.0f * PI * 5.0f; // f_cut : 5Hz Position Control |
Lightvalve | 67:c2812cf26c38 | 955 | |
Lightvalve | 69:3995ffeaa786 | 956 | if ((OPERATING_MODE & 0x01) == 0) { // Rotary Mode |
Lightvalve | 67:c2812cf26c38 | 957 | 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 | 958 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 69:3995ffeaa786 | 959 | } else if ((OPERATING_MODE & 0x01) == 1) { |
Lightvalve | 67:c2812cf26c38 | 960 | 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 | 961 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 67:c2812cf26c38 | 962 | } |
Lightvalve | 67:c2812cf26c38 | 963 | 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 | 964 | else I_REF_POS = temp_vel_pos * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f)))); |
Lightvalve | 67:c2812cf26c38 | 965 | |
Lightvalve | 67:c2812cf26c38 | 966 | I_REF = I_REF_POS; |
Lightvalve | 67:c2812cf26c38 | 967 | |
Lightvalve | 67:c2812cf26c38 | 968 | |
Lightvalve | 67:c2812cf26c38 | 969 | |
Lightvalve | 67:c2812cf26c38 | 970 | } else { |
Lightvalve | 67:c2812cf26c38 | 971 | float VALVE_POS_RAW_FORCE_FB = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 972 | 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 | 973 | |
Lightvalve | 67:c2812cf26c38 | 974 | if (VALVE_POS_RAW_FORCE_FB >= 0) { |
Lightvalve | 67:c2812cf26c38 | 975 | valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_PLUS; |
Lightvalve | 67:c2812cf26c38 | 976 | } else { |
Lightvalve | 67:c2812cf26c38 | 977 | valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_MINUS; |
Lightvalve | 67:c2812cf26c38 | 978 | } |
Lightvalve | 67:c2812cf26c38 | 979 | |
Lightvalve | 67:c2812cf26c38 | 980 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 67:c2812cf26c38 | 981 | |
Lightvalve | 67:c2812cf26c38 | 982 | V_out = (float) Vout.ref; |
Lightvalve | 67:c2812cf26c38 | 983 | |
Lightvalve | 67:c2812cf26c38 | 984 | } |
Lightvalve | 67:c2812cf26c38 | 985 | |
Lightvalve | 67:c2812cf26c38 | 986 | |
Lightvalve | 67:c2812cf26c38 | 987 | |
Lightvalve | 67:c2812cf26c38 | 988 | |
Lightvalve | 59:f308b1656d9c | 989 | // pos.err = pos.ref - (float)pos.sen; |
Lightvalve | 59:f308b1656d9c | 990 | // float VALVE_POS_RAW_POS_FB = 0.0f; |
Lightvalve | 59:f308b1656d9c | 991 | // VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * 0.01f * pos.err/(float) ENC_PULSE_PER_POSITION; |
Lightvalve | 59:f308b1656d9c | 992 | // valve_pos.ref = VALVE_POS_RAW_POS_FB + (float) VALVE_CENTER; |
Lightvalve | 59:f308b1656d9c | 993 | // VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 29:69f3f5445d6d | 994 | |
Lightvalve | 29:69f3f5445d6d | 995 | cnt_findhome++; |
Lightvalve | 29:69f3f5445d6d | 996 | if (cnt_findhome >= T_move) { |
Lightvalve | 29:69f3f5445d6d | 997 | //REFERENCE_MODE = MODE_REF_DIRECT; |
Lightvalve | 29:69f3f5445d6d | 998 | cnt_findhome = 0; |
Lightvalve | 30:8d561f16383b | 999 | pos.ref = 0.0f; |
Lightvalve | 30:8d561f16383b | 1000 | vel.ref = 0.0f; |
Lightvalve | 30:8d561f16383b | 1001 | pos.ref_home_pos = 0.0f; |
Lightvalve | 30:8d561f16383b | 1002 | vel.ref_home_pos = 0.0f; |
Lightvalve | 29:69f3f5445d6d | 1003 | FINDHOME_STAGE = FINDHOME_INIT; |
Lightvalve | 57:f4819de54e7a | 1004 | CONTROL_UTILITY_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 29:69f3f5445d6d | 1005 | } |
Lightvalve | 13:747daba9cf59 | 1006 | } |
Lightvalve | 19:23b7c1ad8683 | 1007 | |
Lightvalve | 13:747daba9cf59 | 1008 | break; |
Lightvalve | 13:747daba9cf59 | 1009 | } |
Lightvalve | 14:8e7590227d22 | 1010 | |
Lightvalve | 50:3c630b5eba9f | 1011 | // case MODE_VALVE_GAIN_SETTING: { |
Lightvalve | 50:3c630b5eba9f | 1012 | // if (TMR3_COUNT_FLOWRATE == 0) { |
Lightvalve | 50:3c630b5eba9f | 1013 | // if (pos_plus_end == pos_minus_end) need_enc_init = true; |
Lightvalve | 50:3c630b5eba9f | 1014 | // else { |
Lightvalve | 50:3c630b5eba9f | 1015 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1016 | // temp_time = (int) (0.5f * (float) TMR_FREQ_5k); |
Lightvalve | 50:3c630b5eba9f | 1017 | // } |
Lightvalve | 50:3c630b5eba9f | 1018 | // } |
Lightvalve | 50:3c630b5eba9f | 1019 | // if (need_enc_init) { |
Lightvalve | 50:3c630b5eba9f | 1020 | // if (TMR3_COUNT_FLOWRATE < (int) (0.5f * (float) TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 1021 | // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1022 | // pos_plus_end = pos.sen; |
Lightvalve | 50:3c630b5eba9f | 1023 | // } else if (TMR3_COUNT_FLOWRATE < TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1024 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1025 | // pos_minus_end = pos.sen; |
Lightvalve | 50:3c630b5eba9f | 1026 | // } else if (TMR3_COUNT_FLOWRATE == TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1027 | // need_enc_init = false; |
Lightvalve | 50:3c630b5eba9f | 1028 | // check_vel_pos_init = (int) (0.9f * (float) (pos_plus_end - pos_minus_end)); |
Lightvalve | 50:3c630b5eba9f | 1029 | // check_vel_pos_fin = (int) (0.95f * (float) (pos_plus_end - pos_minus_end)); |
Lightvalve | 50:3c630b5eba9f | 1030 | // check_vel_pos_interv = check_vel_pos_fin - check_vel_pos_init; |
Lightvalve | 50:3c630b5eba9f | 1031 | // } |
Lightvalve | 50:3c630b5eba9f | 1032 | // temp_time = TMR_FREQ_5k; |
Lightvalve | 50:3c630b5eba9f | 1033 | // } |
Lightvalve | 50:3c630b5eba9f | 1034 | // TMR3_COUNT_FLOWRATE++; |
Lightvalve | 50:3c630b5eba9f | 1035 | // if (TMR3_COUNT_FLOWRATE > temp_time) { |
Lightvalve | 50:3c630b5eba9f | 1036 | // if (flag_flowrate % 2 == 0) { // (+) |
Lightvalve | 50:3c630b5eba9f | 1037 | // VALVE_VOLTAGE = 1000.0f * (float) (flag_flowrate / 2 + 1); |
Lightvalve | 50:3c630b5eba9f | 1038 | // V_out = VALVE_VOLTAGE; |
Lightvalve | 50:3c630b5eba9f | 1039 | // if (pos.sen > (pos_minus_end + check_vel_pos_init) && pos.sen < (pos_minus_end + check_vel_pos_fin)) { |
Lightvalve | 50:3c630b5eba9f | 1040 | // fl_temp_cnt++; |
Lightvalve | 50:3c630b5eba9f | 1041 | // } else if (pos.sen >= (pos_minus_end + check_vel_pos_fin) && CUR_VELOCITY == 0) { |
Lightvalve | 50:3c630b5eba9f | 1042 | // 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 | 1043 | // // 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 | 1044 | // fl_temp_cnt2++; |
Lightvalve | 50:3c630b5eba9f | 1045 | // } |
Lightvalve | 50:3c630b5eba9f | 1046 | // } else if (flag_flowrate % 2 == 1) { // (-) |
Lightvalve | 50:3c630b5eba9f | 1047 | // VALVE_VOLTAGE = -1. * (float) (flag_flowrate / 2 + 1); |
Lightvalve | 50:3c630b5eba9f | 1048 | // V_out = VALVE_VOLTAGE; |
Lightvalve | 50:3c630b5eba9f | 1049 | // if (pos.sen < (pos_plus_end - check_vel_pos_init) && pos.sen > (pos_plus_end - check_vel_pos_fin)) { |
Lightvalve | 50:3c630b5eba9f | 1050 | // fl_temp_cnt++; |
Lightvalve | 50:3c630b5eba9f | 1051 | // } else if (pos.sen <= (pos_plus_end - check_vel_pos_fin) && CUR_VELOCITY == 0) { |
Lightvalve | 50:3c630b5eba9f | 1052 | // 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 | 1053 | // // 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 | 1054 | // fl_temp_cnt2++; |
Lightvalve | 50:3c630b5eba9f | 1055 | // } |
Lightvalve | 50:3c630b5eba9f | 1056 | // } |
Lightvalve | 50:3c630b5eba9f | 1057 | // if (fl_temp_cnt2 == 100) { |
Lightvalve | 50:3c630b5eba9f | 1058 | // |
Lightvalve | 50:3c630b5eba9f | 1059 | // ROM_RESET_DATA(); |
Lightvalve | 50:3c630b5eba9f | 1060 | // |
Lightvalve | 50:3c630b5eba9f | 1061 | // //spi_eeprom_write(RID_VALVE_GAIN_PLUS_1 + flag_flowrate, (int16_t) (VALVE_GAIN_LPM_PER_V[flag_flowrate] * 100.0f)); |
Lightvalve | 50:3c630b5eba9f | 1062 | // cur_vel_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 1063 | // fl_temp_cnt = 0; |
Lightvalve | 50:3c630b5eba9f | 1064 | // fl_temp_cnt2 = 0; |
Lightvalve | 50:3c630b5eba9f | 1065 | // flag_flowrate++; |
Lightvalve | 50:3c630b5eba9f | 1066 | // } |
Lightvalve | 50:3c630b5eba9f | 1067 | // if (flag_flowrate == 10) { |
Lightvalve | 50:3c630b5eba9f | 1068 | // V_out = 0; |
Lightvalve | 50:3c630b5eba9f | 1069 | // flag_flowrate = 0; |
Lightvalve | 50:3c630b5eba9f | 1070 | // TMR3_COUNT_FLOWRATE = 0; |
Lightvalve | 50:3c630b5eba9f | 1071 | // valve_gain_repeat_cnt++; |
Lightvalve | 50:3c630b5eba9f | 1072 | // if (valve_gain_repeat_cnt >= 1) { |
Lightvalve | 50:3c630b5eba9f | 1073 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 50:3c630b5eba9f | 1074 | // valve_gain_repeat_cnt = 0; |
Lightvalve | 50:3c630b5eba9f | 1075 | // } |
Lightvalve | 50:3c630b5eba9f | 1076 | // |
Lightvalve | 50:3c630b5eba9f | 1077 | // } |
Lightvalve | 50:3c630b5eba9f | 1078 | // break; |
Lightvalve | 50:3c630b5eba9f | 1079 | // } |
Lightvalve | 50:3c630b5eba9f | 1080 | // |
Lightvalve | 50:3c630b5eba9f | 1081 | // } |
Lightvalve | 14:8e7590227d22 | 1082 | case MODE_PRESSURE_SENSOR_NULLING: { |
Lightvalve | 13:747daba9cf59 | 1083 | // DAC Voltage reference set |
Lightvalve | 14:8e7590227d22 | 1084 | if (TMR3_COUNT_PRES_NULL < TMR_FREQ_5k * 2) { |
Lightvalve | 14:8e7590227d22 | 1085 | CUR_PRES_A_sum += pres_A.sen; |
Lightvalve | 14:8e7590227d22 | 1086 | CUR_PRES_B_sum += pres_B.sen; |
Lightvalve | 14:8e7590227d22 | 1087 | |
Lightvalve | 14:8e7590227d22 | 1088 | if (TMR3_COUNT_PRES_NULL % 10 == 0) { |
Lightvalve | 30:8d561f16383b | 1089 | CUR_PRES_A_mean = CUR_PRES_A_sum / 10.0f; |
Lightvalve | 30:8d561f16383b | 1090 | CUR_PRES_B_mean = CUR_PRES_B_sum / 10.0f; |
Lightvalve | 13:747daba9cf59 | 1091 | CUR_PRES_A_sum = 0; |
Lightvalve | 13:747daba9cf59 | 1092 | CUR_PRES_B_sum = 0; |
Lightvalve | 14:8e7590227d22 | 1093 | |
Lightvalve | 38:118df027d851 | 1094 | float VREF_NullingGain = 0.0003f; |
Lightvalve | 58:2eade98630e2 | 1095 | PRES_A_VREF = PRES_A_VREF + VREF_NullingGain * CUR_PRES_A_mean; |
Lightvalve | 58:2eade98630e2 | 1096 | PRES_B_VREF = PRES_B_VREF + VREF_NullingGain * CUR_PRES_B_mean; |
Lightvalve | 14:8e7590227d22 | 1097 | |
Lightvalve | 30:8d561f16383b | 1098 | if (PRES_A_VREF > 3.3f) PRES_A_VREF = 3.3f; |
Lightvalve | 30:8d561f16383b | 1099 | if (PRES_A_VREF < 0.0f) PRES_A_VREF = 0.0f; |
Lightvalve | 30:8d561f16383b | 1100 | if (PRES_B_VREF > 3.3f) PRES_B_VREF = 3.3f; |
Lightvalve | 30:8d561f16383b | 1101 | if (PRES_B_VREF < 0.0f) PRES_B_VREF = 0.0f; |
Lightvalve | 19:23b7c1ad8683 | 1102 | |
Lightvalve | 30:8d561f16383b | 1103 | dac_1 = PRES_A_VREF / 3.3f; |
Lightvalve | 30:8d561f16383b | 1104 | dac_2 = PRES_B_VREF / 3.3f; |
Lightvalve | 13:747daba9cf59 | 1105 | } |
Lightvalve | 13:747daba9cf59 | 1106 | } else { |
Lightvalve | 57:f4819de54e7a | 1107 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 14:8e7590227d22 | 1108 | TMR3_COUNT_PRES_NULL = 0; |
Lightvalve | 13:747daba9cf59 | 1109 | CUR_PRES_A_sum = 0; |
Lightvalve | 13:747daba9cf59 | 1110 | CUR_PRES_B_sum = 0; |
Lightvalve | 13:747daba9cf59 | 1111 | CUR_PRES_A_mean = 0; |
Lightvalve | 13:747daba9cf59 | 1112 | CUR_PRES_B_mean = 0; |
Lightvalve | 14:8e7590227d22 | 1113 | |
Lightvalve | 16:903b5a4433b4 | 1114 | ROM_RESET_DATA(); |
Lightvalve | 19:23b7c1ad8683 | 1115 | |
Lightvalve | 30:8d561f16383b | 1116 | dac_1 = PRES_A_VREF / 3.3f; |
Lightvalve | 30:8d561f16383b | 1117 | dac_2 = PRES_B_VREF / 3.3f; |
Lightvalve | 17:1865016ca2e7 | 1118 | //pc.printf("nulling end"); |
Lightvalve | 13:747daba9cf59 | 1119 | } |
Lightvalve | 14:8e7590227d22 | 1120 | TMR3_COUNT_PRES_NULL++; |
Lightvalve | 13:747daba9cf59 | 1121 | break; |
Lightvalve | 13:747daba9cf59 | 1122 | } |
Lightvalve | 14:8e7590227d22 | 1123 | |
Lightvalve | 50:3c630b5eba9f | 1124 | // case MODE_PRESSURE_SENSOR_CALIB: { |
Lightvalve | 50:3c630b5eba9f | 1125 | // if (TMR3_COUNT_PRES_CALIB < 2 * TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1126 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1127 | // if (TMR3_COUNT_PRES_CALIB >= TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1128 | // CUR_PRES_A_sum += CUR_PRES_A; |
Lightvalve | 50:3c630b5eba9f | 1129 | // } |
Lightvalve | 50:3c630b5eba9f | 1130 | // } else if (TMR3_COUNT_PRES_CALIB < 4 * TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1131 | // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1132 | // if (TMR3_COUNT_PRES_CALIB >= 3 * TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1133 | // CUR_PRES_B_sum += CUR_PRES_B; |
Lightvalve | 50:3c630b5eba9f | 1134 | // } |
Lightvalve | 50:3c630b5eba9f | 1135 | // } else { |
Lightvalve | 50:3c630b5eba9f | 1136 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 50:3c630b5eba9f | 1137 | // TMR3_COUNT_PRES_CALIB = 0; |
Lightvalve | 50:3c630b5eba9f | 1138 | // V_out = 0; |
Lightvalve | 50:3c630b5eba9f | 1139 | // PRES_SENSOR_A_PULSE_PER_BAR = CUR_PRES_A_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_A_NULL; |
Lightvalve | 50:3c630b5eba9f | 1140 | // PRES_SENSOR_A_PULSE_PER_BAR = PRES_SENSOR_A_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f); |
Lightvalve | 50:3c630b5eba9f | 1141 | // PRES_SENSOR_B_PULSE_PER_BAR = CUR_PRES_B_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_B_NULL; |
Lightvalve | 50:3c630b5eba9f | 1142 | // PRES_SENSOR_B_PULSE_PER_BAR = PRES_SENSOR_B_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f); |
Lightvalve | 50:3c630b5eba9f | 1143 | // CUR_PRES_A_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 1144 | // CUR_PRES_B_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 1145 | // CUR_PRES_A_mean = 0; |
Lightvalve | 50:3c630b5eba9f | 1146 | // CUR_PRES_B_mean = 0; |
Lightvalve | 50:3c630b5eba9f | 1147 | // |
Lightvalve | 50:3c630b5eba9f | 1148 | // ROM_RESET_DATA(); |
Lightvalve | 50:3c630b5eba9f | 1149 | // |
Lightvalve | 50:3c630b5eba9f | 1150 | // //spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f)); |
Lightvalve | 50:3c630b5eba9f | 1151 | // //spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f)); |
Lightvalve | 50:3c630b5eba9f | 1152 | // } |
Lightvalve | 50:3c630b5eba9f | 1153 | // TMR3_COUNT_PRES_CALIB++; |
Lightvalve | 50:3c630b5eba9f | 1154 | // break; |
Lightvalve | 50:3c630b5eba9f | 1155 | // } |
Lightvalve | 19:23b7c1ad8683 | 1156 | |
Lightvalve | 50:3c630b5eba9f | 1157 | // case MODE_ROTARY_FRICTION_TUNING: { |
Lightvalve | 50:3c630b5eba9f | 1158 | // 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 | 1159 | // V_out = PWM_out * sin(2 * 3.14159f * freq_fric_tune * TMR3_COUNT_ROTARY_FRIC_TUNE * 0.0001f); |
Lightvalve | 50:3c630b5eba9f | 1160 | // if (V_out > 0) V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1161 | // else V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1162 | // TMR3_COUNT_ROTARY_FRIC_TUNE++; |
Lightvalve | 50:3c630b5eba9f | 1163 | // if (TMR3_COUNT_ROTARY_FRIC_TUNE > TUNING_TIME * TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1164 | // TMR3_COUNT_ROTARY_FRIC_TUNE = 0; |
Lightvalve | 50:3c630b5eba9f | 1165 | // V_out = 0.0f; |
Lightvalve | 50:3c630b5eba9f | 1166 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 50:3c630b5eba9f | 1167 | // } |
Lightvalve | 50:3c630b5eba9f | 1168 | // break; |
Lightvalve | 50:3c630b5eba9f | 1169 | // } |
Lightvalve | 14:8e7590227d22 | 1170 | |
Lightvalve | 14:8e7590227d22 | 1171 | case MODE_DDV_POS_VS_PWM_ID: { |
Lightvalve | 59:f308b1656d9c | 1172 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 13:747daba9cf59 | 1173 | VALVE_ID_timer = VALVE_ID_timer + 1; |
Lightvalve | 14:8e7590227d22 | 1174 | |
Lightvalve | 14:8e7590227d22 | 1175 | if(VALVE_ID_timer < TMR_FREQ_5k*1) { |
Lightvalve | 60:64181f1d3e60 | 1176 | Vout.ref = 3000.0f * sin(2.0f*3.14f*VALVE_ID_timer/TMR_FREQ_5k * 100.0f); |
Lightvalve | 14:8e7590227d22 | 1177 | } else if(VALVE_ID_timer < TMR_FREQ_5k*2) { |
Lightvalve | 59:f308b1656d9c | 1178 | Vout.ref = 1000.0f*(ID_index_array[ID_index]); |
Lightvalve | 14:8e7590227d22 | 1179 | } else if(VALVE_ID_timer == TMR_FREQ_5k*2) { |
Lightvalve | 13:747daba9cf59 | 1180 | VALVE_POS_TMP = 0; |
Lightvalve | 13:747daba9cf59 | 1181 | data_num = 0; |
Lightvalve | 14:8e7590227d22 | 1182 | } else if(VALVE_ID_timer < TMR_FREQ_5k*3) { |
Lightvalve | 13:747daba9cf59 | 1183 | data_num = data_num + 1; |
Lightvalve | 13:747daba9cf59 | 1184 | VALVE_POS_TMP = VALVE_POS_TMP + value; |
Lightvalve | 14:8e7590227d22 | 1185 | } else if(VALVE_ID_timer == TMR_FREQ_5k*3) { |
Lightvalve | 59:f308b1656d9c | 1186 | Vout.ref = 0.0f; |
Lightvalve | 59:f308b1656d9c | 1187 | } else { |
Lightvalve | 13:747daba9cf59 | 1188 | VALVE_POS_AVG[ID_index] = VALVE_POS_TMP / data_num; |
Lightvalve | 13:747daba9cf59 | 1189 | VALVE_ID_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1190 | ID_index= ID_index +1; |
Lightvalve | 13:747daba9cf59 | 1191 | } |
Lightvalve | 14:8e7590227d22 | 1192 | |
Lightvalve | 17:1865016ca2e7 | 1193 | if(ID_index>=25) { |
Lightvalve | 13:747daba9cf59 | 1194 | int i; |
Lightvalve | 13:747daba9cf59 | 1195 | VALVE_POS_AVG_OLD = VALVE_POS_AVG[0]; |
Lightvalve | 17:1865016ca2e7 | 1196 | for(i=0; i<25; i++) { |
Lightvalve | 13:747daba9cf59 | 1197 | VALVE_POS_VS_PWM[i] = (int16_t) (VALVE_POS_AVG[i]); |
Lightvalve | 14:8e7590227d22 | 1198 | if(VALVE_POS_AVG[i] > VALVE_POS_AVG_OLD) { |
Lightvalve | 13:747daba9cf59 | 1199 | VALVE_MAX_POS = VALVE_POS_AVG[i]; |
Lightvalve | 13:747daba9cf59 | 1200 | VALVE_POS_AVG_OLD = VALVE_MAX_POS; |
Lightvalve | 14:8e7590227d22 | 1201 | } else if(VALVE_POS_AVG[i] < VALVE_POS_AVG_OLD) { |
Lightvalve | 13:747daba9cf59 | 1202 | VALVE_MIN_POS = VALVE_POS_AVG[i]; |
Lightvalve | 13:747daba9cf59 | 1203 | VALVE_POS_AVG_OLD = VALVE_MIN_POS; |
Lightvalve | 13:747daba9cf59 | 1204 | } |
Lightvalve | 13:747daba9cf59 | 1205 | } |
Lightvalve | 59:f308b1656d9c | 1206 | ROM_RESET_DATA(); |
Lightvalve | 13:747daba9cf59 | 1207 | ID_index = 0; |
Lightvalve | 57:f4819de54e7a | 1208 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 13:747daba9cf59 | 1209 | } |
Lightvalve | 14:8e7590227d22 | 1210 | |
Lightvalve | 14:8e7590227d22 | 1211 | |
Lightvalve | 13:747daba9cf59 | 1212 | break; |
Lightvalve | 13:747daba9cf59 | 1213 | } |
Lightvalve | 14:8e7590227d22 | 1214 | |
Lightvalve | 14:8e7590227d22 | 1215 | case MODE_DDV_DEADZONE_AND_CENTER: { |
Lightvalve | 59:f308b1656d9c | 1216 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 13:747daba9cf59 | 1217 | VALVE_DZ_timer = VALVE_DZ_timer + 1; |
Lightvalve | 14:8e7590227d22 | 1218 | if(first_check == 0) { |
Lightvalve | 30:8d561f16383b | 1219 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1220 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 30:8d561f16383b | 1221 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1222 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1223 | pos_plus_end = pos.sen; |
Lightvalve | 30:8d561f16383b | 1224 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1225 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 30:8d561f16383b | 1226 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1227 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1228 | pos_minus_end = pos.sen; |
Lightvalve | 30:8d561f16383b | 1229 | } else if(VALVE_DZ_timer < (int) (3.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1230 | 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 | 1231 | } else if(VALVE_DZ_timer < (int) (4.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1232 | 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 | 1233 | data_num = data_num + 1; |
Lightvalve | 13:747daba9cf59 | 1234 | VALVE_POS_TMP = VALVE_POS_TMP + value; |
Lightvalve | 30:8d561f16383b | 1235 | } else if(VALVE_DZ_timer == (int) (4.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1236 | 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 | 1237 | DDV_POS_AVG = VALVE_POS_TMP / data_num; |
Lightvalve | 14:8e7590227d22 | 1238 | START_POS = pos.sen; |
Lightvalve | 13:747daba9cf59 | 1239 | VALVE_POS_TMP = 0; |
Lightvalve | 13:747daba9cf59 | 1240 | data_num = 0; |
Lightvalve | 14:8e7590227d22 | 1241 | |
Lightvalve | 30:8d561f16383b | 1242 | } else if(VALVE_DZ_timer < (int) (5.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1243 | valve_pos.ref = DDV_POS_AVG; |
Lightvalve | 14:8e7590227d22 | 1244 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 14:8e7590227d22 | 1245 | |
Lightvalve | 30:8d561f16383b | 1246 | } else if(VALVE_DZ_timer < (int) (6.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1247 | valve_pos.ref = DDV_POS_AVG; |
Lightvalve | 14:8e7590227d22 | 1248 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 60:64181f1d3e60 | 1249 | |
Lightvalve | 30:8d561f16383b | 1250 | } else if(VALVE_DZ_timer == (int) (6.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1251 | valve_pos.ref = DDV_POS_AVG; |
Lightvalve | 14:8e7590227d22 | 1252 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 14:8e7590227d22 | 1253 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1254 | |
Lightvalve | 60:64181f1d3e60 | 1255 | if((FINAL_POS - START_POS)>200) { |
Lightvalve | 13:747daba9cf59 | 1256 | DZ_case = 1; |
Lightvalve | 60:64181f1d3e60 | 1257 | } else if((FINAL_POS - START_POS)<-200) { |
Lightvalve | 13:747daba9cf59 | 1258 | DZ_case = -1; |
Lightvalve | 14:8e7590227d22 | 1259 | } else { |
Lightvalve | 13:747daba9cf59 | 1260 | DZ_case = 0; |
Lightvalve | 13:747daba9cf59 | 1261 | } |
Lightvalve | 61:bc8c8270f0ab | 1262 | |
Lightvalve | 60:64181f1d3e60 | 1263 | CAN_TX_PRES((int16_t) (DZ_case), (int16_t) (6)); |
Lightvalve | 50:3c630b5eba9f | 1264 | |
Lightvalve | 13:747daba9cf59 | 1265 | first_check = 1; |
Lightvalve | 13:747daba9cf59 | 1266 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1267 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1268 | Ref_Valve_Pos_Old = DDV_POS_AVG; |
Lightvalve | 13:747daba9cf59 | 1269 | DZ_NUM = 1; |
Lightvalve | 13:747daba9cf59 | 1270 | DZ_index = 1; |
Lightvalve | 14:8e7590227d22 | 1271 | |
Lightvalve | 13:747daba9cf59 | 1272 | } |
Lightvalve | 19:23b7c1ad8683 | 1273 | } else { |
Lightvalve | 14:8e7590227d22 | 1274 | if((DZ_case == -1 && DZ_NUM == 1) | (DZ_case == 1 && DZ_NUM == 1)) { |
Lightvalve | 30:8d561f16383b | 1275 | if(VALVE_DZ_timer < (int) (1.0 * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1276 | 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 | 1277 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 60:64181f1d3e60 | 1278 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1279 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1280 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1281 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1282 | valve_pos.ref = Ref_Valve_Pos_Old - DZ_case * DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1283 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1284 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1285 | } else if(valve_pos.ref >= VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1286 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 13:747daba9cf59 | 1287 | } |
Lightvalve | 14:8e7590227d22 | 1288 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 60:64181f1d3e60 | 1289 | |
Lightvalve | 30:8d561f16383b | 1290 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1291 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1292 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1293 | |
Lightvalve | 14:8e7590227d22 | 1294 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 14:8e7590227d22 | 1295 | DZ_DIRECTION = 1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1296 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 14:8e7590227d22 | 1297 | DZ_DIRECTION = -1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1298 | } else { |
Lightvalve | 13:747daba9cf59 | 1299 | DZ_DIRECTION = 1 * DZ_case; |
Lightvalve | 13:747daba9cf59 | 1300 | } |
Lightvalve | 14:8e7590227d22 | 1301 | |
Lightvalve | 13:747daba9cf59 | 1302 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1303 | DZ_index= DZ_index *2; |
Lightvalve | 14:8e7590227d22 | 1304 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1305 | FIRST_DZ = valve_pos.ref; |
Lightvalve | 13:747daba9cf59 | 1306 | DZ_NUM = 2; |
Lightvalve | 13:747daba9cf59 | 1307 | Ref_Valve_Pos_Old = FIRST_DZ; |
Lightvalve | 13:747daba9cf59 | 1308 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1309 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1310 | } |
Lightvalve | 13:747daba9cf59 | 1311 | } |
Lightvalve | 14:8e7590227d22 | 1312 | } else if((DZ_case == -1 && DZ_NUM == 2) | (DZ_case == 1 && DZ_NUM == 2)) { |
Lightvalve | 30:8d561f16383b | 1313 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1314 | 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 | 1315 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 60:64181f1d3e60 | 1316 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1317 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1318 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1319 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1320 | valve_pos.ref = Ref_Valve_Pos_Old - DZ_case * DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1321 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1322 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1323 | } else if(valve_pos.ref >= VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1324 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 13:747daba9cf59 | 1325 | } |
Lightvalve | 14:8e7590227d22 | 1326 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 61:bc8c8270f0ab | 1327 | |
Lightvalve | 30:8d561f16383b | 1328 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1329 | Vout.ref = 0.0f; |
Lightvalve | 59:f308b1656d9c | 1330 | } else if(VALVE_DZ_timer > (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1331 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1332 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1333 | |
Lightvalve | 14:8e7590227d22 | 1334 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 60:64181f1d3e60 | 1335 | DZ_DIRECTION = 1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1336 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 60:64181f1d3e60 | 1337 | DZ_DIRECTION = -1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1338 | } else { |
Lightvalve | 60:64181f1d3e60 | 1339 | DZ_DIRECTION = -1 * DZ_case; |
Lightvalve | 13:747daba9cf59 | 1340 | } |
Lightvalve | 14:8e7590227d22 | 1341 | |
Lightvalve | 13:747daba9cf59 | 1342 | VALVE_DZ_timer = 0; |
Lightvalve | 60:64181f1d3e60 | 1343 | DZ_index= DZ_index * 2; |
Lightvalve | 14:8e7590227d22 | 1344 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1345 | SECOND_DZ = valve_pos.ref; |
Lightvalve | 57:f4819de54e7a | 1346 | VALVE_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ)); |
Lightvalve | 13:747daba9cf59 | 1347 | first_check = 0; |
Lightvalve | 33:91b17819ec30 | 1348 | VALVE_DEADZONE_MINUS = (float) FIRST_DZ; |
Lightvalve | 33:91b17819ec30 | 1349 | VALVE_DEADZONE_PLUS = (float) SECOND_DZ; |
Lightvalve | 19:23b7c1ad8683 | 1350 | |
Lightvalve | 16:903b5a4433b4 | 1351 | ROM_RESET_DATA(); |
Lightvalve | 34:bb2ca2fc2a8e | 1352 | |
Lightvalve | 60:64181f1d3e60 | 1353 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 13:747daba9cf59 | 1354 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1355 | } |
Lightvalve | 13:747daba9cf59 | 1356 | } |
Lightvalve | 14:8e7590227d22 | 1357 | } else if(DZ_case == 0 && DZ_NUM ==1) { |
Lightvalve | 30:8d561f16383b | 1358 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1359 | 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 | 1360 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 60:64181f1d3e60 | 1361 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1362 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1363 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1364 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1365 | valve_pos.ref = Ref_Valve_Pos_Old - DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1366 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1367 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1368 | } else if(valve_pos.ref >= VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1369 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 13:747daba9cf59 | 1370 | } |
Lightvalve | 14:8e7590227d22 | 1371 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 61:bc8c8270f0ab | 1372 | |
Lightvalve | 30:8d561f16383b | 1373 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1374 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1375 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1376 | |
Lightvalve | 14:8e7590227d22 | 1377 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 14:8e7590227d22 | 1378 | DZ_DIRECTION = 1; |
Lightvalve | 14:8e7590227d22 | 1379 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 14:8e7590227d22 | 1380 | DZ_DIRECTION = -1; |
Lightvalve | 14:8e7590227d22 | 1381 | } else { |
Lightvalve | 13:747daba9cf59 | 1382 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1383 | } |
Lightvalve | 13:747daba9cf59 | 1384 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1385 | DZ_index= DZ_index *2; |
Lightvalve | 14:8e7590227d22 | 1386 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1387 | FIRST_DZ = valve_pos.ref; |
Lightvalve | 13:747daba9cf59 | 1388 | DZ_NUM = 2; |
Lightvalve | 13:747daba9cf59 | 1389 | Ref_Valve_Pos_Old = FIRST_DZ; |
Lightvalve | 13:747daba9cf59 | 1390 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1391 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1392 | } |
Lightvalve | 13:747daba9cf59 | 1393 | } |
Lightvalve | 14:8e7590227d22 | 1394 | } else { |
Lightvalve | 30:8d561f16383b | 1395 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1396 | 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 | 1397 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 60:64181f1d3e60 | 1398 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1399 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1400 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1401 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1402 | valve_pos.ref = Ref_Valve_Pos_Old + DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1403 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1404 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1405 | } else if(valve_pos.ref > VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1406 | valve_pos.ref = VALVE_MAX_POS - 1; |
Lightvalve | 13:747daba9cf59 | 1407 | } |
Lightvalve | 14:8e7590227d22 | 1408 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 60:64181f1d3e60 | 1409 | |
Lightvalve | 30:8d561f16383b | 1410 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1411 | Vout.ref = 0.0f; |
Lightvalve | 59:f308b1656d9c | 1412 | } else if(VALVE_DZ_timer > (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1413 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1414 | FINAL_POS = pos.sen; |
Lightvalve | 61:bc8c8270f0ab | 1415 | |
Lightvalve | 60:64181f1d3e60 | 1416 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 13:747daba9cf59 | 1417 | DZ_DIRECTION = 1; |
Lightvalve | 60:64181f1d3e60 | 1418 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 60:64181f1d3e60 | 1419 | DZ_DIRECTION = -1; |
Lightvalve | 60:64181f1d3e60 | 1420 | } else { |
Lightvalve | 13:747daba9cf59 | 1421 | DZ_DIRECTION = 1; |
Lightvalve | 60:64181f1d3e60 | 1422 | } |
Lightvalve | 14:8e7590227d22 | 1423 | |
Lightvalve | 13:747daba9cf59 | 1424 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1425 | DZ_index= DZ_index *2; |
Lightvalve | 14:8e7590227d22 | 1426 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1427 | SECOND_DZ = valve_pos.ref; |
Lightvalve | 57:f4819de54e7a | 1428 | VALVE_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ)); |
Lightvalve | 13:747daba9cf59 | 1429 | first_check = 0; |
Lightvalve | 33:91b17819ec30 | 1430 | VALVE_DEADZONE_MINUS = (float) FIRST_DZ; |
Lightvalve | 33:91b17819ec30 | 1431 | VALVE_DEADZONE_PLUS = (float) SECOND_DZ; |
Lightvalve | 61:bc8c8270f0ab | 1432 | |
Lightvalve | 59:f308b1656d9c | 1433 | ROM_RESET_DATA(); |
Lightvalve | 34:bb2ca2fc2a8e | 1434 | |
Lightvalve | 57:f4819de54e7a | 1435 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 13:747daba9cf59 | 1436 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1437 | } |
Lightvalve | 13:747daba9cf59 | 1438 | } |
Lightvalve | 13:747daba9cf59 | 1439 | } |
Lightvalve | 14:8e7590227d22 | 1440 | } |
Lightvalve | 13:747daba9cf59 | 1441 | break; |
Lightvalve | 13:747daba9cf59 | 1442 | } |
Lightvalve | 14:8e7590227d22 | 1443 | |
Lightvalve | 14:8e7590227d22 | 1444 | case MODE_DDV_POS_VS_FLOWRATE: { |
Lightvalve | 59:f308b1656d9c | 1445 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 13:747daba9cf59 | 1446 | VALVE_FR_timer = VALVE_FR_timer + 1; |
Lightvalve | 14:8e7590227d22 | 1447 | if(first_check == 0) { |
Lightvalve | 30:8d561f16383b | 1448 | if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1449 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 23:59218d4a256d | 1450 | //CAN_TX_PRES((int16_t) (VALVE_FR_timer), (int16_t) (6)); |
Lightvalve | 30:8d561f16383b | 1451 | } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1452 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1453 | pos_plus_end = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1454 | // CAN_TX_PRES((int16_t) (V_out), (int16_t) (7)); |
Lightvalve | 30:8d561f16383b | 1455 | } else if(VALVE_FR_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1456 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 30:8d561f16383b | 1457 | } else if(VALVE_FR_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1458 | // CAN_TX_PRES((int16_t) (V_out), (int16_t) (8)); |
Lightvalve | 59:f308b1656d9c | 1459 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1460 | pos_minus_end = pos.sen; |
Lightvalve | 13:747daba9cf59 | 1461 | first_check = 1; |
Lightvalve | 13:747daba9cf59 | 1462 | VALVE_FR_timer = 0; |
Lightvalve | 57:f4819de54e7a | 1463 | valve_pos.ref = (float) VALVE_CENTER; |
Lightvalve | 13:747daba9cf59 | 1464 | ID_index = 0; |
Lightvalve | 13:747daba9cf59 | 1465 | max_check = 0; |
Lightvalve | 13:747daba9cf59 | 1466 | min_check = 0; |
Lightvalve | 13:747daba9cf59 | 1467 | } |
Lightvalve | 14:8e7590227d22 | 1468 | } else { |
Lightvalve | 30:8d561f16383b | 1469 | if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1470 | //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 | 1471 | pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 59:f308b1656d9c | 1472 | CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1473 | } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 13:747daba9cf59 | 1474 | data_num = 0; |
Lightvalve | 57:f4819de54e7a | 1475 | valve_pos.ref = 10.0f*((float) ID_index_array[ID_index]) + (float) VALVE_CENTER; |
Lightvalve | 14:8e7590227d22 | 1476 | |
Lightvalve | 14:8e7590227d22 | 1477 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 14:8e7590227d22 | 1478 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1479 | } else if(VALVE_FR_timer < (int) (5.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f4819de54e7a | 1480 | valve_pos.ref = 10.0f*((float) ID_index_array[ID_index]) + (float) VALVE_CENTER; |
Lightvalve | 14:8e7590227d22 | 1481 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 13:747daba9cf59 | 1482 | data_num = data_num + 1; |
Lightvalve | 30:8d561f16383b | 1483 | if(abs(0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen) > 20000.0f) { |
Lightvalve | 14:8e7590227d22 | 1484 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1485 | one_period_end = 1; |
Lightvalve | 13:747daba9cf59 | 1486 | } |
Lightvalve | 30:8d561f16383b | 1487 | } else if(VALVE_FR_timer == (int) (5.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1488 | FINAL_POS = pos.sen; |
Lightvalve | 13:747daba9cf59 | 1489 | one_period_end = 1; |
Lightvalve | 59:f308b1656d9c | 1490 | V_out = 0.0f; |
Lightvalve | 13:747daba9cf59 | 1491 | } |
Lightvalve | 14:8e7590227d22 | 1492 | |
Lightvalve | 14:8e7590227d22 | 1493 | if(one_period_end == 1) { |
Lightvalve | 14:8e7590227d22 | 1494 | if(valve_pos.ref > VALVE_MAX_POS) { |
Lightvalve | 13:747daba9cf59 | 1495 | max_check = 1; |
Lightvalve | 14:8e7590227d22 | 1496 | } else if(valve_pos.ref < VALVE_MIN_POS) { |
Lightvalve | 13:747daba9cf59 | 1497 | min_check = 1; |
Lightvalve | 13:747daba9cf59 | 1498 | } |
Lightvalve | 13:747daba9cf59 | 1499 | JOINT_VEL[ID_index] = (FINAL_POS - START_POS) / data_num * TMR_FREQ_5k; // pulse/sec |
Lightvalve | 19:23b7c1ad8683 | 1500 | |
Lightvalve | 13:747daba9cf59 | 1501 | VALVE_FR_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1502 | one_period_end = 0; |
Lightvalve | 13:747daba9cf59 | 1503 | ID_index= ID_index +1; |
Lightvalve | 30:8d561f16383b | 1504 | V_out = 0.0f; |
Lightvalve | 13:747daba9cf59 | 1505 | } |
Lightvalve | 14:8e7590227d22 | 1506 | |
Lightvalve | 14:8e7590227d22 | 1507 | if(max_check == 1 && min_check == 1) { |
Lightvalve | 19:23b7c1ad8683 | 1508 | |
Lightvalve | 13:747daba9cf59 | 1509 | VALVE_POS_NUM = ID_index; |
Lightvalve | 59:f308b1656d9c | 1510 | ROM_RESET_DATA(); |
Lightvalve | 13:747daba9cf59 | 1511 | ID_index = 0; |
Lightvalve | 13:747daba9cf59 | 1512 | first_check = 0; |
Lightvalve | 13:747daba9cf59 | 1513 | VALVE_FR_timer = 0; |
Lightvalve | 57:f4819de54e7a | 1514 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 49:e7bcfc244d40 | 1515 | // CAN_TX_PRES((int16_t) (VALVE_FR_timer), (int16_t) (6)); |
Lightvalve | 13:747daba9cf59 | 1516 | } |
Lightvalve | 13:747daba9cf59 | 1517 | } |
Lightvalve | 13:747daba9cf59 | 1518 | break; |
Lightvalve | 13:747daba9cf59 | 1519 | } |
Lightvalve | 58:2eade98630e2 | 1520 | |
Lightvalve | 57:f4819de54e7a | 1521 | case MODE_SYSTEM_ID: { |
Lightvalve | 57:f4819de54e7a | 1522 | freq_sysid_Iref = (double) cnt_sysid * DT_TMR3 * 3.; |
Lightvalve | 57:f4819de54e7a | 1523 | valve_pos.ref = 2500.0f * sin(2.0f * 3.14159f * freq_sysid_Iref * (double) cnt_sysid * DT_TMR3); |
Lightvalve | 57:f4819de54e7a | 1524 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 57:f4819de54e7a | 1525 | cnt_sysid++; |
Lightvalve | 57:f4819de54e7a | 1526 | if (freq_sysid_Iref >= 300) { |
Lightvalve | 57:f4819de54e7a | 1527 | cnt_sysid = 0; |
Lightvalve | 57:f4819de54e7a | 1528 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 57:f4819de54e7a | 1529 | } |
Lightvalve | 57:f4819de54e7a | 1530 | break; |
Lightvalve | 57:f4819de54e7a | 1531 | } |
Lightvalve | 58:2eade98630e2 | 1532 | |
Lightvalve | 58:2eade98630e2 | 1533 | |
Lightvalve | 57:f4819de54e7a | 1534 | |
Lightvalve | 57:f4819de54e7a | 1535 | default: |
Lightvalve | 57:f4819de54e7a | 1536 | break; |
Lightvalve | 57:f4819de54e7a | 1537 | } |
Lightvalve | 57:f4819de54e7a | 1538 | |
Lightvalve | 57:f4819de54e7a | 1539 | // CONTROL MODE ------------------------------------------------------------ |
Lightvalve | 57:f4819de54e7a | 1540 | |
Lightvalve | 57:f4819de54e7a | 1541 | switch (CONTROL_MODE) { |
Lightvalve | 57:f4819de54e7a | 1542 | case MODE_NO_ACT: { |
Lightvalve | 57:f4819de54e7a | 1543 | V_out = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1544 | break; |
Lightvalve | 57:f4819de54e7a | 1545 | } |
Lightvalve | 57:f4819de54e7a | 1546 | |
Lightvalve | 57:f4819de54e7a | 1547 | case MODE_VALVE_POSITION_CONTROL: { |
Lightvalve | 67:c2812cf26c38 | 1548 | if (OPERATING_MODE == 5) { //SW Valve |
Lightvalve | 57:f4819de54e7a | 1549 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 59:f308b1656d9c | 1550 | V_out = Vout.ref; |
Lightvalve | 67:c2812cf26c38 | 1551 | } else if (CURRENT_CONTROL_MODE == 0) { //PWM |
Lightvalve | 67:c2812cf26c38 | 1552 | V_out = valve_pos.ref; |
Lightvalve | 67:c2812cf26c38 | 1553 | } else { |
Lightvalve | 67:c2812cf26c38 | 1554 | I_REF = valve_pos.ref * 0.001f; |
Lightvalve | 57:f4819de54e7a | 1555 | } |
Lightvalve | 58:2eade98630e2 | 1556 | |
Lightvalve | 57:f4819de54e7a | 1557 | break; |
Lightvalve | 57:f4819de54e7a | 1558 | } |
Lightvalve | 57:f4819de54e7a | 1559 | |
Lightvalve | 57:f4819de54e7a | 1560 | case MODE_JOINT_CONTROL: { |
Lightvalve | 57:f4819de54e7a | 1561 | double torq_ref = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1562 | pos.err = (pos.ref - pos.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm] |
Lightvalve | 67:c2812cf26c38 | 1563 | vel.err = (0.0f - vel.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm/s] |
Lightvalve | 57:f4819de54e7a | 1564 | pos.err_sum += pos.err/(float) TMR_FREQ_5k; //[mm] |
Lightvalve | 67:c2812cf26c38 | 1565 | |
Lightvalve | 67:c2812cf26c38 | 1566 | //K & D Low Pass Filter |
Lightvalve | 67:c2812cf26c38 | 1567 | float alpha_K_D = 1.0f/(1.0f + 5000.0f/(2.0f*3.14f*30.0f)); // f_cutoff : 30Hz |
Lightvalve | 67:c2812cf26c38 | 1568 | K_LPF = K_LPF*(1.0f-alpha_K_D)+K_SPRING*(alpha_K_D); |
Lightvalve | 67:c2812cf26c38 | 1569 | D_LPF = D_LPF*(1.0f-alpha_K_D)+D_DAMPER*(alpha_K_D); |
Lightvalve | 67:c2812cf26c38 | 1570 | |
Lightvalve | 67:c2812cf26c38 | 1571 | torq_ref = torq.ref + K_LPF * pos.err - D_LPF * vel.sen / ENC_PULSE_PER_POSITION; //[N] |
Lightvalve | 57:f4819de54e7a | 1572 | |
Lightvalve | 57:f4819de54e7a | 1573 | // torque feedback |
Lightvalve | 67:c2812cf26c38 | 1574 | torq.err = torq_ref - torq.sen; //[N] |
Lightvalve | 57:f4819de54e7a | 1575 | torq.err_sum += torq.err/(float) TMR_FREQ_5k; //[N] |
Lightvalve | 57:f4819de54e7a | 1576 | |
Lightvalve | 57:f4819de54e7a | 1577 | if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) { |
Lightvalve | 58:2eade98630e2 | 1578 | |
Lightvalve | 57:f4819de54e7a | 1579 | double I_REF_POS = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1580 | double I_REF_FORCE_FB = 0.0f; // I_REF by Force Feedback |
Lightvalve | 57:f4819de54e7a | 1581 | double I_REF_VC = 0.0f; // I_REF for velocity compensation |
Lightvalve | 57:f4819de54e7a | 1582 | |
Lightvalve | 57:f4819de54e7a | 1583 | double temp_vel_pos = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1584 | double temp_vel_torq = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1585 | double wn_Pos = 2.0f * PI * 5.0f; // f_cut : 5Hz Position Control |
Lightvalve | 58:2eade98630e2 | 1586 | |
Lightvalve | 69:3995ffeaa786 | 1587 | if ((OPERATING_MODE & 0x01) == 0) { // Rotary Mode |
Lightvalve | 57:f4819de54e7a | 1588 | 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 | 1589 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 69:3995ffeaa786 | 1590 | } else if ((OPERATING_MODE & 0x01) == 1) { |
Lightvalve | 57:f4819de54e7a | 1591 | 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 | 1592 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 57:f4819de54e7a | 1593 | } |
Lightvalve | 57:f4819de54e7a | 1594 | 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 | 1595 | else I_REF_POS = temp_vel_pos * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f)))); |
Lightvalve | 57:f4819de54e7a | 1596 | |
Lightvalve | 57:f4819de54e7a | 1597 | // velocity compensation for torque control |
Lightvalve | 69:3995ffeaa786 | 1598 | if ((OPERATING_MODE & 0x01) == 0) { // Rotary Mode |
Lightvalve | 57:f4819de54e7a | 1599 | I_REF_FORCE_FB = 0.001f * ((double) P_GAIN_JOINT_TORQUE * torq.err + (double) I_GAIN_JOINT_TORQUE * torq.err_sum); |
Lightvalve | 57:f4819de54e7a | 1600 | // 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 | 1601 | temp_vel_torq = (0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / (double) ENC_PULSE_PER_POSITION) * PI / 180.0f; // rad/s |
Lightvalve | 57:f4819de54e7a | 1602 | // L feedforward velocity |
Lightvalve | 69:3995ffeaa786 | 1603 | } else if ((OPERATING_MODE & 0x01) == 1) { |
Lightvalve | 57:f4819de54e7a | 1604 | 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 | 1605 | // temp_vel_torq = (0.01 * (double) VELOCITY_COMP_GAIN * (double) CUR_VELOCITY / (double) ENC_PULSE_PER_POSITION); // mm/s |
Lightvalve | 57:f4819de54e7a | 1606 | temp_vel_torq = (0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / (double) ENC_PULSE_PER_POSITION); // mm/s |
Lightvalve | 57:f4819de54e7a | 1607 | // L feedforward velocity |
Lightvalve | 57:f4819de54e7a | 1608 | } |
Lightvalve | 57:f4819de54e7a | 1609 | 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 | 1610 | else I_REF_VC = temp_vel_torq * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f)))); |
Lightvalve | 57:f4819de54e7a | 1611 | // L velocity(rad/s or mm/s) >> I_ref(mA) |
Lightvalve | 57:f4819de54e7a | 1612 | // Ref_Joint_FT_dot = (Ref_Joint_FT_Nm - Ref_Joint_FT_Nm_old) / TMR_DT_5k; |
Lightvalve | 57:f4819de54e7a | 1613 | // Ref_Joint_FT_Nm_old = Ref_Joint_FT_Nm; |
Lightvalve | 57:f4819de54e7a | 1614 | |
Lightvalve | 57:f4819de54e7a | 1615 | I_REF = (1.0f - alpha_trans) * I_REF_POS + alpha_trans * (I_REF_VC + I_REF_FORCE_FB); |
Lightvalve | 67:c2812cf26c38 | 1616 | |
Lightvalve | 67:c2812cf26c38 | 1617 | // Anti-windup for FT |
Lightvalve | 67:c2812cf26c38 | 1618 | if (I_GAIN_JOINT_TORQUE != 0) { |
Lightvalve | 67:c2812cf26c38 | 1619 | double I_MAX = 10.0f; // Maximum Current : 10mV |
Lightvalve | 67:c2812cf26c38 | 1620 | double Ka = 2.0f / ((double) I_GAIN_JOINT_TORQUE * 0.001f); |
Lightvalve | 67:c2812cf26c38 | 1621 | if (I_REF > I_MAX) { |
Lightvalve | 67:c2812cf26c38 | 1622 | double I_rem = I_REF - I_MAX; |
Lightvalve | 67:c2812cf26c38 | 1623 | I_rem = Ka*I_rem; |
Lightvalve | 67:c2812cf26c38 | 1624 | I_REF = I_MAX; |
Lightvalve | 67:c2812cf26c38 | 1625 | torq.err_sum = torq.err_sum - I_rem /(float) TMR_FREQ_5k; |
Lightvalve | 67:c2812cf26c38 | 1626 | } else if (I_REF < -I_MAX) { |
Lightvalve | 67:c2812cf26c38 | 1627 | double I_rem = I_REF - (-I_MAX); |
Lightvalve | 67:c2812cf26c38 | 1628 | I_rem = Ka*I_rem; |
Lightvalve | 67:c2812cf26c38 | 1629 | I_REF = -I_MAX; |
Lightvalve | 67:c2812cf26c38 | 1630 | torq.err_sum = torq.err_sum - I_rem /(float) TMR_FREQ_5k; |
Lightvalve | 67:c2812cf26c38 | 1631 | } |
Lightvalve | 67:c2812cf26c38 | 1632 | } |
Lightvalve | 57:f4819de54e7a | 1633 | |
Lightvalve | 57:f4819de54e7a | 1634 | } else { |
Lightvalve | 57:f4819de54e7a | 1635 | float VALVE_POS_RAW_FORCE_FB = 0.0f; |
Lightvalve | 72:3436ce769b1e | 1636 | float VALVE_POS_RAW_FORCE_FF = 0.0f; |
Lightvalve | 72:3436ce769b1e | 1637 | float VALVE_POS_RAW = 0.0f; |
Lightvalve | 72:3436ce769b1e | 1638 | |
Lightvalve | 57:f4819de54e7a | 1639 | 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 | 1640 | + 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 | 1641 | |
Lightvalve | 72:3436ce769b1e | 1642 | VALVE_POS_RAW_FORCE_FF = P_GAIN_JOINT_TORQUE_FF * torq_ref * 0.001f + D_GAIN_JOINT_TORQUE_FF * (torq_ref - torq_ref_past) * 0.0001f; |
Lightvalve | 72:3436ce769b1e | 1643 | |
Lightvalve | 72:3436ce769b1e | 1644 | VALVE_POS_RAW = VALVE_POS_RAW_FORCE_FB + VALVE_POS_RAW_FORCE_FF; |
Lightvalve | 72:3436ce769b1e | 1645 | |
Lightvalve | 72:3436ce769b1e | 1646 | |
Lightvalve | 72:3436ce769b1e | 1647 | if (VALVE_POS_RAW >= 0) { |
Lightvalve | 72:3436ce769b1e | 1648 | valve_pos.ref = VALVE_POS_RAW + VALVE_DEADZONE_PLUS; |
Lightvalve | 57:f4819de54e7a | 1649 | } else { |
Lightvalve | 72:3436ce769b1e | 1650 | valve_pos.ref = VALVE_POS_RAW + VALVE_DEADZONE_MINUS; |
Lightvalve | 57:f4819de54e7a | 1651 | } |
Lightvalve | 57:f4819de54e7a | 1652 | |
Lightvalve | 57:f4819de54e7a | 1653 | if(I_GAIN_JOINT_TORQUE != 0) { |
Lightvalve | 57:f4819de54e7a | 1654 | double Ka = 1.0f / (double) I_GAIN_JOINT_TORQUE * 100.0f; |
Lightvalve | 57:f4819de54e7a | 1655 | if(valve_pos.ref>VALVE_MAX_POS) { |
Lightvalve | 57:f4819de54e7a | 1656 | double valve_pos_rem = valve_pos.ref - VALVE_MAX_POS; |
Lightvalve | 57:f4819de54e7a | 1657 | valve_pos_rem = valve_pos_rem * Ka; |
Lightvalve | 57:f4819de54e7a | 1658 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 57:f4819de54e7a | 1659 | torq.err_sum = torq.err_sum - valve_pos_rem/(float) TMR_FREQ_5k; |
Lightvalve | 57:f4819de54e7a | 1660 | } else if(valve_pos.ref < VALVE_MIN_POS) { |
Lightvalve | 57:f4819de54e7a | 1661 | double valve_pos_rem = valve_pos.ref - VALVE_MIN_POS; |
Lightvalve | 57:f4819de54e7a | 1662 | valve_pos_rem = valve_pos_rem * Ka; |
Lightvalve | 57:f4819de54e7a | 1663 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 57:f4819de54e7a | 1664 | torq.err_sum = torq.err_sum - valve_pos_rem/(float) TMR_FREQ_5k; |
Lightvalve | 57:f4819de54e7a | 1665 | } |
Lightvalve | 57:f4819de54e7a | 1666 | } |
Lightvalve | 61:bc8c8270f0ab | 1667 | |
Lightvalve | 57:f4819de54e7a | 1668 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 61:bc8c8270f0ab | 1669 | |
Lightvalve | 67:c2812cf26c38 | 1670 | // Vout.ref = (float) P_GAIN_JOINT_POSITION * 0.01f * ((float) pos.err); |
Lightvalve | 60:64181f1d3e60 | 1671 | V_out = (float) Vout.ref; |
Lightvalve | 57:f4819de54e7a | 1672 | |
Lightvalve | 57:f4819de54e7a | 1673 | } |
Lightvalve | 72:3436ce769b1e | 1674 | |
Lightvalve | 72:3436ce769b1e | 1675 | torq_ref_past = torq_ref; |
Lightvalve | 58:2eade98630e2 | 1676 | |
Lightvalve | 57:f4819de54e7a | 1677 | break; |
Lightvalve | 57:f4819de54e7a | 1678 | } |
Lightvalve | 58:2eade98630e2 | 1679 | |
Lightvalve | 57:f4819de54e7a | 1680 | case MODE_VALVE_OPEN_LOOP: { |
Lightvalve | 57:f4819de54e7a | 1681 | V_out = (float) Vout.ref; |
Lightvalve | 57:f4819de54e7a | 1682 | break; |
Lightvalve | 57:f4819de54e7a | 1683 | } |
Lightvalve | 14:8e7590227d22 | 1684 | |
Lightvalve | 12:6f2531038ea4 | 1685 | default: |
Lightvalve | 12:6f2531038ea4 | 1686 | break; |
Lightvalve | 12:6f2531038ea4 | 1687 | } |
Lightvalve | 14:8e7590227d22 | 1688 | |
Lightvalve | 57:f4819de54e7a | 1689 | |
Lightvalve | 57:f4819de54e7a | 1690 | if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) { //Moog Valve or KNR Valve |
Lightvalve | 58:2eade98630e2 | 1691 | |
Lightvalve | 57:f4819de54e7a | 1692 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1693 | //////////////////////////// CURRENT CONTROL ////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1694 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1695 | if (CURRENT_CONTROL_MODE) { |
Lightvalve | 67:c2812cf26c38 | 1696 | double alpha_update_Iref = 1.0f / (1.0f + 5000.0f / (2.0f * 3.14f * 300.0f)); // f_cutoff : 500Hz |
Lightvalve | 57:f4819de54e7a | 1697 | I_REF_fil = (1.0f - alpha_update_Iref) * I_REF_fil + alpha_update_Iref*I_REF; |
Lightvalve | 57:f4819de54e7a | 1698 | |
Lightvalve | 57:f4819de54e7a | 1699 | I_ERR = I_REF_fil - cur.sen; |
Lightvalve | 67:c2812cf26c38 | 1700 | I_ERR_INT = I_ERR_INT + (I_ERR) * 0.0002f; |
Lightvalve | 57:f4819de54e7a | 1701 | |
Lightvalve | 57:f4819de54e7a | 1702 | |
Lightvalve | 57:f4819de54e7a | 1703 | // Moog Valve Current Control Gain |
Lightvalve | 67:c2812cf26c38 | 1704 | double R_model = 500.0f; // ohm |
Lightvalve | 57:f4819de54e7a | 1705 | double L_model = 1.2f; |
Lightvalve | 57:f4819de54e7a | 1706 | double w0 = 2.0f * 3.14f * 150.0f; |
Lightvalve | 57:f4819de54e7a | 1707 | double KP_I = 0.1f * L_model*w0; |
Lightvalve | 57:f4819de54e7a | 1708 | double KI_I = 0.1f * R_model*w0; |
Lightvalve | 57:f4819de54e7a | 1709 | |
Lightvalve | 57:f4819de54e7a | 1710 | // KNR Valve Current Control Gain |
Lightvalve | 57:f4819de54e7a | 1711 | if (((OPERATING_MODE & 0b110)>>1) == 1) { // KNR Valve |
Lightvalve | 57:f4819de54e7a | 1712 | R_model = 163.0f; // ohm |
Lightvalve | 57:f4819de54e7a | 1713 | L_model = 1.0f; |
Lightvalve | 57:f4819de54e7a | 1714 | w0 = 2.0f * 3.14f * 80.0f; |
Lightvalve | 57:f4819de54e7a | 1715 | KP_I = 1.0f * L_model*w0; |
Lightvalve | 57:f4819de54e7a | 1716 | KI_I = 0.08f * R_model*w0; |
Lightvalve | 57:f4819de54e7a | 1717 | } |
Lightvalve | 57:f4819de54e7a | 1718 | |
Lightvalve | 57:f4819de54e7a | 1719 | double FF_gain = 1.0f; |
Lightvalve | 57:f4819de54e7a | 1720 | |
Lightvalve | 67:c2812cf26c38 | 1721 | VALVE_PWM_RAW = KP_I * 2.0f * I_ERR + KI_I * 2.0f* I_ERR_INT; |
Lightvalve | 57:f4819de54e7a | 1722 | // VALVE_PWM_RAW = VALVE_PWM_RAW + FF_gain * (R_model*I_REF); // Unit : mV |
Lightvalve | 57:f4819de54e7a | 1723 | I_REF_fil_diff = I_REF_fil - I_REF_fil_old; |
Lightvalve | 57:f4819de54e7a | 1724 | I_REF_fil_old = I_REF_fil; |
Lightvalve | 67:c2812cf26c38 | 1725 | // 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 | 1726 | VALVE_PWM_RAW = VALVE_PWM_RAW + FF_gain * (R_model * I_REF_fil); // Unit : mV |
Lightvalve | 67:c2812cf26c38 | 1727 | double V_MAX = 12000.0f; // Maximum Voltage : 12V = 12000mV |
Lightvalve | 57:f4819de54e7a | 1728 | |
Lightvalve | 57:f4819de54e7a | 1729 | double Ka = 3.0f / KP_I; |
Lightvalve | 57:f4819de54e7a | 1730 | if (VALVE_PWM_RAW > V_MAX) { |
Lightvalve | 57:f4819de54e7a | 1731 | V_rem = VALVE_PWM_RAW - V_MAX; |
Lightvalve | 57:f4819de54e7a | 1732 | V_rem = Ka*V_rem; |
Lightvalve | 57:f4819de54e7a | 1733 | VALVE_PWM_RAW = V_MAX; |
Lightvalve | 67:c2812cf26c38 | 1734 | I_ERR_INT = I_ERR_INT - V_rem * 0.0002f; |
Lightvalve | 57:f4819de54e7a | 1735 | } else if (VALVE_PWM_RAW < -V_MAX) { |
Lightvalve | 57:f4819de54e7a | 1736 | V_rem = VALVE_PWM_RAW - (-V_MAX); |
Lightvalve | 57:f4819de54e7a | 1737 | V_rem = Ka*V_rem; |
Lightvalve | 57:f4819de54e7a | 1738 | VALVE_PWM_RAW = -V_MAX; |
Lightvalve | 67:c2812cf26c38 | 1739 | I_ERR_INT = I_ERR_INT - V_rem * 0.0002f; |
Lightvalve | 57:f4819de54e7a | 1740 | } |
Lightvalve | 57:f4819de54e7a | 1741 | Cur_Valve_Open_pulse = cur.sen / mA_PER_pulse; |
Lightvalve | 57:f4819de54e7a | 1742 | } else { |
Lightvalve | 57:f4819de54e7a | 1743 | VALVE_PWM_RAW = I_REF * mV_PER_mA; |
Lightvalve | 57:f4819de54e7a | 1744 | Cur_Valve_Open_pulse = I_REF / mA_PER_pulse; |
Lightvalve | 57:f4819de54e7a | 1745 | } |
Lightvalve | 57:f4819de54e7a | 1746 | |
Lightvalve | 57:f4819de54e7a | 1747 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1748 | ///////////////// Dead Zone Cancellation & Linearization ////////////////// |
Lightvalve | 57:f4819de54e7a | 1749 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1750 | // Dead Zone Cancellation (Mechanical Valve dead-zone) |
Lightvalve | 57:f4819de54e7a | 1751 | if (FLAG_VALVE_DEADZONE) { |
Lightvalve | 57:f4819de54e7a | 1752 | if (VALVE_PWM_RAW > 0) VALVE_PWM_RAW = VALVE_PWM_RAW + VALVE_DEADZONE_PLUS * mV_PER_pulse; // unit: mV |
Lightvalve | 57:f4819de54e7a | 1753 | else if (VALVE_PWM_RAW < 0) VALVE_PWM_RAW = VALVE_PWM_RAW + VALVE_DEADZONE_MINUS * mV_PER_pulse; // unit: mV |
Lightvalve | 57:f4819de54e7a | 1754 | |
Lightvalve | 57:f4819de54e7a | 1755 | VALVE_PWM_VALVE_DZ = VALVE_PWM_RAW + (double)VALVE_CENTER * mV_PER_pulse; // unit: mV |
Lightvalve | 57:f4819de54e7a | 1756 | |
Lightvalve | 57:f4819de54e7a | 1757 | } else { |
Lightvalve | 57:f4819de54e7a | 1758 | VALVE_PWM_VALVE_DZ = VALVE_PWM_RAW; |
Lightvalve | 57:f4819de54e7a | 1759 | } |
Lightvalve | 57:f4819de54e7a | 1760 | |
Lightvalve | 57:f4819de54e7a | 1761 | // Output Voltage Linearization |
Lightvalve | 57:f4819de54e7a | 1762 | double CUR_PWM_nonlin = VALVE_PWM_VALVE_DZ; // Unit : mV |
Lightvalve | 67:c2812cf26c38 | 1763 | double CUR_PWM_lin = PWM_duty_byLT(CUR_PWM_nonlin); // -8000~8000 |
Lightvalve | 57:f4819de54e7a | 1764 | |
Lightvalve | 57:f4819de54e7a | 1765 | // Dead Zone Cancellation (Electrical dead-zone) |
Lightvalve | 67:c2812cf26c38 | 1766 | if (CUR_PWM_lin > 0) V_out = (float) (CUR_PWM_lin + 169.0f); |
Lightvalve | 67:c2812cf26c38 | 1767 | else if (CUR_PWM_lin < 0) V_out = (float) (CUR_PWM_lin - 174.0f); |
Lightvalve | 67:c2812cf26c38 | 1768 | else V_out = (float) (CUR_PWM_lin); |
Lightvalve | 57:f4819de54e7a | 1769 | } |
Lightvalve | 89:a7b45368ea0f | 1770 | else { //////////////////////////sw valve |
Lightvalve | 89:a7b45368ea0f | 1771 | // Output Voltage Linearization |
Lightvalve | 89:a7b45368ea0f | 1772 | double CUR_PWM_nonlin = V_out; // Unit : mV |
Lightvalve | 89:a7b45368ea0f | 1773 | double CUR_PWM_lin = PWM_duty_byLT(CUR_PWM_nonlin); // -8000~8000 |
Lightvalve | 89:a7b45368ea0f | 1774 | |
Lightvalve | 89:a7b45368ea0f | 1775 | // Dead Zone Cancellation (Electrical dead-zone) |
Lightvalve | 89:a7b45368ea0f | 1776 | if (CUR_PWM_lin > 0) V_out = (float) (CUR_PWM_lin + 169.0f); |
Lightvalve | 89:a7b45368ea0f | 1777 | else if (CUR_PWM_lin < 0) V_out = (float) (CUR_PWM_lin - 174.0f); |
Lightvalve | 89:a7b45368ea0f | 1778 | else V_out = (float) (CUR_PWM_lin); |
Lightvalve | 89:a7b45368ea0f | 1779 | } |
Lightvalve | 67:c2812cf26c38 | 1780 | |
Lightvalve | 67:c2812cf26c38 | 1781 | // if(V_out > 0.0f) V_out = (float) (V_out + 169.0f); |
Lightvalve | 67:c2812cf26c38 | 1782 | // else if(V_out < 0.0f) V_out = (float) (V_out - 174.0f); |
Lightvalve | 67:c2812cf26c38 | 1783 | // else V_out = V_out; |
Lightvalve | 67:c2812cf26c38 | 1784 | |
jobuuu | 7:e9086c72bb22 | 1785 | /******************************************************* |
jobuuu | 7:e9086c72bb22 | 1786 | *** PWM |
jobuuu | 7:e9086c72bb22 | 1787 | ********************************************************/ |
Lightvalve | 67:c2812cf26c38 | 1788 | if(DIR_VALVE<0){ |
Lightvalve | 67:c2812cf26c38 | 1789 | V_out = -V_out; |
Lightvalve | 67:c2812cf26c38 | 1790 | } |
Lightvalve | 67:c2812cf26c38 | 1791 | |
Lightvalve | 49:e7bcfc244d40 | 1792 | if (V_out >= VALVE_VOLTAGE_LIMIT*1000.0f) { |
Lightvalve | 49:e7bcfc244d40 | 1793 | V_out = VALVE_VOLTAGE_LIMIT*1000.0f; |
Lightvalve | 49:e7bcfc244d40 | 1794 | } else if(V_out<=-VALVE_VOLTAGE_LIMIT*1000.0f) { |
Lightvalve | 49:e7bcfc244d40 | 1795 | V_out = -VALVE_VOLTAGE_LIMIT*1000.0f; |
Lightvalve | 27:a2254a485f23 | 1796 | } |
Lightvalve | 49:e7bcfc244d40 | 1797 | PWM_out= V_out/(SUPPLY_VOLTAGE*1000.0f); // Full duty : 12000.0mV |
Lightvalve | 13:747daba9cf59 | 1798 | |
Lightvalve | 19:23b7c1ad8683 | 1799 | // Saturation of output voltage to 12.0V |
Lightvalve | 30:8d561f16383b | 1800 | if(PWM_out > 1.0f) PWM_out=1.0f; |
Lightvalve | 30:8d561f16383b | 1801 | else if (PWM_out < -1.0f) PWM_out=-1.0f; |
Lightvalve | 13:747daba9cf59 | 1802 | |
Lightvalve | 30:8d561f16383b | 1803 | if (PWM_out>0.0f) { |
Lightvalve | 30:8d561f16383b | 1804 | dtc_v=0.0f; |
jobuuu | 1:e04e563be5ce | 1805 | dtc_w=PWM_out; |
jobuuu | 1:e04e563be5ce | 1806 | } else { |
jobuuu | 2:a1c0a37df760 | 1807 | dtc_v=-PWM_out; |
Lightvalve | 30:8d561f16383b | 1808 | dtc_w=0.0f; |
jobuuu | 1:e04e563be5ce | 1809 | } |
Lightvalve | 13:747daba9cf59 | 1810 | |
jobuuu | 1:e04e563be5ce | 1811 | //pwm |
Lightvalve | 30:8d561f16383b | 1812 | TIM4->CCR2 = (PWM_ARR)*(1.0f-dtc_v); |
Lightvalve | 30:8d561f16383b | 1813 | TIM4->CCR1 = (PWM_ARR)*(1.0f-dtc_w); |
Lightvalve | 67:c2812cf26c38 | 1814 | |
Lightvalve | 61:bc8c8270f0ab | 1815 | |
Lightvalve | 57:f4819de54e7a | 1816 | if (TMR2_COUNT_CAN_TX % (int) ((int) TMR_FREQ_5k/CAN_FREQ) == 0) { |
Lightvalve | 20:806196fda269 | 1817 | |
Lightvalve | 54:647072f5307a | 1818 | // Position, Velocity, and Torque (ID:1200) |
Lightvalve | 56:6f50d9d3bfee | 1819 | if (flag_data_request[0] == HIGH) { |
Lightvalve | 57:f4819de54e7a | 1820 | if ((OPERATING_MODE & 0b01) == 0) { // Rotary Actuator |
Lightvalve | 54:647072f5307a | 1821 | if (SENSING_MODE == 0) { |
Lightvalve | 67:c2812cf26c38 | 1822 | CAN_TX_POSITION_FT((int16_t) (pos.sen), (int16_t) (vel.sen/10.0f), (int16_t) (torq.sen*10.0f)); |
Lightvalve | 54:647072f5307a | 1823 | } else if (SENSING_MODE == 1) { |
Lightvalve | 58:2eade98630e2 | 1824 | 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 | 1825 | } |
Lightvalve | 57:f4819de54e7a | 1826 | } else if ((OPERATING_MODE & 0b01) == 1) { // Linear Actuator |
Lightvalve | 54:647072f5307a | 1827 | if (SENSING_MODE == 0) { |
Lightvalve | 67:c2812cf26c38 | 1828 | 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 | 1829 | } else if (SENSING_MODE == 1) { |
Lightvalve | 67:c2812cf26c38 | 1830 | 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 | 1831 | } |
Lightvalve | 52:8ea76864368a | 1832 | } |
Lightvalve | 52:8ea76864368a | 1833 | } |
Lightvalve | 56:6f50d9d3bfee | 1834 | if (flag_data_request[1] == HIGH) { |
Lightvalve | 54:647072f5307a | 1835 | //valve position |
Lightvalve | 54:647072f5307a | 1836 | double t_value = 0; |
Lightvalve | 89:a7b45368ea0f | 1837 | // if(valve_pos.ref>=(float) VALVE_CENTER) { |
Lightvalve | 89:a7b45368ea0f | 1838 | // t_value = 10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); |
Lightvalve | 89:a7b45368ea0f | 1839 | // } else { |
Lightvalve | 89:a7b45368ea0f | 1840 | // t_value = -10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); |
Lightvalve | 89:a7b45368ea0f | 1841 | // } |
Lightvalve | 89:a7b45368ea0f | 1842 | if(OPERATING_MODE==5) { |
Lightvalve | 89:a7b45368ea0f | 1843 | if(valve_pos.ref>=(float) VALVE_CENTER) { |
Lightvalve | 89:a7b45368ea0f | 1844 | t_value = 10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); |
Lightvalve | 89:a7b45368ea0f | 1845 | } else { |
Lightvalve | 89:a7b45368ea0f | 1846 | t_value = -10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); |
Lightvalve | 89:a7b45368ea0f | 1847 | } |
Lightvalve | 89:a7b45368ea0f | 1848 | //t_value = (double) value; |
Lightvalve | 89:a7b45368ea0f | 1849 | } else if(CURRENT_CONTROL_MODE==1) { |
Lightvalve | 89:a7b45368ea0f | 1850 | t_value = cur.sen * 1000.0f; |
Lightvalve | 67:c2812cf26c38 | 1851 | } else { |
Lightvalve | 89:a7b45368ea0f | 1852 | t_value = V_out; |
Lightvalve | 67:c2812cf26c38 | 1853 | } |
Lightvalve | 67:c2812cf26c38 | 1854 | CAN_TX_TORQUE((int16_t) (t_value)); //1300 |
Lightvalve | 67:c2812cf26c38 | 1855 | //CAN_TX_TORQUE((int16_t) (cur.sen * 1000.0f)); //1300 |
Lightvalve | 67:c2812cf26c38 | 1856 | //CAN_TX_TORQUE((int16_t) (I_REF * 1000.0f)); //1300 |
Lightvalve | 54:647072f5307a | 1857 | } |
Lightvalve | 58:2eade98630e2 | 1858 | |
Lightvalve | 58:2eade98630e2 | 1859 | |
Lightvalve | 89:a7b45368ea0f | 1860 | if (flag_data_request[2] == LOW) { |
Lightvalve | 89:a7b45368ea0f | 1861 | //CAN_TX_PRES((int16_t) (pres_A.sen), (int16_t) (pres_B.sen)); // 1400 |
Lightvalve | 89:a7b45368ea0f | 1862 | double t_value = 0; |
Lightvalve | 89:a7b45368ea0f | 1863 | if(valve_pos.ref>=(float) VALVE_CENTER) { |
Lightvalve | 89:a7b45368ea0f | 1864 | t_value = 10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); |
Lightvalve | 89:a7b45368ea0f | 1865 | } else { |
Lightvalve | 89:a7b45368ea0f | 1866 | t_value = -10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); |
Lightvalve | 89:a7b45368ea0f | 1867 | } |
Lightvalve | 89:a7b45368ea0f | 1868 | CAN_TX_PRES((int16_t) (t_value), (int16_t) (V_out)); // 1400 |
Lightvalve | 55:b25725257569 | 1869 | } |
Lightvalve | 58:2eade98630e2 | 1870 | |
Lightvalve | 57:f4819de54e7a | 1871 | //If it doesn't rest, below can can not work. |
Lightvalve | 57:f4819de54e7a | 1872 | for (can_rest = 0; can_rest < 10000; can_rest++) { |
Lightvalve | 57:f4819de54e7a | 1873 | ; |
Lightvalve | 57:f4819de54e7a | 1874 | } |
Lightvalve | 58:2eade98630e2 | 1875 | |
Lightvalve | 56:6f50d9d3bfee | 1876 | if (flag_data_request[3] == HIGH) { |
Lightvalve | 54:647072f5307a | 1877 | //PWM |
Lightvalve | 73:f80dc3970c99 | 1878 | //CAN_TX_PWM((int16_t) value); //1500 |
Lightvalve | 73:f80dc3970c99 | 1879 | CAN_TX_PWM((int16_t) input_NN[0] * 100.0f); //1500 |
Lightvalve | 54:647072f5307a | 1880 | } |
Lightvalve | 57:f4819de54e7a | 1881 | //for (i = 0; i < 10000; i++) { |
Lightvalve | 57:f4819de54e7a | 1882 | // ; |
Lightvalve | 57:f4819de54e7a | 1883 | // } |
Lightvalve | 56:6f50d9d3bfee | 1884 | if (flag_data_request[4] == HIGH) { |
Lightvalve | 54:647072f5307a | 1885 | //valve position |
Lightvalve | 73:f80dc3970c99 | 1886 | CAN_TX_VALVE_POSITION((int16_t) (input_NN[1] * 100.0f), (int16_t) (input_NN[2]* 100.0f), (int16_t) (input_NN[3]* 100.0f), (int16_t) (input_NN[4]* 100.0f)); //1600 |
Lightvalve | 54:647072f5307a | 1887 | } |
Lightvalve | 20:806196fda269 | 1888 | |
Lightvalve | 54:647072f5307a | 1889 | // Others : Reference position, Reference FT, PWM, Current (ID:1300) |
Lightvalve | 52:8ea76864368a | 1890 | // if (flag_data_request[1] == HIGH) { |
Lightvalve | 52:8ea76864368a | 1891 | // CAN_TX_SOMETHING((int) (FORCE_VREF), (int16_t) (1), (int16_t) (2), (int16_t) (3)); |
Lightvalve | 52:8ea76864368a | 1892 | // } |
Lightvalve | 54:647072f5307a | 1893 | //if (flag_delay_test == 1){ |
Lightvalve | 58:2eade98630e2 | 1894 | //CAN_TX_PRES((int16_t) (0),(int16_t) torq_ref); |
Lightvalve | 54:647072f5307a | 1895 | //} |
Lightvalve | 52:8ea76864368a | 1896 | |
Lightvalve | 54:647072f5307a | 1897 | TMR2_COUNT_CAN_TX = 0; |
Lightvalve | 54:647072f5307a | 1898 | } |
Lightvalve | 54:647072f5307a | 1899 | TMR2_COUNT_CAN_TX++; |
Lightvalve | 52:8ea76864368a | 1900 | |
Lightvalve | 20:806196fda269 | 1901 | } |
Lightvalve | 52:8ea76864368a | 1902 | TIM3->SR = 0x0; // reset the status register |
Lightvalve | 52:8ea76864368a | 1903 | |
Lightvalve | 58:2eade98630e2 | 1904 | } |