Sungwoo Kim
/
HydraulicControlBoard_Rainbow_v1_2_copy1
2011
main.cpp@83:b5bba84861d8, 2020-07-06 (annotated)
- Committer:
- Lightvalve
- Date:
- Mon Jul 06 11:21:16 2020 +0000
- Revision:
- 83:b5bba84861d8
- Parent:
- 82:d286749256a4
- Child:
- 84:c355d3e52bf1
200706-2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lightvalve | 83:b5bba84861d8 | 1 | //200706-2 |
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 | 68:328e1be06f5d | 189 | float f_past[num_array_f_past] = {0.0f}; |
Lightvalve | 68:328e1be06f5d | 190 | float f_future[num_array_f_future] = {0.0f}; |
Lightvalve | 66:a8e6799dbce3 | 191 | |
Lightvalve | 73:f80dc3970c99 | 192 | float input_NN[num_input] = { 0.0f }; |
Lightvalve | 65:a2d7c63419c2 | 193 | |
Lightvalve | 66:a8e6799dbce3 | 194 | const float h1[num_input][32] = { |
Lightvalve | 83:b5bba84861d8 | 195 | {-0.64036625623703f,1.0383014678955078f,0.10589459538459778f,-0.925786554813385f,-2.17268967628479f,-0.2096489667892456f,-0.39503079652786255f,2.1954948902130127f,1.0230536460876465f,-1.0036218166351318f,-0.21952824294567108f,0.3812319040298462f,-0.19318288564682007f,0.22179310023784637f,-0.21103838086128235f,-0.8360627293586731f,0.24172484874725342f,0.24935457110404968f,1.3529114723205566f,0.8927454352378845f,-0.33476194739341736f,0.10696089267730713f,-0.3326931595802307f,-0.0792258083820343f,0.37567755579948425f,0.18374285101890564f,-0.1767144799232483f,-1.276111125946045f,-0.316017746925354f,-0.18794111907482147f,-1.2395459413528442f,0.8389857411384583f}, |
Lightvalve | 83:b5bba84861d8 | 196 | {-0.6434633135795593f,0.4447077512741089f,0.29864487051963806f,-0.7598307132720947f,-1.1791192293167114f,-0.12712815403938293f,0.08595754206180573f,1.5064747333526611f,0.5368416905403137f,-0.20615486800670624f,-0.31037288904190063f,-0.04174898564815521f,0.021212786436080933f,0.1555272340774536f,0.045876264572143555f,-0.6860443949699402f,0.0016684229485690594f,0.06295260787010193f,1.1617164611816406f,0.634861946105957f,-0.03096979856491089f,-0.12077532708644867f,-0.09506890177726746f,0.27714261412620544f,-0.058263760060071945f,0.2936786115169525f,0.12686115503311157f,-0.4291762411594391f,-0.46424031257629395f,0.09809011220932007f,-0.9078341126441956f,0.5122535228729248f}, |
Lightvalve | 83:b5bba84861d8 | 197 | {-0.08331747353076935f,0.4453350305557251f,-0.0042223334312438965f,-0.21941234171390533f,-0.798712432384491f,-0.16204027831554413f,0.04914804548025131f,1.291584849357605f,0.7134265899658203f,-0.2033553123474121f,0.2606082558631897f,0.20773349702358246f,-0.03282937407493591f,0.17797671258449554f,-0.31718650460243225f,-0.6647756695747375f,0.40848249197006226f,-0.2658354640007019f,0.6585453748703003f,0.4785183072090149f,0.22159990668296814f,-0.15311938524246216f,0.13552400469779968f,-0.24659553170204163f,0.029999038204550743f,0.14537742733955383f,-0.15514154732227325f,-0.533480167388916f,-0.41111961007118225f,0.302763432264328f,-1.1675143241882324f,-0.04251602664589882f}, |
Lightvalve | 83:b5bba84861d8 | 198 | {-0.046717751771211624f,0.5695285201072693f,-0.20532599091529846f,-1.2181252241134644f,-1.1444178819656372f,0.051552511751651764f,0.08615109324455261f,-0.5481662750244141f,1.113271951675415f,-0.5327227115631104f,0.09830469638109207f,0.7365548014640808f,-0.11809042096138f,0.3226141035556793f,-0.12817290425300598f,-0.49741601943969727f,-0.02993183396756649f,-0.23756909370422363f,0.1354731023311615f,0.21702346205711365f,-0.24942269921302795f,-0.08793863654136658f,-0.14710915088653564f,-0.29148542881011963f,0.36930331587791443f,0.14159366488456726f,0.13380053639411926f,-1.1923422813415527f,0.2520531713962555f,0.1323157548904419f,-0.528695821762085f,0.07832175493240356f}, |
Lightvalve | 83:b5bba84861d8 | 199 | {0.2939143776893616f,0.39517512917518616f,0.08410122990608215f,-0.7896490693092346f,-0.47038841247558594f,0.06861976534128189f,0.08671513199806213f,-3.0042169094085693f,-0.10469677299261093f,0.04593042656779289f,-0.26959267258644104f,0.2231915295124054f,0.211430162191391f,0.21202363073825836f,-0.25075238943099976f,-0.12917086482048035f,-0.3270207345485687f,-0.18436601758003235f,-0.2025948464870453f,-0.5085486173629761f,0.1375632882118225f,0.23587647080421448f,-0.24541926383972168f,-0.07457953691482544f,-0.06533367186784744f,-0.34256690740585327f,0.04057341814041138f,-1.2647837400436401f,0.46373140811920166f,-0.16320037841796875f,0.9752013087272644f,-0.4512197971343994f}, |
Lightvalve | 83:b5bba84861d8 | 200 | {0.9495735764503479f,-2.8530120849609375f,0.30513831973075867f,2.8614296913146973f,2.32742977142334f,0.16561035811901093f,0.10742717236280441f,-1.8813526630401611f,-2.857640266418457f,2.3896453380584717f,0.2602704167366028f,-2.9228105545043945f,-0.03144201636314392f,0.044423945248126984f,0.21901831030845642f,-0.03282030299305916f,-0.9076781272888184f,-0.3195672333240509f,-3.180483818054199f,-1.9639261960983276f,0.13521116971969604f,-0.009676039218902588f,0.12587067484855652f,0.3309326469898224f,-2.939507007598877f,0.20814630389213562f,-0.2925715744495392f,2.055593252182007f,0.5959512591362f,-0.0013132691383361816f,2.6052420139312744f,-1.159593105316162f}, |
Lightvalve | 83:b5bba84861d8 | 201 | {-0.010118883103132248f,0.17603738605976105f,0.16288265585899353f,0.17041069269180298f,0.3467976748943329f,-0.0789240151643753f,-0.19750314950942993f,-0.2856864929199219f,-0.9953857064247131f,-0.6672870516777039f,-0.11525606364011765f,0.03540292754769325f,0.098605215549469f,-0.03643724322319031f,-0.18274356424808502f,-0.33491650223731995f,-0.16071350872516632f,-0.08166468143463135f,-0.09586126357316971f,-0.09420882165431976f,-0.16223669052124023f,-0.1771286129951477f,-0.2626192569732666f,-0.24521145224571228f,0.20916321873664856f,-0.15535086393356323f,-0.1126367449760437f,0.3733903467655182f,-0.2701224088668823f,-0.03486502170562744f,-1.320512056350708f,-0.06048555672168732f}, |
Lightvalve | 83:b5bba84861d8 | 202 | {0.25715816020965576f,-0.03475144878029823f,0.16644713282585144f,0.407154381275177f,1.6552796363830566f,-0.23206715285778046f,0.051666371524333954f,-3.3632619380950928f,0.8518839478492737f,0.04021477326750755f,-0.2550952136516571f,-0.44656333327293396f,0.10806858539581299f,-0.10458404570817947f,0.054826945066452026f,0.14023979008197784f,-0.26521652936935425f,-0.28619682788848877f,-0.5460033416748047f,0.5786210298538208f,-0.07430306077003479f,0.022674113512039185f,-0.12776102125644684f,-0.02844339609146118f,0.0841803178191185f,0.0177537202835083f,-0.341458797454834f,1.914996862411499f,-0.20374681055545807f,0.004316955804824829f,-2.1620028018951416f,-0.015127910301089287f}, |
Lightvalve | 83:b5bba84861d8 | 203 | {0.06626773625612259f,-0.320145845413208f,0.13710039854049683f,0.4238254725933075f,1.579092264175415f,-0.29698872566223145f,-0.023510707542300224f,-4.222825050354004f,0.588687002658844f,0.22302789986133575f,-0.3158661127090454f,-0.017030322924256325f,0.11499327421188354f,0.2358274906873703f,0.24149659276008606f,0.011927744373679161f,-0.3362255096435547f,0.06021764874458313f,-0.0735672265291214f,0.6062617301940918f,-0.30298954248428345f,-0.022329479455947876f,-0.2963099479675293f,0.08446213603019714f,-0.6479023694992065f,-0.08218517899513245f,-0.08906334638595581f,2.5516419410705566f,0.25081536173820496f,-0.11924156546592712f,-2.1845967769622803f,-0.14605742692947388f}, |
Lightvalve | 83:b5bba84861d8 | 204 | {-0.3648415207862854f,-0.26285821199417114f,-0.24446426331996918f,0.12008292227983475f,1.1284105777740479f,-0.19725050032138824f,0.22585070133209229f,-2.587270736694336f,0.09232938289642334f,-0.03573980554938316f,-0.37424713373184204f,-0.2816612720489502f,0.08400186896324158f,0.10918986052274704f,-0.26784712076187134f,-0.5411822199821472f,0.1331600546836853f,0.3319900929927826f,0.2513442039489746f,0.18250450491905212f,-0.20100386440753937f,0.1638341248035431f,-0.11680193245410919f,-0.321638286113739f,-0.3288072645664215f,0.05633258819580078f,0.13587942719459534f,1.922518253326416f,0.135310098528862f,0.30370619893074036f,-0.27041947841644287f,0.2342318594455719f}, |
Lightvalve | 83:b5bba84861d8 | 205 | {-0.3556065559387207f,-0.6742091774940491f,-0.06658771634101868f,0.12671643495559692f,0.23734726011753082f,-0.2812441885471344f,0.11592545360326767f,-0.2247428148984909f,-0.6113523244857788f,-0.3833177983760834f,-0.3629647195339203f,-0.7307411432266235f,-0.1789563000202179f,0.26695486903190613f,0.017138004302978516f,0.10263609886169434f,-0.31221434473991394f,-0.24391496181488037f,0.6401596665382385f,-0.42824262380599976f,0.16973629593849182f,-0.25340327620506287f,0.23975160717964172f,0.011333763599395752f,-0.3207014203071594f,0.10268864035606384f,0.08055207133293152f,0.7507809996604919f,0.052690062671899796f,0.029612571001052856f,1.1032860279083252f,0.3103558123111725f}, |
Lightvalve | 83:b5bba84861d8 | 206 | {-0.13943248987197876f,0.12878988683223724f,-0.3080642819404602f,-0.048004329204559326f,-0.08995503932237625f,-0.5511131882667542f,-0.18336737155914307f,1.4835768938064575f,-0.9105148315429688f,-0.0037339930422604084f,0.27534615993499756f,-0.07330597937107086f,-0.03757423162460327f,-0.1734577715396881f,-0.2992876172065735f,0.10026633739471436f,0.046406250447034836f,-0.1821068376302719f,0.30052053928375244f,-0.5427815318107605f,0.29002442955970764f,0.2275833785533905f,-0.23374228179454803f,0.3280802071094513f,-0.5871660709381104f,0.2108195722103119f,0.33828380703926086f,0.7546223998069763f,-0.02815738320350647f,0.1480078399181366f,1.0429247617721558f,0.07439398765563965f}, |
Lightvalve | 83:b5bba84861d8 | 207 | {-0.14182732999324799f,-0.26824089884757996f,0.19288143515586853f,0.2848929166793823f,0.15902626514434814f,-0.220149427652359f,-0.3229142427444458f,2.1567201614379883f,-0.8948915004730225f,0.03023526258766651f,-0.1647857427597046f,0.3776342570781708f,-0.2720222473144531f,-0.38248714804649353f,0.06489166617393494f,-0.16778093576431274f,-0.2435888648033142f,0.21822473406791687f,0.2452206313610077f,-0.7945815324783325f,-0.25171342492103577f,0.027203470468521118f,0.012447118759155273f,-0.0029686689376831055f,0.023461464792490005f,0.03022313117980957f,0.3424017131328583f,0.3924326002597809f,-0.27592161297798157f,-0.34525999426841736f,0.0023458898067474365f,0.089816614985466f}, |
Lightvalve | 83:b5bba84861d8 | 208 | {-0.40031707286834717f,-0.02017478086054325f,0.06283923983573914f,0.2749215066432953f,-0.2252415418624878f,-0.10143161565065384f,0.21731507778167725f,2.0287230014801025f,-0.6057344675064087f,0.4012513756752014f,0.2761487662792206f,0.07591059803962708f,0.03354460000991821f,0.004837005399167538f,0.1072375476360321f,-0.09884940832853317f,-0.12255830317735672f,0.08871319890022278f,-0.05703575164079666f,-0.5879805684089661f,-0.2227887064218521f,-0.01532900333404541f,0.11891454458236694f,-0.33143535256385803f,0.15345007181167603f,-0.1485452950000763f,0.25882163643836975f,-0.7195655703544617f,-0.027022292837500572f,0.24182012677192688f,-0.19213852286338806f,0.27589938044548035f}, |
Lightvalve | 83:b5bba84861d8 | 209 | {0.0009785505244508386f,-0.5968310236930847f,0.25620588660240173f,0.4549611210823059f,-0.44449374079704285f,0.05395924672484398f,0.1512405127286911f,1.007339596748352f,-0.16030868887901306f,0.7290225625038147f,-0.0617513433098793f,0.07565976679325104f,0.18931713700294495f,-0.3407898247241974f,0.03958520293235779f,0.28566330671310425f,0.021778641268610954f,-0.07219305634498596f,0.36551982164382935f,-0.3949628174304962f,0.31619134545326233f,0.26330670714378357f,0.026431173086166382f,0.237522691488266f,-0.02845417521893978f,0.19442179799079895f,0.1992029845714569f,-1.2599095106124878f,-0.32174769043922424f,-0.10433453321456909f,-0.40581196546554565f,-0.13936783373355865f}, |
Lightvalve | 83:b5bba84861d8 | 210 | {-0.49818694591522217f,-0.2966457009315491f,-0.13789941370487213f,0.520455539226532f,-0.583653450012207f,0.10172753036022186f,-0.2910226583480835f,0.7780567407608032f,-0.0416196770966053f,1.0302135944366455f,-0.338738352060318f,0.20651310682296753f,0.06288954615592957f,-0.22876010835170746f,0.28114965558052063f,-0.49572569131851196f,0.09090108424425125f,-0.14027439057826996f,-0.08486009389162064f,-0.4277127981185913f,0.18525317311286926f,0.07025247812271118f,-0.12988737225532532f,0.04382038116455078f,0.35900405049324036f,-0.12333536148071289f,-0.12442702054977417f,-0.8916861414909363f,-0.2975360155105591f,0.27953919768333435f,-0.1144266203045845f,0.19119742512702942f}, |
Lightvalve | 83:b5bba84861d8 | 211 | {-0.15271641314029694f,-0.42013081908226013f,0.23826703429222107f,-0.1933271288871765f,-1.0072599649429321f,-0.2096155732870102f,0.23362237215042114f,1.037949562072754f,0.9768444299697876f,1.9921762943267822f,-0.3631672263145447f,-0.4422250986099243f,0.012096136808395386f,-0.07563285529613495f,-0.03951779007911682f,-0.20281916856765747f,0.06151115521788597f,0.2508954107761383f,0.18990781903266907f,-0.5633195638656616f,0.22447606921195984f,0.30379387736320496f,-0.006355375051498413f,-0.11041811108589172f,-0.36673539876937866f,-0.28886765241622925f,-0.05783697962760925f,-1.9456329345703125f,-0.13858269155025482f,-0.1556464582681656f,0.01802002266049385f,-0.06157972663640976f}, |
Lightvalve | 65:a2d7c63419c2 | 212 | }; |
Lightvalve | 65:a2d7c63419c2 | 213 | |
Lightvalve | 66:a8e6799dbce3 | 214 | const float h2[32][32] = { |
Lightvalve | 83:b5bba84861d8 | 215 | {-0.13349971175193787f,-0.10295046865940094f,-0.04925942420959473f,0.005883673205971718f,-0.15490937232971191f,0.16251355409622192f,-0.22063873708248138f,0.06396704912185669f,-0.30411389470100403f,-0.10008957982063293f,0.09501579403877258f,-0.4757978320121765f,0.09169831871986389f,-0.04981523007154465f,-0.4899395704269409f,-0.20975033938884735f,0.07803884148597717f,-0.21483641862869263f,-0.4824053645133972f,-0.0014381716027855873f,-0.4462721347808838f,-0.37364646792411804f,-0.3560675084590912f,-0.20666398108005524f,-2.0170915126800537f,0.6765809059143066f,-0.7102095484733582f,-0.4072538912296295f,0.23828622698783875f,-0.03586537390947342f,-0.24613501131534576f,-0.20819377899169922f}, |
Lightvalve | 83:b5bba84861d8 | 216 | {-0.22919906675815582f,0.002147972583770752f,-0.04321768879890442f,0.1460515260696411f,0.039372533559799194f,-0.24251529574394226f,-0.6329693794250488f,-0.05986310541629791f,0.24677053093910217f,0.048597872257232666f,-0.21330727636814117f,-0.47644495964050293f,0.11025732755661011f,-1.333216905593872f,-2.717913866043091f,1.6632221937179565f,0.056778669357299805f,-0.2737269401550293f,-0.13714197278022766f,0.08000627160072327f,1.0931211709976196f,-0.1088254526257515f,-0.3513537347316742f,0.29302915930747986f,0.25829067826271057f,0.753427267074585f,-0.2536275386810303f,0.09150303155183792f,-0.4305570721626282f,-0.20952638983726501f,0.0655287504196167f,0.052672531455755234f}, |
Lightvalve | 66:a8e6799dbce3 | 217 | {-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 | 83:b5bba84861d8 | 218 | {-0.46422722935676575f,-0.01806354522705078f,-0.23058539628982544f,-0.13447904586791992f,-0.27190759778022766f,-0.3261217474937439f,-0.5193619728088379f,0.08759373426437378f,-0.06944303214550018f,0.09271347522735596f,-0.4052128195762634f,-0.38887396454811096f,-0.3069044053554535f,0.5471137762069702f,0.10067101567983627f,-1.0313479900360107f,0.10996055603027344f,0.24023392796516418f,-0.004984395578503609f,-0.21222959458827972f,-0.3814924657344818f,-0.5187252759933472f,-0.226375013589859f,-0.21457882225513458f,-1.5298705101013184f,1.2749768495559692f,-0.5545745491981506f,-0.31423911452293396f,-0.33003994822502136f,0.10548660159111023f,-0.10664685815572739f,0.11603645235300064f}, |
Lightvalve | 83:b5bba84861d8 | 219 | {-0.3042767643928528f,0.2506926953792572f,-0.0804666131734848f,-0.10104617476463318f,0.02918580174446106f,-0.3085322380065918f,-3.119076728820801f,0.0013494789600372314f,0.043158918619155884f,-0.2690317630767822f,-0.18963946402072906f,-3.2566471099853516f,-0.3352719247341156f,0.228376567363739f,-0.3840715289115906f,-0.6106191277503967f,-0.10307048261165619f,0.15626338124275208f,-0.736420750617981f,-0.0323917455971241f,0.681183397769928f,-0.19529549777507782f,0.012721757404506207f,-0.25640106201171875f,-4.884658336639404f,-0.7305920124053955f,-1.2165623903274536f,0.16116231679916382f,0.17340433597564697f,-0.34337812662124634f,-0.14482758939266205f,-0.1783686876296997f}, |
Lightvalve | 83:b5bba84861d8 | 220 | {-0.19158349931240082f,-0.004258692264556885f,0.032371193170547485f,-0.3145107626914978f,-0.023485273122787476f,-0.31737861037254333f,-0.050338100641965866f,-0.14440131187438965f,-0.03548547625541687f,0.08825305104255676f,-0.24471108615398407f,0.2423708438873291f,-0.2578849494457245f,0.08850430697202682f,-0.1670907437801361f,-0.05479445680975914f,0.2371552288532257f,0.24713221192359924f,0.32049933075904846f,0.161422461271286f,-0.03278316929936409f,0.18465445935726166f,-0.1307595670223236f,-0.07995601743459702f,-0.13440389931201935f,-0.27653828263282776f,0.188252255320549f,-0.13351300358772278f,0.05800282955169678f,-0.26823562383651733f,0.17187702655792236f,0.1526932716369629f}, |
Lightvalve | 83:b5bba84861d8 | 221 | {-0.21433322131633759f,-0.1279313862323761f,-0.11171227693557739f,0.2297813594341278f,-0.26441383361816406f,0.2845393121242523f,0.021771641448140144f,-0.20844537019729614f,-0.26620519161224365f,0.17144301533699036f,-0.1301146298646927f,-0.18387873470783234f,0.29584869742393494f,-0.09088432788848877f,-0.09784846752882004f,0.07511107623577118f,-0.16153597831726074f,0.18742787837982178f,-0.06658647209405899f,0.06260894984006882f,0.035784412175416946f,-0.005422413814812899f,-0.07988794147968292f,-0.16740475594997406f,-0.21621882915496826f,0.1278177946805954f,0.139932781457901f,-0.19568563997745514f,-0.11822041869163513f,0.19546762108802795f,-0.16657039523124695f,-0.043908413499593735f}, |
Lightvalve | 83:b5bba84861d8 | 222 | {0.14565640687942505f,0.11346611380577087f,0.04012581706047058f,0.006979561876505613f,0.22828009724617004f,-0.13268056511878967f,-1.4916621446609497f,0.004197537899017334f,0.2864855229854584f,0.01006925106048584f,-0.44853830337524414f,-1.7464444637298584f,-0.17114946246147156f,-1.723611831665039f,-0.25928422808647156f,-1.33587646484375f,-0.2721019387245178f,0.2706601917743683f,-0.2000279724597931f,-0.14498476684093475f,-2.65549898147583f,-0.06484482437372208f,-0.2777160406112671f,0.22138673067092896f,-2.3122189044952393f,-1.074158787727356f,-0.9324250817298889f,-0.2325560599565506f,-0.14135785400867462f,-0.10996681451797485f,0.01516080740839243f,0.055318158119916916f}, |
Lightvalve | 83:b5bba84861d8 | 223 | {0.06490106880664825f,0.2890130579471588f,-0.021617114543914795f,0.027820656076073647f,0.29321715235710144f,-0.1300620585680008f,-0.7480725049972534f,-0.23997274041175842f,0.29470762610435486f,-0.06864601373672485f,-0.41091451048851013f,0.5590778589248657f,0.09142488986253738f,-2.2419216632843018f,0.2561773657798767f,0.030861737206578255f,0.046292245388031006f,0.06025278568267822f,-0.031366195529699326f,0.1076279953122139f,0.839841902256012f,-0.2054455727338791f,0.10160917788743973f,-0.020713727921247482f,1.380825400352478f,-5.573235511779785f,-1.2186083793640137f,-0.1219152957201004f,0.11037639528512955f,-0.3194585144519806f,-0.26529768109321594f,-0.21939682960510254f}, |
Lightvalve | 83:b5bba84861d8 | 224 | {-0.08656720817089081f,0.08643358945846558f,-0.29237738251686096f,-0.42922505736351013f,0.15896368026733398f,-0.28236123919487f,0.38584771752357483f,-0.15540927648544312f,0.18755429983139038f,-0.07031691074371338f,-0.07586068660020828f,1.25897216796875f,-0.02674068510532379f,0.2453230768442154f,-0.6370781660079956f,-0.6411188840866089f,-0.015168905258178711f,-0.2859399914741516f,-0.3979915380477905f,-0.23024821281433105f,-1.7376705408096313f,-0.2026410698890686f,-0.37360402941703796f,0.17243844270706177f,0.5692830681800842f,-0.9987419247627258f,-0.09322743117809296f,-0.12081333994865417f,0.05425053834915161f,-0.06377493590116501f,-0.0010054409503936768f,-0.2794814109802246f}, |
Lightvalve | 83:b5bba84861d8 | 225 | {0.19981321692466736f,0.1956864297389984f,-0.033508092164993286f,-0.22838544845581055f,-0.12505969405174255f,0.026693344116210938f,0.07821325212717056f,0.14285165071487427f,-0.17670965194702148f,0.17403557896614075f,-0.1916860193014145f,0.10965214669704437f,-0.1060299277305603f,-0.005117397289723158f,-0.16311120986938477f,0.05849427357316017f,0.03990337252616882f,0.0716913640499115f,0.15468956530094147f,-0.09167034924030304f,0.2548150420188904f,0.09461261332035065f,0.07470300793647766f,0.2958023250102997f,0.05625919997692108f,0.06173352524638176f,-0.014309915713965893f,-0.25180554389953613f,0.13817378878593445f,0.17853263020515442f,-0.009185433387756348f,-0.0204818956553936f}, |
Lightvalve | 83:b5bba84861d8 | 226 | {-0.45362135767936707f,-0.09556084871292114f,0.12328919768333435f,-0.08168020844459534f,-0.258735328912735f,0.01663784869015217f,-1.4426089525222778f,-0.10312946140766144f,0.17735600471496582f,0.009893029928207397f,-0.1033797562122345f,-1.0786514282226562f,-0.23033499717712402f,-0.4104976952075958f,-1.0593940019607544f,0.5192559957504272f,0.009990394115447998f,0.10842388868331909f,-0.06464047729969025f,0.07205235213041306f,-1.9534685611724854f,-0.28341323137283325f,-0.08327019214630127f,0.07130808383226395f,-1.0867469310760498f,-1.06252121925354f,-1.0615464448928833f,0.018923405557870865f,-0.44636133313179016f,-0.3959900140762329f,0.028612444177269936f,0.2719894051551819f}, |
Lightvalve | 66:a8e6799dbce3 | 227 | {-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 | 83:b5bba84861d8 | 228 | {0.14700931310653687f,0.1833711564540863f,-0.0858893096446991f,0.03526987135410309f,-0.25116482377052307f,0.2733006179332733f,0.21833287179470062f,-0.16134384274482727f,0.000652611255645752f,-0.22920364141464233f,0.2454860806465149f,-0.16050085425376892f,0.26723334193229675f,0.30877137184143066f,-0.14376986026763916f,-0.3925645351409912f,-0.07963520288467407f,0.14483880996704102f,-0.31889814138412476f,-0.2053186297416687f,-0.0862332284450531f,0.20113295316696167f,-0.2228696048259735f,0.2447444051504135f,-0.04024190455675125f,-0.06843708455562592f,0.15156546235084534f,0.08498335629701614f,-0.011228948831558228f,0.26896968483924866f,-0.28556761145591736f,-0.13113045692443848f}, |
Lightvalve | 66:a8e6799dbce3 | 229 | {-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 | 83:b5bba84861d8 | 230 | {-0.1617974042892456f,0.1317739188671112f,0.03260180354118347f,-0.21369372308254242f,-0.05160003900527954f,-0.30379876494407654f,-0.48692527413368225f,0.11372503638267517f,0.05445769429206848f,0.07657262682914734f,-0.3314072787761688f,0.00248530856333673f,0.22289374470710754f,-0.35908129811286926f,-0.07195352762937546f,-0.18584707379341125f,-0.25386664271354675f,-0.18997573852539062f,-0.2897074520587921f,-0.26648837327957153f,-0.26833876967430115f,-0.0980667993426323f,-0.5251437425613403f,0.24791452288627625f,0.278769314289093f,-0.5315976142883301f,0.04644494876265526f,-0.455558180809021f,-0.0006675124168395996f,-0.38848909735679626f,-0.035532981157302856f,0.26054325699806213f}, |
Lightvalve | 83:b5bba84861d8 | 231 | {0.036086976528167725f,-0.062024205923080444f,0.10704237222671509f,-0.15739846229553223f,-0.04875987768173218f,0.09125488996505737f,-0.14311747252941132f,0.27597710490226746f,-0.23304778337478638f,-0.035415440797805786f,-0.04678364098072052f,0.08488292992115021f,0.17716765403747559f,-0.27189451456069946f,0.123504638671875f,-0.20082353055477142f,-0.027234435081481934f,0.19620582461357117f,0.16419850289821625f,-0.26965123414993286f,-0.08356523513793945f,-0.16791100800037384f,-0.2161911427974701f,-0.29613974690437317f,0.21002039313316345f,-0.9153975248336792f,-0.1615580916404724f,0.11685207486152649f,-0.2531542181968689f,0.04203394427895546f,-0.21812304854393005f,-0.1704932600259781f}, |
Lightvalve | 67:c2812cf26c38 | 232 | {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 | 83:b5bba84861d8 | 233 | {-0.039692603051662445f,0.2841971218585968f,-0.0814327746629715f,-0.09517354518175125f,-0.017610490322113037f,-0.0059724003076553345f,-1.2536425590515137f,0.20642486214637756f,-0.2925014793872833f,0.022429823875427246f,-0.7223549485206604f,2.6212077140808105f,-0.3065248429775238f,-3.2365400791168213f,8.271857261657715f,2.3236031532287598f,0.1296386420726776f,0.027322769165039062f,0.4322223663330078f,-0.036404721438884735f,-1.2764407396316528f,-0.0728035569190979f,-0.1420556753873825f,0.1591874063014984f,1.4104642868041992f,6.028079509735107f,-1.307969570159912f,-0.17443321645259857f,-0.10256446897983551f,-0.3348820209503174f,-0.31045663356781006f,0.1232137680053711f}, |
Lightvalve | 83:b5bba84861d8 | 234 | {-0.14775772392749786f,0.29651907086372375f,0.02990397810935974f,-0.07645538449287415f,0.1826970875263214f,-0.359224408864975f,-0.26463383436203003f,0.26979032158851624f,-0.2325194776058197f,-0.2458522766828537f,-0.4399057626724243f,-4.241488933563232f,-0.2042773962020874f,-0.19516001641750336f,1.486624836921692f,1.1970772743225098f,0.2577105462551117f,0.11064860224723816f,-0.3248942196369171f,-0.020190348848700523f,3.287468671798706f,-0.43067821860313416f,-0.2715495526790619f,0.005708260927349329f,-1.2052972316741943f,-0.8186207413673401f,-0.562594473361969f,0.1350025087594986f,-0.2205982804298401f,0.12672844529151917f,-0.1669490486383438f,0.08364412188529968f}, |
Lightvalve | 74:2bd13b02ed17 | 235 | {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 | 66:a8e6799dbce3 | 236 | {-0.06283275783061981f,-0.26753589510917664f,-0.10381917655467987f,-0.13344663381576538f,0.2644997537136078f,0.2204643189907074f,0.2924788296222687f,-0.17931663990020752f,-0.09078609943389893f,-0.17306232452392578f,0.02247890830039978f,-0.26996222138404846f,0.22075030207633972f,-0.3029964864253998f,0.21873190999031067f,-0.0030784308910369873f,0.18228653073310852f,0.09971508383750916f,-0.242676243185997f,-0.1424383968114853f,0.19031599164009094f,0.3004438579082489f,-0.23650792241096497f,-0.2683113217353821f,0.29957786202430725f,0.08561205863952637f,-0.1366746425628662f,-0.15950153768062592f,-0.07675467431545258f,-0.2218506634235382f,-0.2795913517475128f,0.1869203746318817f}, |
Lightvalve | 66:a8e6799dbce3 | 237 | {0.2003176510334015f,-0.27792131900787354f,0.055196613073349f,-0.27959588170051575f,0.18430876731872559f,-0.05316638946533203f,0.16156336665153503f,-0.18850930035114288f,0.09482413530349731f,0.021483391523361206f,0.009039878845214844f,0.1586727499961853f,0.11457142233848572f,0.2876913249492645f,-0.24802550673484802f,0.14089101552963257f,-0.06842575967311859f,-0.10107968747615814f,0.06239110231399536f,-0.2528536915779114f,-0.27538973093032837f,0.15457189083099365f,-0.15549622476100922f,0.20245882868766785f,0.08544808626174927f,0.22650876641273499f,-0.05268847942352295f,0.20387354493141174f,0.24724552035331726f,0.21444126963615417f,0.05186706781387329f,-0.11084021627902985f}, |
Lightvalve | 66:a8e6799dbce3 | 238 | {-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 | 83:b5bba84861d8 | 239 | {-0.1194835677742958f,-0.25281068682670593f,-0.10565309226512909f,-0.23310962319374084f,0.2702934443950653f,-0.21871773898601532f,-1.72031569480896f,-0.19997140765190125f,-0.06814777851104736f,-0.24531681835651398f,-0.49088218808174133f,-4.137485504150391f,-0.1536514312028885f,-0.8431317806243896f,-0.6788159608840942f,1.5851374864578247f,0.2015441358089447f,0.04417389631271362f,0.04470941796898842f,-0.03303630277514458f,-2.7294132709503174f,-0.21549883484840393f,-0.44236835837364197f,0.28239932656288147f,-7.252325534820557f,-5.330204963684082f,-1.2775461673736572f,-0.277432918548584f,-0.327739953994751f,-0.32964906096458435f,0.04830574616789818f,0.28093934059143066f}, |
Lightvalve | 66:a8e6799dbce3 | 240 | {-0.10580866038799286f,-0.17215237021446228f,-0.01352420449256897f,-0.13443149626255035f,-0.10265451669692993f,-0.2169143706560135f,0.30098411440849304f,-0.2986297905445099f,0.07908004522323608f,-0.30061498284339905f,0.10424068570137024f,-0.018799901008605957f,-0.18665757775306702f,0.005998075008392334f,-0.2969498336315155f,0.18525955080986023f,0.2379322350025177f,0.15184926986694336f,0.215760737657547f,-0.19088758528232574f,0.08620095252990723f,0.019999295473098755f,-0.0752219706773758f,0.11181813478469849f,0.1881926953792572f,0.2210972011089325f,0.13236162066459656f,-0.06690356135368347f,-0.18345263600349426f,-0.14861416816711426f,0.08577704429626465f,-0.09683996438980103f}, |
Lightvalve | 66:a8e6799dbce3 | 241 | {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 | 83:b5bba84861d8 | 242 | {0.2769129276275635f,-0.11652402579784393f,0.24921879172325134f,0.03028584085404873f,-0.2817712128162384f,-0.3285594582557678f,-0.7831640839576721f,-0.11968852579593658f,0.23963233828544617f,0.21321198344230652f,-0.484195739030838f,-3.9378204345703125f,-0.16443446278572083f,0.023402491584420204f,1.4171576499938965f,-0.6656811237335205f,-0.19791248440742493f,0.2487291395664215f,-0.5942062139511108f,-0.2980404198169708f,1.9019050598144531f,-0.0994596779346466f,-0.27820414304733276f,-0.2320869117975235f,-3.610471725463867f,0.6188204884529114f,-1.0333298444747925f,-0.12684693932533264f,-0.12579141557216644f,0.12054212391376495f,-0.14617536962032318f,-0.057861607521772385f}, |
Lightvalve | 83:b5bba84861d8 | 243 | {-0.17075178027153015f,0.009595632553100586f,0.2466227114200592f,0.03264760226011276f,-0.29828932881355286f,-0.4100177586078644f,-0.1470797061920166f,-0.15331926941871643f,-0.2516406178474426f,0.012286126613616943f,0.1774468868970871f,-0.30450114607810974f,-0.09437626600265503f,-0.16432997584342957f,-0.11507974565029144f,0.028795959427952766f,-0.24087269604206085f,-0.048499464988708496f,-0.37276214361190796f,0.011330265551805496f,-0.4677097201347351f,-0.23363769054412842f,-0.031352698802948f,0.2812359035015106f,-0.4456702768802643f,-0.12324901670217514f,-0.2695859372615814f,0.2152492254972458f,-0.07090267539024353f,-0.3899269104003906f,-0.2543276250362396f,-0.009422880597412586f}, |
Lightvalve | 66:a8e6799dbce3 | 244 | {-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 | 83:b5bba84861d8 | 245 | {-0.3216961920261383f,-0.17203155159950256f,0.0620841383934021f,-0.20148849487304688f,-0.07396678626537323f,-0.27091896533966064f,0.1492607444524765f,0.17422041296958923f,-0.21029016375541687f,0.2210421860218048f,-0.16701525449752808f,-0.4054226875305176f,-0.108514204621315f,1.803159475326538f,0.10307883471250534f,0.554818868637085f,0.10771593451499939f,-0.29308468103408813f,-0.4572890102863312f,-0.2202519029378891f,0.28893792629241943f,-0.2122606635093689f,-0.45239317417144775f,0.1775902509689331f,-0.6399175524711609f,-1.7756084203720093f,0.39235720038414f,-0.0477338507771492f,0.03053330071270466f,-0.13966171443462372f,0.14392727613449097f,0.10427560657262802f}, |
Lightvalve | 83:b5bba84861d8 | 246 | {-0.11539766937494278f,-0.22750279307365417f,-0.22503364086151123f,-0.05188126116991043f,-0.012498408555984497f,-0.24329537153244019f,-0.012629247270524502f,0.08175003528594971f,-0.016126900911331177f,0.06972584128379822f,-0.6929265260696411f,1.9283177852630615f,-0.031845152378082275f,-1.2385159730911255f,1.6594690084457397f,-0.05135693401098251f,-0.09216172993183136f,0.04617339372634888f,-0.44848328828811646f,-0.1298399418592453f,-0.2594316601753235f,-0.3740636110305786f,-0.21858008205890656f,-0.2995438575744629f,1.1884921789169312f,0.9635776281356812f,-1.4520230293273926f,-0.3110574781894684f,-0.16326025128364563f,-0.009630477987229824f,-0.02675291895866394f,0.12033155560493469f}, |
Lightvalve | 65:a2d7c63419c2 | 247 | }; |
Lightvalve | 65:a2d7c63419c2 | 248 | |
Lightvalve | 66:a8e6799dbce3 | 249 | const float h3[32][32] = { |
Lightvalve | 83:b5bba84861d8 | 250 | {-0.2551194727420807f,-0.09101890027523041f,-0.026477575302124023f,-0.24469062685966492f,0.05671628192067146f,-0.21566259860992432f,0.23563924431800842f,0.21467849612236023f,-0.17011712491512299f,0.034586966037750244f,-0.296426922082901f,0.28293344378471375f,0.17930611968040466f,0.1791038066148758f,-0.2476848065853119f,0.13452908396720886f,0.033751994371414185f,0.2061004936695099f,-0.05710269510746002f,-0.10083381831645966f,-0.11890523135662079f,0.18555119633674622f,-0.22618433833122253f,0.044178664684295654f,0.05070437863469124f,-0.1258748173713684f,0.2930828630924225f,-0.22082221508026123f,0.04324357956647873f,0.2922307550907135f,-0.21407078206539154f,-0.045762743800878525f}, |
Lightvalve | 83:b5bba84861d8 | 251 | {0.05588451027870178f,0.19731858372688293f,-0.055143773555755615f,0.030042022466659546f,-0.13887283205986023f,-0.1361943781375885f,-0.2855546772480011f,0.011247634887695312f,0.1085631251335144f,0.021339505910873413f,0.17599248886108398f,0.09762296080589294f,-0.05771490931510925f,-0.14660483598709106f,-0.21469902992248535f,0.03876742720603943f,-0.21865856647491455f,-0.12651903927326202f,0.22753819823265076f,-0.23926785588264465f,-0.14443452656269073f,0.06739777326583862f,0.14157342910766602f,0.049514561891555786f,-0.1251431256532669f,-0.25851932168006897f,0.0932874083518982f,0.2900666892528534f,-0.023782014846801758f,0.050485759973526f,0.09447437524795532f,0.0058679282665252686f}, |
Lightvalve | 66:a8e6799dbce3 | 252 | {-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 | 83:b5bba84861d8 | 253 | {0.2906629145145416f,0.19203472137451172f,-0.2048129439353943f,0.2633720338344574f,0.10813106596469879f,0.1065712422132492f,-0.061309605836868286f,-0.17915479838848114f,-0.05819859355688095f,-0.044261813163757324f,-0.1308283805847168f,0.24970653653144836f,0.05474856495857239f,0.10647635161876678f,0.22106656432151794f,-0.23978039622306824f,-0.28915077447891235f,0.030949801206588745f,-0.2948352098464966f,0.1836264431476593f,0.21191391348838806f,0.07747724652290344f,-0.16484108567237854f,-0.27595841884613037f,0.10204685479402542f,-0.11024686694145203f,-0.09994620084762573f,-0.041024450212717056f,-0.1939506083726883f,-0.25852420926094055f,0.05653107166290283f,-0.05374797061085701f}, |
Lightvalve | 83:b5bba84861d8 | 254 | {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 | 83:b5bba84861d8 | 255 | {0.10931676626205444f,0.2396949827671051f,0.12925085425376892f,-0.01787710189819336f,-0.050438664853572845f,0.11531509459018707f,-0.061815500259399414f,0.04091137647628784f,0.015645310282707214f,-0.15699732303619385f,0.08972057700157166f,-0.21529507637023926f,0.031493134796619415f,-0.1298101544380188f,0.2971965968608856f,0.25175121426582336f,-0.2889891266822815f,-0.13035915791988373f,0.1481376737356186f,0.06524023413658142f,0.08440709114074707f,-0.2353462427854538f,0.023232191801071167f,0.27409639954566956f,-0.1158725842833519f,-0.18302330374717712f,0.09057381749153137f,-0.010599695146083832f,-0.27729424834251404f,-0.29547566175460815f,-0.25800079107284546f,0.24402263760566711f}, |
Lightvalve | 83:b5bba84861d8 | 256 | {-0.21155381202697754f,0.23928597569465637f,-0.28679442405700684f,-0.3798370063304901f,-0.20062953233718872f,0.5300439596176147f,-0.07957221567630768f,0.2444917857646942f,-0.42357754707336426f,-0.2905992567539215f,0.7120198607444763f,-0.3290978968143463f,0.5076509714126587f,0.2544768154621124f,0.25543639063835144f,-0.1192857176065445f,-0.18917083740234375f,0.011466026306152344f,-0.13750670850276947f,0.014042076654732227f,-0.638232409954071f,0.29154765605926514f,-0.2539873421192169f,-0.2255190908908844f,0.14571280777454376f,-0.2910519242286682f,-0.3027200698852539f,-1.121808409690857f,1.592147946357727f,-0.09532724320888519f,0.0728168785572052f,-0.03254098817706108f}, |
Lightvalve | 83:b5bba84861d8 | 257 | {-0.01093912124633789f,-0.23583689332008362f,0.28153905272483826f,0.2877257764339447f,0.08201509714126587f,-0.2699383497238159f,0.036741942167282104f,-0.0059101879596710205f,-0.24633634090423584f,-0.27182313799858093f,0.09319102764129639f,-0.08139897882938385f,0.19774547219276428f,-0.020215511322021484f,0.0685860812664032f,-0.29903873801231384f,0.1317853033542633f,0.20550194382667542f,-0.12251400947570801f,-0.28424710035324097f,0.24172750115394592f,0.11755815148353577f,0.0343703031539917f,0.12564969062805176f,0.03227102756500244f,0.23886635899543762f,-0.2778390347957611f,0.13853725790977478f,0.28547611832618713f,0.17161712050437927f,-0.017215043306350708f,-0.05991865694522858f}, |
Lightvalve | 66:a8e6799dbce3 | 258 | {-0.20420776307582855f,0.1970202624797821f,0.23591408133506775f,-0.282694011926651f,0.09019026160240173f,0.20012763142585754f,0.028453975915908813f,0.23323127627372742f,0.15246456861495972f,-0.1270071268081665f,0.20025727152824402f,0.13077861070632935f,-0.2238168716430664f,-0.20709244906902313f,-0.0045506954193115234f,-0.16448761522769928f,0.28163614869117737f,0.1971360743045807f,0.30405697226524353f,-0.28959211707115173f,-0.2255709171295166f,0.15360668301582336f,0.24163606762886047f,0.19554737210273743f,-0.1804599016904831f,0.07604315876960754f,-0.1459394246339798f,-0.14081311225891113f,-0.29656586050987244f,0.19529584050178528f,-0.05168652534484863f,-0.03415781259536743f}, |
Lightvalve | 66:a8e6799dbce3 | 259 | {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 | 83:b5bba84861d8 | 260 | {-0.023678362369537354f,0.2536241114139557f,-0.2825886607170105f,0.17558999359607697f,0.01551743596792221f,-0.09121204912662506f,0.0393199622631073f,0.196751207113266f,-0.044080838561058044f,0.22249583899974823f,-0.06140158325433731f,-0.18992534279823303f,-0.2183508574962616f,-0.2859346270561218f,0.080221027135849f,-0.2471318244934082f,0.026521950960159302f,0.28880444169044495f,0.19618196785449982f,-0.23591196537017822f,-0.04967387020587921f,0.5277329087257385f,0.06278499215841293f,0.2614522874355316f,-0.05968416854739189f,-0.25962090492248535f,-0.03464147821068764f,0.4126087427139282f,0.909105658531189f,-0.2912617325782776f,-0.44183045625686646f,0.004618979059159756f}, |
Lightvalve | 83:b5bba84861d8 | 261 | {0.2680447995662689f,-0.038279686123132706f,-0.35619276762008667f,0.04982487112283707f,-0.21997271478176117f,0.32281622290611267f,0.15373970568180084f,-0.17794576287269592f,-0.08524645119905472f,-0.5343239307403564f,0.3492487370967865f,0.08063314855098724f,0.15112140774726868f,-0.016918547451496124f,0.23152390122413635f,-0.07731422781944275f,0.21101722121238708f,-0.15284278988838196f,-1.8817192316055298f,-0.12916453182697296f,2.3906779289245605f,0.4866367280483246f,0.010935630649328232f,0.024144932627677917f,1.248098373413086f,1.9067994356155396f,-0.2816470265388489f,1.6799968481063843f,2.667992115020752f,-0.1739533692598343f,-0.35024988651275635f,-5.484776973724365f}, |
Lightvalve | 83:b5bba84861d8 | 262 | {0.10771462321281433f,0.1270637810230255f,-0.1647956818342209f,-0.00161704421043396f,0.13797834515571594f,0.14787162840366364f,-0.2502448558807373f,-0.05063694715499878f,-0.28954532742500305f,-0.11501708626747131f,0.21253573894500732f,0.11519002914428711f,-0.1879904866218567f,0.06972655653953552f,-0.0055807530879974365f,0.05870962142944336f,-0.0561012327671051f,-0.1419317126274109f,-0.24982497096061707f,-0.05947013199329376f,-0.21285000443458557f,-0.2671023905277252f,0.2986377775669098f,-0.2888573110103607f,-0.1775677353143692f,-0.03866580128669739f,0.09892630577087402f,0.1996987760066986f,0.08316867053508759f,0.024399906396865845f,-0.264041006565094f,-0.037910252809524536f}, |
Lightvalve | 83:b5bba84861d8 | 263 | {0.07240793108940125f,-0.12949003279209137f,-0.2614954710006714f,-0.23108132183551788f,-0.28553202748298645f,-0.1450670063495636f,0.03592598810791969f,-0.09019742906093597f,-0.6764151453971863f,-0.5278627872467041f,-0.23027421534061432f,-0.04667649418115616f,-0.24767546355724335f,-0.5792484879493713f,0.13272255659103394f,-0.0684008002281189f,-0.13351139426231384f,0.2471931278705597f,-0.1907733827829361f,-0.31478482484817505f,-2.926006317138672f,1.1519678831100464f,-0.49200639128685f,0.2120276689529419f,1.1263060569763184f,-0.18562918901443481f,-0.28624120354652405f,-2.980358123779297f,-1.6278588771820068f,-0.29330405592918396f,-0.1960911899805069f,-0.6492596864700317f}, |
Lightvalve | 83:b5bba84861d8 | 264 | {-0.27890223264694214f,-0.053967710584402084f,-0.10038548707962036f,-0.13000500202178955f,-0.1145521029829979f,-0.4984058737754822f,-0.3744382858276367f,-0.2674597501754761f,-0.1953929215669632f,-0.15229563415050507f,-0.43962323665618896f,-0.23222799599170685f,-0.5651020407676697f,-3.210010051727295f,-0.02410009503364563f,0.10129088163375854f,0.22686699032783508f,-0.30486053228378296f,-0.891793429851532f,-0.05401764065027237f,1.176089882850647f,0.9243209958076477f,-0.5909084677696228f,0.10166658461093903f,1.2401347160339355f,0.9118716716766357f,-0.18564987182617188f,-3.3185391426086426f,0.47212836146354675f,0.06508117914199829f,-0.03392584249377251f,-0.7368423342704773f}, |
Lightvalve | 83:b5bba84861d8 | 265 | {0.3047083914279938f,-0.054776135832071304f,-0.26112133264541626f,-1.2606362104415894f,0.7822770476341248f,-0.49979227781295776f,-0.13952845335006714f,-0.25786101818084717f,-0.7730901837348938f,-0.2839975357055664f,-0.48489639163017273f,-0.36110901832580566f,1.1508419513702393f,-0.4725552201271057f,0.062144935131073f,-0.28920799493789673f,0.03473195433616638f,-0.0016761720180511475f,-0.11218152195215225f,-0.9571448564529419f,0.9306015968322754f,-0.030425677075982094f,0.21862870454788208f,-0.07393793016672134f,-0.8341898918151855f,-0.6905441284179688f,-0.32371214032173157f,-0.6016409397125244f,-2.290815591812134f,0.017086774110794067f,-0.3676358461380005f,-1.1898276805877686f}, |
Lightvalve | 66:a8e6799dbce3 | 266 | {-0.06136500835418701f,-0.11579577624797821f,-0.23311558365821838f,-0.020844489336013794f,0.161813884973526f,0.22929790616035461f,0.11958792805671692f,-0.0384809672832489f,-0.10647237300872803f,-0.09010881185531616f,0.22322741150856018f,-0.1071339100599289f,0.05349445343017578f,-0.23458370566368103f,0.040097206830978394f,0.08616101741790771f,-0.15468145906925201f,-0.21275553107261658f,-0.21210846304893494f,-0.23840199410915375f,0.12352427840232849f,0.282552570104599f,0.14114680886268616f,0.09007054567337036f,-0.05948364734649658f,0.12031787633895874f,-0.184563547372818f,0.07786750793457031f,-0.2169322669506073f,-0.24735762178897858f,-0.0892629474401474f,-0.11765947937965393f}, |
Lightvalve | 67:c2812cf26c38 | 267 | {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 | 83:b5bba84861d8 | 268 | {-0.16101892292499542f,0.06497228145599365f,0.11283258348703384f,0.10336695611476898f,0.17365415394306183f,-0.4159308969974518f,0.1589156985282898f,-0.17396175861358643f,0.17419855296611786f,-0.3644612431526184f,0.18124964833259583f,-0.12519730627536774f,0.2603936195373535f,-0.2726782560348511f,-0.2592318058013916f,0.1978430449962616f,0.18047624826431274f,0.2863751947879791f,-0.31257450580596924f,-0.02364540845155716f,-0.2651146352291107f,-0.011300995945930481f,0.278888076543808f,0.13123968243598938f,-0.07520616054534912f,-0.28873488306999207f,-0.09411037713289261f,0.379178524017334f,0.5606015920639038f,0.18439257144927979f,0.0877244770526886f,-0.0018147015944123268f}, |
Lightvalve | 83:b5bba84861d8 | 269 | {0.261911004781723f,-0.28497835993766785f,-0.2993849217891693f,-0.02090274915099144f,0.17428316175937653f,0.04684234783053398f,-0.06670857965946198f,-0.030254334211349487f,-0.2705722749233246f,0.1197996437549591f,0.01667046546936035f,-0.2924177646636963f,0.2824140191078186f,-0.13779650628566742f,-0.20773646235466003f,-0.10781967639923096f,-0.15712574124336243f,0.16112294793128967f,0.23715557157993317f,0.19160643219947815f,0.2064272165298462f,0.11916334182024002f,-0.3001303970813751f,0.14906415343284607f,0.1447947919368744f,0.0025720298290252686f,-0.0866558700799942f,-0.09870617091655731f,0.08046156913042068f,0.21125611662864685f,-0.05751854181289673f,-0.22727590799331665f}, |
Lightvalve | 83:b5bba84861d8 | 270 | {0.14277681708335876f,-0.1988920122385025f,-0.0071234330534935f,-0.22211427986621857f,-1.0135077238082886f,1.099861979484558f,0.014805803075432777f,-0.27022814750671387f,-0.05514232814311981f,-0.3372078239917755f,-1.6646058559417725f,0.18551066517829895f,0.2513187527656555f,1.2335745096206665f,-0.03100520372390747f,-0.2484396994113922f,0.06366744637489319f,-0.2764144539833069f,-1.5335239171981812f,0.046944133937358856f,-0.8008513450622559f,-0.15706850588321686f,0.16810284554958344f,-0.24267734587192535f,-0.6570789813995361f,-0.9997603297233582f,-0.05704247206449509f,-4.044283390045166f,0.5052591562271118f,-0.10488687455654144f,-0.21563708782196045f,-0.9821208119392395f}, |
Lightvalve | 83:b5bba84861d8 | 271 | {0.29069945216178894f,-0.23835359513759613f,0.019009560346603394f,-0.30945703387260437f,0.11959921568632126f,-0.16606459021568298f,0.045349299907684326f,-0.17138783633708954f,-0.15196284651756287f,0.028545528650283813f,-0.12396366894245148f,-0.15074089169502258f,-0.12348470836877823f,-0.21887588500976562f,0.09875330328941345f,0.08164769411087036f,0.2294725477695465f,0.10683679580688477f,-0.26680272817611694f,-0.11484634131193161f,0.16850495338439941f,0.26372745633125305f,0.16651621460914612f,-0.15362010896205902f,0.3393794298171997f,0.023651927709579468f,-0.1729920208454132f,0.2149815857410431f,0.1284196823835373f,0.19045329093933105f,0.02994692325592041f,-0.18855193257331848f}, |
Lightvalve | 83:b5bba84861d8 | 272 | {0.1991647183895111f,0.12534403800964355f,-0.04112154245376587f,0.23123982548713684f,-0.3497884273529053f,-0.1329444795846939f,-0.1610087752342224f,-0.031804412603378296f,0.10274738073348999f,-0.25018924474716187f,0.2946159541606903f,-0.057292819023132324f,-0.05505186691880226f,0.24260291457176208f,0.2151305377483368f,0.2952744662761688f,-0.21319252252578735f,0.04970458149909973f,0.05997588858008385f,0.3050673305988312f,0.093289315700531f,0.014060966670513153f,0.13887640833854675f,0.25299301743507385f,0.05719318985939026f,-0.07015113532543182f,-0.287551611661911f,-0.19553273916244507f,0.033006701618433f,-0.24420931935310364f,0.015819430351257324f,-0.10595546662807465f}, |
Lightvalve | 83:b5bba84861d8 | 273 | {0.12202468514442444f,0.14455528557300568f,-0.10034829378128052f,-0.32563531398773193f,0.1958308219909668f,0.0528622604906559f,-0.06113804876804352f,-0.11568751931190491f,0.3194258213043213f,-0.2827228009700775f,-0.06917986273765564f,-0.11160935461521149f,-0.10023307800292969f,-0.21255841851234436f,-0.06735922396183014f,0.05864924192428589f,-0.25733181834220886f,-0.17565661668777466f,0.0866393893957138f,-0.11256621032953262f,-0.2250165492296219f,0.15532204508781433f,0.173453688621521f,-0.05681343376636505f,0.21084356307983398f,0.1795230209827423f,0.19069638848304749f,0.04286597669124603f,-0.19449935853481293f,0.2425754964351654f,-0.22172409296035767f,-0.009572982788085938f}, |
Lightvalve | 83:b5bba84861d8 | 274 | {-0.3055141270160675f,-0.23396925628185272f,-0.13814328610897064f,0.1697840690612793f,0.5527177453041077f,0.9395255446434021f,0.01318096648901701f,0.21086838841438293f,-0.10907246172428131f,-0.03148574009537697f,1.7018142938613892f,-0.24582231044769287f,0.018156766891479492f,-0.5426051020622253f,-0.023131370544433594f,0.036719828844070435f,0.16260939836502075f,0.05286213755607605f,1.856697916984558f,-0.15212079882621765f,1.5639160871505737f,-0.8050225377082825f,0.11681541800498962f,0.17590752243995667f,1.3197003602981567f,0.1411813497543335f,-0.2059394270181656f,1.1517573595046997f,0.5357142686843872f,0.1865309774875641f,0.02574482187628746f,-0.8128886222839355f}, |
Lightvalve | 83:b5bba84861d8 | 275 | {0.1782623827457428f,-0.03187307342886925f,-0.4789814352989197f,-0.46980202198028564f,1.192139983177185f,1.404646396636963f,-0.3069397509098053f,0.1475539207458496f,0.08588419109582901f,-0.03753579407930374f,0.4975596070289612f,-0.3257468044757843f,-1.0051426887512207f,2.7759180068969727f,-0.2527656555175781f,-0.3049176335334778f,0.032145023345947266f,-0.25376296043395996f,-3.2294020652770996f,-0.23520873486995697f,-3.906024932861328f,-0.4205939471721649f,-0.024129211902618408f,-0.026399224996566772f,0.905106246471405f,-2.5426788330078125f,-0.18039503693580627f,0.7740312814712524f,-0.6857896447181702f,0.1616479754447937f,-0.2583863139152527f,0.06322457641363144f}, |
Lightvalve | 83:b5bba84861d8 | 276 | {-0.17396044731140137f,-0.13460135459899902f,-0.3125343322753906f,-0.6462283134460449f,-0.2689957618713379f,-0.24209626019001007f,-0.21531152725219727f,-0.1761629432439804f,-0.49065038561820984f,-0.5117147564888f,0.4159700274467468f,-0.36334797739982605f,0.09220767021179199f,0.025269145146012306f,-0.19851773977279663f,-0.10762731730937958f,0.14198419451713562f,0.10370296239852905f,-0.9062182903289795f,-0.4525596499443054f,-0.3710545301437378f,-0.22467981278896332f,0.1569238305091858f,-0.19857197999954224f,0.09245038032531738f,-0.2665709853172302f,0.19575466215610504f,0.05997905507683754f,0.27721330523490906f,-0.1200934648513794f,-0.26498913764953613f,-0.9675976634025574f}, |
Lightvalve | 83:b5bba84861d8 | 277 | {-0.12546227872371674f,-0.040895745158195496f,-0.08090300858020782f,0.13400162756443024f,-0.14662517607212067f,-0.29301342368125916f,-0.28310835361480713f,-0.020981580018997192f,0.010351124219596386f,-0.1294756382703781f,-0.19499319791793823f,0.046816736459732056f,-0.005123240407556295f,-0.09859045594930649f,-0.0649729073047638f,0.2468220293521881f,0.060016900300979614f,-0.16779978573322296f,0.07262704521417618f,0.0829080268740654f,-0.16057102382183075f,0.09701334685087204f,-0.28036168217658997f,0.22389158606529236f,-0.0448453351855278f,0.020356476306915283f,-0.26727598905563354f,0.249968022108078f,0.08561224490404129f,-0.000007510185241699219f,0.094448983669281f,-0.08219978213310242f}, |
Lightvalve | 83:b5bba84861d8 | 278 | {0.07555973529815674f,-0.0029259920120239258f,-0.08789914846420288f,0.06678077578544617f,-0.1265704184770584f,-0.025904223322868347f,-0.14982634782791138f,0.12075316905975342f,-0.2766430675983429f,0.013024389743804932f,0.2112746685743332f,-0.20200279355049133f,0.10446741431951523f,-0.39846673607826233f,0.2882818281650543f,0.05304515361785889f,-0.15297894179821014f,0.07341468334197998f,0.05268138647079468f,0.1067940890789032f,-0.12317532300949097f,-0.16722092032432556f,0.1843600869178772f,0.2517976462841034f,-0.0900656133890152f,-0.16655482351779938f,-0.23432010412216187f,0.15254825353622437f,-0.20769748091697693f,-0.017525076866149902f,0.20926335453987122f,-0.1038133054971695f}, |
Lightvalve | 83:b5bba84861d8 | 279 | {0.06582912802696228f,0.2796666920185089f,-0.2556927502155304f,0.0023079216480255127f,0.3613894581794739f,-0.01434530969709158f,0.06556430459022522f,0.29767414927482605f,0.40706509351730347f,-0.16670267283916473f,-0.2714720368385315f,-0.06570860743522644f,-0.06654709577560425f,0.021350549533963203f,-0.014884740114212036f,-0.05300724506378174f,0.26490333676338196f,0.15243005752563477f,0.0841580331325531f,0.2353842556476593f,0.39228516817092896f,0.004803914111107588f,-0.04174882173538208f,-0.11559568345546722f,-0.216618150472641f,0.21069613099098206f,-0.19532959163188934f,-0.09529750049114227f,0.032513976097106934f,-0.2712400257587433f,-0.19435247778892517f,-0.23200613260269165f}, |
Lightvalve | 83:b5bba84861d8 | 280 | {-0.1299392580986023f,-0.06208275258541107f,-0.18067686259746552f,0.062329649925231934f,-0.22328625619411469f,-0.06877543032169342f,-0.19175797700881958f,0.02903696894645691f,-0.2614779472351074f,0.016345679759979248f,-0.24952805042266846f,0.2033931314945221f,-0.29699447751045227f,0.08271035552024841f,0.13206014037132263f,0.15829482674598694f,-0.21012049913406372f,0.2088232934474945f,0.07014858722686768f,-0.19175665080547333f,0.28649166226387024f,0.05041047930717468f,-0.27260470390319824f,-0.025072306394577026f,0.2722422182559967f,-0.007939159870147705f,-0.22979341447353363f,0.11936154961585999f,0.1298319399356842f,0.18135693669319153f,-0.008151531219482422f,0.15906798839569092f}, |
Lightvalve | 83:b5bba84861d8 | 281 | {0.07638216018676758f,0.07732139527797699f,-0.30373215675354004f,-0.27519625425338745f,0.13013198971748352f,0.015126615762710571f,0.2795381247997284f,-0.25668495893478394f,-0.08089734613895416f,0.09238649159669876f,-0.026776641607284546f,0.02524423599243164f,0.11048605293035507f,0.25715363025665283f,-0.029521822929382324f,-0.19500072300434113f,0.06506577134132385f,-0.011876672506332397f,0.12295812368392944f,0.24479621648788452f,0.1355903446674347f,-0.00015643970982637256f,-0.1791561245918274f,-0.17324526607990265f,0.21761217713356018f,0.1901901364326477f,-0.27123093605041504f,-0.06252744793891907f,-0.11570298671722412f,0.22636333107948303f,-0.2677184045314789f,0.21909776329994202f}, |
Lightvalve | 66:a8e6799dbce3 | 282 | }; |
Lightvalve | 65:a2d7c63419c2 | 283 | |
Lightvalve | 83:b5bba84861d8 | 284 | const float hout[32] = { 0.3285340666770935f,0.13846565783023834f,-0.07104799896478653f,0.18257376551628113f,-0.16361720860004425f,0.11612511426210403f,0.03588892146945f,0.1081397533416748f,0.11910854279994965f,0.10337844491004944f,0.13150642812252045f,-0.11640904098749161f,-0.23372183740139008f,0.1647065281867981f,0.2356991171836853f,-0.1462659239768982f,0.09851181507110596f,-0.21499931812286377f,0.0772331953048706f,-0.07612764835357666f,-0.23285314440727234f,-0.18265759944915771f,0.04004863277077675f,-0.11024488508701324f,0.2793011963367462f,0.2669006288051605f,-0.3283284902572632f,-0.8490635752677917f,0.3065551519393921f,-0.3257754445075989f,-0.22434811294078827f,-0.19677908718585968f }; |
Lightvalve | 66:a8e6799dbce3 | 285 | |
Lightvalve | 83:b5bba84861d8 | 286 | const float b1[32] = { 0.5102354884147644f,1.4454234838485718f,-1.7145336866378784f,-0.13135932385921478f,1.8859272003173828f,0.7050048112869263f,-0.08465349674224854f,1.0487871170043945f,0.858688235282898f,-1.6059504747390747f,0.5568068623542786f,2.217176675796509f,-0.3425353467464447f,-0.9377808570861816f,-1.087764859199524f,0.9572884440422058f,0.5541136860847473f,-0.26377663016319275f,-0.449740469455719f,0.5352871417999268f,-0.284685879945755f,-1.1118980646133423f,-1.6770726442337036f,-1.2263047695159912f,3.0480804443359375f,-2.0880801677703857f,-1.0489267110824585f,0.9022058844566345f,0.2357945293188095f,-1.0887231826782227f,2.7682852745056152f,-0.5293285846710205f }; |
Lightvalve | 65:a2d7c63419c2 | 287 | |
Lightvalve | 83:b5bba84861d8 | 288 | const float b2[32] = { -0.3680103123188019f,-0.7642630338668823f,-1.4564176797866821f,-0.6497427821159363f,-0.6939148902893066f,-0.020249705761671066f,-0.372101366519928f,-0.30969977378845215f,-1.20063054561615f,-1.912178635597229f,0.023847151547670364f,0.5569860935211182f,-0.2355569750070572f,1.793886423110962f,-0.5586162209510803f,1.0859285593032837f,-1.798204779624939f,-1.5844906568527222f,0.009519282728433609f,-0.46726593375205994f,0.49785974621772766f,0.052135393023490906f,-0.07042714953422546f,-1.0452868938446045f,0.25523853302001953f,2.1917080879211426f,0.15757890045642853f,-0.2608587145805359f,-0.7634363770484924f,-0.5724443197250366f,-1.323826551437378f,-1.3565272092819214f }; |
Lightvalve | 65:a2d7c63419c2 | 289 | |
Lightvalve | 83:b5bba84861d8 | 290 | const float b3[32] = { -1.963319182395935f,-0.5446904301643372f,-0.3016548156738281f,-0.8402144312858582f,-0.6773909330368042f,0.8409193754196167f,-0.6582568883895874f,-0.6562485098838806f,-0.009772130288183689f,-0.06044171005487442f,1.192558765411377f,-0.5217856168746948f,-1.4038946628570557f,-0.7718222141265869f,-1.1428403854370117f,-0.3598397970199585f,-1.3594286441802979f,-1.0192245244979858f,-0.9686634540557861f,-0.27930739521980286f,-3.1515591144561768f,-1.206493854522705f,-1.1485735177993774f,-0.8956993222236633f,0.4146289527416229f,-1.1049379110336304f,-0.12451136857271194f,-1.522766351699829f,-1.0368304252624512f,-2.3236680030822754f,-0.17192073166370392f,1.6605290174484253f }; |
Lightvalve | 66:a8e6799dbce3 | 291 | |
Lightvalve | 83:b5bba84861d8 | 292 | const float bout[1] = { -0.11106075346469879f }; |
Lightvalve | 61:bc8c8270f0ab | 293 | |
Lightvalve | 61:bc8c8270f0ab | 294 | |
GiJeongKim | 0:51c43836c1d7 | 295 | int main() |
GiJeongKim | 0:51c43836c1d7 | 296 | { |
Lightvalve | 66:a8e6799dbce3 | 297 | |
Lightvalve | 65:a2d7c63419c2 | 298 | HAL_Init(); |
Lightvalve | 65:a2d7c63419c2 | 299 | SystemClock_Config(); |
Lightvalve | 65:a2d7c63419c2 | 300 | |
jobuuu | 6:df07d3491e3a | 301 | /********************************* |
jobuuu | 1:e04e563be5ce | 302 | *** Initialization |
jobuuu | 6:df07d3491e3a | 303 | *********************************/ |
Lightvalve | 69:3995ffeaa786 | 304 | LED = 0; |
Lightvalve | 61:bc8c8270f0ab | 305 | pc.baud(9600); |
Lightvalve | 21:e5f1a43ea6f9 | 306 | |
GiJeongKim | 0:51c43836c1d7 | 307 | // i2c init |
Lightvalve | 8:5d2eebdad025 | 308 | i2c.frequency(400 * 1000); // 0.4 mHz |
Lightvalve | 8:5d2eebdad025 | 309 | wait_ms(2); // Power Up wait |
Lightvalve | 8:5d2eebdad025 | 310 | look_for_hardware_i2c(); // Hardware present |
Lightvalve | 8:5d2eebdad025 | 311 | init_as5510(i2c_slave_addr1); |
Lightvalve | 11:82d8768d7351 | 312 | make_delay(); |
jobuuu | 2:a1c0a37df760 | 313 | |
GiJeongKim | 0:51c43836c1d7 | 314 | // // spi init |
Lightvalve | 16:903b5a4433b4 | 315 | //eeprom.format(8,3); |
Lightvalve | 16:903b5a4433b4 | 316 | //eeprom.frequency(5000000); //5M |
GiJeongKim | 0:51c43836c1d7 | 317 | enc.format(8,0); |
GiJeongKim | 0:51c43836c1d7 | 318 | enc.frequency(5000000); //5M |
Lightvalve | 11:82d8768d7351 | 319 | make_delay(); |
Lightvalve | 21:e5f1a43ea6f9 | 320 | |
Lightvalve | 16:903b5a4433b4 | 321 | //rom |
Lightvalve | 19:23b7c1ad8683 | 322 | ROM_CALL_DATA(); |
Lightvalve | 16:903b5a4433b4 | 323 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 324 | |
GiJeongKim | 0:51c43836c1d7 | 325 | // ADC init |
jobuuu | 5:a4319f79457b | 326 | Init_ADC(); |
Lightvalve | 11:82d8768d7351 | 327 | make_delay(); |
jobuuu | 2:a1c0a37df760 | 328 | |
GiJeongKim | 0:51c43836c1d7 | 329 | // Pwm init |
GiJeongKim | 0:51c43836c1d7 | 330 | Init_PWM(); |
GiJeongKim | 0:51c43836c1d7 | 331 | TIM4->CR1 ^= TIM_CR1_UDIS; |
Lightvalve | 11:82d8768d7351 | 332 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 333 | |
Lightvalve | 11:82d8768d7351 | 334 | // TMR3 init |
Lightvalve | 11:82d8768d7351 | 335 | Init_TMR3(); |
Lightvalve | 11:82d8768d7351 | 336 | TIM3->CR1 ^= TIM_CR1_UDIS; |
Lightvalve | 11:82d8768d7351 | 337 | make_delay(); |
Lightvalve | 21:e5f1a43ea6f9 | 338 | |
Lightvalve | 50:3c630b5eba9f | 339 | // TMR2 init |
Lightvalve | 56:6f50d9d3bfee | 340 | // Init_TMR2(); |
Lightvalve | 56:6f50d9d3bfee | 341 | // TIM2->CR1 ^= TIM_CR1_UDIS; |
Lightvalve | 56:6f50d9d3bfee | 342 | // make_delay(); |
Lightvalve | 21:e5f1a43ea6f9 | 343 | |
GiJeongKim | 0:51c43836c1d7 | 344 | // CAN |
jobuuu | 2:a1c0a37df760 | 345 | can.attach(&CAN_RX_HANDLER); |
Lightvalve | 11:82d8768d7351 | 346 | CAN_ID_INIT(); |
Lightvalve | 11:82d8768d7351 | 347 | make_delay(); |
Lightvalve | 34:bb2ca2fc2a8e | 348 | |
Lightvalve | 23:59218d4a256d | 349 | //Timer priority |
Lightvalve | 23:59218d4a256d | 350 | NVIC_SetPriority(TIM3_IRQn, 2); |
Lightvalve | 57:f4819de54e7a | 351 | //NVIC_SetPriority(TIM2_IRQn, 3); |
Lightvalve | 54:647072f5307a | 352 | NVIC_SetPriority(TIM4_IRQn, 3); |
Lightvalve | 34:bb2ca2fc2a8e | 353 | |
Lightvalve | 23:59218d4a256d | 354 | //can.reset(); |
Lightvalve | 19:23b7c1ad8683 | 355 | can.filter(msg.id, 0xFFFFF000, CANStandard); |
Lightvalve | 34:bb2ca2fc2a8e | 356 | |
GiJeongKim | 0:51c43836c1d7 | 357 | // spi _ enc |
GiJeongKim | 0:51c43836c1d7 | 358 | spi_enc_set_init(); |
Lightvalve | 11:82d8768d7351 | 359 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 360 | |
Lightvalve | 11:82d8768d7351 | 361 | //DAC init |
Lightvalve | 58:2eade98630e2 | 362 | if (SENSING_MODE == 0) { |
Lightvalve | 58:2eade98630e2 | 363 | dac_1 = TORQUE_VREF / 3.3f; |
Lightvalve | 58:2eade98630e2 | 364 | dac_2 = 0.0f; |
Lightvalve | 58:2eade98630e2 | 365 | } else if (SENSING_MODE == 1) { |
Lightvalve | 58:2eade98630e2 | 366 | dac_1 = PRES_A_VREF / 3.3f; |
Lightvalve | 58:2eade98630e2 | 367 | dac_2 = PRES_B_VREF / 3.3f; |
Lightvalve | 58:2eade98630e2 | 368 | } |
Lightvalve | 11:82d8768d7351 | 369 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 370 | |
Lightvalve | 19:23b7c1ad8683 | 371 | for (int i=0; i<50; i++) { |
Lightvalve | 11:82d8768d7351 | 372 | if(i%2==0) |
Lightvalve | 38:118df027d851 | 373 | ID_index_array[i] = - i * 0.5f; |
Lightvalve | 11:82d8768d7351 | 374 | else |
Lightvalve | 38:118df027d851 | 375 | ID_index_array[i] = (i+1) * 0.5f; |
Lightvalve | 11:82d8768d7351 | 376 | } |
Lightvalve | 61:bc8c8270f0ab | 377 | |
Lightvalve | 61:bc8c8270f0ab | 378 | |
jobuuu | 6:df07d3491e3a | 379 | /************************************ |
jobuuu | 1:e04e563be5ce | 380 | *** Program is operating! |
jobuuu | 6:df07d3491e3a | 381 | *************************************/ |
GiJeongKim | 0:51c43836c1d7 | 382 | while(1) { |
Lightvalve | 66:a8e6799dbce3 | 383 | // if(timer_while==1000 && OPERATING_MODE==5) { |
Lightvalve | 66:a8e6799dbce3 | 384 | //if(timer_while==1000) { |
Lightvalve | 65:a2d7c63419c2 | 385 | //i2c |
Lightvalve | 66:a8e6799dbce3 | 386 | |
Lightvalve | 65:a2d7c63419c2 | 387 | read_field(i2c_slave_addr1); |
Lightvalve | 65:a2d7c63419c2 | 388 | if(DIR_VALVE_ENC < 0) value = 1023 - value; |
Lightvalve | 65:a2d7c63419c2 | 389 | // if(LED==1) { |
Lightvalve | 65:a2d7c63419c2 | 390 | // LED=0; |
Lightvalve | 65:a2d7c63419c2 | 391 | // } else |
Lightvalve | 65:a2d7c63419c2 | 392 | // LED = 1; |
Lightvalve | 65:a2d7c63419c2 | 393 | timer_while = 0; |
Lightvalve | 66:a8e6799dbce3 | 394 | //} |
Lightvalve | 66:a8e6799dbce3 | 395 | |
Lightvalve | 66:a8e6799dbce3 | 396 | timer_while ++; |
Lightvalve | 66:a8e6799dbce3 | 397 | |
Lightvalve | 73:f80dc3970c99 | 398 | if(NN_Control_Flag == 0) { |
Lightvalve | 73:f80dc3970c99 | 399 | LED = 0; |
Lightvalve | 73:f80dc3970c99 | 400 | } |
Lightvalve | 66:a8e6799dbce3 | 401 | |
Lightvalve | 73:f80dc3970c99 | 402 | else if(NN_Control_Flag == 1) { |
Lightvalve | 66:a8e6799dbce3 | 403 | float output1[32] = { 0.0f }; |
Lightvalve | 66:a8e6799dbce3 | 404 | float output2[32] = { 0.0f }; |
Lightvalve | 66:a8e6799dbce3 | 405 | float output3[32] = { 0.0f }; |
Lightvalve | 66:a8e6799dbce3 | 406 | float output = 0.0f; |
Lightvalve | 65:a2d7c63419c2 | 407 | |
Lightvalve | 66:a8e6799dbce3 | 408 | for (int index2 = 0; index2 < 32; index2++) { |
Lightvalve | 68:328e1be06f5d | 409 | for (int index1 = 0; index1 < num_input; index1++) { |
Lightvalve | 66:a8e6799dbce3 | 410 | output1[index2] = output1[index2] |
Lightvalve | 73:f80dc3970c99 | 411 | + h1[index1][index2] * input_NN[index1]; |
Lightvalve | 66:a8e6799dbce3 | 412 | } |
Lightvalve | 66:a8e6799dbce3 | 413 | output1[index2] = output1[index2] + b1[index2]; |
Lightvalve | 66:a8e6799dbce3 | 414 | if (output1[index2] < 0) { |
Lightvalve | 66:a8e6799dbce3 | 415 | output1[index2] = 0; |
Lightvalve | 66:a8e6799dbce3 | 416 | } |
Lightvalve | 66:a8e6799dbce3 | 417 | } |
Lightvalve | 65:a2d7c63419c2 | 418 | |
Lightvalve | 66:a8e6799dbce3 | 419 | for (int index2 = 0; index2 < 32; index2++) { |
Lightvalve | 66:a8e6799dbce3 | 420 | for (int index1 = 0; index1 < 32; index1++) { |
Lightvalve | 66:a8e6799dbce3 | 421 | output2[index2] = output2[index2] |
Lightvalve | 66:a8e6799dbce3 | 422 | + h2[index1][index2] * output1[index1]; |
Lightvalve | 66:a8e6799dbce3 | 423 | } |
Lightvalve | 66:a8e6799dbce3 | 424 | output2[index2] = output2[index2] + b2[index2]; |
Lightvalve | 66:a8e6799dbce3 | 425 | if (output2[index2] < 0) { |
Lightvalve | 66:a8e6799dbce3 | 426 | output2[index2] = 0; |
Lightvalve | 66:a8e6799dbce3 | 427 | } |
Lightvalve | 66:a8e6799dbce3 | 428 | } |
Lightvalve | 65:a2d7c63419c2 | 429 | |
Lightvalve | 66:a8e6799dbce3 | 430 | for (int index2 = 0; index2 < 32; index2++) { |
Lightvalve | 66:a8e6799dbce3 | 431 | for (int index1 = 0; index1 < 32; index1++) { |
Lightvalve | 66:a8e6799dbce3 | 432 | output3[index2] = output3[index2] |
Lightvalve | 66:a8e6799dbce3 | 433 | + h3[index1][index2] * output2[index1]; |
Lightvalve | 66:a8e6799dbce3 | 434 | } |
Lightvalve | 66:a8e6799dbce3 | 435 | output3[index2] = output3[index2] + b3[index2]; |
Lightvalve | 66:a8e6799dbce3 | 436 | if (output3[index2] < 0) { |
Lightvalve | 66:a8e6799dbce3 | 437 | output3[index2] = 0; |
Lightvalve | 66:a8e6799dbce3 | 438 | } |
Lightvalve | 65:a2d7c63419c2 | 439 | } |
Lightvalve | 66:a8e6799dbce3 | 440 | |
Lightvalve | 66:a8e6799dbce3 | 441 | for (int index2 = 0; index2 < 1; index2++) { |
Lightvalve | 66:a8e6799dbce3 | 442 | for (int index1 = 0; index1 < 32; index1++) { |
Lightvalve | 73:f80dc3970c99 | 443 | output = output + hout[index1] * output3[index1]; |
Lightvalve | 66:a8e6799dbce3 | 444 | } |
Lightvalve | 66:a8e6799dbce3 | 445 | output = output + bout[index2]; |
Lightvalve | 73:f80dc3970c99 | 446 | |
Lightvalve | 66:a8e6799dbce3 | 447 | } |
Lightvalve | 73:f80dc3970c99 | 448 | output = 1.0f/(1.0f+exp(-output)); |
Lightvalve | 68:328e1be06f5d | 449 | output = output * 20000.0f - 10000.0f; |
Lightvalve | 66:a8e6799dbce3 | 450 | if(output>=0) { |
Lightvalve | 66:a8e6799dbce3 | 451 | valve_pos.ref = output*0.0001f*((double)VALVE_MAX_POS - (double) VALVE_CENTER) + (double) VALVE_CENTER; |
Lightvalve | 66:a8e6799dbce3 | 452 | } else { |
Lightvalve | 66:a8e6799dbce3 | 453 | valve_pos.ref = -output*0.0001f*((double)VALVE_MIN_POS - (double) VALVE_CENTER) + (double) VALVE_CENTER; |
Lightvalve | 65:a2d7c63419c2 | 454 | } |
Lightvalve | 69:3995ffeaa786 | 455 | |
Lightvalve | 69:3995ffeaa786 | 456 | if(LED==1) { |
Lightvalve | 69:3995ffeaa786 | 457 | LED=0; |
Lightvalve | 69:3995ffeaa786 | 458 | } else |
Lightvalve | 69:3995ffeaa786 | 459 | LED = 1; |
Lightvalve | 69:3995ffeaa786 | 460 | |
Lightvalve | 65:a2d7c63419c2 | 461 | } |
Lightvalve | 62:b5452adfb2cd | 462 | |
Lightvalve | 69:3995ffeaa786 | 463 | |
Lightvalve | 66:a8e6799dbce3 | 464 | |
GiJeongKim | 0:51c43836c1d7 | 465 | } |
jobuuu | 1:e04e563be5ce | 466 | } |
jobuuu | 1:e04e563be5ce | 467 | |
Lightvalve | 33:91b17819ec30 | 468 | float DDV_JOINT_POS_FF(float REF_JOINT_VEL) |
Lightvalve | 14:8e7590227d22 | 469 | { |
Lightvalve | 14:8e7590227d22 | 470 | |
Lightvalve | 13:747daba9cf59 | 471 | int i = 0; |
Lightvalve | 48:889798ff9329 | 472 | float Ref_Valve_Pos_FF = 0.0f; |
Lightvalve | 14:8e7590227d22 | 473 | for(i=0; i<VALVE_POS_NUM; i++) { |
Lightvalve | 14:8e7590227d22 | 474 | 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 | 475 | if(i==0) { |
Lightvalve | 50:3c630b5eba9f | 476 | if(JOINT_VEL[i+1] == JOINT_VEL[i]) { |
Lightvalve | 57:f4819de54e7a | 477 | Ref_Valve_Pos_FF = (float) VALVE_CENTER; |
Lightvalve | 50:3c630b5eba9f | 478 | } else { |
Lightvalve | 57:f4819de54e7a | 479 | 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 | 480 | } |
Lightvalve | 14:8e7590227d22 | 481 | } else { |
Lightvalve | 50:3c630b5eba9f | 482 | if(JOINT_VEL[i+1] == JOINT_VEL[i-1]) { |
Lightvalve | 57:f4819de54e7a | 483 | Ref_Valve_Pos_FF = (float) VALVE_CENTER; |
Lightvalve | 50:3c630b5eba9f | 484 | } else { |
Lightvalve | 57:f4819de54e7a | 485 | 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 | 486 | } |
Lightvalve | 13:747daba9cf59 | 487 | } |
Lightvalve | 13:747daba9cf59 | 488 | break; |
Lightvalve | 13:747daba9cf59 | 489 | } |
Lightvalve | 13:747daba9cf59 | 490 | } |
Lightvalve | 14:8e7590227d22 | 491 | if(REF_JOINT_VEL > max(JOINT_VEL[VALVE_POS_NUM-1], JOINT_VEL[VALVE_POS_NUM-2])) { |
Lightvalve | 33:91b17819ec30 | 492 | Ref_Valve_Pos_FF = (float) VALVE_MAX_POS; |
Lightvalve | 14:8e7590227d22 | 493 | } else if(REF_JOINT_VEL < min(JOINT_VEL[VALVE_POS_NUM-1], JOINT_VEL[VALVE_POS_NUM-2])) { |
Lightvalve | 33:91b17819ec30 | 494 | Ref_Valve_Pos_FF = (float) VALVE_MIN_POS; |
Lightvalve | 13:747daba9cf59 | 495 | } |
Lightvalve | 36:a46e63505ed8 | 496 | |
Lightvalve | 57:f4819de54e7a | 497 | Ref_Valve_Pos_FF = (float) VELOCITY_COMP_GAIN * 0.01f * (float) (Ref_Valve_Pos_FF - (float) VALVE_CENTER); |
Lightvalve | 13:747daba9cf59 | 498 | return Ref_Valve_Pos_FF; |
Lightvalve | 50:3c630b5eba9f | 499 | |
Lightvalve | 13:747daba9cf59 | 500 | } |
jobuuu | 6:df07d3491e3a | 501 | |
jobuuu | 6:df07d3491e3a | 502 | |
Lightvalve | 30:8d561f16383b | 503 | void VALVE_POS_CONTROL(float REF_VALVE_POS) |
Lightvalve | 14:8e7590227d22 | 504 | { |
Lightvalve | 13:747daba9cf59 | 505 | int i = 0; |
Lightvalve | 13:747daba9cf59 | 506 | |
Lightvalve | 38:118df027d851 | 507 | if(REF_VALVE_POS > VALVE_MAX_POS) { |
Lightvalve | 38:118df027d851 | 508 | REF_VALVE_POS = VALVE_MAX_POS; |
Lightvalve | 38:118df027d851 | 509 | } else if(REF_VALVE_POS < VALVE_MIN_POS) { |
Lightvalve | 38:118df027d851 | 510 | REF_VALVE_POS = VALVE_MIN_POS; |
Lightvalve | 38:118df027d851 | 511 | } |
Lightvalve | 38:118df027d851 | 512 | |
Lightvalve | 13:747daba9cf59 | 513 | valve_pos_err = REF_VALVE_POS - value; |
Lightvalve | 13:747daba9cf59 | 514 | valve_pos_err_diff = valve_pos_err - valve_pos_err_old; |
Lightvalve | 13:747daba9cf59 | 515 | valve_pos_err_old = valve_pos_err; |
Lightvalve | 13:747daba9cf59 | 516 | valve_pos_err_sum += valve_pos_err; |
Lightvalve | 13:747daba9cf59 | 517 | if (valve_pos_err_sum > 1000) valve_pos_err_sum = 1000; |
Lightvalve | 13:747daba9cf59 | 518 | if (valve_pos_err_sum<-1000) valve_pos_err_sum = -1000; |
Lightvalve | 13:747daba9cf59 | 519 | |
Lightvalve | 13:747daba9cf59 | 520 | 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 | 521 | |
Lightvalve | 18:b8adf1582ea3 | 522 | for(i=0; i<24; i++) { |
Lightvalve | 14:8e7590227d22 | 523 | if(REF_VALVE_POS >= min(VALVE_POS_VS_PWM[i],VALVE_POS_VS_PWM[i+1]) && REF_VALVE_POS <= max(VALVE_POS_VS_PWM[i],VALVE_POS_VS_PWM[i+1])) { |
Lightvalve | 14:8e7590227d22 | 524 | if(i==0) { |
Lightvalve | 48:889798ff9329 | 525 | 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 | 526 | } else { |
Lightvalve | 48:889798ff9329 | 527 | 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 | 528 | } |
Lightvalve | 13:747daba9cf59 | 529 | break; |
Lightvalve | 13:747daba9cf59 | 530 | } |
Lightvalve | 13:747daba9cf59 | 531 | } |
Lightvalve | 59:f308b1656d9c | 532 | Vout.ref = VALVE_PWM_RAW_FF + VALVE_PWM_RAW_FB; |
Lightvalve | 13:747daba9cf59 | 533 | } |
Lightvalve | 13:747daba9cf59 | 534 | |
Lightvalve | 14:8e7590227d22 | 535 | #define LT_MAX_IDX 57 |
Lightvalve | 30:8d561f16383b | 536 | 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 | 537 | -19.0f, -18.0f, -17.0f, -16.0f, -15.0f, -14.0f, -13.0f, -12.0f, -11.0f, -10.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 538 | -9.0f, -8.0f, -7.0f, -6.0f, -5.0f, -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 539 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 540 | 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 541 | 25.0f, 30.0f, 35.0f, 40.0f, 50.0f, 60.0f, 80.0f, 100.0f |
Lightvalve | 34:bb2ca2fc2a8e | 542 | }; // duty |
Lightvalve | 67:c2812cf26c38 | 543 | 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 | 544 | -150.0f, -145.0f, -145.0f, -145.0f, -135.0f, -135.0f, -135.0f, -127.5f, -127.5f, -115.0f, |
Lightvalve | 67:c2812cf26c38 | 545 | -115.0f, -115.0F, -100.0f, -100.0f, -100.0f, -60.0f, -60.0f, -10.0f, -5.0f, 0.0f, |
Lightvalve | 67:c2812cf26c38 | 546 | 7.5f, 14.0f, 14.0f, 14.0f, 42.5f, 42.5f, 42.5f, 80.0f, 80.0f, 105.0f, |
Lightvalve | 67:c2812cf26c38 | 547 | 105.0f, 105.0f, 120.0f, 120.0f, 120.0f, 131.0f, 131.0f, 140.0f, 140.0f, 140.0f, |
Lightvalve | 67:c2812cf26c38 | 548 | 155.0f, 160.0f, 170.0f, 174.0f, 182.0f, 191.0f, 212.0f, 230.0f |
Lightvalve | 34:bb2ca2fc2a8e | 549 | }; // mV |
Lightvalve | 13:747daba9cf59 | 550 | |
Lightvalve | 30:8d561f16383b | 551 | float PWM_duty_byLT(float Ref_V) |
Lightvalve | 14:8e7590227d22 | 552 | { |
Lightvalve | 30:8d561f16383b | 553 | float PWM_duty = 0.0f; |
Lightvalve | 13:747daba9cf59 | 554 | if(Ref_V<LT_Voltage_Output[0]) { |
Lightvalve | 30:8d561f16383b | 555 | PWM_duty = (Ref_V-LT_Voltage_Output[0])/1.5f+LT_PWM_duty[0]; |
Lightvalve | 13:747daba9cf59 | 556 | } else if (Ref_V>=LT_Voltage_Output[LT_MAX_IDX-1]) { |
Lightvalve | 30:8d561f16383b | 557 | PWM_duty = (Ref_V-LT_Voltage_Output[LT_MAX_IDX-1])/1.5f+LT_PWM_duty[LT_MAX_IDX-1]; |
Lightvalve | 13:747daba9cf59 | 558 | } else { |
Lightvalve | 13:747daba9cf59 | 559 | int idx = 0; |
Lightvalve | 13:747daba9cf59 | 560 | for(idx=0; idx<LT_MAX_IDX-1; idx++) { |
Lightvalve | 30:8d561f16383b | 561 | float ini_x = LT_Voltage_Output[idx]; |
Lightvalve | 30:8d561f16383b | 562 | float fin_x = LT_Voltage_Output[idx+1]; |
Lightvalve | 30:8d561f16383b | 563 | float ini_y = LT_PWM_duty[idx]; |
Lightvalve | 30:8d561f16383b | 564 | float fin_y = LT_PWM_duty[idx+1]; |
Lightvalve | 13:747daba9cf59 | 565 | if(Ref_V>=ini_x && Ref_V<fin_x) { |
Lightvalve | 13:747daba9cf59 | 566 | PWM_duty = (fin_y-ini_y)/(fin_x-ini_x)*(Ref_V-ini_x) + ini_y; |
Lightvalve | 13:747daba9cf59 | 567 | break; |
Lightvalve | 13:747daba9cf59 | 568 | } |
Lightvalve | 13:747daba9cf59 | 569 | } |
Lightvalve | 13:747daba9cf59 | 570 | } |
Lightvalve | 14:8e7590227d22 | 571 | |
Lightvalve | 13:747daba9cf59 | 572 | return PWM_duty; |
Lightvalve | 13:747daba9cf59 | 573 | } |
jobuuu | 6:df07d3491e3a | 574 | |
Lightvalve | 57:f4819de54e7a | 575 | |
Lightvalve | 57:f4819de54e7a | 576 | |
Lightvalve | 57:f4819de54e7a | 577 | |
Lightvalve | 57:f4819de54e7a | 578 | |
jobuuu | 2:a1c0a37df760 | 579 | /******************************************************************************* |
jobuuu | 2:a1c0a37df760 | 580 | TIMER INTERRUPT |
jobuuu | 2:a1c0a37df760 | 581 | *******************************************************************************/ |
jobuuu | 2:a1c0a37df760 | 582 | |
Lightvalve | 51:b46bed7fec80 | 583 | float FREQ_TMR4 = (float)FREQ_20k; |
Lightvalve | 51:b46bed7fec80 | 584 | float DT_TMR4 = (float)DT_20k; |
Lightvalve | 57:f4819de54e7a | 585 | long CNT_TMR4 = 0; |
Lightvalve | 57:f4819de54e7a | 586 | int TMR4_FREQ_10k = (int)FREQ_10k; |
jobuuu | 1:e04e563be5ce | 587 | extern "C" void TIM4_IRQHandler(void) |
jobuuu | 1:e04e563be5ce | 588 | { |
Lightvalve | 19:23b7c1ad8683 | 589 | if (TIM4->SR & TIM_SR_UIF ) { |
Lightvalve | 21:e5f1a43ea6f9 | 590 | |
Lightvalve | 21:e5f1a43ea6f9 | 591 | /******************************************************* |
Lightvalve | 21:e5f1a43ea6f9 | 592 | *** Sensor Read & Data Handling |
Lightvalve | 21:e5f1a43ea6f9 | 593 | ********************************************************/ |
Lightvalve | 13:747daba9cf59 | 594 | |
Lightvalve | 57:f4819de54e7a | 595 | //Encoder |
Lightvalve | 57:f4819de54e7a | 596 | if (CNT_TMR4 % (int) ((int) FREQ_TMR4/TMR4_FREQ_10k) == 0) { |
Lightvalve | 57:f4819de54e7a | 597 | ENC_UPDATE(); |
Lightvalve | 57:f4819de54e7a | 598 | } |
Lightvalve | 61:bc8c8270f0ab | 599 | |
Lightvalve | 61:bc8c8270f0ab | 600 | ADC1->CR2 |= 0x40000000; |
Lightvalve | 58:2eade98630e2 | 601 | if (SENSING_MODE == 0) { |
Lightvalve | 58:2eade98630e2 | 602 | // Torque Sensing (0~210)bar ============================================= |
Lightvalve | 58:2eade98630e2 | 603 | float pres_A_new = (((float) ADC1->DR) - 2047.5f); |
Lightvalve | 58:2eade98630e2 | 604 | double alpha_update_ft = 1.0f / (1.0f + FREQ_TMR4 / (2.0f * 3.14f * 100.0f)); // f_cutoff : 200Hz |
Lightvalve | 58:2eade98630e2 | 605 | pres_A.sen = (1.0f - alpha_update_ft) * pres_A.sen + alpha_update_ft * pres_A_new; |
Lightvalve | 67:c2812cf26c38 | 606 | torq.sen = -pres_A.sen / TORQUE_SENSOR_PULSE_PER_TORQUE; |
Lightvalve | 67:c2812cf26c38 | 607 | |
Lightvalve | 67:c2812cf26c38 | 608 | |
Lightvalve | 67:c2812cf26c38 | 609 | // float alpha_update_pres_A = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f)); |
Lightvalve | 67:c2812cf26c38 | 610 | //// float pres_A_new = ((float)ADC1->DR - PRES_A_NULL) / PRES_SENSOR_A_PULSE_PER_BAR; |
Lightvalve | 67:c2812cf26c38 | 611 | // float pres_A_new = ((float)ADC1->DR); |
Lightvalve | 67:c2812cf26c38 | 612 | // pres_A.sen = pres_A.sen*(1.0f-alpha_update_pres_A)+pres_A_new*(alpha_update_pres_A); |
Lightvalve | 67:c2812cf26c38 | 613 | // torq.sen = - (pres_A.sen-2048.0f); //pulse -2047~2047 |
Lightvalve | 67:c2812cf26c38 | 614 | |
Lightvalve | 17:1865016ca2e7 | 615 | |
Lightvalve | 58:2eade98630e2 | 616 | } else if (SENSING_MODE == 1) { |
Lightvalve | 58:2eade98630e2 | 617 | // Pressure Sensing (0~210)bar ============================================= |
Lightvalve | 58:2eade98630e2 | 618 | float pres_A_new = (((float)ADC1->DR) - PRES_A_NULL); |
Lightvalve | 58:2eade98630e2 | 619 | float pres_B_new = (((float)ADC2->DR) - PRES_B_NULL); |
Lightvalve | 58:2eade98630e2 | 620 | double alpha_update_pres = 1.0f / (1.0f + FREQ_TMR4 / (2.0f * 3.14f * 200.0f)); // f_cutoff : 500Hz |
Lightvalve | 58:2eade98630e2 | 621 | pres_A.sen = (1.0f - alpha_update_pres) * pres_A.sen + alpha_update_pres * pres_A_new; |
Lightvalve | 58:2eade98630e2 | 622 | pres_B.sen = (1.0f - alpha_update_pres) * pres_B.sen + alpha_update_pres * pres_B_new; |
Lightvalve | 58:2eade98630e2 | 623 | CUR_PRES_A_BAR = pres_A.sen / PRES_SENSOR_A_PULSE_PER_BAR; |
Lightvalve | 58:2eade98630e2 | 624 | CUR_PRES_B_BAR = pres_B.sen / PRES_SENSOR_B_PULSE_PER_BAR; |
Lightvalve | 50:3c630b5eba9f | 625 | |
Lightvalve | 58:2eade98630e2 | 626 | if ((OPERATING_MODE & 0x01) == 0) { // Rotary Actuator |
Lightvalve | 58:2eade98630e2 | 627 | 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 | 628 | } else if ((OPERATING_MODE & 0x01) == 1) { // Linear Actuator |
Lightvalve | 58:2eade98630e2 | 629 | 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 | 630 | } |
Lightvalve | 58:2eade98630e2 | 631 | } |
Lightvalve | 61:bc8c8270f0ab | 632 | |
Lightvalve | 58:2eade98630e2 | 633 | // //Pressure sensor A |
Lightvalve | 58:2eade98630e2 | 634 | // ADC1->CR2 |= 0x40000000; // adc _ 12bit |
Lightvalve | 58:2eade98630e2 | 635 | // //while((ADC1->SR & 0b10)); |
Lightvalve | 58:2eade98630e2 | 636 | // float alpha_update_pres_A = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f)); |
Lightvalve | 58:2eade98630e2 | 637 | // float pres_A_new = ((float)ADC1->DR); |
Lightvalve | 58:2eade98630e2 | 638 | // pres_A.sen = pres_A.sen*(1.0f-alpha_update_pres_A)+pres_A_new*(alpha_update_pres_A); |
Lightvalve | 58:2eade98630e2 | 639 | // 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 | 640 | // |
Lightvalve | 58:2eade98630e2 | 641 | // |
Lightvalve | 58:2eade98630e2 | 642 | // //Pressure sensor B |
Lightvalve | 58:2eade98630e2 | 643 | // float alpha_update_pres_B = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f)); |
Lightvalve | 58:2eade98630e2 | 644 | // float pres_B_new = ((float)ADC2->DR); |
Lightvalve | 58:2eade98630e2 | 645 | // pres_B.sen = pres_B.sen*(1.0f-alpha_update_pres_B)+pres_B_new*(alpha_update_pres_B); |
Lightvalve | 58:2eade98630e2 | 646 | // //torq.sen = pres_A.sen * (float) PISTON_AREA_A - pres_B.sen * (float) PISTON_AREA_B; |
Lightvalve | 17:1865016ca2e7 | 647 | |
Lightvalve | 17:1865016ca2e7 | 648 | |
Lightvalve | 21:e5f1a43ea6f9 | 649 | //Current |
Lightvalve | 21:e5f1a43ea6f9 | 650 | //ADC3->CR2 |= 0x40000000; // adc _ 12bit |
Lightvalve | 25:3e6b574cab5c | 651 | //int raw_cur = ADC3->DR; |
Lightvalve | 21:e5f1a43ea6f9 | 652 | //while((ADC3->SR & 0b10)); |
Lightvalve | 51:b46bed7fec80 | 653 | float alpha_update_cur = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*500.0f)); // f_cutoff : 500Hz |
Lightvalve | 30:8d561f16383b | 654 | float cur_new = ((float)ADC3->DR-2048.0f)*20.0f/4096.0f; // unit : mA |
Lightvalve | 30:8d561f16383b | 655 | cur.sen=cur.sen*(1.0f-alpha_update_cur)+cur_new*(alpha_update_cur); |
Lightvalve | 25:3e6b574cab5c | 656 | //cur.sen = raw_cur; |
Lightvalve | 58:2eade98630e2 | 657 | |
Lightvalve | 57:f4819de54e7a | 658 | CNT_TMR4++; |
Lightvalve | 21:e5f1a43ea6f9 | 659 | } |
Lightvalve | 11:82d8768d7351 | 660 | TIM4->SR = 0x0; // reset the status register |
Lightvalve | 11:82d8768d7351 | 661 | } |
Lightvalve | 19:23b7c1ad8683 | 662 | |
Lightvalve | 19:23b7c1ad8683 | 663 | |
Lightvalve | 18:b8adf1582ea3 | 664 | int j =0; |
Lightvalve | 54:647072f5307a | 665 | float FREQ_TMR3 = (float)FREQ_5k; |
Lightvalve | 48:889798ff9329 | 666 | float DT_TMR3 = (float)DT_5k; |
Lightvalve | 45:35fa6884d0c6 | 667 | int cnt_trans = 0; |
Lightvalve | 48:889798ff9329 | 668 | double VALVE_POS_RAW_FORCE_FB_LOGGING = 0.0f; |
Lightvalve | 57:f4819de54e7a | 669 | int can_rest =0; |
Lightvalve | 48:889798ff9329 | 670 | |
Lightvalve | 11:82d8768d7351 | 671 | extern "C" void TIM3_IRQHandler(void) |
Lightvalve | 21:e5f1a43ea6f9 | 672 | { |
Lightvalve | 19:23b7c1ad8683 | 673 | if (TIM3->SR & TIM_SR_UIF ) { |
Lightvalve | 57:f4819de54e7a | 674 | |
Lightvalve | 57:f4819de54e7a | 675 | if (((OPERATING_MODE&0b110)>>1) == 0) { |
Lightvalve | 57:f4819de54e7a | 676 | K_v = 0.4f; // Moog (LPM >> mA) , 100bar |
Lightvalve | 57:f4819de54e7a | 677 | mV_PER_mA = 500.0f; // 5000mV/10mA |
Lightvalve | 57:f4819de54e7a | 678 | mV_PER_pulse = 0.5f; // 5000mV/10000pulse |
Lightvalve | 57:f4819de54e7a | 679 | mA_PER_pulse = 0.001f; // 10mA/10000pulse |
Lightvalve | 57:f4819de54e7a | 680 | } else if (((OPERATING_MODE&0b110)>>1) == 1) { |
Lightvalve | 57:f4819de54e7a | 681 | K_v = 0.5f; // KNR (LPM >> mA) , 100bar |
Lightvalve | 57:f4819de54e7a | 682 | mV_PER_mA = 166.6666f; // 5000mV/30mA |
Lightvalve | 57:f4819de54e7a | 683 | mV_PER_pulse = 0.5f; // 5000mV/10000pulse |
Lightvalve | 57:f4819de54e7a | 684 | mA_PER_pulse = 0.003f; // 30mA/10000pulse |
Lightvalve | 57:f4819de54e7a | 685 | } |
Lightvalve | 50:3c630b5eba9f | 686 | |
Lightvalve | 50:3c630b5eba9f | 687 | if(MODE_POS_FT_TRANS == 1) { |
Lightvalve | 48:889798ff9329 | 688 | alpha_trans = (float)(1.0f - cos(3.141592f * (float)cnt_trans * DT_TMR3 /3.0f))/2.0f; |
Lightvalve | 45:35fa6884d0c6 | 689 | cnt_trans++; |
Lightvalve | 46:2694daea349b | 690 | torq.err_sum = 0; |
Lightvalve | 48:889798ff9329 | 691 | if((float)cnt_trans * DT_TMR3 > 3.0f) |
Lightvalve | 45:35fa6884d0c6 | 692 | MODE_POS_FT_TRANS = 2; |
Lightvalve | 50:3c630b5eba9f | 693 | } else if(MODE_POS_FT_TRANS == 3) { |
Lightvalve | 48:889798ff9329 | 694 | alpha_trans = (float)(1.0f + cos(3.141592f * (float)cnt_trans * DT_TMR3 /3.0f))/2.0f; |
Lightvalve | 45:35fa6884d0c6 | 695 | cnt_trans++; |
Lightvalve | 46:2694daea349b | 696 | torq.err_sum = 0; |
Lightvalve | 48:889798ff9329 | 697 | if((float) cnt_trans * DT_TMR3 > 3.0f ) |
Lightvalve | 45:35fa6884d0c6 | 698 | MODE_POS_FT_TRANS = 0; |
Lightvalve | 50:3c630b5eba9f | 699 | } else if(MODE_POS_FT_TRANS == 2) { |
Lightvalve | 58:2eade98630e2 | 700 | alpha_trans = 1.0f; |
Lightvalve | 45:35fa6884d0c6 | 701 | cnt_trans = 0; |
Lightvalve | 50:3c630b5eba9f | 702 | } else { |
Lightvalve | 58:2eade98630e2 | 703 | alpha_trans = 0.0f; |
Lightvalve | 45:35fa6884d0c6 | 704 | cnt_trans = 0; |
Lightvalve | 45:35fa6884d0c6 | 705 | } |
Lightvalve | 45:35fa6884d0c6 | 706 | |
Lightvalve | 50:3c630b5eba9f | 707 | |
Lightvalve | 57:f4819de54e7a | 708 | int UTILITY_MODE = 0; |
Lightvalve | 57:f4819de54e7a | 709 | int CONTROL_MODE = 0; |
Lightvalve | 58:2eade98630e2 | 710 | |
Lightvalve | 57:f4819de54e7a | 711 | if (CONTROL_UTILITY_MODE >= 20 || CONTROL_UTILITY_MODE == 0) { |
Lightvalve | 57:f4819de54e7a | 712 | UTILITY_MODE = CONTROL_UTILITY_MODE; |
Lightvalve | 57:f4819de54e7a | 713 | CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 57:f4819de54e7a | 714 | } else { |
Lightvalve | 57:f4819de54e7a | 715 | CONTROL_MODE = CONTROL_UTILITY_MODE; |
Lightvalve | 57:f4819de54e7a | 716 | UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 57:f4819de54e7a | 717 | } |
Lightvalve | 56:6f50d9d3bfee | 718 | |
Lightvalve | 56:6f50d9d3bfee | 719 | |
Lightvalve | 56:6f50d9d3bfee | 720 | |
Lightvalve | 57:f4819de54e7a | 721 | // UTILITY MODE ------------------------------------------------------------ |
Lightvalve | 56:6f50d9d3bfee | 722 | |
Lightvalve | 57:f4819de54e7a | 723 | switch (UTILITY_MODE) { |
Lightvalve | 57:f4819de54e7a | 724 | case MODE_NO_ACT: { |
Lightvalve | 13:747daba9cf59 | 725 | break; |
Lightvalve | 13:747daba9cf59 | 726 | } |
Lightvalve | 14:8e7590227d22 | 727 | |
Lightvalve | 14:8e7590227d22 | 728 | case MODE_TORQUE_SENSOR_NULLING: { |
Lightvalve | 13:747daba9cf59 | 729 | // DAC Voltage reference set |
Lightvalve | 14:8e7590227d22 | 730 | if (TMR3_COUNT_TORQUE_NULL < TMR_FREQ_5k * 2) { |
Lightvalve | 15:bd0d12728506 | 731 | CUR_TORQUE_sum += torq.sen; |
Lightvalve | 19:23b7c1ad8683 | 732 | |
Lightvalve | 14:8e7590227d22 | 733 | if (TMR3_COUNT_TORQUE_NULL % 10 == 0) { |
Lightvalve | 30:8d561f16383b | 734 | CUR_TORQUE_mean = CUR_TORQUE_sum / 10.0f; |
Lightvalve | 13:747daba9cf59 | 735 | CUR_TORQUE_sum = 0; |
Lightvalve | 14:8e7590227d22 | 736 | |
Lightvalve | 59:f308b1656d9c | 737 | TORQUE_VREF += 0.0003f * (0.0f - CUR_TORQUE_mean); |
Lightvalve | 19:23b7c1ad8683 | 738 | |
Lightvalve | 30:8d561f16383b | 739 | if (TORQUE_VREF > 3.3f) TORQUE_VREF = 3.3f; |
Lightvalve | 59:f308b1656d9c | 740 | if (TORQUE_VREF < 0.0f) TORQUE_VREF = 0.0f; |
Lightvalve | 50:3c630b5eba9f | 741 | |
Lightvalve | 16:903b5a4433b4 | 742 | //spi_eeprom_write(RID_TORQUE_SENSOR_VREF, (int16_t) (TORQUE_VREF * 1000.0)); |
Lightvalve | 30:8d561f16383b | 743 | dac_1 = TORQUE_VREF / 3.3f; |
Lightvalve | 13:747daba9cf59 | 744 | } |
Lightvalve | 13:747daba9cf59 | 745 | } else { |
Lightvalve | 58:2eade98630e2 | 746 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 14:8e7590227d22 | 747 | TMR3_COUNT_TORQUE_NULL = 0; |
Lightvalve | 13:747daba9cf59 | 748 | CUR_TORQUE_sum = 0; |
Lightvalve | 13:747daba9cf59 | 749 | CUR_TORQUE_mean = 0; |
Lightvalve | 19:23b7c1ad8683 | 750 | |
Lightvalve | 16:903b5a4433b4 | 751 | ROM_RESET_DATA(); |
Lightvalve | 19:23b7c1ad8683 | 752 | |
Lightvalve | 30:8d561f16383b | 753 | dac_1 = TORQUE_VREF / 3.3f; |
Lightvalve | 14:8e7590227d22 | 754 | |
Lightvalve | 13:747daba9cf59 | 755 | } |
Lightvalve | 14:8e7590227d22 | 756 | TMR3_COUNT_TORQUE_NULL++; |
Lightvalve | 13:747daba9cf59 | 757 | break; |
Lightvalve | 19:23b7c1ad8683 | 758 | } |
Lightvalve | 14:8e7590227d22 | 759 | |
Lightvalve | 50:3c630b5eba9f | 760 | // case MODE_VALVE_NULLING_AND_DEADZONE_SETTING: { |
Lightvalve | 50:3c630b5eba9f | 761 | // if (TMR3_COUNT_DEADZONE == 0) { |
Lightvalve | 50:3c630b5eba9f | 762 | // if (pos_plus_end == pos_minus_end) need_enc_init = true; |
Lightvalve | 50:3c630b5eba9f | 763 | // else temp_time = 0; |
Lightvalve | 50:3c630b5eba9f | 764 | // } |
Lightvalve | 50:3c630b5eba9f | 765 | // if (need_enc_init) { |
Lightvalve | 50:3c630b5eba9f | 766 | // if (TMR3_COUNT_DEADZONE < (int) (0.5f * (float) TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 767 | // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 768 | // pos_plus_end = pos.sen; |
Lightvalve | 50:3c630b5eba9f | 769 | // } else if (TMR3_COUNT_DEADZONE < TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 770 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 771 | // pos_minus_end = pos.sen; |
Lightvalve | 50:3c630b5eba9f | 772 | // } else if (TMR3_COUNT_DEADZONE == TMR_FREQ_5k) need_enc_init = false; |
Lightvalve | 50:3c630b5eba9f | 773 | // temp_time = TMR_FREQ_5k; |
Lightvalve | 50:3c630b5eba9f | 774 | // } |
Lightvalve | 50:3c630b5eba9f | 775 | // |
Lightvalve | 50:3c630b5eba9f | 776 | // if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 777 | // 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 | 778 | // VALVE_CENTER = VALVE_DEADZONE_PLUS = VALVE_DEADZONE_MINUS = 0; |
Lightvalve | 50:3c630b5eba9f | 779 | // |
Lightvalve | 50:3c630b5eba9f | 780 | // } else if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + (int) (1.9f * (float) TMR_FREQ_5k))) { |
Lightvalve | 50:3c630b5eba9f | 781 | // V_out = 0; |
Lightvalve | 50:3c630b5eba9f | 782 | // CUR_VELOCITY_sum += CUR_VELOCITY; |
Lightvalve | 50:3c630b5eba9f | 783 | // } else if (TMR3_COUNT_DEADZONE == (temp_time + 2 * TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 784 | // if (CUR_VELOCITY_sum == 0) DZ_dir = 1; |
Lightvalve | 50:3c630b5eba9f | 785 | // else if (CUR_VELOCITY_sum > 0) DZ_dir = 1; |
Lightvalve | 50:3c630b5eba9f | 786 | // else if (CUR_VELOCITY_sum < 0) DZ_dir = -1; |
Lightvalve | 50:3c630b5eba9f | 787 | // else DZ_temp_cnt2 = DZ_end; |
Lightvalve | 50:3c630b5eba9f | 788 | // CUR_VELOCITY_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 789 | // } else if (TMR3_COUNT_DEADZONE > (temp_time + 2 * TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 790 | // if (TMR3_COUNT_DEADZONE > (temp_time + 10 * TMR_FREQ_5k)) DZ_temp_cnt2 = DZ_end; |
Lightvalve | 50:3c630b5eba9f | 791 | // |
Lightvalve | 50:3c630b5eba9f | 792 | // // Position of Dead Zone |
Lightvalve | 50:3c630b5eba9f | 793 | // // (CUR_VELOCITY < 0) (CUR_VELOCITY == 0) (CUR_VELOCITY > 0) |
Lightvalve | 50:3c630b5eba9f | 794 | // // | / | / |/ |
Lightvalve | 50:3c630b5eba9f | 795 | // // | ______/ ___|___/ ______/| |
Lightvalve | 50:3c630b5eba9f | 796 | // // |/ / | / | |
Lightvalve | 50:3c630b5eba9f | 797 | // // /| / | / | |
Lightvalve | 50:3c630b5eba9f | 798 | // // 0V 0V 0V |
Lightvalve | 50:3c630b5eba9f | 799 | // |
Lightvalve | 50:3c630b5eba9f | 800 | // if (DZ_temp_cnt2 < DZ_end) { |
Lightvalve | 50:3c630b5eba9f | 801 | // if (TMR3_COUNT_DEADZONE % 20 != 0) { |
Lightvalve | 50:3c630b5eba9f | 802 | // CUR_VELOCITY_sum += CUR_VELOCITY; |
Lightvalve | 50:3c630b5eba9f | 803 | // } else { |
Lightvalve | 50:3c630b5eba9f | 804 | // V_out -= DZ_dir; |
Lightvalve | 50:3c630b5eba9f | 805 | // if (CUR_VELOCITY_sum * DZ_dir < 0) DZ_temp_cnt++; |
Lightvalve | 50:3c630b5eba9f | 806 | // CUR_VELOCITY_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 807 | // } |
Lightvalve | 50:3c630b5eba9f | 808 | // if (DZ_temp_cnt == 5) { |
Lightvalve | 50:3c630b5eba9f | 809 | // if (DZ_dir >= 0) VALVE_DEADZONE_MINUS = (int16_t) V_out; |
Lightvalve | 50:3c630b5eba9f | 810 | // else VALVE_DEADZONE_PLUS = (int16_t) V_out; |
Lightvalve | 50:3c630b5eba9f | 811 | // DZ_dir = -DZ_dir; |
Lightvalve | 50:3c630b5eba9f | 812 | // DZ_temp_cnt = 0; |
Lightvalve | 50:3c630b5eba9f | 813 | // DZ_temp_cnt2++; |
Lightvalve | 50:3c630b5eba9f | 814 | // } |
Lightvalve | 50:3c630b5eba9f | 815 | // } else { |
Lightvalve | 50:3c630b5eba9f | 816 | // TMR3_COUNT_DEADZONE = -1; |
Lightvalve | 50:3c630b5eba9f | 817 | // VALVE_CENTER = VALVE_DEADZONE_PLUS / 2 + VALVE_DEADZONE_MINUS / 2; |
Lightvalve | 50:3c630b5eba9f | 818 | // if (VALVE_DEADZONE_PLUS < VALVE_DEADZONE_MINUS) { |
Lightvalve | 50:3c630b5eba9f | 819 | // VALVE_DEADZONE_PLUS = VALVE_CENTER; |
Lightvalve | 50:3c630b5eba9f | 820 | // VALVE_DEADZONE_MINUS = VALVE_CENTER; |
Lightvalve | 50:3c630b5eba9f | 821 | // } |
Lightvalve | 50:3c630b5eba9f | 822 | // V_out = 0; |
Lightvalve | 50:3c630b5eba9f | 823 | // |
Lightvalve | 50:3c630b5eba9f | 824 | // ROM_RESET_DATA(); |
Lightvalve | 50:3c630b5eba9f | 825 | // |
Lightvalve | 50:3c630b5eba9f | 826 | // //spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, VALVE_DEADZONE_PLUS); |
Lightvalve | 50:3c630b5eba9f | 827 | // //spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, VALVE_DEADZONE_MINUS); |
Lightvalve | 50:3c630b5eba9f | 828 | // |
Lightvalve | 50:3c630b5eba9f | 829 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 50:3c630b5eba9f | 830 | // DZ_temp_cnt2 = 0; |
Lightvalve | 50:3c630b5eba9f | 831 | // } |
Lightvalve | 50:3c630b5eba9f | 832 | // } |
Lightvalve | 50:3c630b5eba9f | 833 | // TMR3_COUNT_DEADZONE++; |
Lightvalve | 50:3c630b5eba9f | 834 | // break; |
Lightvalve | 50:3c630b5eba9f | 835 | // } |
Lightvalve | 14:8e7590227d22 | 836 | |
Lightvalve | 14:8e7590227d22 | 837 | case MODE_FIND_HOME: { |
Lightvalve | 29:69f3f5445d6d | 838 | if (FINDHOME_STAGE == FINDHOME_INIT) { |
Lightvalve | 14:8e7590227d22 | 839 | cnt_findhome = 0; |
Lightvalve | 14:8e7590227d22 | 840 | cnt_vel_findhome = 0; |
Lightvalve | 14:8e7590227d22 | 841 | //REFERENCE_MODE = MODE_REF_NO_ACT; // Stop taking reference data from PODO |
Lightvalve | 59:f308b1656d9c | 842 | pos.ref = pos.sen; |
Lightvalve | 59:f308b1656d9c | 843 | vel.ref = 0.0f; |
Lightvalve | 29:69f3f5445d6d | 844 | FINDHOME_STAGE = FINDHOME_GOTOLIMIT; |
Lightvalve | 29:69f3f5445d6d | 845 | } else if (FINDHOME_STAGE == FINDHOME_GOTOLIMIT) { |
Lightvalve | 67:c2812cf26c38 | 846 | int cnt_check_enc = (TMR_FREQ_5k/20); |
Lightvalve | 29:69f3f5445d6d | 847 | if(cnt_findhome%cnt_check_enc == 0) { |
Lightvalve | 29:69f3f5445d6d | 848 | FINDHOME_POSITION = pos.sen; |
Lightvalve | 29:69f3f5445d6d | 849 | FINDHOME_VELOCITY = FINDHOME_POSITION - FINDHOME_POSITION_OLD; |
Lightvalve | 29:69f3f5445d6d | 850 | FINDHOME_POSITION_OLD = FINDHOME_POSITION; |
Lightvalve | 29:69f3f5445d6d | 851 | } |
Lightvalve | 29:69f3f5445d6d | 852 | cnt_findhome++; |
Lightvalve | 14:8e7590227d22 | 853 | |
Lightvalve | 29:69f3f5445d6d | 854 | if (abs(FINDHOME_VELOCITY) <= 1) { |
Lightvalve | 29:69f3f5445d6d | 855 | cnt_vel_findhome = cnt_vel_findhome + 1; |
Lightvalve | 29:69f3f5445d6d | 856 | } else { |
Lightvalve | 29:69f3f5445d6d | 857 | cnt_vel_findhome = 0; |
Lightvalve | 29:69f3f5445d6d | 858 | } |
Lightvalve | 19:23b7c1ad8683 | 859 | |
Lightvalve | 57:f4819de54e7a | 860 | if ((cnt_vel_findhome < 3*TMR_FREQ_5k) && cnt_findhome < 10*TMR_FREQ_5k) { // wait for 3sec |
Lightvalve | 29:69f3f5445d6d | 861 | //REFERENCE_MODE = MODE_REF_NO_ACT; |
Lightvalve | 67:c2812cf26c38 | 862 | if (HOMEPOS_OFFSET > 0) pos.ref = pos.ref + 12.0f; |
Lightvalve | 67:c2812cf26c38 | 863 | else pos.ref = pos.ref - 12.0f; |
Lightvalve | 61:bc8c8270f0ab | 864 | |
Lightvalve | 59:f308b1656d9c | 865 | // pos.err = pos.ref_home_pos - pos.sen; |
Lightvalve | 59:f308b1656d9c | 866 | // float VALVE_POS_RAW_POS_FB = 0.0f; |
Lightvalve | 59:f308b1656d9c | 867 | // VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * pos.err/(float) ENC_PULSE_PER_POSITION * 0.01f; |
Lightvalve | 59:f308b1656d9c | 868 | // valve_pos.ref = VALVE_POS_RAW_POS_FB + (float) VALVE_CENTER; |
Lightvalve | 59:f308b1656d9c | 869 | // VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 61:bc8c8270f0ab | 870 | |
Lightvalve | 59:f308b1656d9c | 871 | CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 59:f308b1656d9c | 872 | alpha_trans = 0.0f; |
Lightvalve | 61:bc8c8270f0ab | 873 | |
Lightvalve | 34:bb2ca2fc2a8e | 874 | |
Lightvalve | 29:69f3f5445d6d | 875 | } else { |
Lightvalve | 29:69f3f5445d6d | 876 | ENC_SET(HOMEPOS_OFFSET); |
Lightvalve | 67:c2812cf26c38 | 877 | // ENC_SET_ZERO(); |
Lightvalve | 29:69f3f5445d6d | 878 | INIT_REF_POS = HOMEPOS_OFFSET; |
Lightvalve | 29:69f3f5445d6d | 879 | REF_POSITION = 0; |
Lightvalve | 29:69f3f5445d6d | 880 | REF_VELOCITY = 0; |
Lightvalve | 29:69f3f5445d6d | 881 | FINDHOME_POSITION = 0; |
Lightvalve | 29:69f3f5445d6d | 882 | FINDHOME_POSITION_OLD = 0; |
Lightvalve | 29:69f3f5445d6d | 883 | FINDHOME_VELOCITY = 0; |
Lightvalve | 29:69f3f5445d6d | 884 | cnt_findhome = 0; |
Lightvalve | 29:69f3f5445d6d | 885 | cnt_vel_findhome = 0; |
Lightvalve | 29:69f3f5445d6d | 886 | FINDHOME_STAGE = FINDHOME_ZEROPOSE; |
Lightvalve | 67:c2812cf26c38 | 887 | |
Lightvalve | 67:c2812cf26c38 | 888 | |
Lightvalve | 67:c2812cf26c38 | 889 | cnt_findhome = 0; |
Lightvalve | 67:c2812cf26c38 | 890 | pos.ref = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 891 | vel.ref = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 892 | pos.ref_home_pos = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 893 | vel.ref_home_pos = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 894 | //FINDHOME_STAGE = FINDHOME_INIT; |
Lightvalve | 67:c2812cf26c38 | 895 | //CONTROL_UTILITY_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 67:c2812cf26c38 | 896 | |
Lightvalve | 67:c2812cf26c38 | 897 | |
Lightvalve | 29:69f3f5445d6d | 898 | } |
Lightvalve | 29:69f3f5445d6d | 899 | } else if (FINDHOME_STAGE == FINDHOME_ZEROPOSE) { |
Lightvalve | 29:69f3f5445d6d | 900 | int T_move = 2*TMR_FREQ_5k; |
Lightvalve | 59:f308b1656d9c | 901 | 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 | 902 | //pos.ref = 0.0f; |
Lightvalve | 59:f308b1656d9c | 903 | vel.ref = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 904 | |
Lightvalve | 29:69f3f5445d6d | 905 | // input for position control |
Lightvalve | 67:c2812cf26c38 | 906 | |
Lightvalve | 67:c2812cf26c38 | 907 | // CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 67:c2812cf26c38 | 908 | alpha_trans = 0.0f; |
Lightvalve | 61:bc8c8270f0ab | 909 | |
Lightvalve | 67:c2812cf26c38 | 910 | double torq_ref = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 911 | pos.err = (pos.ref - pos.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm] |
Lightvalve | 67:c2812cf26c38 | 912 | vel.err = (0.0f - vel.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm/s] |
Lightvalve | 67:c2812cf26c38 | 913 | pos.err_sum += pos.err/(float) TMR_FREQ_5k; //[mm] |
Lightvalve | 67:c2812cf26c38 | 914 | |
Lightvalve | 67:c2812cf26c38 | 915 | if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) { |
Lightvalve | 67:c2812cf26c38 | 916 | |
Lightvalve | 67:c2812cf26c38 | 917 | double I_REF_POS = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 918 | double I_REF_FORCE_FB = 0.0f; // I_REF by Force Feedback |
Lightvalve | 67:c2812cf26c38 | 919 | double I_REF_VC = 0.0f; // I_REF for velocity compensation |
Lightvalve | 67:c2812cf26c38 | 920 | |
Lightvalve | 67:c2812cf26c38 | 921 | double temp_vel_pos = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 922 | double temp_vel_torq = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 923 | double wn_Pos = 2.0f * PI * 5.0f; // f_cut : 5Hz Position Control |
Lightvalve | 67:c2812cf26c38 | 924 | |
Lightvalve | 69:3995ffeaa786 | 925 | if ((OPERATING_MODE & 0x01) == 0) { // Rotary Mode |
Lightvalve | 67:c2812cf26c38 | 926 | 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 | 927 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 69:3995ffeaa786 | 928 | } else if ((OPERATING_MODE & 0x01) == 1) { |
Lightvalve | 67:c2812cf26c38 | 929 | 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 | 930 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 67:c2812cf26c38 | 931 | } |
Lightvalve | 67:c2812cf26c38 | 932 | 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 | 933 | else I_REF_POS = temp_vel_pos * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f)))); |
Lightvalve | 67:c2812cf26c38 | 934 | |
Lightvalve | 67:c2812cf26c38 | 935 | I_REF = I_REF_POS; |
Lightvalve | 67:c2812cf26c38 | 936 | |
Lightvalve | 67:c2812cf26c38 | 937 | |
Lightvalve | 67:c2812cf26c38 | 938 | |
Lightvalve | 67:c2812cf26c38 | 939 | } else { |
Lightvalve | 67:c2812cf26c38 | 940 | float VALVE_POS_RAW_FORCE_FB = 0.0f; |
Lightvalve | 67:c2812cf26c38 | 941 | 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 | 942 | |
Lightvalve | 67:c2812cf26c38 | 943 | if (VALVE_POS_RAW_FORCE_FB >= 0) { |
Lightvalve | 67:c2812cf26c38 | 944 | valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_PLUS; |
Lightvalve | 67:c2812cf26c38 | 945 | } else { |
Lightvalve | 67:c2812cf26c38 | 946 | valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_MINUS; |
Lightvalve | 67:c2812cf26c38 | 947 | } |
Lightvalve | 67:c2812cf26c38 | 948 | |
Lightvalve | 67:c2812cf26c38 | 949 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 67:c2812cf26c38 | 950 | |
Lightvalve | 67:c2812cf26c38 | 951 | V_out = (float) Vout.ref; |
Lightvalve | 67:c2812cf26c38 | 952 | |
Lightvalve | 67:c2812cf26c38 | 953 | } |
Lightvalve | 67:c2812cf26c38 | 954 | |
Lightvalve | 67:c2812cf26c38 | 955 | |
Lightvalve | 67:c2812cf26c38 | 956 | |
Lightvalve | 67:c2812cf26c38 | 957 | |
Lightvalve | 59:f308b1656d9c | 958 | // pos.err = pos.ref - (float)pos.sen; |
Lightvalve | 59:f308b1656d9c | 959 | // float VALVE_POS_RAW_POS_FB = 0.0f; |
Lightvalve | 59:f308b1656d9c | 960 | // VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * 0.01f * pos.err/(float) ENC_PULSE_PER_POSITION; |
Lightvalve | 59:f308b1656d9c | 961 | // valve_pos.ref = VALVE_POS_RAW_POS_FB + (float) VALVE_CENTER; |
Lightvalve | 59:f308b1656d9c | 962 | // VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 29:69f3f5445d6d | 963 | |
Lightvalve | 29:69f3f5445d6d | 964 | cnt_findhome++; |
Lightvalve | 29:69f3f5445d6d | 965 | if (cnt_findhome >= T_move) { |
Lightvalve | 29:69f3f5445d6d | 966 | //REFERENCE_MODE = MODE_REF_DIRECT; |
Lightvalve | 29:69f3f5445d6d | 967 | cnt_findhome = 0; |
Lightvalve | 30:8d561f16383b | 968 | pos.ref = 0.0f; |
Lightvalve | 30:8d561f16383b | 969 | vel.ref = 0.0f; |
Lightvalve | 30:8d561f16383b | 970 | pos.ref_home_pos = 0.0f; |
Lightvalve | 30:8d561f16383b | 971 | vel.ref_home_pos = 0.0f; |
Lightvalve | 29:69f3f5445d6d | 972 | FINDHOME_STAGE = FINDHOME_INIT; |
Lightvalve | 57:f4819de54e7a | 973 | CONTROL_UTILITY_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 29:69f3f5445d6d | 974 | } |
Lightvalve | 13:747daba9cf59 | 975 | } |
Lightvalve | 19:23b7c1ad8683 | 976 | |
Lightvalve | 13:747daba9cf59 | 977 | break; |
Lightvalve | 13:747daba9cf59 | 978 | } |
Lightvalve | 14:8e7590227d22 | 979 | |
Lightvalve | 50:3c630b5eba9f | 980 | // case MODE_VALVE_GAIN_SETTING: { |
Lightvalve | 50:3c630b5eba9f | 981 | // if (TMR3_COUNT_FLOWRATE == 0) { |
Lightvalve | 50:3c630b5eba9f | 982 | // if (pos_plus_end == pos_minus_end) need_enc_init = true; |
Lightvalve | 50:3c630b5eba9f | 983 | // else { |
Lightvalve | 50:3c630b5eba9f | 984 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 985 | // temp_time = (int) (0.5f * (float) TMR_FREQ_5k); |
Lightvalve | 50:3c630b5eba9f | 986 | // } |
Lightvalve | 50:3c630b5eba9f | 987 | // } |
Lightvalve | 50:3c630b5eba9f | 988 | // if (need_enc_init) { |
Lightvalve | 50:3c630b5eba9f | 989 | // if (TMR3_COUNT_FLOWRATE < (int) (0.5f * (float) TMR_FREQ_5k)) { |
Lightvalve | 50:3c630b5eba9f | 990 | // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 991 | // pos_plus_end = pos.sen; |
Lightvalve | 50:3c630b5eba9f | 992 | // } else if (TMR3_COUNT_FLOWRATE < TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 993 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 994 | // pos_minus_end = pos.sen; |
Lightvalve | 50:3c630b5eba9f | 995 | // } else if (TMR3_COUNT_FLOWRATE == TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 996 | // need_enc_init = false; |
Lightvalve | 50:3c630b5eba9f | 997 | // check_vel_pos_init = (int) (0.9f * (float) (pos_plus_end - pos_minus_end)); |
Lightvalve | 50:3c630b5eba9f | 998 | // check_vel_pos_fin = (int) (0.95f * (float) (pos_plus_end - pos_minus_end)); |
Lightvalve | 50:3c630b5eba9f | 999 | // check_vel_pos_interv = check_vel_pos_fin - check_vel_pos_init; |
Lightvalve | 50:3c630b5eba9f | 1000 | // } |
Lightvalve | 50:3c630b5eba9f | 1001 | // temp_time = TMR_FREQ_5k; |
Lightvalve | 50:3c630b5eba9f | 1002 | // } |
Lightvalve | 50:3c630b5eba9f | 1003 | // TMR3_COUNT_FLOWRATE++; |
Lightvalve | 50:3c630b5eba9f | 1004 | // if (TMR3_COUNT_FLOWRATE > temp_time) { |
Lightvalve | 50:3c630b5eba9f | 1005 | // if (flag_flowrate % 2 == 0) { // (+) |
Lightvalve | 50:3c630b5eba9f | 1006 | // VALVE_VOLTAGE = 1000.0f * (float) (flag_flowrate / 2 + 1); |
Lightvalve | 50:3c630b5eba9f | 1007 | // V_out = VALVE_VOLTAGE; |
Lightvalve | 50:3c630b5eba9f | 1008 | // if (pos.sen > (pos_minus_end + check_vel_pos_init) && pos.sen < (pos_minus_end + check_vel_pos_fin)) { |
Lightvalve | 50:3c630b5eba9f | 1009 | // fl_temp_cnt++; |
Lightvalve | 50:3c630b5eba9f | 1010 | // } else if (pos.sen >= (pos_minus_end + check_vel_pos_fin) && CUR_VELOCITY == 0) { |
Lightvalve | 50:3c630b5eba9f | 1011 | // 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 | 1012 | // // 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 | 1013 | // fl_temp_cnt2++; |
Lightvalve | 50:3c630b5eba9f | 1014 | // } |
Lightvalve | 50:3c630b5eba9f | 1015 | // } else if (flag_flowrate % 2 == 1) { // (-) |
Lightvalve | 50:3c630b5eba9f | 1016 | // VALVE_VOLTAGE = -1. * (float) (flag_flowrate / 2 + 1); |
Lightvalve | 50:3c630b5eba9f | 1017 | // V_out = VALVE_VOLTAGE; |
Lightvalve | 50:3c630b5eba9f | 1018 | // if (pos.sen < (pos_plus_end - check_vel_pos_init) && pos.sen > (pos_plus_end - check_vel_pos_fin)) { |
Lightvalve | 50:3c630b5eba9f | 1019 | // fl_temp_cnt++; |
Lightvalve | 50:3c630b5eba9f | 1020 | // } else if (pos.sen <= (pos_plus_end - check_vel_pos_fin) && CUR_VELOCITY == 0) { |
Lightvalve | 50:3c630b5eba9f | 1021 | // 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 | 1022 | // // 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 | 1023 | // fl_temp_cnt2++; |
Lightvalve | 50:3c630b5eba9f | 1024 | // } |
Lightvalve | 50:3c630b5eba9f | 1025 | // } |
Lightvalve | 50:3c630b5eba9f | 1026 | // if (fl_temp_cnt2 == 100) { |
Lightvalve | 50:3c630b5eba9f | 1027 | // |
Lightvalve | 50:3c630b5eba9f | 1028 | // ROM_RESET_DATA(); |
Lightvalve | 50:3c630b5eba9f | 1029 | // |
Lightvalve | 50:3c630b5eba9f | 1030 | // //spi_eeprom_write(RID_VALVE_GAIN_PLUS_1 + flag_flowrate, (int16_t) (VALVE_GAIN_LPM_PER_V[flag_flowrate] * 100.0f)); |
Lightvalve | 50:3c630b5eba9f | 1031 | // cur_vel_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 1032 | // fl_temp_cnt = 0; |
Lightvalve | 50:3c630b5eba9f | 1033 | // fl_temp_cnt2 = 0; |
Lightvalve | 50:3c630b5eba9f | 1034 | // flag_flowrate++; |
Lightvalve | 50:3c630b5eba9f | 1035 | // } |
Lightvalve | 50:3c630b5eba9f | 1036 | // if (flag_flowrate == 10) { |
Lightvalve | 50:3c630b5eba9f | 1037 | // V_out = 0; |
Lightvalve | 50:3c630b5eba9f | 1038 | // flag_flowrate = 0; |
Lightvalve | 50:3c630b5eba9f | 1039 | // TMR3_COUNT_FLOWRATE = 0; |
Lightvalve | 50:3c630b5eba9f | 1040 | // valve_gain_repeat_cnt++; |
Lightvalve | 50:3c630b5eba9f | 1041 | // if (valve_gain_repeat_cnt >= 1) { |
Lightvalve | 50:3c630b5eba9f | 1042 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 50:3c630b5eba9f | 1043 | // valve_gain_repeat_cnt = 0; |
Lightvalve | 50:3c630b5eba9f | 1044 | // } |
Lightvalve | 50:3c630b5eba9f | 1045 | // |
Lightvalve | 50:3c630b5eba9f | 1046 | // } |
Lightvalve | 50:3c630b5eba9f | 1047 | // break; |
Lightvalve | 50:3c630b5eba9f | 1048 | // } |
Lightvalve | 50:3c630b5eba9f | 1049 | // |
Lightvalve | 50:3c630b5eba9f | 1050 | // } |
Lightvalve | 14:8e7590227d22 | 1051 | case MODE_PRESSURE_SENSOR_NULLING: { |
Lightvalve | 13:747daba9cf59 | 1052 | // DAC Voltage reference set |
Lightvalve | 14:8e7590227d22 | 1053 | if (TMR3_COUNT_PRES_NULL < TMR_FREQ_5k * 2) { |
Lightvalve | 14:8e7590227d22 | 1054 | CUR_PRES_A_sum += pres_A.sen; |
Lightvalve | 14:8e7590227d22 | 1055 | CUR_PRES_B_sum += pres_B.sen; |
Lightvalve | 14:8e7590227d22 | 1056 | |
Lightvalve | 14:8e7590227d22 | 1057 | if (TMR3_COUNT_PRES_NULL % 10 == 0) { |
Lightvalve | 30:8d561f16383b | 1058 | CUR_PRES_A_mean = CUR_PRES_A_sum / 10.0f; |
Lightvalve | 30:8d561f16383b | 1059 | CUR_PRES_B_mean = CUR_PRES_B_sum / 10.0f; |
Lightvalve | 13:747daba9cf59 | 1060 | CUR_PRES_A_sum = 0; |
Lightvalve | 13:747daba9cf59 | 1061 | CUR_PRES_B_sum = 0; |
Lightvalve | 14:8e7590227d22 | 1062 | |
Lightvalve | 38:118df027d851 | 1063 | float VREF_NullingGain = 0.0003f; |
Lightvalve | 58:2eade98630e2 | 1064 | PRES_A_VREF = PRES_A_VREF + VREF_NullingGain * CUR_PRES_A_mean; |
Lightvalve | 58:2eade98630e2 | 1065 | PRES_B_VREF = PRES_B_VREF + VREF_NullingGain * CUR_PRES_B_mean; |
Lightvalve | 14:8e7590227d22 | 1066 | |
Lightvalve | 30:8d561f16383b | 1067 | if (PRES_A_VREF > 3.3f) PRES_A_VREF = 3.3f; |
Lightvalve | 30:8d561f16383b | 1068 | if (PRES_A_VREF < 0.0f) PRES_A_VREF = 0.0f; |
Lightvalve | 30:8d561f16383b | 1069 | if (PRES_B_VREF > 3.3f) PRES_B_VREF = 3.3f; |
Lightvalve | 30:8d561f16383b | 1070 | if (PRES_B_VREF < 0.0f) PRES_B_VREF = 0.0f; |
Lightvalve | 19:23b7c1ad8683 | 1071 | |
Lightvalve | 30:8d561f16383b | 1072 | dac_1 = PRES_A_VREF / 3.3f; |
Lightvalve | 30:8d561f16383b | 1073 | dac_2 = PRES_B_VREF / 3.3f; |
Lightvalve | 13:747daba9cf59 | 1074 | } |
Lightvalve | 13:747daba9cf59 | 1075 | } else { |
Lightvalve | 57:f4819de54e7a | 1076 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 14:8e7590227d22 | 1077 | TMR3_COUNT_PRES_NULL = 0; |
Lightvalve | 13:747daba9cf59 | 1078 | CUR_PRES_A_sum = 0; |
Lightvalve | 13:747daba9cf59 | 1079 | CUR_PRES_B_sum = 0; |
Lightvalve | 13:747daba9cf59 | 1080 | CUR_PRES_A_mean = 0; |
Lightvalve | 13:747daba9cf59 | 1081 | CUR_PRES_B_mean = 0; |
Lightvalve | 14:8e7590227d22 | 1082 | |
Lightvalve | 16:903b5a4433b4 | 1083 | ROM_RESET_DATA(); |
Lightvalve | 19:23b7c1ad8683 | 1084 | |
Lightvalve | 30:8d561f16383b | 1085 | dac_1 = PRES_A_VREF / 3.3f; |
Lightvalve | 30:8d561f16383b | 1086 | dac_2 = PRES_B_VREF / 3.3f; |
Lightvalve | 17:1865016ca2e7 | 1087 | //pc.printf("nulling end"); |
Lightvalve | 13:747daba9cf59 | 1088 | } |
Lightvalve | 14:8e7590227d22 | 1089 | TMR3_COUNT_PRES_NULL++; |
Lightvalve | 13:747daba9cf59 | 1090 | break; |
Lightvalve | 13:747daba9cf59 | 1091 | } |
Lightvalve | 14:8e7590227d22 | 1092 | |
Lightvalve | 50:3c630b5eba9f | 1093 | // case MODE_PRESSURE_SENSOR_CALIB: { |
Lightvalve | 50:3c630b5eba9f | 1094 | // if (TMR3_COUNT_PRES_CALIB < 2 * TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1095 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1096 | // if (TMR3_COUNT_PRES_CALIB >= TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1097 | // CUR_PRES_A_sum += CUR_PRES_A; |
Lightvalve | 50:3c630b5eba9f | 1098 | // } |
Lightvalve | 50:3c630b5eba9f | 1099 | // } else if (TMR3_COUNT_PRES_CALIB < 4 * TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1100 | // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1101 | // if (TMR3_COUNT_PRES_CALIB >= 3 * TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1102 | // CUR_PRES_B_sum += CUR_PRES_B; |
Lightvalve | 50:3c630b5eba9f | 1103 | // } |
Lightvalve | 50:3c630b5eba9f | 1104 | // } else { |
Lightvalve | 50:3c630b5eba9f | 1105 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 50:3c630b5eba9f | 1106 | // TMR3_COUNT_PRES_CALIB = 0; |
Lightvalve | 50:3c630b5eba9f | 1107 | // V_out = 0; |
Lightvalve | 50:3c630b5eba9f | 1108 | // PRES_SENSOR_A_PULSE_PER_BAR = CUR_PRES_A_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_A_NULL; |
Lightvalve | 50:3c630b5eba9f | 1109 | // PRES_SENSOR_A_PULSE_PER_BAR = PRES_SENSOR_A_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f); |
Lightvalve | 50:3c630b5eba9f | 1110 | // PRES_SENSOR_B_PULSE_PER_BAR = CUR_PRES_B_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_B_NULL; |
Lightvalve | 50:3c630b5eba9f | 1111 | // PRES_SENSOR_B_PULSE_PER_BAR = PRES_SENSOR_B_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f); |
Lightvalve | 50:3c630b5eba9f | 1112 | // CUR_PRES_A_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 1113 | // CUR_PRES_B_sum = 0; |
Lightvalve | 50:3c630b5eba9f | 1114 | // CUR_PRES_A_mean = 0; |
Lightvalve | 50:3c630b5eba9f | 1115 | // CUR_PRES_B_mean = 0; |
Lightvalve | 50:3c630b5eba9f | 1116 | // |
Lightvalve | 50:3c630b5eba9f | 1117 | // ROM_RESET_DATA(); |
Lightvalve | 50:3c630b5eba9f | 1118 | // |
Lightvalve | 50:3c630b5eba9f | 1119 | // //spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f)); |
Lightvalve | 50:3c630b5eba9f | 1120 | // //spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f)); |
Lightvalve | 50:3c630b5eba9f | 1121 | // } |
Lightvalve | 50:3c630b5eba9f | 1122 | // TMR3_COUNT_PRES_CALIB++; |
Lightvalve | 50:3c630b5eba9f | 1123 | // break; |
Lightvalve | 50:3c630b5eba9f | 1124 | // } |
Lightvalve | 19:23b7c1ad8683 | 1125 | |
Lightvalve | 50:3c630b5eba9f | 1126 | // case MODE_ROTARY_FRICTION_TUNING: { |
Lightvalve | 50:3c630b5eba9f | 1127 | // 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 | 1128 | // V_out = PWM_out * sin(2 * 3.14159f * freq_fric_tune * TMR3_COUNT_ROTARY_FRIC_TUNE * 0.0001f); |
Lightvalve | 50:3c630b5eba9f | 1129 | // if (V_out > 0) V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1130 | // else V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 50:3c630b5eba9f | 1131 | // TMR3_COUNT_ROTARY_FRIC_TUNE++; |
Lightvalve | 50:3c630b5eba9f | 1132 | // if (TMR3_COUNT_ROTARY_FRIC_TUNE > TUNING_TIME * TMR_FREQ_5k) { |
Lightvalve | 50:3c630b5eba9f | 1133 | // TMR3_COUNT_ROTARY_FRIC_TUNE = 0; |
Lightvalve | 50:3c630b5eba9f | 1134 | // V_out = 0.0f; |
Lightvalve | 50:3c630b5eba9f | 1135 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 50:3c630b5eba9f | 1136 | // } |
Lightvalve | 50:3c630b5eba9f | 1137 | // break; |
Lightvalve | 50:3c630b5eba9f | 1138 | // } |
Lightvalve | 14:8e7590227d22 | 1139 | |
Lightvalve | 14:8e7590227d22 | 1140 | case MODE_DDV_POS_VS_PWM_ID: { |
Lightvalve | 59:f308b1656d9c | 1141 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 13:747daba9cf59 | 1142 | VALVE_ID_timer = VALVE_ID_timer + 1; |
Lightvalve | 14:8e7590227d22 | 1143 | |
Lightvalve | 14:8e7590227d22 | 1144 | if(VALVE_ID_timer < TMR_FREQ_5k*1) { |
Lightvalve | 60:64181f1d3e60 | 1145 | Vout.ref = 3000.0f * sin(2.0f*3.14f*VALVE_ID_timer/TMR_FREQ_5k * 100.0f); |
Lightvalve | 14:8e7590227d22 | 1146 | } else if(VALVE_ID_timer < TMR_FREQ_5k*2) { |
Lightvalve | 59:f308b1656d9c | 1147 | Vout.ref = 1000.0f*(ID_index_array[ID_index]); |
Lightvalve | 14:8e7590227d22 | 1148 | } else if(VALVE_ID_timer == TMR_FREQ_5k*2) { |
Lightvalve | 13:747daba9cf59 | 1149 | VALVE_POS_TMP = 0; |
Lightvalve | 13:747daba9cf59 | 1150 | data_num = 0; |
Lightvalve | 14:8e7590227d22 | 1151 | } else if(VALVE_ID_timer < TMR_FREQ_5k*3) { |
Lightvalve | 13:747daba9cf59 | 1152 | data_num = data_num + 1; |
Lightvalve | 13:747daba9cf59 | 1153 | VALVE_POS_TMP = VALVE_POS_TMP + value; |
Lightvalve | 14:8e7590227d22 | 1154 | } else if(VALVE_ID_timer == TMR_FREQ_5k*3) { |
Lightvalve | 59:f308b1656d9c | 1155 | Vout.ref = 0.0f; |
Lightvalve | 59:f308b1656d9c | 1156 | } else { |
Lightvalve | 13:747daba9cf59 | 1157 | VALVE_POS_AVG[ID_index] = VALVE_POS_TMP / data_num; |
Lightvalve | 13:747daba9cf59 | 1158 | VALVE_ID_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1159 | ID_index= ID_index +1; |
Lightvalve | 13:747daba9cf59 | 1160 | } |
Lightvalve | 14:8e7590227d22 | 1161 | |
Lightvalve | 17:1865016ca2e7 | 1162 | if(ID_index>=25) { |
Lightvalve | 13:747daba9cf59 | 1163 | int i; |
Lightvalve | 13:747daba9cf59 | 1164 | VALVE_POS_AVG_OLD = VALVE_POS_AVG[0]; |
Lightvalve | 17:1865016ca2e7 | 1165 | for(i=0; i<25; i++) { |
Lightvalve | 13:747daba9cf59 | 1166 | VALVE_POS_VS_PWM[i] = (int16_t) (VALVE_POS_AVG[i]); |
Lightvalve | 14:8e7590227d22 | 1167 | if(VALVE_POS_AVG[i] > VALVE_POS_AVG_OLD) { |
Lightvalve | 13:747daba9cf59 | 1168 | VALVE_MAX_POS = VALVE_POS_AVG[i]; |
Lightvalve | 13:747daba9cf59 | 1169 | VALVE_POS_AVG_OLD = VALVE_MAX_POS; |
Lightvalve | 14:8e7590227d22 | 1170 | } else if(VALVE_POS_AVG[i] < VALVE_POS_AVG_OLD) { |
Lightvalve | 13:747daba9cf59 | 1171 | VALVE_MIN_POS = VALVE_POS_AVG[i]; |
Lightvalve | 13:747daba9cf59 | 1172 | VALVE_POS_AVG_OLD = VALVE_MIN_POS; |
Lightvalve | 13:747daba9cf59 | 1173 | } |
Lightvalve | 13:747daba9cf59 | 1174 | } |
Lightvalve | 59:f308b1656d9c | 1175 | ROM_RESET_DATA(); |
Lightvalve | 13:747daba9cf59 | 1176 | ID_index = 0; |
Lightvalve | 57:f4819de54e7a | 1177 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 13:747daba9cf59 | 1178 | } |
Lightvalve | 14:8e7590227d22 | 1179 | |
Lightvalve | 14:8e7590227d22 | 1180 | |
Lightvalve | 13:747daba9cf59 | 1181 | break; |
Lightvalve | 13:747daba9cf59 | 1182 | } |
Lightvalve | 14:8e7590227d22 | 1183 | |
Lightvalve | 14:8e7590227d22 | 1184 | case MODE_DDV_DEADZONE_AND_CENTER: { |
Lightvalve | 59:f308b1656d9c | 1185 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 13:747daba9cf59 | 1186 | VALVE_DZ_timer = VALVE_DZ_timer + 1; |
Lightvalve | 14:8e7590227d22 | 1187 | if(first_check == 0) { |
Lightvalve | 30:8d561f16383b | 1188 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1189 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 30:8d561f16383b | 1190 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1191 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1192 | pos_plus_end = pos.sen; |
Lightvalve | 30:8d561f16383b | 1193 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1194 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 30:8d561f16383b | 1195 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1196 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1197 | pos_minus_end = pos.sen; |
Lightvalve | 30:8d561f16383b | 1198 | } else if(VALVE_DZ_timer < (int) (3.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1199 | 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 | 1200 | } else if(VALVE_DZ_timer < (int) (4.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1201 | 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 | 1202 | data_num = data_num + 1; |
Lightvalve | 13:747daba9cf59 | 1203 | VALVE_POS_TMP = VALVE_POS_TMP + value; |
Lightvalve | 30:8d561f16383b | 1204 | } else if(VALVE_DZ_timer == (int) (4.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1205 | 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 | 1206 | DDV_POS_AVG = VALVE_POS_TMP / data_num; |
Lightvalve | 14:8e7590227d22 | 1207 | START_POS = pos.sen; |
Lightvalve | 13:747daba9cf59 | 1208 | VALVE_POS_TMP = 0; |
Lightvalve | 13:747daba9cf59 | 1209 | data_num = 0; |
Lightvalve | 14:8e7590227d22 | 1210 | |
Lightvalve | 30:8d561f16383b | 1211 | } else if(VALVE_DZ_timer < (int) (5.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1212 | valve_pos.ref = DDV_POS_AVG; |
Lightvalve | 14:8e7590227d22 | 1213 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 14:8e7590227d22 | 1214 | |
Lightvalve | 30:8d561f16383b | 1215 | } else if(VALVE_DZ_timer < (int) (6.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1216 | valve_pos.ref = DDV_POS_AVG; |
Lightvalve | 14:8e7590227d22 | 1217 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 60:64181f1d3e60 | 1218 | |
Lightvalve | 30:8d561f16383b | 1219 | } else if(VALVE_DZ_timer == (int) (6.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1220 | valve_pos.ref = DDV_POS_AVG; |
Lightvalve | 14:8e7590227d22 | 1221 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 14:8e7590227d22 | 1222 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1223 | |
Lightvalve | 60:64181f1d3e60 | 1224 | if((FINAL_POS - START_POS)>200) { |
Lightvalve | 13:747daba9cf59 | 1225 | DZ_case = 1; |
Lightvalve | 60:64181f1d3e60 | 1226 | } else if((FINAL_POS - START_POS)<-200) { |
Lightvalve | 13:747daba9cf59 | 1227 | DZ_case = -1; |
Lightvalve | 14:8e7590227d22 | 1228 | } else { |
Lightvalve | 13:747daba9cf59 | 1229 | DZ_case = 0; |
Lightvalve | 13:747daba9cf59 | 1230 | } |
Lightvalve | 61:bc8c8270f0ab | 1231 | |
Lightvalve | 60:64181f1d3e60 | 1232 | CAN_TX_PRES((int16_t) (DZ_case), (int16_t) (6)); |
Lightvalve | 50:3c630b5eba9f | 1233 | |
Lightvalve | 13:747daba9cf59 | 1234 | first_check = 1; |
Lightvalve | 13:747daba9cf59 | 1235 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1236 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1237 | Ref_Valve_Pos_Old = DDV_POS_AVG; |
Lightvalve | 13:747daba9cf59 | 1238 | DZ_NUM = 1; |
Lightvalve | 13:747daba9cf59 | 1239 | DZ_index = 1; |
Lightvalve | 14:8e7590227d22 | 1240 | |
Lightvalve | 13:747daba9cf59 | 1241 | } |
Lightvalve | 19:23b7c1ad8683 | 1242 | } else { |
Lightvalve | 14:8e7590227d22 | 1243 | if((DZ_case == -1 && DZ_NUM == 1) | (DZ_case == 1 && DZ_NUM == 1)) { |
Lightvalve | 30:8d561f16383b | 1244 | if(VALVE_DZ_timer < (int) (1.0 * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1245 | 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 | 1246 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 60:64181f1d3e60 | 1247 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1248 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1249 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1250 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1251 | valve_pos.ref = Ref_Valve_Pos_Old - DZ_case * DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1252 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1253 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1254 | } else if(valve_pos.ref >= VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1255 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 13:747daba9cf59 | 1256 | } |
Lightvalve | 14:8e7590227d22 | 1257 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 60:64181f1d3e60 | 1258 | |
Lightvalve | 30:8d561f16383b | 1259 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1260 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1261 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1262 | |
Lightvalve | 14:8e7590227d22 | 1263 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 14:8e7590227d22 | 1264 | DZ_DIRECTION = 1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1265 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 14:8e7590227d22 | 1266 | DZ_DIRECTION = -1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1267 | } else { |
Lightvalve | 13:747daba9cf59 | 1268 | DZ_DIRECTION = 1 * DZ_case; |
Lightvalve | 13:747daba9cf59 | 1269 | } |
Lightvalve | 14:8e7590227d22 | 1270 | |
Lightvalve | 13:747daba9cf59 | 1271 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1272 | DZ_index= DZ_index *2; |
Lightvalve | 14:8e7590227d22 | 1273 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1274 | FIRST_DZ = valve_pos.ref; |
Lightvalve | 13:747daba9cf59 | 1275 | DZ_NUM = 2; |
Lightvalve | 13:747daba9cf59 | 1276 | Ref_Valve_Pos_Old = FIRST_DZ; |
Lightvalve | 13:747daba9cf59 | 1277 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1278 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1279 | } |
Lightvalve | 13:747daba9cf59 | 1280 | } |
Lightvalve | 14:8e7590227d22 | 1281 | } else if((DZ_case == -1 && DZ_NUM == 2) | (DZ_case == 1 && DZ_NUM == 2)) { |
Lightvalve | 30:8d561f16383b | 1282 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1283 | 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 | 1284 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 60:64181f1d3e60 | 1285 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1286 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1287 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1288 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1289 | valve_pos.ref = Ref_Valve_Pos_Old - DZ_case * DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1290 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1291 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1292 | } else if(valve_pos.ref >= VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1293 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 13:747daba9cf59 | 1294 | } |
Lightvalve | 14:8e7590227d22 | 1295 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 61:bc8c8270f0ab | 1296 | |
Lightvalve | 30:8d561f16383b | 1297 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1298 | Vout.ref = 0.0f; |
Lightvalve | 59:f308b1656d9c | 1299 | } else if(VALVE_DZ_timer > (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1300 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1301 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1302 | |
Lightvalve | 14:8e7590227d22 | 1303 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 60:64181f1d3e60 | 1304 | DZ_DIRECTION = 1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1305 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 60:64181f1d3e60 | 1306 | DZ_DIRECTION = -1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1307 | } else { |
Lightvalve | 60:64181f1d3e60 | 1308 | DZ_DIRECTION = -1 * DZ_case; |
Lightvalve | 13:747daba9cf59 | 1309 | } |
Lightvalve | 14:8e7590227d22 | 1310 | |
Lightvalve | 13:747daba9cf59 | 1311 | VALVE_DZ_timer = 0; |
Lightvalve | 60:64181f1d3e60 | 1312 | DZ_index= DZ_index * 2; |
Lightvalve | 14:8e7590227d22 | 1313 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1314 | SECOND_DZ = valve_pos.ref; |
Lightvalve | 57:f4819de54e7a | 1315 | VALVE_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ)); |
Lightvalve | 13:747daba9cf59 | 1316 | first_check = 0; |
Lightvalve | 33:91b17819ec30 | 1317 | VALVE_DEADZONE_MINUS = (float) FIRST_DZ; |
Lightvalve | 33:91b17819ec30 | 1318 | VALVE_DEADZONE_PLUS = (float) SECOND_DZ; |
Lightvalve | 19:23b7c1ad8683 | 1319 | |
Lightvalve | 16:903b5a4433b4 | 1320 | ROM_RESET_DATA(); |
Lightvalve | 34:bb2ca2fc2a8e | 1321 | |
Lightvalve | 60:64181f1d3e60 | 1322 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 13:747daba9cf59 | 1323 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1324 | } |
Lightvalve | 13:747daba9cf59 | 1325 | } |
Lightvalve | 14:8e7590227d22 | 1326 | } else if(DZ_case == 0 && DZ_NUM ==1) { |
Lightvalve | 30:8d561f16383b | 1327 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1328 | 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 | 1329 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 60:64181f1d3e60 | 1330 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1331 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1332 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1333 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1334 | valve_pos.ref = Ref_Valve_Pos_Old - DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1335 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1336 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1337 | } else if(valve_pos.ref >= VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1338 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 13:747daba9cf59 | 1339 | } |
Lightvalve | 14:8e7590227d22 | 1340 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 61:bc8c8270f0ab | 1341 | |
Lightvalve | 30:8d561f16383b | 1342 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1343 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1344 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1345 | |
Lightvalve | 14:8e7590227d22 | 1346 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 14:8e7590227d22 | 1347 | DZ_DIRECTION = 1; |
Lightvalve | 14:8e7590227d22 | 1348 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 14:8e7590227d22 | 1349 | DZ_DIRECTION = -1; |
Lightvalve | 14:8e7590227d22 | 1350 | } else { |
Lightvalve | 13:747daba9cf59 | 1351 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1352 | } |
Lightvalve | 13:747daba9cf59 | 1353 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1354 | DZ_index= DZ_index *2; |
Lightvalve | 14:8e7590227d22 | 1355 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1356 | FIRST_DZ = valve_pos.ref; |
Lightvalve | 13:747daba9cf59 | 1357 | DZ_NUM = 2; |
Lightvalve | 13:747daba9cf59 | 1358 | Ref_Valve_Pos_Old = FIRST_DZ; |
Lightvalve | 13:747daba9cf59 | 1359 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1360 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1361 | } |
Lightvalve | 13:747daba9cf59 | 1362 | } |
Lightvalve | 14:8e7590227d22 | 1363 | } else { |
Lightvalve | 30:8d561f16383b | 1364 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 60:64181f1d3e60 | 1365 | 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 | 1366 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 60:64181f1d3e60 | 1367 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1368 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1369 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1370 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1371 | valve_pos.ref = Ref_Valve_Pos_Old + DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1372 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1373 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1374 | } else if(valve_pos.ref > VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1375 | valve_pos.ref = VALVE_MAX_POS - 1; |
Lightvalve | 13:747daba9cf59 | 1376 | } |
Lightvalve | 14:8e7590227d22 | 1377 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 60:64181f1d3e60 | 1378 | |
Lightvalve | 30:8d561f16383b | 1379 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1380 | Vout.ref = 0.0f; |
Lightvalve | 59:f308b1656d9c | 1381 | } else if(VALVE_DZ_timer > (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1382 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1383 | FINAL_POS = pos.sen; |
Lightvalve | 61:bc8c8270f0ab | 1384 | |
Lightvalve | 60:64181f1d3e60 | 1385 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 13:747daba9cf59 | 1386 | DZ_DIRECTION = 1; |
Lightvalve | 60:64181f1d3e60 | 1387 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 60:64181f1d3e60 | 1388 | DZ_DIRECTION = -1; |
Lightvalve | 60:64181f1d3e60 | 1389 | } else { |
Lightvalve | 13:747daba9cf59 | 1390 | DZ_DIRECTION = 1; |
Lightvalve | 60:64181f1d3e60 | 1391 | } |
Lightvalve | 14:8e7590227d22 | 1392 | |
Lightvalve | 13:747daba9cf59 | 1393 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1394 | DZ_index= DZ_index *2; |
Lightvalve | 14:8e7590227d22 | 1395 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1396 | SECOND_DZ = valve_pos.ref; |
Lightvalve | 57:f4819de54e7a | 1397 | VALVE_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ)); |
Lightvalve | 13:747daba9cf59 | 1398 | first_check = 0; |
Lightvalve | 33:91b17819ec30 | 1399 | VALVE_DEADZONE_MINUS = (float) FIRST_DZ; |
Lightvalve | 33:91b17819ec30 | 1400 | VALVE_DEADZONE_PLUS = (float) SECOND_DZ; |
Lightvalve | 61:bc8c8270f0ab | 1401 | |
Lightvalve | 59:f308b1656d9c | 1402 | ROM_RESET_DATA(); |
Lightvalve | 34:bb2ca2fc2a8e | 1403 | |
Lightvalve | 57:f4819de54e7a | 1404 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 13:747daba9cf59 | 1405 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1406 | } |
Lightvalve | 13:747daba9cf59 | 1407 | } |
Lightvalve | 13:747daba9cf59 | 1408 | } |
Lightvalve | 14:8e7590227d22 | 1409 | } |
Lightvalve | 13:747daba9cf59 | 1410 | break; |
Lightvalve | 13:747daba9cf59 | 1411 | } |
Lightvalve | 14:8e7590227d22 | 1412 | |
Lightvalve | 14:8e7590227d22 | 1413 | case MODE_DDV_POS_VS_FLOWRATE: { |
Lightvalve | 59:f308b1656d9c | 1414 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 13:747daba9cf59 | 1415 | VALVE_FR_timer = VALVE_FR_timer + 1; |
Lightvalve | 14:8e7590227d22 | 1416 | if(first_check == 0) { |
Lightvalve | 30:8d561f16383b | 1417 | if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1418 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 23:59218d4a256d | 1419 | //CAN_TX_PRES((int16_t) (VALVE_FR_timer), (int16_t) (6)); |
Lightvalve | 30:8d561f16383b | 1420 | } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1421 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1422 | pos_plus_end = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1423 | // CAN_TX_PRES((int16_t) (V_out), (int16_t) (7)); |
Lightvalve | 30:8d561f16383b | 1424 | } else if(VALVE_FR_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1425 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 30:8d561f16383b | 1426 | } else if(VALVE_FR_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1427 | // CAN_TX_PRES((int16_t) (V_out), (int16_t) (8)); |
Lightvalve | 59:f308b1656d9c | 1428 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1429 | pos_minus_end = pos.sen; |
Lightvalve | 13:747daba9cf59 | 1430 | first_check = 1; |
Lightvalve | 13:747daba9cf59 | 1431 | VALVE_FR_timer = 0; |
Lightvalve | 57:f4819de54e7a | 1432 | valve_pos.ref = (float) VALVE_CENTER; |
Lightvalve | 13:747daba9cf59 | 1433 | ID_index = 0; |
Lightvalve | 13:747daba9cf59 | 1434 | max_check = 0; |
Lightvalve | 13:747daba9cf59 | 1435 | min_check = 0; |
Lightvalve | 13:747daba9cf59 | 1436 | } |
Lightvalve | 14:8e7590227d22 | 1437 | } else { |
Lightvalve | 30:8d561f16383b | 1438 | if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 59:f308b1656d9c | 1439 | //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 | 1440 | pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 59:f308b1656d9c | 1441 | CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1442 | } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 13:747daba9cf59 | 1443 | data_num = 0; |
Lightvalve | 57:f4819de54e7a | 1444 | valve_pos.ref = 10.0f*((float) ID_index_array[ID_index]) + (float) VALVE_CENTER; |
Lightvalve | 14:8e7590227d22 | 1445 | |
Lightvalve | 14:8e7590227d22 | 1446 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 14:8e7590227d22 | 1447 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1448 | } else if(VALVE_FR_timer < (int) (5.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f4819de54e7a | 1449 | valve_pos.ref = 10.0f*((float) ID_index_array[ID_index]) + (float) VALVE_CENTER; |
Lightvalve | 14:8e7590227d22 | 1450 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 13:747daba9cf59 | 1451 | data_num = data_num + 1; |
Lightvalve | 30:8d561f16383b | 1452 | if(abs(0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen) > 20000.0f) { |
Lightvalve | 14:8e7590227d22 | 1453 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1454 | one_period_end = 1; |
Lightvalve | 13:747daba9cf59 | 1455 | } |
Lightvalve | 30:8d561f16383b | 1456 | } else if(VALVE_FR_timer == (int) (5.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1457 | FINAL_POS = pos.sen; |
Lightvalve | 13:747daba9cf59 | 1458 | one_period_end = 1; |
Lightvalve | 59:f308b1656d9c | 1459 | V_out = 0.0f; |
Lightvalve | 13:747daba9cf59 | 1460 | } |
Lightvalve | 14:8e7590227d22 | 1461 | |
Lightvalve | 14:8e7590227d22 | 1462 | if(one_period_end == 1) { |
Lightvalve | 14:8e7590227d22 | 1463 | if(valve_pos.ref > VALVE_MAX_POS) { |
Lightvalve | 13:747daba9cf59 | 1464 | max_check = 1; |
Lightvalve | 14:8e7590227d22 | 1465 | } else if(valve_pos.ref < VALVE_MIN_POS) { |
Lightvalve | 13:747daba9cf59 | 1466 | min_check = 1; |
Lightvalve | 13:747daba9cf59 | 1467 | } |
Lightvalve | 13:747daba9cf59 | 1468 | JOINT_VEL[ID_index] = (FINAL_POS - START_POS) / data_num * TMR_FREQ_5k; // pulse/sec |
Lightvalve | 19:23b7c1ad8683 | 1469 | |
Lightvalve | 13:747daba9cf59 | 1470 | VALVE_FR_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1471 | one_period_end = 0; |
Lightvalve | 13:747daba9cf59 | 1472 | ID_index= ID_index +1; |
Lightvalve | 30:8d561f16383b | 1473 | V_out = 0.0f; |
Lightvalve | 13:747daba9cf59 | 1474 | } |
Lightvalve | 14:8e7590227d22 | 1475 | |
Lightvalve | 14:8e7590227d22 | 1476 | if(max_check == 1 && min_check == 1) { |
Lightvalve | 19:23b7c1ad8683 | 1477 | |
Lightvalve | 13:747daba9cf59 | 1478 | VALVE_POS_NUM = ID_index; |
Lightvalve | 59:f308b1656d9c | 1479 | ROM_RESET_DATA(); |
Lightvalve | 13:747daba9cf59 | 1480 | ID_index = 0; |
Lightvalve | 13:747daba9cf59 | 1481 | first_check = 0; |
Lightvalve | 13:747daba9cf59 | 1482 | VALVE_FR_timer = 0; |
Lightvalve | 57:f4819de54e7a | 1483 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 49:e7bcfc244d40 | 1484 | // CAN_TX_PRES((int16_t) (VALVE_FR_timer), (int16_t) (6)); |
Lightvalve | 13:747daba9cf59 | 1485 | } |
Lightvalve | 13:747daba9cf59 | 1486 | } |
Lightvalve | 13:747daba9cf59 | 1487 | break; |
Lightvalve | 13:747daba9cf59 | 1488 | } |
Lightvalve | 58:2eade98630e2 | 1489 | |
Lightvalve | 57:f4819de54e7a | 1490 | case MODE_SYSTEM_ID: { |
Lightvalve | 57:f4819de54e7a | 1491 | freq_sysid_Iref = (double) cnt_sysid * DT_TMR3 * 3.; |
Lightvalve | 57:f4819de54e7a | 1492 | valve_pos.ref = 2500.0f * sin(2.0f * 3.14159f * freq_sysid_Iref * (double) cnt_sysid * DT_TMR3); |
Lightvalve | 57:f4819de54e7a | 1493 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 57:f4819de54e7a | 1494 | cnt_sysid++; |
Lightvalve | 57:f4819de54e7a | 1495 | if (freq_sysid_Iref >= 300) { |
Lightvalve | 57:f4819de54e7a | 1496 | cnt_sysid = 0; |
Lightvalve | 57:f4819de54e7a | 1497 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 57:f4819de54e7a | 1498 | } |
Lightvalve | 57:f4819de54e7a | 1499 | break; |
Lightvalve | 57:f4819de54e7a | 1500 | } |
Lightvalve | 58:2eade98630e2 | 1501 | |
Lightvalve | 58:2eade98630e2 | 1502 | |
Lightvalve | 57:f4819de54e7a | 1503 | |
Lightvalve | 57:f4819de54e7a | 1504 | default: |
Lightvalve | 57:f4819de54e7a | 1505 | break; |
Lightvalve | 57:f4819de54e7a | 1506 | } |
Lightvalve | 57:f4819de54e7a | 1507 | |
Lightvalve | 57:f4819de54e7a | 1508 | // CONTROL MODE ------------------------------------------------------------ |
Lightvalve | 57:f4819de54e7a | 1509 | |
Lightvalve | 57:f4819de54e7a | 1510 | switch (CONTROL_MODE) { |
Lightvalve | 57:f4819de54e7a | 1511 | case MODE_NO_ACT: { |
Lightvalve | 57:f4819de54e7a | 1512 | V_out = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1513 | break; |
Lightvalve | 57:f4819de54e7a | 1514 | } |
Lightvalve | 57:f4819de54e7a | 1515 | |
Lightvalve | 57:f4819de54e7a | 1516 | case MODE_VALVE_POSITION_CONTROL: { |
Lightvalve | 67:c2812cf26c38 | 1517 | if (OPERATING_MODE == 5) { //SW Valve |
Lightvalve | 57:f4819de54e7a | 1518 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 59:f308b1656d9c | 1519 | V_out = Vout.ref; |
Lightvalve | 67:c2812cf26c38 | 1520 | } else if (CURRENT_CONTROL_MODE == 0) { //PWM |
Lightvalve | 67:c2812cf26c38 | 1521 | V_out = valve_pos.ref; |
Lightvalve | 67:c2812cf26c38 | 1522 | } else { |
Lightvalve | 67:c2812cf26c38 | 1523 | I_REF = valve_pos.ref * 0.001f; |
Lightvalve | 57:f4819de54e7a | 1524 | } |
Lightvalve | 58:2eade98630e2 | 1525 | |
Lightvalve | 57:f4819de54e7a | 1526 | break; |
Lightvalve | 57:f4819de54e7a | 1527 | } |
Lightvalve | 57:f4819de54e7a | 1528 | |
Lightvalve | 57:f4819de54e7a | 1529 | case MODE_JOINT_CONTROL: { |
Lightvalve | 57:f4819de54e7a | 1530 | double torq_ref = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1531 | pos.err = (pos.ref - pos.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm] |
Lightvalve | 67:c2812cf26c38 | 1532 | vel.err = (0.0f - vel.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm/s] |
Lightvalve | 57:f4819de54e7a | 1533 | pos.err_sum += pos.err/(float) TMR_FREQ_5k; //[mm] |
Lightvalve | 67:c2812cf26c38 | 1534 | |
Lightvalve | 67:c2812cf26c38 | 1535 | //K & D Low Pass Filter |
Lightvalve | 67:c2812cf26c38 | 1536 | float alpha_K_D = 1.0f/(1.0f + 5000.0f/(2.0f*3.14f*30.0f)); // f_cutoff : 30Hz |
Lightvalve | 67:c2812cf26c38 | 1537 | K_LPF = K_LPF*(1.0f-alpha_K_D)+K_SPRING*(alpha_K_D); |
Lightvalve | 67:c2812cf26c38 | 1538 | D_LPF = D_LPF*(1.0f-alpha_K_D)+D_DAMPER*(alpha_K_D); |
Lightvalve | 67:c2812cf26c38 | 1539 | |
Lightvalve | 67:c2812cf26c38 | 1540 | torq_ref = torq.ref + K_LPF * pos.err - D_LPF * vel.sen / ENC_PULSE_PER_POSITION; //[N] |
Lightvalve | 57:f4819de54e7a | 1541 | |
Lightvalve | 57:f4819de54e7a | 1542 | // torque feedback |
Lightvalve | 67:c2812cf26c38 | 1543 | torq.err = torq_ref - torq.sen; //[N] |
Lightvalve | 57:f4819de54e7a | 1544 | torq.err_sum += torq.err/(float) TMR_FREQ_5k; //[N] |
Lightvalve | 57:f4819de54e7a | 1545 | |
Lightvalve | 57:f4819de54e7a | 1546 | if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) { |
Lightvalve | 58:2eade98630e2 | 1547 | |
Lightvalve | 57:f4819de54e7a | 1548 | double I_REF_POS = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1549 | double I_REF_FORCE_FB = 0.0f; // I_REF by Force Feedback |
Lightvalve | 57:f4819de54e7a | 1550 | double I_REF_VC = 0.0f; // I_REF for velocity compensation |
Lightvalve | 57:f4819de54e7a | 1551 | |
Lightvalve | 57:f4819de54e7a | 1552 | double temp_vel_pos = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1553 | double temp_vel_torq = 0.0f; |
Lightvalve | 57:f4819de54e7a | 1554 | double wn_Pos = 2.0f * PI * 5.0f; // f_cut : 5Hz Position Control |
Lightvalve | 58:2eade98630e2 | 1555 | |
Lightvalve | 69:3995ffeaa786 | 1556 | if ((OPERATING_MODE & 0x01) == 0) { // Rotary Mode |
Lightvalve | 57:f4819de54e7a | 1557 | 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 | 1558 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 69:3995ffeaa786 | 1559 | } else if ((OPERATING_MODE & 0x01) == 1) { |
Lightvalve | 57:f4819de54e7a | 1560 | 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 | 1561 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 57:f4819de54e7a | 1562 | } |
Lightvalve | 57:f4819de54e7a | 1563 | 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 | 1564 | else I_REF_POS = temp_vel_pos * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f)))); |
Lightvalve | 57:f4819de54e7a | 1565 | |
Lightvalve | 57:f4819de54e7a | 1566 | // velocity compensation for torque control |
Lightvalve | 69:3995ffeaa786 | 1567 | if ((OPERATING_MODE & 0x01) == 0) { // Rotary Mode |
Lightvalve | 57:f4819de54e7a | 1568 | I_REF_FORCE_FB = 0.001f * ((double) P_GAIN_JOINT_TORQUE * torq.err + (double) I_GAIN_JOINT_TORQUE * torq.err_sum); |
Lightvalve | 57:f4819de54e7a | 1569 | // 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 | 1570 | temp_vel_torq = (0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / (double) ENC_PULSE_PER_POSITION) * PI / 180.0f; // rad/s |
Lightvalve | 57:f4819de54e7a | 1571 | // L feedforward velocity |
Lightvalve | 69:3995ffeaa786 | 1572 | } else if ((OPERATING_MODE & 0x01) == 1) { |
Lightvalve | 57:f4819de54e7a | 1573 | 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 | 1574 | // temp_vel_torq = (0.01 * (double) VELOCITY_COMP_GAIN * (double) CUR_VELOCITY / (double) ENC_PULSE_PER_POSITION); // mm/s |
Lightvalve | 57:f4819de54e7a | 1575 | temp_vel_torq = (0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / (double) ENC_PULSE_PER_POSITION); // mm/s |
Lightvalve | 57:f4819de54e7a | 1576 | // L feedforward velocity |
Lightvalve | 57:f4819de54e7a | 1577 | } |
Lightvalve | 57:f4819de54e7a | 1578 | 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 | 1579 | else I_REF_VC = temp_vel_torq * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f)))); |
Lightvalve | 57:f4819de54e7a | 1580 | // L velocity(rad/s or mm/s) >> I_ref(mA) |
Lightvalve | 57:f4819de54e7a | 1581 | // Ref_Joint_FT_dot = (Ref_Joint_FT_Nm - Ref_Joint_FT_Nm_old) / TMR_DT_5k; |
Lightvalve | 57:f4819de54e7a | 1582 | // Ref_Joint_FT_Nm_old = Ref_Joint_FT_Nm; |
Lightvalve | 57:f4819de54e7a | 1583 | |
Lightvalve | 57:f4819de54e7a | 1584 | I_REF = (1.0f - alpha_trans) * I_REF_POS + alpha_trans * (I_REF_VC + I_REF_FORCE_FB); |
Lightvalve | 67:c2812cf26c38 | 1585 | |
Lightvalve | 67:c2812cf26c38 | 1586 | // Anti-windup for FT |
Lightvalve | 67:c2812cf26c38 | 1587 | if (I_GAIN_JOINT_TORQUE != 0) { |
Lightvalve | 67:c2812cf26c38 | 1588 | double I_MAX = 10.0f; // Maximum Current : 10mV |
Lightvalve | 67:c2812cf26c38 | 1589 | double Ka = 2.0f / ((double) I_GAIN_JOINT_TORQUE * 0.001f); |
Lightvalve | 67:c2812cf26c38 | 1590 | if (I_REF > I_MAX) { |
Lightvalve | 67:c2812cf26c38 | 1591 | double I_rem = I_REF - I_MAX; |
Lightvalve | 67:c2812cf26c38 | 1592 | I_rem = Ka*I_rem; |
Lightvalve | 67:c2812cf26c38 | 1593 | I_REF = I_MAX; |
Lightvalve | 67:c2812cf26c38 | 1594 | torq.err_sum = torq.err_sum - I_rem /(float) TMR_FREQ_5k; |
Lightvalve | 67:c2812cf26c38 | 1595 | } else if (I_REF < -I_MAX) { |
Lightvalve | 67:c2812cf26c38 | 1596 | double I_rem = I_REF - (-I_MAX); |
Lightvalve | 67:c2812cf26c38 | 1597 | I_rem = Ka*I_rem; |
Lightvalve | 67:c2812cf26c38 | 1598 | I_REF = -I_MAX; |
Lightvalve | 67:c2812cf26c38 | 1599 | torq.err_sum = torq.err_sum - I_rem /(float) TMR_FREQ_5k; |
Lightvalve | 67:c2812cf26c38 | 1600 | } |
Lightvalve | 67:c2812cf26c38 | 1601 | } |
Lightvalve | 57:f4819de54e7a | 1602 | |
Lightvalve | 57:f4819de54e7a | 1603 | } else { |
Lightvalve | 57:f4819de54e7a | 1604 | float VALVE_POS_RAW_FORCE_FB = 0.0f; |
Lightvalve | 72:3436ce769b1e | 1605 | float VALVE_POS_RAW_FORCE_FF = 0.0f; |
Lightvalve | 72:3436ce769b1e | 1606 | float VALVE_POS_RAW = 0.0f; |
Lightvalve | 72:3436ce769b1e | 1607 | |
Lightvalve | 57:f4819de54e7a | 1608 | 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 | 1609 | + 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 | 1610 | |
Lightvalve | 72:3436ce769b1e | 1611 | 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 | 1612 | |
Lightvalve | 72:3436ce769b1e | 1613 | VALVE_POS_RAW = VALVE_POS_RAW_FORCE_FB + VALVE_POS_RAW_FORCE_FF; |
Lightvalve | 72:3436ce769b1e | 1614 | |
Lightvalve | 72:3436ce769b1e | 1615 | |
Lightvalve | 72:3436ce769b1e | 1616 | if (VALVE_POS_RAW >= 0) { |
Lightvalve | 72:3436ce769b1e | 1617 | valve_pos.ref = VALVE_POS_RAW + VALVE_DEADZONE_PLUS; |
Lightvalve | 57:f4819de54e7a | 1618 | } else { |
Lightvalve | 72:3436ce769b1e | 1619 | valve_pos.ref = VALVE_POS_RAW + VALVE_DEADZONE_MINUS; |
Lightvalve | 57:f4819de54e7a | 1620 | } |
Lightvalve | 57:f4819de54e7a | 1621 | |
Lightvalve | 57:f4819de54e7a | 1622 | if(I_GAIN_JOINT_TORQUE != 0) { |
Lightvalve | 57:f4819de54e7a | 1623 | double Ka = 1.0f / (double) I_GAIN_JOINT_TORQUE * 100.0f; |
Lightvalve | 57:f4819de54e7a | 1624 | if(valve_pos.ref>VALVE_MAX_POS) { |
Lightvalve | 57:f4819de54e7a | 1625 | double valve_pos_rem = valve_pos.ref - VALVE_MAX_POS; |
Lightvalve | 57:f4819de54e7a | 1626 | valve_pos_rem = valve_pos_rem * Ka; |
Lightvalve | 57:f4819de54e7a | 1627 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 57:f4819de54e7a | 1628 | torq.err_sum = torq.err_sum - valve_pos_rem/(float) TMR_FREQ_5k; |
Lightvalve | 57:f4819de54e7a | 1629 | } else if(valve_pos.ref < VALVE_MIN_POS) { |
Lightvalve | 57:f4819de54e7a | 1630 | double valve_pos_rem = valve_pos.ref - VALVE_MIN_POS; |
Lightvalve | 57:f4819de54e7a | 1631 | valve_pos_rem = valve_pos_rem * Ka; |
Lightvalve | 57:f4819de54e7a | 1632 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 57:f4819de54e7a | 1633 | torq.err_sum = torq.err_sum - valve_pos_rem/(float) TMR_FREQ_5k; |
Lightvalve | 57:f4819de54e7a | 1634 | } |
Lightvalve | 57:f4819de54e7a | 1635 | } |
Lightvalve | 61:bc8c8270f0ab | 1636 | |
Lightvalve | 57:f4819de54e7a | 1637 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 61:bc8c8270f0ab | 1638 | |
Lightvalve | 67:c2812cf26c38 | 1639 | // Vout.ref = (float) P_GAIN_JOINT_POSITION * 0.01f * ((float) pos.err); |
Lightvalve | 60:64181f1d3e60 | 1640 | V_out = (float) Vout.ref; |
Lightvalve | 57:f4819de54e7a | 1641 | |
Lightvalve | 57:f4819de54e7a | 1642 | } |
Lightvalve | 72:3436ce769b1e | 1643 | |
Lightvalve | 72:3436ce769b1e | 1644 | torq_ref_past = torq_ref; |
Lightvalve | 58:2eade98630e2 | 1645 | |
Lightvalve | 57:f4819de54e7a | 1646 | break; |
Lightvalve | 57:f4819de54e7a | 1647 | } |
Lightvalve | 58:2eade98630e2 | 1648 | |
Lightvalve | 57:f4819de54e7a | 1649 | case MODE_VALVE_OPEN_LOOP: { |
Lightvalve | 57:f4819de54e7a | 1650 | V_out = (float) Vout.ref; |
Lightvalve | 57:f4819de54e7a | 1651 | break; |
Lightvalve | 57:f4819de54e7a | 1652 | } |
Lightvalve | 14:8e7590227d22 | 1653 | |
Lightvalve | 12:6f2531038ea4 | 1654 | default: |
Lightvalve | 12:6f2531038ea4 | 1655 | break; |
Lightvalve | 12:6f2531038ea4 | 1656 | } |
Lightvalve | 14:8e7590227d22 | 1657 | |
Lightvalve | 57:f4819de54e7a | 1658 | |
Lightvalve | 57:f4819de54e7a | 1659 | if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) { //Moog Valve or KNR Valve |
Lightvalve | 58:2eade98630e2 | 1660 | |
Lightvalve | 57:f4819de54e7a | 1661 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1662 | //////////////////////////// CURRENT CONTROL ////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1663 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1664 | if (CURRENT_CONTROL_MODE) { |
Lightvalve | 67:c2812cf26c38 | 1665 | double alpha_update_Iref = 1.0f / (1.0f + 5000.0f / (2.0f * 3.14f * 300.0f)); // f_cutoff : 500Hz |
Lightvalve | 57:f4819de54e7a | 1666 | I_REF_fil = (1.0f - alpha_update_Iref) * I_REF_fil + alpha_update_Iref*I_REF; |
Lightvalve | 57:f4819de54e7a | 1667 | |
Lightvalve | 57:f4819de54e7a | 1668 | I_ERR = I_REF_fil - cur.sen; |
Lightvalve | 67:c2812cf26c38 | 1669 | I_ERR_INT = I_ERR_INT + (I_ERR) * 0.0002f; |
Lightvalve | 57:f4819de54e7a | 1670 | |
Lightvalve | 57:f4819de54e7a | 1671 | |
Lightvalve | 57:f4819de54e7a | 1672 | // Moog Valve Current Control Gain |
Lightvalve | 67:c2812cf26c38 | 1673 | double R_model = 500.0f; // ohm |
Lightvalve | 57:f4819de54e7a | 1674 | double L_model = 1.2f; |
Lightvalve | 57:f4819de54e7a | 1675 | double w0 = 2.0f * 3.14f * 150.0f; |
Lightvalve | 57:f4819de54e7a | 1676 | double KP_I = 0.1f * L_model*w0; |
Lightvalve | 57:f4819de54e7a | 1677 | double KI_I = 0.1f * R_model*w0; |
Lightvalve | 57:f4819de54e7a | 1678 | |
Lightvalve | 57:f4819de54e7a | 1679 | // KNR Valve Current Control Gain |
Lightvalve | 57:f4819de54e7a | 1680 | if (((OPERATING_MODE & 0b110)>>1) == 1) { // KNR Valve |
Lightvalve | 57:f4819de54e7a | 1681 | R_model = 163.0f; // ohm |
Lightvalve | 57:f4819de54e7a | 1682 | L_model = 1.0f; |
Lightvalve | 57:f4819de54e7a | 1683 | w0 = 2.0f * 3.14f * 80.0f; |
Lightvalve | 57:f4819de54e7a | 1684 | KP_I = 1.0f * L_model*w0; |
Lightvalve | 57:f4819de54e7a | 1685 | KI_I = 0.08f * R_model*w0; |
Lightvalve | 57:f4819de54e7a | 1686 | } |
Lightvalve | 57:f4819de54e7a | 1687 | |
Lightvalve | 57:f4819de54e7a | 1688 | double FF_gain = 1.0f; |
Lightvalve | 57:f4819de54e7a | 1689 | |
Lightvalve | 67:c2812cf26c38 | 1690 | VALVE_PWM_RAW = KP_I * 2.0f * I_ERR + KI_I * 2.0f* I_ERR_INT; |
Lightvalve | 57:f4819de54e7a | 1691 | // VALVE_PWM_RAW = VALVE_PWM_RAW + FF_gain * (R_model*I_REF); // Unit : mV |
Lightvalve | 57:f4819de54e7a | 1692 | I_REF_fil_diff = I_REF_fil - I_REF_fil_old; |
Lightvalve | 57:f4819de54e7a | 1693 | I_REF_fil_old = I_REF_fil; |
Lightvalve | 67:c2812cf26c38 | 1694 | // 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 | 1695 | VALVE_PWM_RAW = VALVE_PWM_RAW + FF_gain * (R_model * I_REF_fil); // Unit : mV |
Lightvalve | 67:c2812cf26c38 | 1696 | double V_MAX = 12000.0f; // Maximum Voltage : 12V = 12000mV |
Lightvalve | 57:f4819de54e7a | 1697 | |
Lightvalve | 57:f4819de54e7a | 1698 | double Ka = 3.0f / KP_I; |
Lightvalve | 57:f4819de54e7a | 1699 | if (VALVE_PWM_RAW > V_MAX) { |
Lightvalve | 57:f4819de54e7a | 1700 | V_rem = VALVE_PWM_RAW - V_MAX; |
Lightvalve | 57:f4819de54e7a | 1701 | V_rem = Ka*V_rem; |
Lightvalve | 57:f4819de54e7a | 1702 | VALVE_PWM_RAW = V_MAX; |
Lightvalve | 67:c2812cf26c38 | 1703 | I_ERR_INT = I_ERR_INT - V_rem * 0.0002f; |
Lightvalve | 57:f4819de54e7a | 1704 | } else if (VALVE_PWM_RAW < -V_MAX) { |
Lightvalve | 57:f4819de54e7a | 1705 | V_rem = VALVE_PWM_RAW - (-V_MAX); |
Lightvalve | 57:f4819de54e7a | 1706 | V_rem = Ka*V_rem; |
Lightvalve | 57:f4819de54e7a | 1707 | VALVE_PWM_RAW = -V_MAX; |
Lightvalve | 67:c2812cf26c38 | 1708 | I_ERR_INT = I_ERR_INT - V_rem * 0.0002f; |
Lightvalve | 57:f4819de54e7a | 1709 | } |
Lightvalve | 57:f4819de54e7a | 1710 | Cur_Valve_Open_pulse = cur.sen / mA_PER_pulse; |
Lightvalve | 57:f4819de54e7a | 1711 | } else { |
Lightvalve | 57:f4819de54e7a | 1712 | VALVE_PWM_RAW = I_REF * mV_PER_mA; |
Lightvalve | 57:f4819de54e7a | 1713 | Cur_Valve_Open_pulse = I_REF / mA_PER_pulse; |
Lightvalve | 57:f4819de54e7a | 1714 | } |
Lightvalve | 57:f4819de54e7a | 1715 | |
Lightvalve | 57:f4819de54e7a | 1716 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1717 | ///////////////// Dead Zone Cancellation & Linearization ////////////////// |
Lightvalve | 57:f4819de54e7a | 1718 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 57:f4819de54e7a | 1719 | // Dead Zone Cancellation (Mechanical Valve dead-zone) |
Lightvalve | 57:f4819de54e7a | 1720 | if (FLAG_VALVE_DEADZONE) { |
Lightvalve | 57:f4819de54e7a | 1721 | if (VALVE_PWM_RAW > 0) VALVE_PWM_RAW = VALVE_PWM_RAW + VALVE_DEADZONE_PLUS * mV_PER_pulse; // unit: mV |
Lightvalve | 57:f4819de54e7a | 1722 | else if (VALVE_PWM_RAW < 0) VALVE_PWM_RAW = VALVE_PWM_RAW + VALVE_DEADZONE_MINUS * mV_PER_pulse; // unit: mV |
Lightvalve | 57:f4819de54e7a | 1723 | |
Lightvalve | 57:f4819de54e7a | 1724 | VALVE_PWM_VALVE_DZ = VALVE_PWM_RAW + (double)VALVE_CENTER * mV_PER_pulse; // unit: mV |
Lightvalve | 57:f4819de54e7a | 1725 | |
Lightvalve | 57:f4819de54e7a | 1726 | } else { |
Lightvalve | 57:f4819de54e7a | 1727 | VALVE_PWM_VALVE_DZ = VALVE_PWM_RAW; |
Lightvalve | 57:f4819de54e7a | 1728 | } |
Lightvalve | 57:f4819de54e7a | 1729 | |
Lightvalve | 57:f4819de54e7a | 1730 | // Output Voltage Linearization |
Lightvalve | 57:f4819de54e7a | 1731 | double CUR_PWM_nonlin = VALVE_PWM_VALVE_DZ; // Unit : mV |
Lightvalve | 67:c2812cf26c38 | 1732 | double CUR_PWM_lin = PWM_duty_byLT(CUR_PWM_nonlin); // -8000~8000 |
Lightvalve | 57:f4819de54e7a | 1733 | |
Lightvalve | 57:f4819de54e7a | 1734 | // Dead Zone Cancellation (Electrical dead-zone) |
Lightvalve | 67:c2812cf26c38 | 1735 | if (CUR_PWM_lin > 0) V_out = (float) (CUR_PWM_lin + 169.0f); |
Lightvalve | 67:c2812cf26c38 | 1736 | else if (CUR_PWM_lin < 0) V_out = (float) (CUR_PWM_lin - 174.0f); |
Lightvalve | 67:c2812cf26c38 | 1737 | else V_out = (float) (CUR_PWM_lin); |
Lightvalve | 57:f4819de54e7a | 1738 | } |
Lightvalve | 67:c2812cf26c38 | 1739 | |
Lightvalve | 67:c2812cf26c38 | 1740 | // if(V_out > 0.0f) V_out = (float) (V_out + 169.0f); |
Lightvalve | 67:c2812cf26c38 | 1741 | // else if(V_out < 0.0f) V_out = (float) (V_out - 174.0f); |
Lightvalve | 67:c2812cf26c38 | 1742 | // else V_out = V_out; |
Lightvalve | 67:c2812cf26c38 | 1743 | |
jobuuu | 7:e9086c72bb22 | 1744 | /******************************************************* |
jobuuu | 7:e9086c72bb22 | 1745 | *** PWM |
jobuuu | 7:e9086c72bb22 | 1746 | ********************************************************/ |
Lightvalve | 67:c2812cf26c38 | 1747 | if(DIR_VALVE<0){ |
Lightvalve | 67:c2812cf26c38 | 1748 | V_out = -V_out; |
Lightvalve | 67:c2812cf26c38 | 1749 | } |
Lightvalve | 67:c2812cf26c38 | 1750 | |
Lightvalve | 49:e7bcfc244d40 | 1751 | if (V_out >= VALVE_VOLTAGE_LIMIT*1000.0f) { |
Lightvalve | 49:e7bcfc244d40 | 1752 | V_out = VALVE_VOLTAGE_LIMIT*1000.0f; |
Lightvalve | 49:e7bcfc244d40 | 1753 | } else if(V_out<=-VALVE_VOLTAGE_LIMIT*1000.0f) { |
Lightvalve | 49:e7bcfc244d40 | 1754 | V_out = -VALVE_VOLTAGE_LIMIT*1000.0f; |
Lightvalve | 27:a2254a485f23 | 1755 | } |
Lightvalve | 49:e7bcfc244d40 | 1756 | PWM_out= V_out/(SUPPLY_VOLTAGE*1000.0f); // Full duty : 12000.0mV |
Lightvalve | 13:747daba9cf59 | 1757 | |
Lightvalve | 19:23b7c1ad8683 | 1758 | // Saturation of output voltage to 12.0V |
Lightvalve | 30:8d561f16383b | 1759 | if(PWM_out > 1.0f) PWM_out=1.0f; |
Lightvalve | 30:8d561f16383b | 1760 | else if (PWM_out < -1.0f) PWM_out=-1.0f; |
Lightvalve | 13:747daba9cf59 | 1761 | |
Lightvalve | 30:8d561f16383b | 1762 | if (PWM_out>0.0f) { |
Lightvalve | 30:8d561f16383b | 1763 | dtc_v=0.0f; |
jobuuu | 1:e04e563be5ce | 1764 | dtc_w=PWM_out; |
jobuuu | 1:e04e563be5ce | 1765 | } else { |
jobuuu | 2:a1c0a37df760 | 1766 | dtc_v=-PWM_out; |
Lightvalve | 30:8d561f16383b | 1767 | dtc_w=0.0f; |
jobuuu | 1:e04e563be5ce | 1768 | } |
Lightvalve | 13:747daba9cf59 | 1769 | |
jobuuu | 1:e04e563be5ce | 1770 | //pwm |
Lightvalve | 30:8d561f16383b | 1771 | TIM4->CCR2 = (PWM_ARR)*(1.0f-dtc_v); |
Lightvalve | 30:8d561f16383b | 1772 | TIM4->CCR1 = (PWM_ARR)*(1.0f-dtc_w); |
Lightvalve | 67:c2812cf26c38 | 1773 | |
Lightvalve | 61:bc8c8270f0ab | 1774 | |
Lightvalve | 57:f4819de54e7a | 1775 | if (TMR2_COUNT_CAN_TX % (int) ((int) TMR_FREQ_5k/CAN_FREQ) == 0) { |
Lightvalve | 20:806196fda269 | 1776 | |
Lightvalve | 54:647072f5307a | 1777 | // Position, Velocity, and Torque (ID:1200) |
Lightvalve | 56:6f50d9d3bfee | 1778 | if (flag_data_request[0] == HIGH) { |
Lightvalve | 57:f4819de54e7a | 1779 | if ((OPERATING_MODE & 0b01) == 0) { // Rotary Actuator |
Lightvalve | 54:647072f5307a | 1780 | if (SENSING_MODE == 0) { |
Lightvalve | 67:c2812cf26c38 | 1781 | CAN_TX_POSITION_FT((int16_t) (pos.sen), (int16_t) (vel.sen/10.0f), (int16_t) (torq.sen*10.0f)); |
Lightvalve | 54:647072f5307a | 1782 | } else if (SENSING_MODE == 1) { |
Lightvalve | 58:2eade98630e2 | 1783 | 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 | 1784 | } |
Lightvalve | 57:f4819de54e7a | 1785 | } else if ((OPERATING_MODE & 0b01) == 1) { // Linear Actuator |
Lightvalve | 54:647072f5307a | 1786 | if (SENSING_MODE == 0) { |
Lightvalve | 67:c2812cf26c38 | 1787 | 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 | 1788 | } else if (SENSING_MODE == 1) { |
Lightvalve | 67:c2812cf26c38 | 1789 | 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 | 1790 | } |
Lightvalve | 52:8ea76864368a | 1791 | } |
Lightvalve | 52:8ea76864368a | 1792 | } |
Lightvalve | 56:6f50d9d3bfee | 1793 | if (flag_data_request[1] == HIGH) { |
Lightvalve | 54:647072f5307a | 1794 | //valve position |
Lightvalve | 54:647072f5307a | 1795 | double t_value = 0; |
Lightvalve | 67:c2812cf26c38 | 1796 | if(valve_pos.ref>=(float) VALVE_CENTER) { |
Lightvalve | 67:c2812cf26c38 | 1797 | t_value = 10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); |
Lightvalve | 67:c2812cf26c38 | 1798 | } else { |
Lightvalve | 67:c2812cf26c38 | 1799 | t_value = -10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); |
Lightvalve | 67:c2812cf26c38 | 1800 | } |
Lightvalve | 67:c2812cf26c38 | 1801 | // if(OPERATING_MODE==5) { |
Lightvalve | 67:c2812cf26c38 | 1802 | // t_value = (double) value; |
Lightvalve | 67:c2812cf26c38 | 1803 | // } else if(CURRENT_CONTROL_MODE==1) { |
Lightvalve | 67:c2812cf26c38 | 1804 | // t_value = cur.sen; |
Lightvalve | 57:f4819de54e7a | 1805 | // } else { |
Lightvalve | 67:c2812cf26c38 | 1806 | // t_value = V_out; |
Lightvalve | 67:c2812cf26c38 | 1807 | // } |
Lightvalve | 67:c2812cf26c38 | 1808 | CAN_TX_TORQUE((int16_t) (t_value)); //1300 |
Lightvalve | 67:c2812cf26c38 | 1809 | //CAN_TX_TORQUE((int16_t) (cur.sen * 1000.0f)); //1300 |
Lightvalve | 67:c2812cf26c38 | 1810 | //CAN_TX_TORQUE((int16_t) (I_REF * 1000.0f)); //1300 |
Lightvalve | 54:647072f5307a | 1811 | } |
Lightvalve | 58:2eade98630e2 | 1812 | |
Lightvalve | 58:2eade98630e2 | 1813 | |
Lightvalve | 56:6f50d9d3bfee | 1814 | if (flag_data_request[2] == HIGH) { |
Lightvalve | 56:6f50d9d3bfee | 1815 | //pressure A and B |
Lightvalve | 57:f4819de54e7a | 1816 | CAN_TX_PRES((int16_t) (pres_A.sen), (int16_t) (pres_B.sen)); // CUR_PRES_X : 0(0bar)~4096(210bar) //1400 |
Lightvalve | 55:b25725257569 | 1817 | } |
Lightvalve | 58:2eade98630e2 | 1818 | |
Lightvalve | 57:f4819de54e7a | 1819 | //If it doesn't rest, below can can not work. |
Lightvalve | 57:f4819de54e7a | 1820 | for (can_rest = 0; can_rest < 10000; can_rest++) { |
Lightvalve | 57:f4819de54e7a | 1821 | ; |
Lightvalve | 57:f4819de54e7a | 1822 | } |
Lightvalve | 58:2eade98630e2 | 1823 | |
Lightvalve | 56:6f50d9d3bfee | 1824 | if (flag_data_request[3] == HIGH) { |
Lightvalve | 54:647072f5307a | 1825 | //PWM |
Lightvalve | 73:f80dc3970c99 | 1826 | //CAN_TX_PWM((int16_t) value); //1500 |
Lightvalve | 73:f80dc3970c99 | 1827 | CAN_TX_PWM((int16_t) input_NN[0] * 100.0f); //1500 |
Lightvalve | 54:647072f5307a | 1828 | } |
Lightvalve | 57:f4819de54e7a | 1829 | //for (i = 0; i < 10000; i++) { |
Lightvalve | 57:f4819de54e7a | 1830 | // ; |
Lightvalve | 57:f4819de54e7a | 1831 | // } |
Lightvalve | 56:6f50d9d3bfee | 1832 | if (flag_data_request[4] == HIGH) { |
Lightvalve | 54:647072f5307a | 1833 | //valve position |
Lightvalve | 73:f80dc3970c99 | 1834 | 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 | 1835 | } |
Lightvalve | 20:806196fda269 | 1836 | |
Lightvalve | 54:647072f5307a | 1837 | // Others : Reference position, Reference FT, PWM, Current (ID:1300) |
Lightvalve | 52:8ea76864368a | 1838 | // if (flag_data_request[1] == HIGH) { |
Lightvalve | 52:8ea76864368a | 1839 | // CAN_TX_SOMETHING((int) (FORCE_VREF), (int16_t) (1), (int16_t) (2), (int16_t) (3)); |
Lightvalve | 52:8ea76864368a | 1840 | // } |
Lightvalve | 54:647072f5307a | 1841 | //if (flag_delay_test == 1){ |
Lightvalve | 58:2eade98630e2 | 1842 | //CAN_TX_PRES((int16_t) (0),(int16_t) torq_ref); |
Lightvalve | 54:647072f5307a | 1843 | //} |
Lightvalve | 52:8ea76864368a | 1844 | |
Lightvalve | 54:647072f5307a | 1845 | TMR2_COUNT_CAN_TX = 0; |
Lightvalve | 54:647072f5307a | 1846 | } |
Lightvalve | 54:647072f5307a | 1847 | TMR2_COUNT_CAN_TX++; |
Lightvalve | 52:8ea76864368a | 1848 | |
Lightvalve | 20:806196fda269 | 1849 | } |
Lightvalve | 52:8ea76864368a | 1850 | TIM3->SR = 0x0; // reset the status register |
Lightvalve | 52:8ea76864368a | 1851 | |
Lightvalve | 58:2eade98630e2 | 1852 | } |