Sungwoo Kim
/
HydraulicControlBoard_Rainbow_v1_2_copy
2011
main.cpp@64:a8e6799dbce3, 2020-05-12 (annotated)
- Committer:
- Lightvalve
- Date:
- Tue May 12 06:23:46 2020 +0000
- Revision:
- 64:a8e6799dbce3
- Parent:
- 63:a2d7c63419c2
- Child:
- 65:c2812cf26c38
200512
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GiJeongKim | 0:51c43836c1d7 | 1 | #include "mbed.h" |
GiJeongKim | 0:51c43836c1d7 | 2 | #include "FastPWM.h" |
GiJeongKim | 0:51c43836c1d7 | 3 | #include "INIT_HW.h" |
jobuuu | 2:a1c0a37df760 | 4 | #include "function_CAN.h" |
GiJeongKim | 0:51c43836c1d7 | 5 | #include "SPI_EEP_ENC.h" |
GiJeongKim | 0:51c43836c1d7 | 6 | #include "I2C_AS5510.h" |
GiJeongKim | 0:51c43836c1d7 | 7 | #include "setting.h" |
Lightvalve | 11:82d8768d7351 | 8 | #include "function_utilities.h" |
Lightvalve | 16:903b5a4433b4 | 9 | #include "stm32f4xx_flash.h" |
Lightvalve | 63:a2d7c63419c2 | 10 | #include "FlashWriter.h" |
Lightvalve | 59:bc8c8270f0ab | 11 | |
Lightvalve | 59:bc8c8270f0ab | 12 | using namespace std; |
Lightvalve | 59:bc8c8270f0ab | 13 | Timer t; |
GiJeongKim | 0:51c43836c1d7 | 14 | |
Lightvalve | 31:66738bfecec5 | 15 | ///191008//// |
Lightvalve | 31:66738bfecec5 | 16 | |
jobuuu | 7:e9086c72bb22 | 17 | // dac & check /////////////////////////////////////////// |
GiJeongKim | 0:51c43836c1d7 | 18 | DigitalOut check(PC_2); |
GiJeongKim | 0:51c43836c1d7 | 19 | DigitalOut check_2(PC_3); |
GiJeongKim | 0:51c43836c1d7 | 20 | AnalogOut dac_1(PA_4); |
GiJeongKim | 0:51c43836c1d7 | 21 | AnalogOut dac_2(PA_5); |
Lightvalve | 14:8e7590227d22 | 22 | AnalogIn adc1(PC_4); //pressure_1 |
Lightvalve | 14:8e7590227d22 | 23 | AnalogIn adc2(PB_0); //pressure_2 |
Lightvalve | 14:8e7590227d22 | 24 | AnalogIn adc3(PC_1); //current |
GiJeongKim | 0:51c43836c1d7 | 25 | |
Lightvalve | 24:ef6e1092e9e6 | 26 | |
jobuuu | 7:e9086c72bb22 | 27 | // PWM /////////////////////////////////////////// |
Lightvalve | 30:8d561f16383b | 28 | float dtc_v=0.0f; |
Lightvalve | 30:8d561f16383b | 29 | float dtc_w=0.0f; |
GiJeongKim | 0:51c43836c1d7 | 30 | |
jobuuu | 7:e9086c72bb22 | 31 | // I2C /////////////////////////////////////////// |
GiJeongKim | 0:51c43836c1d7 | 32 | I2C i2c(PC_9,PA_8); // SDA, SCL (for K22F) |
GiJeongKim | 0:51c43836c1d7 | 33 | const int i2c_slave_addr1 = 0x56; |
GiJeongKim | 0:51c43836c1d7 | 34 | unsigned int value; // 10bit output of reading sensor AS5510 |
GiJeongKim | 0:51c43836c1d7 | 35 | |
jobuuu | 7:e9086c72bb22 | 36 | // SPI /////////////////////////////////////////// |
Lightvalve | 16:903b5a4433b4 | 37 | //SPI eeprom(PB_15, PB_14, PB_13); // EEPROM //(SPI_MOSI, SPI_MISO, SPI_SCK); |
Lightvalve | 16:903b5a4433b4 | 38 | //DigitalOut eeprom_cs(PB_12); |
Lightvalve | 16:903b5a4433b4 | 39 | //FlashWriter writer(6);//2부터 7까지 되는듯 아마 sector |
GiJeongKim | 0:51c43836c1d7 | 40 | SPI enc(PC_12,PC_11,PC_10); |
GiJeongKim | 0:51c43836c1d7 | 41 | DigitalOut enc_cs(PD_2); |
Lightvalve | 11:82d8768d7351 | 42 | DigitalOut LED(PA_15); |
GiJeongKim | 0:51c43836c1d7 | 43 | |
jobuuu | 7:e9086c72bb22 | 44 | // UART /////////////////////////////////////////// |
GiJeongKim | 0:51c43836c1d7 | 45 | Serial pc(PA_9,PA_10); // _ UART |
GiJeongKim | 0:51c43836c1d7 | 46 | |
jobuuu | 7:e9086c72bb22 | 47 | // CAN /////////////////////////////////////////// |
GiJeongKim | 0:51c43836c1d7 | 48 | CAN can(PB_8, PB_9, 1000000); |
GiJeongKim | 0:51c43836c1d7 | 49 | CANMessage msg; |
Lightvalve | 11:82d8768d7351 | 50 | void onMsgReceived() |
Lightvalve | 11:82d8768d7351 | 51 | { |
Lightvalve | 11:82d8768d7351 | 52 | CAN_RX_HANDLER(); |
Lightvalve | 11:82d8768d7351 | 53 | } |
jobuuu | 2:a1c0a37df760 | 54 | |
jobuuu | 7:e9086c72bb22 | 55 | // Variables /////////////////////////////////////////// |
jobuuu | 7:e9086c72bb22 | 56 | State pos; |
jobuuu | 7:e9086c72bb22 | 57 | State vel; |
jobuuu | 7:e9086c72bb22 | 58 | State Vout; |
jobuuu | 7:e9086c72bb22 | 59 | State torq; |
jobuuu | 7:e9086c72bb22 | 60 | State pres_A; |
jobuuu | 7:e9086c72bb22 | 61 | State pres_B; |
jobuuu | 7:e9086c72bb22 | 62 | State cur; |
Lightvalve | 14:8e7590227d22 | 63 | State valve_pos; |
Lightvalve | 14:8e7590227d22 | 64 | |
Lightvalve | 14:8e7590227d22 | 65 | State INIT_Vout; |
Lightvalve | 14:8e7590227d22 | 66 | State INIT_Valve_Pos; |
Lightvalve | 14:8e7590227d22 | 67 | State INIT_Pos; |
Lightvalve | 14:8e7590227d22 | 68 | State INIT_torq; |
jobuuu | 5:a4319f79457b | 69 | |
Lightvalve | 19:23b7c1ad8683 | 70 | extern int CID_RX_CMD; |
Lightvalve | 19:23b7c1ad8683 | 71 | extern int CID_RX_REF_POSITION; |
Lightvalve | 48:e7bcfc244d40 | 72 | extern int CID_RX_REF_VALVE_POS; |
Lightvalve | 44:35fa6884d0c6 | 73 | extern int CID_RX_REF_PWM; |
Lightvalve | 19:23b7c1ad8683 | 74 | |
Lightvalve | 19:23b7c1ad8683 | 75 | extern int CID_TX_INFO; |
Lightvalve | 19:23b7c1ad8683 | 76 | extern int CID_TX_POSITION; |
Lightvalve | 19:23b7c1ad8683 | 77 | extern int CID_TX_TORQUE; |
Lightvalve | 19:23b7c1ad8683 | 78 | extern int CID_TX_PRES; |
Lightvalve | 19:23b7c1ad8683 | 79 | extern int CID_TX_VOUT; |
Lightvalve | 19:23b7c1ad8683 | 80 | extern int CID_TX_VALVE_POSITION; |
Lightvalve | 19:23b7c1ad8683 | 81 | |
Lightvalve | 59:bc8c8270f0ab | 82 | |
Lightvalve | 59:bc8c8270f0ab | 83 | |
Lightvalve | 59:bc8c8270f0ab | 84 | |
jobuuu | 7:e9086c72bb22 | 85 | // ============================================================================= |
jobuuu | 7:e9086c72bb22 | 86 | // ============================================================================= |
jobuuu | 7:e9086c72bb22 | 87 | // ============================================================================= |
jobuuu | 7:e9086c72bb22 | 88 | |
Lightvalve | 12:6f2531038ea4 | 89 | /******************************************************************************* |
Lightvalve | 12:6f2531038ea4 | 90 | * REFERENCE MODE |
Lightvalve | 12:6f2531038ea4 | 91 | ******************************************************************************/ |
Lightvalve | 13:747daba9cf59 | 92 | enum _REFERENCE_MODE { |
Lightvalve | 13:747daba9cf59 | 93 | MODE_REF_NO_ACT = 0, //0 |
Lightvalve | 12:6f2531038ea4 | 94 | MODE_REF_DIRECT, //1 |
Lightvalve | 12:6f2531038ea4 | 95 | MODE_REF_COS_INC, //2 |
Lightvalve | 12:6f2531038ea4 | 96 | MODE_REF_LINE_INC, //3 |
Lightvalve | 12:6f2531038ea4 | 97 | MODE_REF_SIN_WAVE, //4 |
Lightvalve | 12:6f2531038ea4 | 98 | MODE_REF_SQUARE_WAVE, //5 |
Lightvalve | 12:6f2531038ea4 | 99 | }; |
Lightvalve | 12:6f2531038ea4 | 100 | |
Lightvalve | 12:6f2531038ea4 | 101 | /******************************************************************************* |
Lightvalve | 12:6f2531038ea4 | 102 | * CONTROL MODE |
Lightvalve | 12:6f2531038ea4 | 103 | ******************************************************************************/ |
Lightvalve | 13:747daba9cf59 | 104 | enum _CONTROL_MODE { |
Lightvalve | 12:6f2531038ea4 | 105 | //control mode |
Lightvalve | 12:6f2531038ea4 | 106 | MODE_NO_ACT = 0, //0 |
Lightvalve | 46:fdcb8bd86fd6 | 107 | MODE_VALVE_POSITION_CONTROL, //1 |
Lightvalve | 46:fdcb8bd86fd6 | 108 | MODE_JOINT_CONTROL, //2 |
Lightvalve | 49:3c630b5eba9f | 109 | |
Lightvalve | 46:fdcb8bd86fd6 | 110 | MODE_VALVE_OPEN_LOOP, //3 |
Lightvalve | 12:6f2531038ea4 | 111 | MODE_JOINT_POSITION_TORQUE_CONTROL_VALVE_POSITION, //4 |
Lightvalve | 12:6f2531038ea4 | 112 | MODE_VALVE_POSITION_TORQUE_CONTROL_LEARNING, //5 |
Lightvalve | 13:747daba9cf59 | 113 | |
Lightvalve | 12:6f2531038ea4 | 114 | MODE_JOINT_POSITION_PRES_CONTROL_PWM, //6 |
Lightvalve | 12:6f2531038ea4 | 115 | MODE_JOINT_POSITION_PRES_CONTROL_VALVE_POSITION, //7 |
Lightvalve | 12:6f2531038ea4 | 116 | MODE_VALVE_POSITION_PRES_CONTROL_LEARNING, //8 |
Lightvalve | 13:747daba9cf59 | 117 | |
Lightvalve | 12:6f2531038ea4 | 118 | MODE_TEST_CURRENT_CONTROL, //9 |
Lightvalve | 12:6f2531038ea4 | 119 | MODE_TEST_PWM_CONTROL, //10 |
Lightvalve | 21:e5f1a43ea6f9 | 120 | |
Lightvalve | 14:8e7590227d22 | 121 | MODE_CURRENT_CONTROL, //11 |
Lightvalve | 14:8e7590227d22 | 122 | MODE_JOINT_POSITION_TORQUE_CONTROL_CURRENT, //12 |
Lightvalve | 14:8e7590227d22 | 123 | MODE_JOINT_POSITION_PRES_CONTROL_CURRENT, //13 |
Lightvalve | 13:747daba9cf59 | 124 | |
Lightvalve | 12:6f2531038ea4 | 125 | //utility |
Lightvalve | 12:6f2531038ea4 | 126 | MODE_TORQUE_SENSOR_NULLING = 20, //20 |
Lightvalve | 12:6f2531038ea4 | 127 | MODE_VALVE_NULLING_AND_DEADZONE_SETTING, //21 |
Lightvalve | 12:6f2531038ea4 | 128 | MODE_FIND_HOME, //22 |
Lightvalve | 55:f4819de54e7a | 129 | MODE_VALVE_GAIN_SETTING, //23 |
Lightvalve | 12:6f2531038ea4 | 130 | MODE_PRESSURE_SENSOR_NULLING, //24 |
Lightvalve | 12:6f2531038ea4 | 131 | MODE_PRESSURE_SENSOR_CALIB, //25 |
Lightvalve | 12:6f2531038ea4 | 132 | MODE_ROTARY_FRICTION_TUNING, //26 |
Lightvalve | 13:747daba9cf59 | 133 | |
Lightvalve | 12:6f2531038ea4 | 134 | MODE_DDV_POS_VS_PWM_ID = 30, //30 |
Lightvalve | 12:6f2531038ea4 | 135 | MODE_DDV_DEADZONE_AND_CENTER, //31 |
Lightvalve | 12:6f2531038ea4 | 136 | MODE_DDV_POS_VS_FLOWRATE, //32 |
Lightvalve | 55:f4819de54e7a | 137 | MODE_SYSTEM_ID, //33 |
Lightvalve | 12:6f2531038ea4 | 138 | }; |
Lightvalve | 12:6f2531038ea4 | 139 | |
Lightvalve | 63:a2d7c63419c2 | 140 | void SystemClock_Config(void) |
Lightvalve | 63:a2d7c63419c2 | 141 | { |
Lightvalve | 63:a2d7c63419c2 | 142 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
Lightvalve | 63:a2d7c63419c2 | 143 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
Lightvalve | 63:a2d7c63419c2 | 144 | |
Lightvalve | 63:a2d7c63419c2 | 145 | /** Configure the main internal regulator output voltage |
Lightvalve | 63:a2d7c63419c2 | 146 | */ |
Lightvalve | 63:a2d7c63419c2 | 147 | __HAL_RCC_PWR_CLK_ENABLE(); |
Lightvalve | 63:a2d7c63419c2 | 148 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
Lightvalve | 63:a2d7c63419c2 | 149 | /** Initializes the CPU, AHB and APB busses clocks |
Lightvalve | 63:a2d7c63419c2 | 150 | */ |
Lightvalve | 63:a2d7c63419c2 | 151 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
Lightvalve | 63:a2d7c63419c2 | 152 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
Lightvalve | 63:a2d7c63419c2 | 153 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
Lightvalve | 63:a2d7c63419c2 | 154 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
Lightvalve | 63:a2d7c63419c2 | 155 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
Lightvalve | 63:a2d7c63419c2 | 156 | RCC_OscInitStruct.PLL.PLLM = 8;//8 |
Lightvalve | 63:a2d7c63419c2 | 157 | RCC_OscInitStruct.PLL.PLLN = 180; //180 |
Lightvalve | 63:a2d7c63419c2 | 158 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; |
Lightvalve | 63:a2d7c63419c2 | 159 | RCC_OscInitStruct.PLL.PLLQ = 2; |
Lightvalve | 63:a2d7c63419c2 | 160 | RCC_OscInitStruct.PLL.PLLR = 2; |
Lightvalve | 63:a2d7c63419c2 | 161 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
Lightvalve | 63:a2d7c63419c2 | 162 | { |
Lightvalve | 63:a2d7c63419c2 | 163 | //Error_Handler(); |
Lightvalve | 63:a2d7c63419c2 | 164 | } |
Lightvalve | 63:a2d7c63419c2 | 165 | /** Activate the Over-Drive mode |
Lightvalve | 63:a2d7c63419c2 | 166 | */ |
Lightvalve | 63:a2d7c63419c2 | 167 | if (HAL_PWREx_EnableOverDrive() != HAL_OK) |
Lightvalve | 63:a2d7c63419c2 | 168 | { |
Lightvalve | 63:a2d7c63419c2 | 169 | //Error_Handler(); |
Lightvalve | 63:a2d7c63419c2 | 170 | } |
Lightvalve | 63:a2d7c63419c2 | 171 | /** Initializes the CPU, AHB and APB busses clocks |
Lightvalve | 63:a2d7c63419c2 | 172 | */ |
Lightvalve | 63:a2d7c63419c2 | 173 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
Lightvalve | 63:a2d7c63419c2 | 174 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
Lightvalve | 63:a2d7c63419c2 | 175 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
Lightvalve | 63:a2d7c63419c2 | 176 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
Lightvalve | 63:a2d7c63419c2 | 177 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; |
Lightvalve | 63:a2d7c63419c2 | 178 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; |
Lightvalve | 63:a2d7c63419c2 | 179 | |
Lightvalve | 63:a2d7c63419c2 | 180 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) |
Lightvalve | 63:a2d7c63419c2 | 181 | { |
Lightvalve | 63:a2d7c63419c2 | 182 | //Error_Handler(); |
Lightvalve | 63:a2d7c63419c2 | 183 | } |
Lightvalve | 63:a2d7c63419c2 | 184 | } |
Lightvalve | 63:a2d7c63419c2 | 185 | |
Lightvalve | 63:a2d7c63419c2 | 186 | |
Lightvalve | 64:a8e6799dbce3 | 187 | float x_future[num_input_array] = {0.0f}; |
Lightvalve | 64:a8e6799dbce3 | 188 | |
Lightvalve | 64:a8e6799dbce3 | 189 | float input[num_input] = { 0.0f }; |
Lightvalve | 63:a2d7c63419c2 | 190 | |
Lightvalve | 64:a8e6799dbce3 | 191 | const float h1[num_input][32] = { |
Lightvalve | 64:a8e6799dbce3 | 192 | {-0.05584605038166046f,-0.11015535145998001f,0.12024858593940735f,0.8710275292396545f,-0.8633008599281311f,0.6032636165618896f,0.1195044070482254f,-0.24131548404693604f,-0.2979300916194916f,-0.06240735203027725f,-0.5634293556213379f,-0.7795512080192566f,-0.2193688154220581f,0.5603419542312622f,-0.2396446317434311f,-0.5459810495376587f,-0.3129505217075348f,0.9516814351081848f,-0.4300021231174469f,0.32531049847602844f,-0.38013890385627747f,0.12145945429801941f,-0.3777896761894226f,-0.0899648368358612f,0.00471434835344553f,0.2086491882801056f,-0.2006681114435196f,-0.8217374086380005f,0.4176312983036041f,-0.21341653168201447f,-0.738452672958374f,0.09072920680046082f}, |
Lightvalve | 64:a8e6799dbce3 | 193 | {-0.8286606073379517f,0.34443455934524536f,0.33912619948387146f,-0.5367521047592163f,-0.2419569194316864f,0.11375948786735535f,0.7230488657951355f,-0.11622462421655655f,-0.06099450960755348f,0.14800310134887695f,-0.44429513812065125f,-0.15811024606227875f,0.024088174104690552f,0.37633487582206726f,0.05209478735923767f,-0.44525954127311707f,-0.35180044174194336f,0.31975269317626953f,0.4067309498786926f,0.42282143235206604f,-0.03516775369644165f,-0.13714641332626343f,-0.10795548558235168f,0.31470927596092224f,-0.34707048535346985f,0.3334867060184479f,0.14405718445777893f,-0.16725023090839386f,-0.10117192566394806f,0.11138620972633362f,-0.507462739944458f,0.11189708113670349f}, |
Lightvalve | 64:a8e6799dbce3 | 194 | {-0.35791441798210144f,0.3758581578731537f,-0.004794687032699585f,-0.05841163173317909f,-0.08767881989479065f,-0.15663278102874756f,0.252312570810318f,-0.3261408507823944f,-0.08955887705087662f,0.09258187562227249f,0.14131738245487213f,-0.011780006811022758f,-0.037279367446899414f,0.30396905541419983f,-0.36018112301826477f,-0.4110696315765381f,0.16343103349208832f,0.05796433240175247f,0.10341846942901611f,0.42017245292663574f,0.2516377866268158f,-0.17387470602989197f,0.15389427542686462f,-0.2800215482711792f,-0.674734354019165f,0.16508331894874573f,-0.1761709749698639f,0.06000325456261635f,-0.14043109118938446f,0.3438030183315277f,-0.5538067817687988f,-0.22203606367111206f}, |
Lightvalve | 64:a8e6799dbce3 | 195 | {-0.15260998904705048f,-0.008754822425544262f,-0.2331579178571701f,-0.49566444754600525f,-0.3155744969844818f,-0.002509156707674265f,0.168622225522995f,-0.5208267569541931f,0.29355648159980774f,0.050865866243839264f,0.01398477889597416f,0.27986469864845276f,-0.13409757614135742f,0.4001019597053528f,-0.14554673433303833f,-0.08893944323062897f,-0.13120734691619873f,-0.24075376987457275f,-0.3130897283554077f,0.08357034623622894f,-0.2832319438457489f,-0.09985870122909546f,-0.16704979538917542f,-0.33099624514579773f,-0.4437883496284485f,0.16078665852546692f,0.15193721652030945f,-0.10225960612297058f,0.34021857380867004f,0.1502511203289032f,-0.0664215236902237f,0.20154133439064026f}, |
Lightvalve | 64:a8e6799dbce3 | 196 | {0.12635438144207f,0.24193024635314941f,0.09550115466117859f,-0.23847319185733795f,-0.10712115466594696f,-0.07988527417182922f,-0.18517336249351501f,-0.5395429730415344f,-0.3816317319869995f,0.30893078446388245f,-0.41678526997566223f,0.23135076463222504f,0.2400895059108734f,0.2607426047325134f,-0.2847418785095215f,0.23095203936100006f,-0.205430269241333f,-0.35568180680274963f,0.05281441658735275f,-0.16010922193527222f,0.15620997548103333f,0.26784953474998474f,-0.2786858379840851f,-0.08468881249427795f,-0.2860216498374939f,-0.3890018165111542f,0.04607313871383667f,-0.34892332553863525f,0.3036911189556122f,-0.18532218039035797f,0.23122631013393402f,0.030484020709991455f}, |
Lightvalve | 64:a8e6799dbce3 | 197 | {0.552375316619873f,0.18492630124092102f,0.34649983048439026f,0.3252255320549011f,0.27798062562942505f,-0.2561512887477875f,-0.41888460516929626f,-0.06891436129808426f,-0.554313600063324f,0.008540602400898933f,0.2860400974750519f,-0.13133136928081512f,-0.03570398688316345f,0.08028116822242737f,0.24870619177818298f,-0.13462437689304352f,-0.46191880106925964f,-0.9220594763755798f,-0.50397789478302f,-0.18426336348056793f,0.1535390317440033f,-0.010987609624862671f,0.1429324448108673f,0.3757905066013336f,-0.5380614995956421f,0.23636052012443542f,-0.3322296440601349f,0.41926270723342896f,0.02858952432870865f,-0.0014912784099578857f,0.09470368921756744f,-0.06355711817741394f}, |
Lightvalve | 63:a2d7c63419c2 | 198 | }; |
Lightvalve | 63:a2d7c63419c2 | 199 | |
Lightvalve | 64:a8e6799dbce3 | 200 | const float h2[32][32] = { |
Lightvalve | 64:a8e6799dbce3 | 201 | {-0.15789742767810822f,-0.10295046865940094f,-0.04925942420959473f,0.02427169866859913f,-0.3309780955314636f,0.2625422775745392f,-0.07511543482542038f,-0.12313280999660492f,-0.30411389470100403f,-0.10008957982063293f,0.09728801995515823f,-0.33915191888809204f,0.039246782660484314f,0.2781885862350464f,-0.048781245946884155f,-1.3332239389419556f,0.07803884148597717f,-1.1428231000900269f,-0.08379222452640533f,-0.005277924705296755f,-0.6905635595321655f,-0.2655806541442871f,-0.23983746767044067f,-0.28387096524238586f,-0.34077632427215576f,0.05632379651069641f,-0.3915008008480072f,-0.728499710559845f,0.23828622698783875f,0.11771553754806519f,-0.2606334388256073f,-0.1630079448223114f}, |
Lightvalve | 64:a8e6799dbce3 | 202 | {-0.16369810700416565f,0.002147972583770752f,-0.04321768879890442f,0.20987394452095032f,0.019099578261375427f,-0.04193764552474022f,-0.18412554264068604f,-0.1351664513349533f,0.24677053093910217f,0.048597872257232666f,0.17539569735527039f,0.12578506767749786f,0.20868071913719177f,-0.4673871099948883f,0.1197722852230072f,-0.020373206585645676f,0.056778669357299805f,-0.7362931370735168f,-0.2244773954153061f,0.26173046231269836f,0.07969770580530167f,0.10356134176254272f,-0.16832955181598663f,0.24518683552742004f,0.01879107765853405f,0.11049672961235046f,-0.022610308602452278f,0.2533881664276123f,-0.28620439767837524f,-0.0511949360370636f,0.14506122469902039f,-0.07415058463811874f}, |
Lightvalve | 64:a8e6799dbce3 | 203 | {-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 | 64:a8e6799dbce3 | 204 | {-0.16211992502212524f,-0.01806354522705078f,-0.23058539628982544f,0.016176925972104073f,-0.36758074164390564f,-0.2103232741355896f,0.4789067804813385f,0.05088663846254349f,-0.06944303214550018f,0.09271347522735596f,0.28064244985580444f,-0.39364251494407654f,-0.22692131996154785f,0.22431465983390808f,-0.6308612823486328f,-0.4144154489040375f,0.10996055603027344f,0.009937502443790436f,0.14824721217155457f,-0.08365598320960999f,-0.2476825714111328f,-0.23250339925289154f,-0.06394433975219727f,-0.20854580402374268f,0.3123001158237457f,-0.6159867644309998f,0.20684100687503815f,-0.5377008318901062f,-0.22396358847618103f,0.2546447217464447f,0.0035619325935840607f,0.7030656337738037f}, |
Lightvalve | 64:a8e6799dbce3 | 205 | {-0.21776385605335236f,0.2506926953792572f,-0.0804666131734848f,0.03153757378458977f,0.022613627836108208f,-0.2632860243320465f,-0.35431790351867676f,0.008866352029144764f,0.043158918619155884f,-0.2690317630767822f,-0.14150169491767883f,-0.374968022108078f,-0.3281933069229126f,-0.42655467987060547f,-0.18895938992500305f,-0.55921870470047f,-0.10307048261165619f,0.11283401399850845f,-0.05229299142956734f,-0.15150074660778046f,0.06649138033390045f,0.024612629786133766f,0.19172045588493347f,-0.31139934062957764f,-0.4171607196331024f,0.19551879167556763f,0.1652800589799881f,0.07979424297809601f,0.2695164978504181f,-0.16498444974422455f,-0.021313229575753212f,-0.07629286497831345f}, |
Lightvalve | 64:a8e6799dbce3 | 206 | {-0.19425427913665771f,-0.004258692264556885f,0.032371193170547485f,-0.3124158978462219f,-0.21592268347740173f,-0.32674968242645264f,0.2015109658241272f,-0.2202046811580658f,-0.03548547625541687f,0.08825305104255676f,-0.12026015669107437f,0.19926147162914276f,-0.30970871448516846f,0.23186630010604858f,-0.36023351550102234f,-0.14563152194023132f,0.2371552288532257f,0.2082187384366989f,0.27887171506881714f,0.2256462275981903f,-0.004931911826133728f,0.1657554805278778f,-0.1307595670223236f,-0.11585996299982071f,0.18855340778827667f,-0.3826330006122589f,0.16525451838970184f,-0.11980683356523514f,0.05800282955169678f,-0.26823562383651733f,0.1340862363576889f,0.15243633091449738f}, |
Lightvalve | 64:a8e6799dbce3 | 207 | {-0.23734791576862335f,-0.1279313862323761f,-0.11171227693557739f,0.2570078372955322f,-0.2643128037452698f,0.25971919298171997f,-0.19050557911396027f,-0.16186389327049255f,-0.26620519161224365f,0.17144301533699036f,-0.20425355434417725f,-1.4636048078536987f,0.2813534736633301f,0.0029944570269435644f,2.1065120697021484f,0.8487206101417542f,-0.16153597831726074f,0.26067855954170227f,0.005116086453199387f,1.9137510061264038f,1.2921271324157715f,-0.037859927862882614f,-0.07988794147968292f,0.026534322649240494f,-0.26978933811187744f,0.5350269079208374f,0.6667125821113586f,-3.922419309616089f,-0.11822041869163513f,0.19546762108802795f,-0.23295406997203827f,0.39758747816085815f}, |
Lightvalve | 64:a8e6799dbce3 | 208 | {0.25867950916290283f,0.11346611380577087f,0.04012581706047058f,0.008744821883738041f,0.22156041860580444f,-0.07410173863172531f,0.010253120213747025f,0.015882238745689392f,0.2864855229854584f,0.01006925106048584f,-0.06536224484443665f,-0.23000890016555786f,-0.09209762513637543f,-0.12586218118667603f,-0.5601587295532227f,-0.8569194674491882f,-0.2721019387245178f,0.292599618434906f,0.2273714244365692f,-0.7375689148902893f,0.13290464878082275f,0.03271213173866272f,-0.07979777455329895f,0.23633572459220886f,-0.013516108505427837f,0.001281818258576095f,0.3719692826271057f,-0.1842835545539856f,-0.14135785400867462f,0.07403197884559631f,0.13239671289920807f,0.2253207117319107f}, |
Lightvalve | 64:a8e6799dbce3 | 209 | {0.2539409101009369f,0.2890130579471588f,-0.021617114543914795f,0.10094909369945526f,0.2422485202550888f,0.048812851309776306f,-0.3630330562591553f,-0.2351820170879364f,0.29470762610435486f,-0.06864601373672485f,-0.33530402183532715f,-0.37237250804901123f,0.24146446585655212f,-0.19978517293930054f,0.16438758373260498f,0.547096848487854f,0.046292245388031006f,0.07754945755004883f,0.2583274841308594f,-0.9994243383407593f,0.1643972545862198f,0.03415673226118088f,0.28743305802345276f,-0.00602338882163167f,0.025531986728310585f,-0.07598508149385452f,-0.01092247199267149f,-0.16599947214126587f,0.2501918375492096f,-0.14010676741600037f,-0.27732717990875244f,-0.24542571604251862f}, |
Lightvalve | 64:a8e6799dbce3 | 210 | {0.2615049183368683f,0.08643358945846558f,-0.29237738251686096f,-0.21275001764297485f,0.15896368026733398f,-0.0771239846944809f,0.17826680839061737f,-0.15540927648544312f,0.18755429983139038f,-0.07031691074371338f,-0.05704077333211899f,-0.07891639322042465f,0.12828806042671204f,0.023495450615882874f,-0.10919437557458878f,0.15277521312236786f,-0.015168905258178711f,-0.3087019622325897f,-0.2701331079006195f,-0.263889342546463f,0.14209482073783875f,0.1012502908706665f,-0.2307620644569397f,0.06770320236682892f,0.014959282241761684f,-0.2128390669822693f,0.18836741149425507f,0.06113395094871521f,0.2113950550556183f,0.0796298086643219f,-0.0010054409503936768f,-0.261382520198822f}, |
Lightvalve | 64:a8e6799dbce3 | 211 | {0.16485314071178436f,0.1956864297389984f,-0.033508092164993286f,-0.26639455556869507f,-0.34537649154663086f,0.021641232073307037f,-0.4067543148994446f,0.04540411755442619f,-0.17670965194702148f,0.17403557896614075f,-0.3332591950893402f,0.0920296236872673f,-0.12011422216892242f,-0.13247939944267273f,0.15030546486377716f,-0.6020031571388245f,0.03990337252616882f,-0.15754885971546173f,0.09520146995782852f,-0.1138940081000328f,-0.1437448263168335f,0.08852394670248032f,0.07470300793647766f,0.21840333938598633f,-0.6091359853744507f,0.2033311128616333f,-0.18447329103946686f,-0.36350181698799133f,0.13817378878593445f,0.17853263020515442f,-0.04912722483277321f,-0.07184508442878723f}, |
Lightvalve | 64:a8e6799dbce3 | 212 | {-0.276756227016449f,-0.09556084871292114f,0.12328919768333435f,0.0523153692483902f,-0.39632028341293335f,0.21103641390800476f,-0.34435954689979553f,-0.14541661739349365f,0.17735600471496582f,0.009893029928207397f,0.22716842591762543f,0.129820317029953f,-0.14130257070064545f,-0.3772110044956207f,0.22669744491577148f,-0.06111280620098114f,0.009990394115447998f,0.04171628877520561f,0.22105933725833893f,0.15490561723709106f,-0.08622822910547256f,-0.1046934574842453f,0.09996896982192993f,0.0052592139691114426f,-0.2729572355747223f,0.05442296713590622f,0.010474600829184055f,0.15220622718334198f,-0.288028746843338f,-0.2434448003768921f,0.14387860894203186f,0.22230251133441925f}, |
Lightvalve | 64:a8e6799dbce3 | 213 | {-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 | 64:a8e6799dbce3 | 214 | {0.14700931310653687f,0.1833711564540863f,-0.0858893096446991f,0.05376690253615379f,-0.25116482377052307f,0.2733006179332733f,0.616862416267395f,-0.16134384274482727f,0.000652611255645752f,-0.22920364141464233f,0.4397837519645691f,-0.10323379188776016f,0.22982220351696014f,0.7219095826148987f,0.10845161229372025f,-0.4085569679737091f,-0.07963520288467407f,-0.016639666631817818f,-2.855013132095337f,1.4770333766937256f,-0.4170447885990143f,0.18475067615509033f,-0.2228696048259735f,-0.025659818202257156f,0.07647764682769775f,-0.5626823902130127f,-0.9380472302436829f,0.1451820731163025f,-0.011228948831558228f,0.26896968483924866f,-0.28556761145591736f,-0.0975443497300148f}, |
Lightvalve | 64:a8e6799dbce3 | 215 | {-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 | 64:a8e6799dbce3 | 216 | {-0.1933428794145584f,0.1317739188671112f,0.03260180354118347f,-0.2179921269416809f,-0.08091507852077484f,-0.22807994484901428f,-0.22678741812705994f,0.1038196012377739f,0.05445769429206848f,0.07657262682914734f,-0.1997295320034027f,-0.3779059648513794f,0.13914218544960022f,-0.15764181315898895f,-0.03628018498420715f,-0.3727618157863617f,-0.25386664271354675f,-0.18937630951404572f,-0.132919579744339f,-0.35168135166168213f,-0.13643017411231995f,-0.15034843981266022f,-0.3044300675392151f,0.2099861353635788f,-0.19237396121025085f,0.12899406254291534f,0.26942041516304016f,-0.5215796232223511f,-0.0006675124168395996f,-0.2239055633544922f,-0.06182236224412918f,0.3648865520954132f}, |
Lightvalve | 64:a8e6799dbce3 | 217 | {0.003377701621502638f,-0.062024205923080444f,0.10704237222671509f,-0.173600435256958f,-0.10311268270015717f,0.13106171786785126f,-0.04082702472805977f,0.27322712540626526f,-0.23304778337478638f,-0.035415440797805786f,-0.18674887716770172f,-0.2658703625202179f,0.17716765403747559f,-0.26335322856903076f,-0.24061410129070282f,-0.0670233964920044f,-0.027234435081481934f,0.15468381345272064f,0.39823445677757263f,-1.344635248184204f,-0.19344455003738403f,-0.09210354834794998f,-0.19671492278575897f,-0.31504860520362854f,-0.28104209899902344f,-0.024750638753175735f,0.22694247961044312f,-0.0659618005156517f,-0.2531542181968689f,0.24004116654396057f,-0.2505103647708893f,0.014428245835006237f}, |
Lightvalve | 64:a8e6799dbce3 | 218 | {0.10417362302541733f,-0.16078773140907288f,0.11784148216247559f,0.25049132108688354f,0.23944823443889618f,0.17158514261245728f,0.637255072593689f,0.19546358287334442f,0.040603965520858765f,-0.2119520902633667f,0.839573860168457f,-0.43544328212738037f,-0.07898660004138947f,0.39737945795059204f,0.35793185234069824f,0.16372835636138916f,0.18204066157341003f,0.31318214535713196f,-0.48514193296432495f,1.6319140195846558f,-0.452179878950119f,-0.32452133297920227f,0.26029130816459656f,0.048208460211753845f,0.21805478632450104f,-0.3413979709148407f,-0.5302722454071045f,0.16525809466838837f,-0.08671019971370697f,-0.019541800022125244f,0.274711012840271f,0.1581207662820816f}, |
Lightvalve | 64:a8e6799dbce3 | 219 | {0.0573292151093483f,0.2841971218585968f,-0.0814327746629715f,-0.02049749158322811f,0.04095759242773056f,0.0875282883644104f,-0.586379885673523f,0.2595977187156677f,-0.2925014793872833f,0.022429823875427246f,-0.7414460182189941f,-0.10722576826810837f,-0.2097223699092865f,-0.4475327432155609f,0.15800122916698456f,0.1385146677494049f,0.1296386420726776f,0.2004876732826233f,0.4598502218723297f,-0.9527428150177002f,0.6063380241394043f,0.08761540800333023f,0.06231796741485596f,0.13851206004619598f,-0.32260265946388245f,0.4560135006904602f,0.12333875149488449f,0.20624111592769623f,0.14345040917396545f,-0.11986468732357025f,-0.22796882688999176f,-0.09410763531923294f}, |
Lightvalve | 64:a8e6799dbce3 | 220 | {-0.12615902721881866f,0.29651907086372375f,0.02990397810935974f,-0.07365071773529053f,-0.16989107429981232f,-0.2611929178237915f,0.22346898913383484f,0.16549158096313477f,-0.2325194776058197f,-0.2458522766828537f,-0.02328617125749588f,-0.05800141021609306f,-0.25158706307411194f,-0.3273783326148987f,0.2659609913825989f,0.22061185538768768f,0.2577105462551117f,0.036843568086624146f,-0.13256382942199707f,0.07302801311016083f,0.3026500940322876f,-0.31398072838783264f,-0.07374785840511322f,-0.024998260661959648f,-0.14720046520233154f,-0.3830925524234772f,-0.35042843222618103f,0.3767944872379303f,-0.2205982804298401f,0.28094157576560974f,-0.22566641867160797f,-0.10086707770824432f}, |
Lightvalve | 64:a8e6799dbce3 | 221 | {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 | 64:a8e6799dbce3 | 222 | {-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 | 64:a8e6799dbce3 | 223 | {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 | 64:a8e6799dbce3 | 224 | {-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 | 64:a8e6799dbce3 | 225 | {-0.04054148495197296f,-0.25281068682670593f,-0.10565309226512909f,-0.10217760503292084f,0.22124066948890686f,-0.016669882461428642f,0.13439533114433289f,-0.21625643968582153f,-0.06814777851104736f,-0.24531681835651398f,-0.10867110639810562f,0.11354860663414001f,-0.012470155954360962f,-0.04834315553307533f,0.2917248010635376f,0.28058484196662903f,0.2015441358089447f,0.05478575825691223f,0.21876852214336395f,0.013968605548143387f,0.1980237513780594f,-0.043646570295095444f,-0.2520882785320282f,0.2706727981567383f,0.23897342383861542f,0.01417838130146265f,0.21818359196186066f,-0.017171617597341537f,-0.18211489915847778f,-0.15127526223659515f,0.16965459287166595f,0.3860800564289093f}, |
Lightvalve | 64:a8e6799dbce3 | 226 | {-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 | 64:a8e6799dbce3 | 227 | {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 | 64:a8e6799dbce3 | 228 | {0.27614301443099976f,-0.11652402579784393f,0.24921879172325134f,0.16725529730319977f,-0.3529522716999054f,-0.22624388337135315f,-0.36159390211105347f,-0.13561266660690308f,0.23963233828544617f,0.21321198344230652f,-0.18729792535305023f,-0.0984758511185646f,-0.19942539930343628f,-0.2174971103668213f,0.14457453787326813f,-0.7122411727905273f,-0.19791248440742493f,0.17975574731826782f,-0.2993890345096588f,-0.2912631928920746f,-0.2584984302520752f,0.1050725057721138f,-0.09928475320339203f,-0.26327425241470337f,-0.5602705478668213f,0.3993833065032959f,0.024057770147919655f,-0.19004622101783752f,-0.03476092219352722f,0.2736774981021881f,-0.03050028160214424f,-0.3570877015590668f}, |
Lightvalve | 64:a8e6799dbce3 | 229 | {-0.17075178027153015f,0.009595632553100586f,0.2466227114200592f,0.05140487849712372f,-0.31388768553733826f,-0.30789920687675476f,-0.0075945379212498665f,-0.3187141418457031f,-0.2516406178474426f,0.012286126613616943f,0.2726706266403198f,-0.3966335654258728f,-0.13968390226364136f,-0.14732563495635986f,-0.0496971495449543f,-0.03776009753346443f,-0.24087269604206085f,0.06394801288843155f,-0.2768625319004059f,0.1040387749671936f,-0.19509759545326233f,-0.2569916546344757f,-0.031352698802948f,0.21324186027050018f,-0.19018572568893433f,-0.30967268347740173f,-0.23032434284687042f,0.1440102756023407f,-0.07090267539024353f,-0.23986908793449402f,-0.27214351296424866f,-0.22093108296394348f}, |
Lightvalve | 64:a8e6799dbce3 | 230 | {-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 | 64:a8e6799dbce3 | 231 | {-0.20768442749977112f,-0.17203155159950256f,0.0620841383934021f,-0.04785560816526413f,-0.09897751361131668f,-0.22745193541049957f,0.009043784812092781f,0.15261369943618774f,-0.21029016375541687f,0.2210421860218048f,-0.3253668248653412f,0.04599811136722565f,-0.16073621809482574f,-0.30910927057266235f,-0.3284757733345032f,-0.4673096537590027f,0.10771593451499939f,-0.3263266384601593f,-0.031224608421325684f,-0.2612304091453552f,0.12845292687416077f,-0.24405217170715332f,-0.22302524745464325f,0.10563395917415619f,-0.3808150887489319f,0.24485471844673157f,0.05545651540160179f,-0.16324345767498016f,0.17976179718971252f,-0.22928372025489807f,0.26136064529418945f,0.24002698063850403f}, |
Lightvalve | 64:a8e6799dbce3 | 232 | {-0.09888127446174622f,-0.22750279307365417f,-0.22503364086151123f,-0.008032619953155518f,-0.012498408555984497f,-0.24329537153244019f,-0.07913157343864441f,0.08175003528594971f,-0.016126900911331177f,0.06972584128379822f,0.06827792525291443f,0.2120952308177948f,-0.031845152378082275f,-0.30540701746940613f,0.18349257111549377f,0.20412376523017883f,-0.09216172993183136f,0.04617339372634888f,-0.09483018517494202f,-0.06833663582801819f,-0.026390254497528076f,-0.28567367792129517f,-0.06047184765338898f,-0.28923499584198f,0.01265987753868103f,-0.2029699683189392f,0.29187360405921936f,-0.2903735339641571f,-0.16326025128364563f,0.11664235591888428f,-0.02675291895866394f,0.1267804503440857f}, |
Lightvalve | 63:a2d7c63419c2 | 233 | }; |
Lightvalve | 63:a2d7c63419c2 | 234 | |
Lightvalve | 64:a8e6799dbce3 | 235 | const float h3[32][32] = { |
Lightvalve | 64:a8e6799dbce3 | 236 | {-0.2551194727420807f,-0.09101890027523041f,-0.039938222616910934f,-0.2297012358903885f,-0.04914749786257744f,-0.05839472636580467f,0.23563924431800842f,0.21467849612236023f,-0.14446713030338287f,0.034586966037750244f,-0.08393588662147522f,0.28293344378471375f,0.10058467835187912f,0.13426963984966278f,-0.2476848065853119f,0.13452908396720886f,0.033751994371414185f,0.2061004936695099f,0.004610735457390547f,-0.047270745038986206f,-0.06896747648715973f,-0.030367758125066757f,-0.1638459414243698f,0.044178664684295654f,0.1966625303030014f,-0.1258748173713684f,0.3543202579021454f,-0.16248615086078644f,0.08456003665924072f,0.2922307550907135f,-0.21407078206539154f,-0.119477279484272f}, |
Lightvalve | 64:a8e6799dbce3 | 237 | {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 | 64:a8e6799dbce3 | 238 | {-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 | 64:a8e6799dbce3 | 239 | {0.2906629145145416f,0.16674396395683289f,-0.2048129439353943f,0.24708573520183563f,0.09334155172109604f,-0.05046384781599045f,-0.061309605836868286f,-0.17915479838848114f,-0.030297284945845604f,-0.044261813163757324f,-0.09506386518478394f,0.24970653653144836f,0.140608549118042f,0.07934696972370148f,0.22106656432151794f,-0.23978039622306824f,-0.28915077447891235f,0.030949801206588745f,-0.28344714641571045f,0.17508044838905334f,0.23260188102722168f,-0.02717127837240696f,-0.18165703117847443f,-0.2539325952529907f,0.2068878710269928f,-0.11024686694145203f,-0.11684871464967728f,-0.008553821593523026f,-0.21804101765155792f,-0.25852420926094055f,0.05653107166290283f,-0.012144584208726883f}, |
Lightvalve | 64:a8e6799dbce3 | 240 | {0.07563930749893188f,-0.0864691436290741f,-0.25957009196281433f,0.14710086584091187f,-0.2755613625049591f,-0.0486634224653244f,-0.17751117050647736f,0.2470131814479828f,-0.3877350091934204f,-0.2740214169025421f,0.48606789112091064f,-0.24627932906150818f,-0.2334918975830078f,-0.08405673503875732f,0.06802645325660706f,-0.048776447772979736f,0.20131775736808777f,-0.017045116052031517f,0.1065007895231247f,0.1723131686449051f,-0.12130393087863922f,0.28655827045440674f,0.09938116371631622f,0.11342830955982208f,-0.12671566009521484f,0.12758469581604004f,0.2596653401851654f,-0.276505708694458f,0.17249789834022522f,-0.09959287941455841f,-0.07189898192882538f,-0.06464556604623795f}, |
Lightvalve | 64:a8e6799dbce3 | 241 | {0.10931676626205444f,0.2396949827671051f,0.12925085425376892f,-0.031216295436024666f,-0.11903928220272064f,0.11186975240707397f,-0.0620582215487957f,0.04091137647628784f,-0.0005325245438143611f,-0.15699732303619385f,0.08972057700157166f,-0.21529507637023926f,-0.028432423248887062f,-0.12350860238075256f,0.2971965968608856f,0.25175121426582336f,-0.2889891266822815f,-0.13035915791988373f,0.15943540632724762f,0.034403007477521896f,0.0786113515496254f,-0.2286425083875656f,-0.01647675596177578f,0.27409639954566956f,-0.11409469693899155f,-0.18302330374717712f,0.051028646528720856f,-0.008777839131653309f,-0.27729424834251404f,-0.29547566175460815f,-0.25800079107284546f,0.21303775906562805f}, |
Lightvalve | 64:a8e6799dbce3 | 242 | {-0.21155381202697754f,0.4169614017009735f,-0.149305060505867f,-0.13649512827396393f,-0.0040439944714307785f,0.16310036182403564f,-0.11482425779104233f,0.2226138561964035f,0.06895330548286438f,-1.709801435470581f,0.05974118411540985f,-0.25618287920951843f,-0.054692342877388f,-0.1533658504486084f,0.25543639063835144f,-0.1192857176065445f,-0.18917083740234375f,-0.019574562087655067f,-0.444706529378891f,-0.020779341459274292f,0.009562673978507519f,-0.11819368600845337f,0.05895781144499779f,-0.11636392772197723f,-0.2627762258052826f,-0.2910519242286682f,-0.22418221831321716f,-0.32023555040359497f,0.23576414585113525f,-0.09532724320888519f,0.26950082182884216f,0.11913502961397171f}, |
Lightvalve | 64:a8e6799dbce3 | 243 | {-0.01093912124633789f,-0.23583689332008362f,0.26154714822769165f,0.3012233376502991f,0.14452683925628662f,-0.3326735496520996f,0.036741942167282104f,-0.0059101879596710205f,-0.18442028760910034f,-0.27182313799858093f,0.09319102764129639f,-0.08139897882938385f,0.259794145822525f,-0.08187927305698395f,0.0685860812664032f,-0.29903873801231384f,0.1317853033542633f,0.20550194382667542f,-0.06596825271844864f,-0.2777772843837738f,0.30158787965774536f,0.055962659418582916f,0.09796766936779022f,0.131951704621315f,-0.030015112832188606f,0.23886635899543762f,-0.21418654918670654f,0.20126910507678986f,0.28547611832618713f,0.17161712050437927f,-0.017215043306350708f,0.0029450233560055494f}, |
Lightvalve | 64:a8e6799dbce3 | 244 | {-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 | 64:a8e6799dbce3 | 245 | {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 | 64:a8e6799dbce3 | 246 | {-0.023678362369537354f,0.3512638509273529f,-0.14722158014774323f,-0.0392800010740757f,0.0885668620467186f,0.0946878045797348f,0.022257043048739433f,0.1716238558292389f,-0.11324318498373032f,0.10974260419607162f,-0.08888526260852814f,-0.06168833374977112f,-0.21815425157546997f,-0.14588837325572968f,0.080221027135849f,-0.2471318244934082f,0.026521950960159302f,0.25768426060676575f,0.29860830307006836f,-0.22593867778778076f,-0.2529640793800354f,0.002077224664390087f,0.2273881733417511f,0.4108573794364929f,0.15727099776268005f,-0.25962090492248535f,-0.008949966169893742f,0.09106230735778809f,0.21897625923156738f,-0.2912617325782776f,-0.28352323174476624f,-0.4088878631591797f}, |
Lightvalve | 64:a8e6799dbce3 | 247 | {0.2680447995662689f,0.001469396986067295f,-0.32541656494140625f,-0.18059521913528442f,0.04238729178905487f,0.11937148123979568f,0.16909809410572052f,-0.2018170952796936f,0.2060541808605194f,0.06578544527292252f,-0.27351343631744385f,0.2547462284564972f,0.28375518321990967f,0.032859668135643005f,0.23152390122413635f,-0.07731422781944275f,0.21101722121238708f,-0.1683351695537567f,-0.08190501481294632f,-0.27668556571006775f,-0.15859590470790863f,0.20617720484733582f,-0.21622483432292938f,0.1618170440196991f,-0.2548491060733795f,0.18312275409698486f,-0.25461483001708984f,0.20886272192001343f,0.12076901644468307f,-0.1739533692598343f,-0.2773703932762146f,-0.6688722372055054f}, |
Lightvalve | 64:a8e6799dbce3 | 248 | {0.10771462321281433f,0.08408418297767639f,-0.1647956818342209f,-0.00161704421043396f,0.10816431045532227f,0.13259877264499664f,-0.2502448558807373f,-0.05063694715499878f,-0.28954532742500305f,-0.11501708626747131f,0.24353471398353577f,0.11519002914428711f,-0.1879904866218567f,-0.026675879955291748f,-0.0055807530879974365f,0.05870962142944336f,-0.0561012327671051f,-0.1419317126274109f,-0.20300637185573578f,-0.027777740731835365f,-0.17170509696006775f,-0.3093981444835663f,0.2986377775669098f,-0.24229218065738678f,-0.19906556606292725f,-0.03866580128669739f,0.09892630577087402f,0.22604267299175262f,0.08111580461263657f,0.024399906396865845f,-0.264041006565094f,-0.037910252809524536f}, |
Lightvalve | 64:a8e6799dbce3 | 249 | {0.07240793108940125f,0.2968745231628418f,0.12581734359264374f,0.14544308185577393f,-0.001873494009487331f,0.18561306595802307f,0.2231290191411972f,-0.11358203738927841f,0.03846980631351471f,-0.5061792135238647f,-0.056825198233127594f,0.030263751745224f,-0.25552064180374146f,0.12521019577980042f,0.13272255659103394f,-0.0684008002281189f,-0.13351139426231384f,0.21587422490119934f,-0.11616086214780807f,0.09435359388589859f,-0.1967686414718628f,0.14476516842842102f,0.2166706919670105f,0.28145694732666016f,0.20255109667778015f,-0.1976800560951233f,-0.1519756019115448f,0.16283585131168365f,-0.08575978130102158f,-0.29330405592918396f,0.004574976861476898f,-0.07021577656269073f}, |
Lightvalve | 64:a8e6799dbce3 | 250 | {-0.27890223264694214f,0.026230525225400925f,0.1517297923564911f,0.19112101197242737f,-0.789542555809021f,-0.16985057294368744f,-0.2505151033401489f,-0.2674597501754761f,-0.23863942921161652f,0.41558414697647095f,-0.4467531740665436f,0.04456409811973572f,0.05523297190666199f,0.0029259631410241127f,-0.02410009503364563f,0.10129088163375854f,0.22686699032783508f,-0.30486053228378296f,-0.2911565601825714f,-0.406606525182724f,-0.10204439610242844f,-0.16477997601032257f,-0.26734399795532227f,0.14678052067756653f,-0.0916958674788475f,-0.025903940200805664f,-0.111304871737957f,0.2614813446998596f,0.14481788873672485f,0.06508117914199829f,0.02118399739265442f,-0.250347763299942f}, |
Lightvalve | 64:a8e6799dbce3 | 251 | {0.3047083914279938f,-0.3829544484615326f,-0.09393081814050674f,-0.32120004296302795f,-0.7049156427383423f,0.30046454071998596f,0.04369795322418213f,-0.2643950879573822f,-0.32492223381996155f,-0.06434918940067291f,-0.16104383766651154f,0.038040339946746826f,0.11545597016811371f,0.1038844883441925f,0.062144935131073f,-0.28920799493789673f,0.03473195433616638f,-0.03177381306886673f,0.8106175065040588f,0.6032338738441467f,-0.24128633737564087f,0.35133063793182373f,0.2712000906467438f,0.3239062428474426f,0.030129436403512955f,-0.031148135662078857f,-0.44779321551322937f,-0.034113068133592606f,0.2235644906759262f,0.017086774110794067f,-0.18175730109214783f,0.003414738457649946f}, |
Lightvalve | 64:a8e6799dbce3 | 252 | {-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 | 64:a8e6799dbce3 | 253 | {0.1169951856136322f,0.22583343088626862f,-0.0623902790248394f,-0.21188730001449585f,0.35504016280174255f,0.1675981730222702f,0.25662973523139954f,0.2666439712047577f,0.016538159921765327f,0.03567033261060715f,-0.6564634442329407f,0.02602824568748474f,0.02023410052061081f,-0.08262813836336136f,0.10762849450111389f,0.06951633095741272f,0.0639207661151886f,0.2458573281764984f,0.5492554306983948f,0.20780347287654877f,-0.47689104080200195f,-0.010499079711735249f,0.1945638209581375f,-0.21918198466300964f,-0.12797842919826508f,0.012219250202178955f,-0.0719306692481041f,-0.21069641411304474f,-0.24534004926681519f,-0.29393887519836426f,-0.08237382769584656f,-0.07659900933504105f}, |
Lightvalve | 64:a8e6799dbce3 | 254 | {-0.16101892292499542f,-2.6252098083496094f,0.16429387032985687f,0.15439511835575104f,-0.22270971536636353f,-0.1778838187456131f,0.10244748741388321f,-0.17396175861358643f,0.09173326194286346f,-0.2543085217475891f,-0.02308499999344349f,-0.04377517104148865f,-0.18632613122463226f,-0.014269514009356499f,-0.2592318058013916f,0.1978430449962616f,0.18047624826431274f,0.25547152757644653f,-0.3583325445652008f,-0.31760597229003906f,-0.34371933341026306f,0.14292629063129425f,0.35391759872436523f,-0.09581347554922104f,-0.04283968731760979f,-0.28873488306999207f,-0.0847386047244072f,0.13971801102161407f,0.23944589495658875f,0.18439257144927979f,0.14335589110851288f,0.29589322209358215f}, |
Lightvalve | 64:a8e6799dbce3 | 255 | {0.261911004781723f,-0.19572317600250244f,-0.3139093816280365f,-0.07572512328624725f,-1.4491221904754639f,0.13928867876529694f,-0.09386739134788513f,-0.05591337010264397f,-0.4786756634712219f,-0.3477703630924225f,0.005039088893681765f,-0.2924177646636963f,0.06799451261758804f,-0.08486802875995636f,-0.20773646235466003f,-0.10781967639923096f,-0.15712574124336243f,0.16112294793128967f,0.27851009368896484f,0.2133936733007431f,-0.11231138557195663f,0.17959244549274445f,-1.9806863069534302f,0.31922289729118347f,0.22832639515399933f,0.0025720298290252686f,-1.1841254234313965f,-0.3099982440471649f,0.12816743552684784f,0.21125611662864685f,-0.05751854181289673f,-2.9703240394592285f}, |
Lightvalve | 64:a8e6799dbce3 | 256 | {0.14277681708335876f,-0.22795183956623077f,0.047815486788749695f,-0.22286657989025116f,-0.15775664150714874f,0.041207365691661835f,0.1075698733329773f,-0.27022814750671387f,-0.19193708896636963f,-0.08106427639722824f,-0.7710232734680176f,0.18551066517829895f,0.16216030716896057f,0.09001287072896957f,-0.03100520372390747f,-0.2484396994113922f,0.06366744637489319f,-0.3076874017715454f,0.3138425350189209f,-0.595535933971405f,-0.5645818114280701f,0.2592972218990326f,0.3755412995815277f,0.4382358491420746f,-0.10754720866680145f,-0.19159743189811707f,0.16949352622032166f,-0.36919495463371277f,-0.5071529150009155f,-0.10488687455654144f,-0.24558058381080627f,0.14848382771015167f}, |
Lightvalve | 64:a8e6799dbce3 | 257 | {0.29069945216178894f,-0.1806652545928955f,0.019009560346603394f,-0.28619009256362915f,0.09075364470481873f,-0.19120927155017853f,0.045349299907684326f,-0.17138783633708954f,-0.17037051916122437f,0.028545528650283813f,-0.16238126158714294f,-0.15074089169502258f,-0.09016353636980057f,-0.23803044855594635f,0.09875330328941345f,0.08164769411087036f,0.2294725477695465f,0.10683679580688477f,-0.26258087158203125f,-0.10248091071844101f,0.16431908309459686f,0.27430880069732666f,0.13898101449012756f,-0.16844238340854645f,0.3061029314994812f,0.023651927709579468f,-0.2052852213382721f,0.21941810846328735f,0.11974992603063583f,0.19045329093933105f,0.02994692325592041f,-0.25522705912590027f}, |
Lightvalve | 64:a8e6799dbce3 | 258 | {0.1991647183895111f,0.12534403800964355f,-0.04112154245376587f,0.23123982548713684f,-0.17588619887828827f,-0.302817702293396f,-0.1610087752342224f,-0.031804412603378296f,0.10274738073348999f,-0.25018924474716187f,0.15975651144981384f,-0.057292819023132324f,0.1464652419090271f,0.08016204833984375f,0.2151305377483368f,0.2952744662761688f,-0.21319252252578735f,0.04970458149909973f,0.10210192203521729f,0.3050673305988312f,0.21167120337486267f,-0.15151944756507874f,0.13887640833854675f,0.25299301743507385f,-0.11117732524871826f,-0.07015113532543182f,-0.287551611661911f,-0.025779157876968384f,-0.07337476313114166f,-0.24420931935310364f,0.015819430351257324f,-0.10595546662807465f}, |
Lightvalve | 64:a8e6799dbce3 | 259 | {0.12202468514442444f,0.11307132244110107f,-0.1393485814332962f,-0.35166671872138977f,0.14782434701919556f,0.10332854837179184f,-0.08385257422924042f,-0.12613117694854736f,0.2619711458683014f,-0.3288128674030304f,-0.06917986273765564f,-0.11160935461521149f,-0.13613487780094147f,-0.16888540983200073f,-0.06735922396183014f,0.05864924192428589f,-0.25733181834220886f,-0.20564723014831543f,0.0336795374751091f,-0.080560602247715f,-0.2635331451892853f,0.20034900307655334f,0.1359344720840454f,0.07558305561542511f,0.25859907269477844f,0.1795230209827423f,0.14820072054862976f,-0.00910326186567545f,-0.17337296903133392f,0.2425754964351654f,-0.22172409296035767f,-0.04560137912631035f}, |
Lightvalve | 64:a8e6799dbce3 | 260 | {-0.3055141270160675f,-0.13576149940490723f,-0.007098792120814323f,-0.22958824038505554f,-0.16869203746318817f,-0.07209712266921997f,0.06344843655824661f,0.1868957281112671f,0.10014556348323822f,-0.26565518975257874f,-0.4981679916381836f,-0.004238337278366089f,0.05754581838846207f,0.043803781270980835f,-0.023131370544433594f,0.036719828844070435f,0.16260939836502075f,0.021452900022268295f,-0.6414809226989746f,-0.33981701731681824f,-0.05313646048307419f,-0.10980580002069473f,0.3931199312210083f,0.14811202883720398f,0.10450282692909241f,-0.02825927734375f,-0.07055894285440445f,-0.243629589676857f,0.05514201894402504f,0.1865309774875641f,0.22191277146339417f,-0.23279036581516266f}, |
Lightvalve | 64:a8e6799dbce3 | 261 | {0.1782623827457428f,0.17329983413219452f,-0.36183589696884155f,-0.13699603080749512f,0.21084707975387573f,0.22825263440608978f,-0.32466426491737366f,0.12530909478664398f,0.2008134126663208f,0.2332226037979126f,-0.33608919382095337f,-0.22968843579292297f,-0.024968745186924934f,0.019941013306379318f,-0.2527656555175781f,-0.3049176335334778f,0.032145023345947266f,-0.2847839891910553f,0.22066818177700043f,-0.2139289677143097f,-0.14646612107753754f,0.08866468816995621f,0.33709555864334106f,0.17495237290859222f,-0.23284006118774414f,0.10029953718185425f,0.2192709743976593f,0.25868454575538635f,-0.332850843667984f,0.1616479754447937f,-0.21182864904403687f,-0.0555347241461277f}, |
Lightvalve | 64:a8e6799dbce3 | 262 | {-0.17396044731140137f,-0.0057539851404726505f,-0.17574112117290497f,-0.006718873977661133f,0.040587734431028366f,-0.13487496972084045f,-0.1976376324892044f,-0.18956288695335388f,-0.3795906603336334f,-0.2926933467388153f,0.12965916097164154f,-0.1146831065416336f,0.21467310190200806f,0.2603026330471039f,-0.19851773977279663f,-0.10762731730937958f,0.14198419451713562f,0.07217786461114883f,0.051015544682741165f,-0.062494050711393356f,-0.29993119835853577f,-0.07717446982860565f,0.36891332268714905f,-0.12070614844560623f,0.27586397528648376f,-0.2665709853172302f,0.27776476740837097f,0.1593986302614212f,-0.0717584639787674f,-0.1200934648513794f,-0.07223458588123322f,-0.16176432371139526f}, |
Lightvalve | 64:a8e6799dbce3 | 263 | {-0.12546227872371674f,-0.0935664176940918f,-0.13015469908714294f,0.0722120925784111f,-0.008691729046404362f,-0.2522052824497223f,-0.28310835361480713f,-0.043121352791786194f,-0.11268676072359085f,-0.7503910660743713f,-0.19499319791793823f,0.046816736459732056f,-0.12017074227333069f,-0.12375825643539429f,-0.0649729073047638f,0.2468220293521881f,0.060016900300979614f,-0.16779978573322296f,-0.19017599523067474f,-0.13085618615150452f,-0.41277334094047546f,0.07795637100934982f,-0.4315490424633026f,0.20171600580215454f,-0.07085483521223068f,0.020356476306915283f,-0.10943791270256042f,0.1812962293624878f,0.16904227435588837f,-7.510185241699219e-06f,0.094448983669281f,-0.7701192498207092f}, |
Lightvalve | 64:a8e6799dbce3 | 264 | {0.07555973529815674f,-0.0029259920120239258f,-0.08789914846420288f,0.06678077578544617f,-0.11083845794200897f,0.11010000109672546f,-0.14982634782791138f,0.12075316905975342f,-0.2766430675983429f,0.013024389743804932f,0.18159812688827515f,-0.20200279355049133f,0.2637675702571869f,-0.1856893002986908f,0.2882818281650543f,0.05304515361785889f,-0.15297894179821014f,0.07341468334197998f,0.05268138647079468f,0.1067940890789032f,-0.2661813795566559f,-0.2009473443031311f,0.1843600869178772f,0.2517976462841034f,-0.07343396544456482f,-0.051110416650772095f,-0.23432010412216187f,0.16746872663497925f,-0.2205146849155426f,-0.017525076866149902f,0.20926335453987122f,-0.2141496241092682f}, |
Lightvalve | 64:a8e6799dbce3 | 265 | {0.06582912802696228f,0.2796666920185089f,-0.2556927502155304f,0.0023079216480255127f,0.2043982446193695f,0.13894453644752502f,0.06556430459022522f,0.29767414927482605f,0.24966773390769958f,-0.16670267283916473f,-0.1203770637512207f,-0.06570860743522644f,-0.015925198793411255f,0.17675906419754028f,-0.014884740114212036f,-0.05300724506378174f,0.26490333676338196f,0.15243005752563477f,-0.07319167256355286f,0.2353842556476593f,0.23596063256263733f,0.1602974534034729f,-0.04174882173538208f,-0.11559568345546722f,-0.06235519051551819f,0.21069613099098206f,-0.19532959163188934f,-0.2486409693956375f,0.032513976097106934f,-0.2712400257587433f,-0.19435247778892517f,-0.23200613260269165f}, |
Lightvalve | 64:a8e6799dbce3 | 266 | {-0.1299392580986023f,-0.06208275258541107f,-0.18067686259746552f,0.03896602615714073f,-0.1559528261423111f,-0.14272382855415344f,-0.19175797700881958f,0.02903696894645691f,-0.21793057024478912f,0.016345679759979248f,-0.24767392873764038f,0.2033931314945221f,-0.2574335038661957f,0.011410274542868137f,0.13206014037132263f,0.15829482674598694f,-0.21012049913406372f,0.2088232934474945f,0.12396217882633209f,-0.17956478893756866f,0.32670894265174866f,-0.021142370998859406f,-0.1977243274450302f,-0.025072306394577026f,0.1991090476512909f,-0.007939159870147705f,-0.15539970993995667f,0.19354887306690216f,0.1298319399356842f,0.18135693669319153f,-0.008151531219482422f,0.23252393305301666f}, |
Lightvalve | 64:a8e6799dbce3 | 267 | {0.07638216018676758f,0.10178792476654053f,-0.3632030189037323f,-0.235545814037323f,0.09491447359323502f,0.007485899608582258f,0.16700564324855804f,-0.25668495893478394f,0.026961220428347588f,0.30681201815605164f,0.036471329629421234f,0.02524423599243164f,-0.10277769714593887f,0.22266533970832825f,-0.029521822929382324f,-0.19500072300434113f,0.06506577134132385f,-0.042979199439287186f,0.38466188311576843f,0.28802499175071716f,0.25258976221084595f,-0.025679901242256165f,-0.13952423632144928f,-0.4421646296977997f,0.20129328966140747f,0.1901901364326477f,-0.14958564937114716f,-0.07797150313854218f,-1.3495779037475586f,0.22636333107948303f,-0.28991997241973877f,0.19003361463546753f}, |
Lightvalve | 64:a8e6799dbce3 | 268 | }; |
Lightvalve | 63:a2d7c63419c2 | 269 | |
Lightvalve | 64:a8e6799dbce3 | 270 | const float hout[32] = { 0.3285340666770935f,0.2312968373298645f,-0.1630605310201645f,-0.052534740418195724f,-0.10057443380355835f,0.2961001396179199f,0.017061835154891014f,0.10350137203931808f,-0.07044677436351776f,-0.6716802716255188f,0.1657922863960266f,-0.19491273164749146f,-0.09723297506570816f,0.11400538682937622f,0.2356991171836853f,-0.1462659239768982f,0.09851181507110596f,-0.18661867082118988f,-0.20936886966228485f,-0.06724883615970612f,-0.012077437713742256f,0.13819065690040588f,-0.36261582374572754f,-0.1528124064207077f,0.21429504454135895f,0.2520971894264221f,-0.25227150321006775f,-0.31772324442863464f,0.180665984749794f,-0.3257754445075989f,-0.39810308814048767f,-0.2707440257072449f }; |
Lightvalve | 64:a8e6799dbce3 | 271 | |
Lightvalve | 64:a8e6799dbce3 | 272 | const float b1[32] = { 0.41725802421569824f,0.677618682384491f,-1.7145336866378784f,0.4289698898792267f,1.0923852920532227f,0.6965276002883911f,-0.33025991916656494f,0.911361813545227f,0.5523963570594788f,-0.9239171743392944f,0.5504469275474548f,1.4532619714736938f,-0.3425353467464447f,-0.9522353410720825f,-1.087764859199524f,1.1365444660186768f,0.6634984612464905f,0.07243652641773224f,0.34714072942733765f,0.4831358790397644f,-0.284685879945755f,-1.1118980646133423f,-1.6770726442337036f,-1.2263047695159912f,1.5655348300933838f,-2.0880801677703857f,-1.0489267110824585f,0.6718418598175049f,0.3125588893890381f,-1.0887231826782227f,1.4772096872329712f,-0.44261544942855835f }; |
Lightvalve | 63:a2d7c63419c2 | 273 | |
Lightvalve | 64:a8e6799dbce3 | 274 | const float b2[32] = { -0.1328246146440506f,-0.7642630338668823f,-1.4564176797866821f,-0.5193768739700317f,-0.770237147808075f,0.2291887253522873f,0.42305076122283936f,-0.330333411693573f,-1.200630784034729f,-1.912178635597229f,0.3195040225982666f,0.6411747336387634f,-0.12948329746723175f,2.127977132797241f,0.03474299982190132f,1.0651566982269287f,-1.798204779624939f,-1.6275829076766968f,0.24063049256801605f,-0.33282727003097534f,0.15034039318561554f,0.3341216742992401f,0.09335067123174667f,-1.0914796590805054f,1.1630909442901611f,1.3906062841415405f,0.9115413427352905f,-0.08930502086877823f,-0.6323830485343933f,-0.4208582937717438f,-1.2135889530181885f,-1.3041324615478516f }; |
Lightvalve | 63:a2d7c63419c2 | 275 | |
Lightvalve | 64:a8e6799dbce3 | 276 | const float b3[32] = { -1.963319182395935f,-0.24137775599956512f,0.16939261555671692f,-0.010520849376916885f,0.16716189682483673f,0.8664999008178711f,-0.5060869455337524f,-0.675765335559845f,0.4948726296424866f,0.49107488989830017f,-0.3517422378063202f,0.050810977816581726f,-0.5689442157745361f,0.5305911302566528f,-1.1428403854370117f,-0.3598397970199585f,-1.3594286441802979f,-1.0502030849456787f,-0.22544679045677185f,0.391804963350296f,1.3067524433135986f,1.170665979385376f,-0.7901832461357117f,-0.7575708627700806f,0.7138406038284302f,-0.36519986391067505f,-0.0393984317779541f,0.7097650170326233f,0.27854597568511963f,-2.3236680030822754f,0.025814389809966087f,0.9480384588241577f }; |
Lightvalve | 64:a8e6799dbce3 | 277 | |
Lightvalve | 64:a8e6799dbce3 | 278 | const float bout[1] = { -0.28343671560287476f }; |
Lightvalve | 59:bc8c8270f0ab | 279 | |
Lightvalve | 59:bc8c8270f0ab | 280 | |
GiJeongKim | 0:51c43836c1d7 | 281 | int main() |
GiJeongKim | 0:51c43836c1d7 | 282 | { |
Lightvalve | 64:a8e6799dbce3 | 283 | |
Lightvalve | 63:a2d7c63419c2 | 284 | HAL_Init(); |
Lightvalve | 63:a2d7c63419c2 | 285 | SystemClock_Config(); |
Lightvalve | 63:a2d7c63419c2 | 286 | |
jobuuu | 6:df07d3491e3a | 287 | /********************************* |
jobuuu | 1:e04e563be5ce | 288 | *** Initialization |
jobuuu | 6:df07d3491e3a | 289 | *********************************/ |
Lightvalve | 55:f4819de54e7a | 290 | LED = 1; |
Lightvalve | 59:bc8c8270f0ab | 291 | pc.baud(9600); |
Lightvalve | 21:e5f1a43ea6f9 | 292 | |
GiJeongKim | 0:51c43836c1d7 | 293 | // i2c init |
Lightvalve | 8:5d2eebdad025 | 294 | i2c.frequency(400 * 1000); // 0.4 mHz |
Lightvalve | 8:5d2eebdad025 | 295 | wait_ms(2); // Power Up wait |
Lightvalve | 8:5d2eebdad025 | 296 | look_for_hardware_i2c(); // Hardware present |
Lightvalve | 8:5d2eebdad025 | 297 | init_as5510(i2c_slave_addr1); |
Lightvalve | 11:82d8768d7351 | 298 | make_delay(); |
jobuuu | 2:a1c0a37df760 | 299 | |
GiJeongKim | 0:51c43836c1d7 | 300 | // // spi init |
Lightvalve | 16:903b5a4433b4 | 301 | //eeprom.format(8,3); |
Lightvalve | 16:903b5a4433b4 | 302 | //eeprom.frequency(5000000); //5M |
GiJeongKim | 0:51c43836c1d7 | 303 | enc.format(8,0); |
GiJeongKim | 0:51c43836c1d7 | 304 | enc.frequency(5000000); //5M |
Lightvalve | 11:82d8768d7351 | 305 | make_delay(); |
Lightvalve | 21:e5f1a43ea6f9 | 306 | |
Lightvalve | 16:903b5a4433b4 | 307 | //rom |
Lightvalve | 19:23b7c1ad8683 | 308 | ROM_CALL_DATA(); |
Lightvalve | 16:903b5a4433b4 | 309 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 310 | |
GiJeongKim | 0:51c43836c1d7 | 311 | // ADC init |
jobuuu | 5:a4319f79457b | 312 | Init_ADC(); |
Lightvalve | 11:82d8768d7351 | 313 | make_delay(); |
jobuuu | 2:a1c0a37df760 | 314 | |
GiJeongKim | 0:51c43836c1d7 | 315 | // Pwm init |
GiJeongKim | 0:51c43836c1d7 | 316 | Init_PWM(); |
GiJeongKim | 0:51c43836c1d7 | 317 | TIM4->CR1 ^= TIM_CR1_UDIS; |
Lightvalve | 11:82d8768d7351 | 318 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 319 | |
Lightvalve | 11:82d8768d7351 | 320 | // TMR3 init |
Lightvalve | 11:82d8768d7351 | 321 | Init_TMR3(); |
Lightvalve | 11:82d8768d7351 | 322 | TIM3->CR1 ^= TIM_CR1_UDIS; |
Lightvalve | 11:82d8768d7351 | 323 | make_delay(); |
Lightvalve | 21:e5f1a43ea6f9 | 324 | |
Lightvalve | 49:3c630b5eba9f | 325 | // TMR2 init |
Lightvalve | 54:6f50d9d3bfee | 326 | // Init_TMR2(); |
Lightvalve | 54:6f50d9d3bfee | 327 | // TIM2->CR1 ^= TIM_CR1_UDIS; |
Lightvalve | 54:6f50d9d3bfee | 328 | // make_delay(); |
Lightvalve | 21:e5f1a43ea6f9 | 329 | |
GiJeongKim | 0:51c43836c1d7 | 330 | // CAN |
jobuuu | 2:a1c0a37df760 | 331 | can.attach(&CAN_RX_HANDLER); |
Lightvalve | 11:82d8768d7351 | 332 | CAN_ID_INIT(); |
Lightvalve | 11:82d8768d7351 | 333 | make_delay(); |
Lightvalve | 34:bb2ca2fc2a8e | 334 | |
Lightvalve | 23:59218d4a256d | 335 | //Timer priority |
Lightvalve | 23:59218d4a256d | 336 | NVIC_SetPriority(TIM3_IRQn, 2); |
Lightvalve | 55:f4819de54e7a | 337 | //NVIC_SetPriority(TIM2_IRQn, 3); |
Lightvalve | 52:647072f5307a | 338 | NVIC_SetPriority(TIM4_IRQn, 3); |
Lightvalve | 34:bb2ca2fc2a8e | 339 | |
Lightvalve | 23:59218d4a256d | 340 | //can.reset(); |
Lightvalve | 19:23b7c1ad8683 | 341 | can.filter(msg.id, 0xFFFFF000, CANStandard); |
Lightvalve | 34:bb2ca2fc2a8e | 342 | |
GiJeongKim | 0:51c43836c1d7 | 343 | // spi _ enc |
GiJeongKim | 0:51c43836c1d7 | 344 | spi_enc_set_init(); |
Lightvalve | 11:82d8768d7351 | 345 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 346 | |
Lightvalve | 11:82d8768d7351 | 347 | //DAC init |
Lightvalve | 56:2eade98630e2 | 348 | if (SENSING_MODE == 0) { |
Lightvalve | 56:2eade98630e2 | 349 | dac_1 = TORQUE_VREF / 3.3f; |
Lightvalve | 56:2eade98630e2 | 350 | dac_2 = 0.0f; |
Lightvalve | 56:2eade98630e2 | 351 | } else if (SENSING_MODE == 1) { |
Lightvalve | 56:2eade98630e2 | 352 | dac_1 = PRES_A_VREF / 3.3f; |
Lightvalve | 56:2eade98630e2 | 353 | dac_2 = PRES_B_VREF / 3.3f; |
Lightvalve | 56:2eade98630e2 | 354 | } |
Lightvalve | 11:82d8768d7351 | 355 | make_delay(); |
Lightvalve | 13:747daba9cf59 | 356 | |
Lightvalve | 19:23b7c1ad8683 | 357 | for (int i=0; i<50; i++) { |
Lightvalve | 11:82d8768d7351 | 358 | if(i%2==0) |
Lightvalve | 38:118df027d851 | 359 | ID_index_array[i] = - i * 0.5f; |
Lightvalve | 11:82d8768d7351 | 360 | else |
Lightvalve | 38:118df027d851 | 361 | ID_index_array[i] = (i+1) * 0.5f; |
Lightvalve | 11:82d8768d7351 | 362 | } |
Lightvalve | 59:bc8c8270f0ab | 363 | |
Lightvalve | 59:bc8c8270f0ab | 364 | |
jobuuu | 6:df07d3491e3a | 365 | /************************************ |
jobuuu | 1:e04e563be5ce | 366 | *** Program is operating! |
jobuuu | 6:df07d3491e3a | 367 | *************************************/ |
GiJeongKim | 0:51c43836c1d7 | 368 | while(1) { |
Lightvalve | 64:a8e6799dbce3 | 369 | // if(timer_while==1000 && OPERATING_MODE==5) { |
Lightvalve | 64:a8e6799dbce3 | 370 | //if(timer_while==1000) { |
Lightvalve | 63:a2d7c63419c2 | 371 | //i2c |
Lightvalve | 64:a8e6799dbce3 | 372 | |
Lightvalve | 63:a2d7c63419c2 | 373 | read_field(i2c_slave_addr1); |
Lightvalve | 63:a2d7c63419c2 | 374 | if(DIR_VALVE_ENC < 0) value = 1023 - value; |
Lightvalve | 63:a2d7c63419c2 | 375 | // if(LED==1) { |
Lightvalve | 63:a2d7c63419c2 | 376 | // LED=0; |
Lightvalve | 63:a2d7c63419c2 | 377 | // } else |
Lightvalve | 63:a2d7c63419c2 | 378 | // LED = 1; |
Lightvalve | 63:a2d7c63419c2 | 379 | timer_while = 0; |
Lightvalve | 64:a8e6799dbce3 | 380 | //} |
Lightvalve | 64:a8e6799dbce3 | 381 | |
Lightvalve | 64:a8e6799dbce3 | 382 | timer_while ++; |
Lightvalve | 64:a8e6799dbce3 | 383 | |
Lightvalve | 64:a8e6799dbce3 | 384 | |
Lightvalve | 64:a8e6799dbce3 | 385 | if(NN_Control_Flag == 1) { |
Lightvalve | 64:a8e6799dbce3 | 386 | float output1[32] = { 0.0f }; |
Lightvalve | 64:a8e6799dbce3 | 387 | float output2[32] = { 0.0f }; |
Lightvalve | 64:a8e6799dbce3 | 388 | float output3[32] = { 0.0f }; |
Lightvalve | 64:a8e6799dbce3 | 389 | float output = 0.0f; |
Lightvalve | 63:a2d7c63419c2 | 390 | |
Lightvalve | 64:a8e6799dbce3 | 391 | |
Lightvalve | 63:a2d7c63419c2 | 392 | |
Lightvalve | 64:a8e6799dbce3 | 393 | for (int index2 = 0; index2 < 32; index2++) { |
Lightvalve | 64:a8e6799dbce3 | 394 | for (int index1 = 0; index1 < 22; index1++) { |
Lightvalve | 64:a8e6799dbce3 | 395 | output1[index2] = output1[index2] |
Lightvalve | 64:a8e6799dbce3 | 396 | + h1[index1][index2] * input[index1]; |
Lightvalve | 64:a8e6799dbce3 | 397 | } |
Lightvalve | 64:a8e6799dbce3 | 398 | output1[index2] = output1[index2] + b1[index2]; |
Lightvalve | 64:a8e6799dbce3 | 399 | if (output1[index2] < 0) { |
Lightvalve | 64:a8e6799dbce3 | 400 | output1[index2] = 0; |
Lightvalve | 64:a8e6799dbce3 | 401 | } |
Lightvalve | 64:a8e6799dbce3 | 402 | } |
Lightvalve | 63:a2d7c63419c2 | 403 | |
Lightvalve | 64:a8e6799dbce3 | 404 | for (int index2 = 0; index2 < 32; index2++) { |
Lightvalve | 64:a8e6799dbce3 | 405 | for (int index1 = 0; index1 < 32; index1++) { |
Lightvalve | 64:a8e6799dbce3 | 406 | output2[index2] = output2[index2] |
Lightvalve | 64:a8e6799dbce3 | 407 | + h2[index1][index2] * output1[index1]; |
Lightvalve | 64:a8e6799dbce3 | 408 | } |
Lightvalve | 64:a8e6799dbce3 | 409 | output2[index2] = output2[index2] + b2[index2]; |
Lightvalve | 64:a8e6799dbce3 | 410 | if (output2[index2] < 0) { |
Lightvalve | 64:a8e6799dbce3 | 411 | output2[index2] = 0; |
Lightvalve | 64:a8e6799dbce3 | 412 | } |
Lightvalve | 64:a8e6799dbce3 | 413 | } |
Lightvalve | 63:a2d7c63419c2 | 414 | |
Lightvalve | 64:a8e6799dbce3 | 415 | for (int index2 = 0; index2 < 32; index2++) { |
Lightvalve | 64:a8e6799dbce3 | 416 | for (int index1 = 0; index1 < 32; index1++) { |
Lightvalve | 64:a8e6799dbce3 | 417 | output3[index2] = output3[index2] |
Lightvalve | 64:a8e6799dbce3 | 418 | + h3[index1][index2] * output2[index1]; |
Lightvalve | 64:a8e6799dbce3 | 419 | } |
Lightvalve | 64:a8e6799dbce3 | 420 | output3[index2] = output3[index2] + b3[index2]; |
Lightvalve | 64:a8e6799dbce3 | 421 | if (output3[index2] < 0) { |
Lightvalve | 64:a8e6799dbce3 | 422 | output3[index2] = 0; |
Lightvalve | 64:a8e6799dbce3 | 423 | } |
Lightvalve | 63:a2d7c63419c2 | 424 | } |
Lightvalve | 64:a8e6799dbce3 | 425 | |
Lightvalve | 64:a8e6799dbce3 | 426 | for (int index2 = 0; index2 < 1; index2++) { |
Lightvalve | 64:a8e6799dbce3 | 427 | for (int index1 = 0; index1 < 32; index1++) { |
Lightvalve | 64:a8e6799dbce3 | 428 | output = output + hout[index2] * output3[index1]; |
Lightvalve | 64:a8e6799dbce3 | 429 | } |
Lightvalve | 64:a8e6799dbce3 | 430 | output = output + bout[index2]; |
Lightvalve | 64:a8e6799dbce3 | 431 | output = 1.0f/(1.0f+exp(-output)); |
Lightvalve | 64:a8e6799dbce3 | 432 | } |
Lightvalve | 64:a8e6799dbce3 | 433 | |
Lightvalve | 64:a8e6799dbce3 | 434 | output = output * 24000.0f - 12000.0f; |
Lightvalve | 64:a8e6799dbce3 | 435 | if(output>=0) { |
Lightvalve | 64:a8e6799dbce3 | 436 | valve_pos.ref = output*0.0001f*((double)VALVE_MAX_POS - (double) VALVE_CENTER) + (double) VALVE_CENTER; |
Lightvalve | 64:a8e6799dbce3 | 437 | } else { |
Lightvalve | 64:a8e6799dbce3 | 438 | valve_pos.ref = -output*0.0001f*((double)VALVE_MIN_POS - (double) VALVE_CENTER) + (double) VALVE_CENTER; |
Lightvalve | 63:a2d7c63419c2 | 439 | } |
Lightvalve | 63:a2d7c63419c2 | 440 | } |
Lightvalve | 60:b5452adfb2cd | 441 | |
Lightvalve | 63:a2d7c63419c2 | 442 | |
Lightvalve | 63:a2d7c63419c2 | 443 | if(LED==1) { |
Lightvalve | 63:a2d7c63419c2 | 444 | LED=0; |
Lightvalve | 63:a2d7c63419c2 | 445 | } else |
Lightvalve | 63:a2d7c63419c2 | 446 | LED = 1; |
Lightvalve | 64:a8e6799dbce3 | 447 | |
GiJeongKim | 0:51c43836c1d7 | 448 | } |
jobuuu | 1:e04e563be5ce | 449 | } |
jobuuu | 1:e04e563be5ce | 450 | |
Lightvalve | 33:91b17819ec30 | 451 | float DDV_JOINT_POS_FF(float REF_JOINT_VEL) |
Lightvalve | 14:8e7590227d22 | 452 | { |
Lightvalve | 14:8e7590227d22 | 453 | |
Lightvalve | 13:747daba9cf59 | 454 | int i = 0; |
Lightvalve | 47:889798ff9329 | 455 | float Ref_Valve_Pos_FF = 0.0f; |
Lightvalve | 14:8e7590227d22 | 456 | for(i=0; i<VALVE_POS_NUM; i++) { |
Lightvalve | 14:8e7590227d22 | 457 | 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 | 458 | if(i==0) { |
Lightvalve | 49:3c630b5eba9f | 459 | if(JOINT_VEL[i+1] == JOINT_VEL[i]) { |
Lightvalve | 55:f4819de54e7a | 460 | Ref_Valve_Pos_FF = (float) VALVE_CENTER; |
Lightvalve | 49:3c630b5eba9f | 461 | } else { |
Lightvalve | 55:f4819de54e7a | 462 | 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 | 463 | } |
Lightvalve | 14:8e7590227d22 | 464 | } else { |
Lightvalve | 49:3c630b5eba9f | 465 | if(JOINT_VEL[i+1] == JOINT_VEL[i-1]) { |
Lightvalve | 55:f4819de54e7a | 466 | Ref_Valve_Pos_FF = (float) VALVE_CENTER; |
Lightvalve | 49:3c630b5eba9f | 467 | } else { |
Lightvalve | 55:f4819de54e7a | 468 | 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 | 469 | } |
Lightvalve | 13:747daba9cf59 | 470 | } |
Lightvalve | 13:747daba9cf59 | 471 | break; |
Lightvalve | 13:747daba9cf59 | 472 | } |
Lightvalve | 13:747daba9cf59 | 473 | } |
Lightvalve | 14:8e7590227d22 | 474 | if(REF_JOINT_VEL > max(JOINT_VEL[VALVE_POS_NUM-1], JOINT_VEL[VALVE_POS_NUM-2])) { |
Lightvalve | 33:91b17819ec30 | 475 | Ref_Valve_Pos_FF = (float) VALVE_MAX_POS; |
Lightvalve | 14:8e7590227d22 | 476 | } else if(REF_JOINT_VEL < min(JOINT_VEL[VALVE_POS_NUM-1], JOINT_VEL[VALVE_POS_NUM-2])) { |
Lightvalve | 33:91b17819ec30 | 477 | Ref_Valve_Pos_FF = (float) VALVE_MIN_POS; |
Lightvalve | 13:747daba9cf59 | 478 | } |
Lightvalve | 36:a46e63505ed8 | 479 | |
Lightvalve | 55:f4819de54e7a | 480 | Ref_Valve_Pos_FF = (float) VELOCITY_COMP_GAIN * 0.01f * (float) (Ref_Valve_Pos_FF - (float) VALVE_CENTER); |
Lightvalve | 13:747daba9cf59 | 481 | return Ref_Valve_Pos_FF; |
Lightvalve | 49:3c630b5eba9f | 482 | |
Lightvalve | 13:747daba9cf59 | 483 | } |
jobuuu | 6:df07d3491e3a | 484 | |
jobuuu | 6:df07d3491e3a | 485 | |
Lightvalve | 30:8d561f16383b | 486 | void VALVE_POS_CONTROL(float REF_VALVE_POS) |
Lightvalve | 14:8e7590227d22 | 487 | { |
Lightvalve | 13:747daba9cf59 | 488 | int i = 0; |
Lightvalve | 13:747daba9cf59 | 489 | |
Lightvalve | 38:118df027d851 | 490 | if(REF_VALVE_POS > VALVE_MAX_POS) { |
Lightvalve | 38:118df027d851 | 491 | REF_VALVE_POS = VALVE_MAX_POS; |
Lightvalve | 38:118df027d851 | 492 | } else if(REF_VALVE_POS < VALVE_MIN_POS) { |
Lightvalve | 38:118df027d851 | 493 | REF_VALVE_POS = VALVE_MIN_POS; |
Lightvalve | 38:118df027d851 | 494 | } |
Lightvalve | 38:118df027d851 | 495 | |
Lightvalve | 13:747daba9cf59 | 496 | valve_pos_err = REF_VALVE_POS - value; |
Lightvalve | 13:747daba9cf59 | 497 | valve_pos_err_diff = valve_pos_err - valve_pos_err_old; |
Lightvalve | 13:747daba9cf59 | 498 | valve_pos_err_old = valve_pos_err; |
Lightvalve | 13:747daba9cf59 | 499 | valve_pos_err_sum += valve_pos_err; |
Lightvalve | 13:747daba9cf59 | 500 | if (valve_pos_err_sum > 1000) valve_pos_err_sum = 1000; |
Lightvalve | 13:747daba9cf59 | 501 | if (valve_pos_err_sum<-1000) valve_pos_err_sum = -1000; |
Lightvalve | 13:747daba9cf59 | 502 | |
Lightvalve | 13:747daba9cf59 | 503 | 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 | 504 | |
Lightvalve | 18:b8adf1582ea3 | 505 | for(i=0; i<24; i++) { |
Lightvalve | 14:8e7590227d22 | 506 | 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 | 507 | if(i==0) { |
Lightvalve | 47:889798ff9329 | 508 | 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 | 509 | } else { |
Lightvalve | 47:889798ff9329 | 510 | 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 | 511 | } |
Lightvalve | 13:747daba9cf59 | 512 | break; |
Lightvalve | 13:747daba9cf59 | 513 | } |
Lightvalve | 13:747daba9cf59 | 514 | } |
Lightvalve | 57:f308b1656d9c | 515 | Vout.ref = VALVE_PWM_RAW_FF + VALVE_PWM_RAW_FB; |
Lightvalve | 13:747daba9cf59 | 516 | } |
Lightvalve | 13:747daba9cf59 | 517 | |
Lightvalve | 14:8e7590227d22 | 518 | #define LT_MAX_IDX 57 |
Lightvalve | 30:8d561f16383b | 519 | 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 | 520 | -19.0f, -18.0f, -17.0f, -16.0f, -15.0f, -14.0f, -13.0f, -12.0f, -11.0f, -10.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 521 | -9.0f, -8.0f, -7.0f, -6.0f, -5.0f, -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 522 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 523 | 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 524 | 25.0f, 30.0f, 35.0f, 40.0f, 50.0f, 60.0f, 80.0f, 100.0f |
Lightvalve | 34:bb2ca2fc2a8e | 525 | }; // duty |
Lightvalve | 30:8d561f16383b | 526 | float LT_Voltage_Output[LT_MAX_IDX] = {-321.4f, -291.3f, -261.5f, -246.8f, -231.7f, -223.9f, -216.1f, -207.9f, -198.8f, |
Lightvalve | 34:bb2ca2fc2a8e | 527 | -196.9f, -195.0f, -192.5f, -188.8f, -184.5f, -180.2f, -175.9f, -171.5f, -166.3f, -161.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 528 | -156.0f, -149.5f, -139.0f, -126.0f, -107.0f, -87.5f, -64.0f, -38.5f, -9.4f, 0.0f, |
Lightvalve | 34:bb2ca2fc2a8e | 529 | 12.0f, 43.5f, 69.0f, 94.0f, 114.0f, 132.0f, 146.0f, 155.5f, 162.3f, 168.2f, |
Lightvalve | 34:bb2ca2fc2a8e | 530 | 173.1f, 178.2f, 182.8f, 187.4f, 191.8f, 196.0f, 199.7f, 201.9f, 203.8f, 205.6f, |
Lightvalve | 34:bb2ca2fc2a8e | 531 | 214.6f, 222.5f, 230.4f, 238.2f, 253.3f, 268.0f, 297.6f, 327.7f |
Lightvalve | 34:bb2ca2fc2a8e | 532 | }; // mV |
Lightvalve | 13:747daba9cf59 | 533 | |
Lightvalve | 30:8d561f16383b | 534 | float PWM_duty_byLT(float Ref_V) |
Lightvalve | 14:8e7590227d22 | 535 | { |
Lightvalve | 30:8d561f16383b | 536 | float PWM_duty = 0.0f; |
Lightvalve | 13:747daba9cf59 | 537 | if(Ref_V<LT_Voltage_Output[0]) { |
Lightvalve | 30:8d561f16383b | 538 | PWM_duty = (Ref_V-LT_Voltage_Output[0])/1.5f+LT_PWM_duty[0]; |
Lightvalve | 13:747daba9cf59 | 539 | } else if (Ref_V>=LT_Voltage_Output[LT_MAX_IDX-1]) { |
Lightvalve | 30:8d561f16383b | 540 | PWM_duty = (Ref_V-LT_Voltage_Output[LT_MAX_IDX-1])/1.5f+LT_PWM_duty[LT_MAX_IDX-1]; |
Lightvalve | 13:747daba9cf59 | 541 | } else { |
Lightvalve | 13:747daba9cf59 | 542 | int idx = 0; |
Lightvalve | 13:747daba9cf59 | 543 | for(idx=0; idx<LT_MAX_IDX-1; idx++) { |
Lightvalve | 30:8d561f16383b | 544 | float ini_x = LT_Voltage_Output[idx]; |
Lightvalve | 30:8d561f16383b | 545 | float fin_x = LT_Voltage_Output[idx+1]; |
Lightvalve | 30:8d561f16383b | 546 | float ini_y = LT_PWM_duty[idx]; |
Lightvalve | 30:8d561f16383b | 547 | float fin_y = LT_PWM_duty[idx+1]; |
Lightvalve | 13:747daba9cf59 | 548 | if(Ref_V>=ini_x && Ref_V<fin_x) { |
Lightvalve | 13:747daba9cf59 | 549 | PWM_duty = (fin_y-ini_y)/(fin_x-ini_x)*(Ref_V-ini_x) + ini_y; |
Lightvalve | 13:747daba9cf59 | 550 | break; |
Lightvalve | 13:747daba9cf59 | 551 | } |
Lightvalve | 13:747daba9cf59 | 552 | } |
Lightvalve | 13:747daba9cf59 | 553 | } |
Lightvalve | 14:8e7590227d22 | 554 | |
Lightvalve | 13:747daba9cf59 | 555 | return PWM_duty; |
Lightvalve | 13:747daba9cf59 | 556 | } |
jobuuu | 6:df07d3491e3a | 557 | |
Lightvalve | 55:f4819de54e7a | 558 | |
Lightvalve | 55:f4819de54e7a | 559 | |
Lightvalve | 55:f4819de54e7a | 560 | |
Lightvalve | 55:f4819de54e7a | 561 | |
jobuuu | 2:a1c0a37df760 | 562 | /******************************************************************************* |
jobuuu | 2:a1c0a37df760 | 563 | TIMER INTERRUPT |
jobuuu | 2:a1c0a37df760 | 564 | *******************************************************************************/ |
jobuuu | 2:a1c0a37df760 | 565 | |
Lightvalve | 50:b46bed7fec80 | 566 | float FREQ_TMR4 = (float)FREQ_20k; |
Lightvalve | 50:b46bed7fec80 | 567 | float DT_TMR4 = (float)DT_20k; |
Lightvalve | 55:f4819de54e7a | 568 | long CNT_TMR4 = 0; |
Lightvalve | 55:f4819de54e7a | 569 | int TMR4_FREQ_10k = (int)FREQ_10k; |
jobuuu | 1:e04e563be5ce | 570 | extern "C" void TIM4_IRQHandler(void) |
jobuuu | 1:e04e563be5ce | 571 | { |
Lightvalve | 19:23b7c1ad8683 | 572 | if (TIM4->SR & TIM_SR_UIF ) { |
Lightvalve | 21:e5f1a43ea6f9 | 573 | |
Lightvalve | 21:e5f1a43ea6f9 | 574 | /******************************************************* |
Lightvalve | 21:e5f1a43ea6f9 | 575 | *** Sensor Read & Data Handling |
Lightvalve | 21:e5f1a43ea6f9 | 576 | ********************************************************/ |
Lightvalve | 13:747daba9cf59 | 577 | |
Lightvalve | 55:f4819de54e7a | 578 | //Encoder |
Lightvalve | 55:f4819de54e7a | 579 | if (CNT_TMR4 % (int) ((int) FREQ_TMR4/TMR4_FREQ_10k) == 0) { |
Lightvalve | 55:f4819de54e7a | 580 | ENC_UPDATE(); |
Lightvalve | 55:f4819de54e7a | 581 | } |
Lightvalve | 60:b5452adfb2cd | 582 | |
Lightvalve | 61:3c6869477483 | 583 | // for(int i=0; i<10; i++){ |
Lightvalve | 61:3c6869477483 | 584 | // position_array[i] = position_array[i+1]; |
Lightvalve | 61:3c6869477483 | 585 | // } |
Lightvalve | 61:3c6869477483 | 586 | // position_array[10] = (pos.ref/(float)(ENC_PULSE_PER_POSITION)+10.0f)/90.0f; |
Lightvalve | 61:3c6869477483 | 587 | // |
Lightvalve | 61:3c6869477483 | 588 | // for(int i=0; i<5; i++){ |
Lightvalve | 61:3c6869477483 | 589 | // input_array[i] = position_array[2*i+2] - (pos.ref/(float)(ENC_PULSE_PER_POSITION)+10.0f)/90.0f; |
Lightvalve | 61:3c6869477483 | 590 | // } |
Lightvalve | 59:bc8c8270f0ab | 591 | |
Lightvalve | 59:bc8c8270f0ab | 592 | ADC1->CR2 |= 0x40000000; |
Lightvalve | 56:2eade98630e2 | 593 | if (SENSING_MODE == 0) { |
Lightvalve | 56:2eade98630e2 | 594 | // Torque Sensing (0~210)bar ============================================= |
Lightvalve | 56:2eade98630e2 | 595 | float pres_A_new = (((float) ADC1->DR) - 2047.5f); |
Lightvalve | 56:2eade98630e2 | 596 | double alpha_update_ft = 1.0f / (1.0f + FREQ_TMR4 / (2.0f * 3.14f * 100.0f)); // f_cutoff : 200Hz |
Lightvalve | 56:2eade98630e2 | 597 | pres_A.sen = (1.0f - alpha_update_ft) * pres_A.sen + alpha_update_ft * pres_A_new; |
Lightvalve | 56:2eade98630e2 | 598 | torq.sen = pres_A.sen / TORQUE_SENSOR_PULSE_PER_TORQUE; |
Lightvalve | 17:1865016ca2e7 | 599 | |
Lightvalve | 56:2eade98630e2 | 600 | } else if (SENSING_MODE == 1) { |
Lightvalve | 56:2eade98630e2 | 601 | // Pressure Sensing (0~210)bar ============================================= |
Lightvalve | 56:2eade98630e2 | 602 | float pres_A_new = (((float)ADC1->DR) - PRES_A_NULL); |
Lightvalve | 56:2eade98630e2 | 603 | float pres_B_new = (((float)ADC2->DR) - PRES_B_NULL); |
Lightvalve | 56:2eade98630e2 | 604 | double alpha_update_pres = 1.0f / (1.0f + FREQ_TMR4 / (2.0f * 3.14f * 200.0f)); // f_cutoff : 500Hz |
Lightvalve | 56:2eade98630e2 | 605 | pres_A.sen = (1.0f - alpha_update_pres) * pres_A.sen + alpha_update_pres * pres_A_new; |
Lightvalve | 56:2eade98630e2 | 606 | pres_B.sen = (1.0f - alpha_update_pres) * pres_B.sen + alpha_update_pres * pres_B_new; |
Lightvalve | 56:2eade98630e2 | 607 | CUR_PRES_A_BAR = pres_A.sen / PRES_SENSOR_A_PULSE_PER_BAR; |
Lightvalve | 56:2eade98630e2 | 608 | CUR_PRES_B_BAR = pres_B.sen / PRES_SENSOR_B_PULSE_PER_BAR; |
Lightvalve | 49:3c630b5eba9f | 609 | |
Lightvalve | 56:2eade98630e2 | 610 | if ((OPERATING_MODE & 0x01) == 0) { // Rotary Actuator |
Lightvalve | 56:2eade98630e2 | 611 | torq.sen = (PISTON_AREA_A * CUR_PRES_A_BAR - PISTON_AREA_B * CUR_PRES_B_BAR) * 0.0001f; // mm^3*bar >> Nm |
Lightvalve | 56:2eade98630e2 | 612 | } else if ((OPERATING_MODE & 0x01) == 1) { // Linear Actuator |
Lightvalve | 56:2eade98630e2 | 613 | torq.sen = (PISTON_AREA_A * CUR_PRES_A_BAR - PISTON_AREA_B * CUR_PRES_B_BAR) * 0.1f; // mm^2*bar >> N |
Lightvalve | 56:2eade98630e2 | 614 | } |
Lightvalve | 56:2eade98630e2 | 615 | } |
Lightvalve | 59:bc8c8270f0ab | 616 | |
Lightvalve | 56:2eade98630e2 | 617 | // //Pressure sensor A |
Lightvalve | 56:2eade98630e2 | 618 | // ADC1->CR2 |= 0x40000000; // adc _ 12bit |
Lightvalve | 56:2eade98630e2 | 619 | // //while((ADC1->SR & 0b10)); |
Lightvalve | 56:2eade98630e2 | 620 | // float alpha_update_pres_A = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f)); |
Lightvalve | 56:2eade98630e2 | 621 | // float pres_A_new = ((float)ADC1->DR); |
Lightvalve | 56:2eade98630e2 | 622 | // pres_A.sen = pres_A.sen*(1.0f-alpha_update_pres_A)+pres_A_new*(alpha_update_pres_A); |
Lightvalve | 56:2eade98630e2 | 623 | // 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 | 56:2eade98630e2 | 624 | // |
Lightvalve | 56:2eade98630e2 | 625 | // |
Lightvalve | 56:2eade98630e2 | 626 | // //Pressure sensor B |
Lightvalve | 56:2eade98630e2 | 627 | // float alpha_update_pres_B = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*100.0f)); |
Lightvalve | 56:2eade98630e2 | 628 | // float pres_B_new = ((float)ADC2->DR); |
Lightvalve | 56:2eade98630e2 | 629 | // pres_B.sen = pres_B.sen*(1.0f-alpha_update_pres_B)+pres_B_new*(alpha_update_pres_B); |
Lightvalve | 56:2eade98630e2 | 630 | // //torq.sen = pres_A.sen * (float) PISTON_AREA_A - pres_B.sen * (float) PISTON_AREA_B; |
Lightvalve | 17:1865016ca2e7 | 631 | |
Lightvalve | 17:1865016ca2e7 | 632 | |
Lightvalve | 21:e5f1a43ea6f9 | 633 | //Current |
Lightvalve | 21:e5f1a43ea6f9 | 634 | //ADC3->CR2 |= 0x40000000; // adc _ 12bit |
Lightvalve | 25:3e6b574cab5c | 635 | //int raw_cur = ADC3->DR; |
Lightvalve | 21:e5f1a43ea6f9 | 636 | //while((ADC3->SR & 0b10)); |
Lightvalve | 50:b46bed7fec80 | 637 | float alpha_update_cur = 1.0f/(1.0f + FREQ_TMR4/(2.0f*3.14f*500.0f)); // f_cutoff : 500Hz |
Lightvalve | 30:8d561f16383b | 638 | float cur_new = ((float)ADC3->DR-2048.0f)*20.0f/4096.0f; // unit : mA |
Lightvalve | 30:8d561f16383b | 639 | cur.sen=cur.sen*(1.0f-alpha_update_cur)+cur_new*(alpha_update_cur); |
Lightvalve | 25:3e6b574cab5c | 640 | //cur.sen = raw_cur; |
Lightvalve | 56:2eade98630e2 | 641 | |
Lightvalve | 55:f4819de54e7a | 642 | CNT_TMR4++; |
Lightvalve | 21:e5f1a43ea6f9 | 643 | } |
Lightvalve | 11:82d8768d7351 | 644 | TIM4->SR = 0x0; // reset the status register |
Lightvalve | 11:82d8768d7351 | 645 | } |
Lightvalve | 19:23b7c1ad8683 | 646 | |
Lightvalve | 19:23b7c1ad8683 | 647 | |
Lightvalve | 18:b8adf1582ea3 | 648 | int j =0; |
Lightvalve | 52:647072f5307a | 649 | float FREQ_TMR3 = (float)FREQ_5k; |
Lightvalve | 47:889798ff9329 | 650 | float DT_TMR3 = (float)DT_5k; |
Lightvalve | 44:35fa6884d0c6 | 651 | int cnt_trans = 0; |
Lightvalve | 47:889798ff9329 | 652 | double VALVE_POS_RAW_FORCE_FB_LOGGING = 0.0f; |
Lightvalve | 55:f4819de54e7a | 653 | int can_rest =0; |
Lightvalve | 47:889798ff9329 | 654 | |
Lightvalve | 11:82d8768d7351 | 655 | extern "C" void TIM3_IRQHandler(void) |
Lightvalve | 21:e5f1a43ea6f9 | 656 | { |
Lightvalve | 19:23b7c1ad8683 | 657 | if (TIM3->SR & TIM_SR_UIF ) { |
Lightvalve | 55:f4819de54e7a | 658 | |
Lightvalve | 55:f4819de54e7a | 659 | if (((OPERATING_MODE&0b110)>>1) == 0) { |
Lightvalve | 55:f4819de54e7a | 660 | K_v = 0.4f; // Moog (LPM >> mA) , 100bar |
Lightvalve | 55:f4819de54e7a | 661 | mV_PER_mA = 500.0f; // 5000mV/10mA |
Lightvalve | 55:f4819de54e7a | 662 | mV_PER_pulse = 0.5f; // 5000mV/10000pulse |
Lightvalve | 55:f4819de54e7a | 663 | mA_PER_pulse = 0.001f; // 10mA/10000pulse |
Lightvalve | 55:f4819de54e7a | 664 | } else if (((OPERATING_MODE&0b110)>>1) == 1) { |
Lightvalve | 55:f4819de54e7a | 665 | K_v = 0.5f; // KNR (LPM >> mA) , 100bar |
Lightvalve | 55:f4819de54e7a | 666 | mV_PER_mA = 166.6666f; // 5000mV/30mA |
Lightvalve | 55:f4819de54e7a | 667 | mV_PER_pulse = 0.5f; // 5000mV/10000pulse |
Lightvalve | 55:f4819de54e7a | 668 | mA_PER_pulse = 0.003f; // 30mA/10000pulse |
Lightvalve | 55:f4819de54e7a | 669 | } |
Lightvalve | 49:3c630b5eba9f | 670 | |
Lightvalve | 49:3c630b5eba9f | 671 | if(MODE_POS_FT_TRANS == 1) { |
Lightvalve | 47:889798ff9329 | 672 | alpha_trans = (float)(1.0f - cos(3.141592f * (float)cnt_trans * DT_TMR3 /3.0f))/2.0f; |
Lightvalve | 44:35fa6884d0c6 | 673 | cnt_trans++; |
Lightvalve | 45:2694daea349b | 674 | torq.err_sum = 0; |
Lightvalve | 47:889798ff9329 | 675 | if((float)cnt_trans * DT_TMR3 > 3.0f) |
Lightvalve | 44:35fa6884d0c6 | 676 | MODE_POS_FT_TRANS = 2; |
Lightvalve | 49:3c630b5eba9f | 677 | } else if(MODE_POS_FT_TRANS == 3) { |
Lightvalve | 47:889798ff9329 | 678 | alpha_trans = (float)(1.0f + cos(3.141592f * (float)cnt_trans * DT_TMR3 /3.0f))/2.0f; |
Lightvalve | 44:35fa6884d0c6 | 679 | cnt_trans++; |
Lightvalve | 45:2694daea349b | 680 | torq.err_sum = 0; |
Lightvalve | 47:889798ff9329 | 681 | if((float) cnt_trans * DT_TMR3 > 3.0f ) |
Lightvalve | 44:35fa6884d0c6 | 682 | MODE_POS_FT_TRANS = 0; |
Lightvalve | 49:3c630b5eba9f | 683 | } else if(MODE_POS_FT_TRANS == 2) { |
Lightvalve | 56:2eade98630e2 | 684 | alpha_trans = 1.0f; |
Lightvalve | 44:35fa6884d0c6 | 685 | cnt_trans = 0; |
Lightvalve | 49:3c630b5eba9f | 686 | } else { |
Lightvalve | 56:2eade98630e2 | 687 | alpha_trans = 0.0f; |
Lightvalve | 44:35fa6884d0c6 | 688 | cnt_trans = 0; |
Lightvalve | 44:35fa6884d0c6 | 689 | } |
Lightvalve | 44:35fa6884d0c6 | 690 | |
Lightvalve | 49:3c630b5eba9f | 691 | |
Lightvalve | 55:f4819de54e7a | 692 | int UTILITY_MODE = 0; |
Lightvalve | 55:f4819de54e7a | 693 | int CONTROL_MODE = 0; |
Lightvalve | 56:2eade98630e2 | 694 | |
Lightvalve | 55:f4819de54e7a | 695 | if (CONTROL_UTILITY_MODE >= 20 || CONTROL_UTILITY_MODE == 0) { |
Lightvalve | 55:f4819de54e7a | 696 | UTILITY_MODE = CONTROL_UTILITY_MODE; |
Lightvalve | 55:f4819de54e7a | 697 | CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 55:f4819de54e7a | 698 | } else { |
Lightvalve | 55:f4819de54e7a | 699 | CONTROL_MODE = CONTROL_UTILITY_MODE; |
Lightvalve | 55:f4819de54e7a | 700 | UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 55:f4819de54e7a | 701 | } |
Lightvalve | 54:6f50d9d3bfee | 702 | |
Lightvalve | 54:6f50d9d3bfee | 703 | |
Lightvalve | 54:6f50d9d3bfee | 704 | |
Lightvalve | 55:f4819de54e7a | 705 | // UTILITY MODE ------------------------------------------------------------ |
Lightvalve | 54:6f50d9d3bfee | 706 | |
Lightvalve | 55:f4819de54e7a | 707 | switch (UTILITY_MODE) { |
Lightvalve | 55:f4819de54e7a | 708 | case MODE_NO_ACT: { |
Lightvalve | 13:747daba9cf59 | 709 | break; |
Lightvalve | 13:747daba9cf59 | 710 | } |
Lightvalve | 14:8e7590227d22 | 711 | |
Lightvalve | 14:8e7590227d22 | 712 | case MODE_TORQUE_SENSOR_NULLING: { |
Lightvalve | 13:747daba9cf59 | 713 | // DAC Voltage reference set |
Lightvalve | 14:8e7590227d22 | 714 | if (TMR3_COUNT_TORQUE_NULL < TMR_FREQ_5k * 2) { |
Lightvalve | 15:bd0d12728506 | 715 | CUR_TORQUE_sum += torq.sen; |
Lightvalve | 19:23b7c1ad8683 | 716 | |
Lightvalve | 14:8e7590227d22 | 717 | if (TMR3_COUNT_TORQUE_NULL % 10 == 0) { |
Lightvalve | 30:8d561f16383b | 718 | CUR_TORQUE_mean = CUR_TORQUE_sum / 10.0f; |
Lightvalve | 13:747daba9cf59 | 719 | CUR_TORQUE_sum = 0; |
Lightvalve | 14:8e7590227d22 | 720 | |
Lightvalve | 57:f308b1656d9c | 721 | TORQUE_VREF += 0.0003f * (0.0f - CUR_TORQUE_mean); |
Lightvalve | 19:23b7c1ad8683 | 722 | |
Lightvalve | 30:8d561f16383b | 723 | if (TORQUE_VREF > 3.3f) TORQUE_VREF = 3.3f; |
Lightvalve | 57:f308b1656d9c | 724 | if (TORQUE_VREF < 0.0f) TORQUE_VREF = 0.0f; |
Lightvalve | 49:3c630b5eba9f | 725 | |
Lightvalve | 16:903b5a4433b4 | 726 | //spi_eeprom_write(RID_TORQUE_SENSOR_VREF, (int16_t) (TORQUE_VREF * 1000.0)); |
Lightvalve | 30:8d561f16383b | 727 | dac_1 = TORQUE_VREF / 3.3f; |
Lightvalve | 13:747daba9cf59 | 728 | } |
Lightvalve | 13:747daba9cf59 | 729 | } else { |
Lightvalve | 56:2eade98630e2 | 730 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 14:8e7590227d22 | 731 | TMR3_COUNT_TORQUE_NULL = 0; |
Lightvalve | 13:747daba9cf59 | 732 | CUR_TORQUE_sum = 0; |
Lightvalve | 13:747daba9cf59 | 733 | CUR_TORQUE_mean = 0; |
Lightvalve | 19:23b7c1ad8683 | 734 | |
Lightvalve | 16:903b5a4433b4 | 735 | ROM_RESET_DATA(); |
Lightvalve | 19:23b7c1ad8683 | 736 | |
Lightvalve | 30:8d561f16383b | 737 | dac_1 = TORQUE_VREF / 3.3f; |
Lightvalve | 14:8e7590227d22 | 738 | |
Lightvalve | 13:747daba9cf59 | 739 | } |
Lightvalve | 14:8e7590227d22 | 740 | TMR3_COUNT_TORQUE_NULL++; |
Lightvalve | 13:747daba9cf59 | 741 | break; |
Lightvalve | 19:23b7c1ad8683 | 742 | } |
Lightvalve | 14:8e7590227d22 | 743 | |
Lightvalve | 49:3c630b5eba9f | 744 | // case MODE_VALVE_NULLING_AND_DEADZONE_SETTING: { |
Lightvalve | 49:3c630b5eba9f | 745 | // if (TMR3_COUNT_DEADZONE == 0) { |
Lightvalve | 49:3c630b5eba9f | 746 | // if (pos_plus_end == pos_minus_end) need_enc_init = true; |
Lightvalve | 49:3c630b5eba9f | 747 | // else temp_time = 0; |
Lightvalve | 49:3c630b5eba9f | 748 | // } |
Lightvalve | 49:3c630b5eba9f | 749 | // if (need_enc_init) { |
Lightvalve | 49:3c630b5eba9f | 750 | // if (TMR3_COUNT_DEADZONE < (int) (0.5f * (float) TMR_FREQ_5k)) { |
Lightvalve | 49:3c630b5eba9f | 751 | // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 49:3c630b5eba9f | 752 | // pos_plus_end = pos.sen; |
Lightvalve | 49:3c630b5eba9f | 753 | // } else if (TMR3_COUNT_DEADZONE < TMR_FREQ_5k) { |
Lightvalve | 49:3c630b5eba9f | 754 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 49:3c630b5eba9f | 755 | // pos_minus_end = pos.sen; |
Lightvalve | 49:3c630b5eba9f | 756 | // } else if (TMR3_COUNT_DEADZONE == TMR_FREQ_5k) need_enc_init = false; |
Lightvalve | 49:3c630b5eba9f | 757 | // temp_time = TMR_FREQ_5k; |
Lightvalve | 49:3c630b5eba9f | 758 | // } |
Lightvalve | 49:3c630b5eba9f | 759 | // |
Lightvalve | 49:3c630b5eba9f | 760 | // if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + TMR_FREQ_5k)) { |
Lightvalve | 49:3c630b5eba9f | 761 | // V_out = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen); |
Lightvalve | 49:3c630b5eba9f | 762 | // VALVE_CENTER = VALVE_DEADZONE_PLUS = VALVE_DEADZONE_MINUS = 0; |
Lightvalve | 49:3c630b5eba9f | 763 | // |
Lightvalve | 49:3c630b5eba9f | 764 | // } else if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + (int) (1.9f * (float) TMR_FREQ_5k))) { |
Lightvalve | 49:3c630b5eba9f | 765 | // V_out = 0; |
Lightvalve | 49:3c630b5eba9f | 766 | // CUR_VELOCITY_sum += CUR_VELOCITY; |
Lightvalve | 49:3c630b5eba9f | 767 | // } else if (TMR3_COUNT_DEADZONE == (temp_time + 2 * TMR_FREQ_5k)) { |
Lightvalve | 49:3c630b5eba9f | 768 | // if (CUR_VELOCITY_sum == 0) DZ_dir = 1; |
Lightvalve | 49:3c630b5eba9f | 769 | // else if (CUR_VELOCITY_sum > 0) DZ_dir = 1; |
Lightvalve | 49:3c630b5eba9f | 770 | // else if (CUR_VELOCITY_sum < 0) DZ_dir = -1; |
Lightvalve | 49:3c630b5eba9f | 771 | // else DZ_temp_cnt2 = DZ_end; |
Lightvalve | 49:3c630b5eba9f | 772 | // CUR_VELOCITY_sum = 0; |
Lightvalve | 49:3c630b5eba9f | 773 | // } else if (TMR3_COUNT_DEADZONE > (temp_time + 2 * TMR_FREQ_5k)) { |
Lightvalve | 49:3c630b5eba9f | 774 | // if (TMR3_COUNT_DEADZONE > (temp_time + 10 * TMR_FREQ_5k)) DZ_temp_cnt2 = DZ_end; |
Lightvalve | 49:3c630b5eba9f | 775 | // |
Lightvalve | 49:3c630b5eba9f | 776 | // // Position of Dead Zone |
Lightvalve | 49:3c630b5eba9f | 777 | // // (CUR_VELOCITY < 0) (CUR_VELOCITY == 0) (CUR_VELOCITY > 0) |
Lightvalve | 49:3c630b5eba9f | 778 | // // | / | / |/ |
Lightvalve | 49:3c630b5eba9f | 779 | // // | ______/ ___|___/ ______/| |
Lightvalve | 49:3c630b5eba9f | 780 | // // |/ / | / | |
Lightvalve | 49:3c630b5eba9f | 781 | // // /| / | / | |
Lightvalve | 49:3c630b5eba9f | 782 | // // 0V 0V 0V |
Lightvalve | 49:3c630b5eba9f | 783 | // |
Lightvalve | 49:3c630b5eba9f | 784 | // if (DZ_temp_cnt2 < DZ_end) { |
Lightvalve | 49:3c630b5eba9f | 785 | // if (TMR3_COUNT_DEADZONE % 20 != 0) { |
Lightvalve | 49:3c630b5eba9f | 786 | // CUR_VELOCITY_sum += CUR_VELOCITY; |
Lightvalve | 49:3c630b5eba9f | 787 | // } else { |
Lightvalve | 49:3c630b5eba9f | 788 | // V_out -= DZ_dir; |
Lightvalve | 49:3c630b5eba9f | 789 | // if (CUR_VELOCITY_sum * DZ_dir < 0) DZ_temp_cnt++; |
Lightvalve | 49:3c630b5eba9f | 790 | // CUR_VELOCITY_sum = 0; |
Lightvalve | 49:3c630b5eba9f | 791 | // } |
Lightvalve | 49:3c630b5eba9f | 792 | // if (DZ_temp_cnt == 5) { |
Lightvalve | 49:3c630b5eba9f | 793 | // if (DZ_dir >= 0) VALVE_DEADZONE_MINUS = (int16_t) V_out; |
Lightvalve | 49:3c630b5eba9f | 794 | // else VALVE_DEADZONE_PLUS = (int16_t) V_out; |
Lightvalve | 49:3c630b5eba9f | 795 | // DZ_dir = -DZ_dir; |
Lightvalve | 49:3c630b5eba9f | 796 | // DZ_temp_cnt = 0; |
Lightvalve | 49:3c630b5eba9f | 797 | // DZ_temp_cnt2++; |
Lightvalve | 49:3c630b5eba9f | 798 | // } |
Lightvalve | 49:3c630b5eba9f | 799 | // } else { |
Lightvalve | 49:3c630b5eba9f | 800 | // TMR3_COUNT_DEADZONE = -1; |
Lightvalve | 49:3c630b5eba9f | 801 | // VALVE_CENTER = VALVE_DEADZONE_PLUS / 2 + VALVE_DEADZONE_MINUS / 2; |
Lightvalve | 49:3c630b5eba9f | 802 | // if (VALVE_DEADZONE_PLUS < VALVE_DEADZONE_MINUS) { |
Lightvalve | 49:3c630b5eba9f | 803 | // VALVE_DEADZONE_PLUS = VALVE_CENTER; |
Lightvalve | 49:3c630b5eba9f | 804 | // VALVE_DEADZONE_MINUS = VALVE_CENTER; |
Lightvalve | 49:3c630b5eba9f | 805 | // } |
Lightvalve | 49:3c630b5eba9f | 806 | // V_out = 0; |
Lightvalve | 49:3c630b5eba9f | 807 | // |
Lightvalve | 49:3c630b5eba9f | 808 | // ROM_RESET_DATA(); |
Lightvalve | 49:3c630b5eba9f | 809 | // |
Lightvalve | 49:3c630b5eba9f | 810 | // //spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, VALVE_DEADZONE_PLUS); |
Lightvalve | 49:3c630b5eba9f | 811 | // //spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, VALVE_DEADZONE_MINUS); |
Lightvalve | 49:3c630b5eba9f | 812 | // |
Lightvalve | 49:3c630b5eba9f | 813 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 49:3c630b5eba9f | 814 | // DZ_temp_cnt2 = 0; |
Lightvalve | 49:3c630b5eba9f | 815 | // } |
Lightvalve | 49:3c630b5eba9f | 816 | // } |
Lightvalve | 49:3c630b5eba9f | 817 | // TMR3_COUNT_DEADZONE++; |
Lightvalve | 49:3c630b5eba9f | 818 | // break; |
Lightvalve | 49:3c630b5eba9f | 819 | // } |
Lightvalve | 14:8e7590227d22 | 820 | |
Lightvalve | 14:8e7590227d22 | 821 | case MODE_FIND_HOME: { |
Lightvalve | 29:69f3f5445d6d | 822 | if (FINDHOME_STAGE == FINDHOME_INIT) { |
Lightvalve | 14:8e7590227d22 | 823 | cnt_findhome = 0; |
Lightvalve | 14:8e7590227d22 | 824 | cnt_vel_findhome = 0; |
Lightvalve | 14:8e7590227d22 | 825 | //REFERENCE_MODE = MODE_REF_NO_ACT; // Stop taking reference data from PODO |
Lightvalve | 57:f308b1656d9c | 826 | pos.ref = pos.sen; |
Lightvalve | 57:f308b1656d9c | 827 | vel.ref = 0.0f; |
Lightvalve | 29:69f3f5445d6d | 828 | FINDHOME_STAGE = FINDHOME_GOTOLIMIT; |
Lightvalve | 29:69f3f5445d6d | 829 | } else if (FINDHOME_STAGE == FINDHOME_GOTOLIMIT) { |
Lightvalve | 29:69f3f5445d6d | 830 | int cnt_check_enc = (TMR_FREQ_5k/500); |
Lightvalve | 29:69f3f5445d6d | 831 | if(cnt_findhome%cnt_check_enc == 0) { |
Lightvalve | 29:69f3f5445d6d | 832 | FINDHOME_POSITION = pos.sen; |
Lightvalve | 29:69f3f5445d6d | 833 | FINDHOME_VELOCITY = FINDHOME_POSITION - FINDHOME_POSITION_OLD; |
Lightvalve | 29:69f3f5445d6d | 834 | FINDHOME_POSITION_OLD = FINDHOME_POSITION; |
Lightvalve | 29:69f3f5445d6d | 835 | } |
Lightvalve | 29:69f3f5445d6d | 836 | cnt_findhome++; |
Lightvalve | 14:8e7590227d22 | 837 | |
Lightvalve | 29:69f3f5445d6d | 838 | if (abs(FINDHOME_VELOCITY) <= 1) { |
Lightvalve | 29:69f3f5445d6d | 839 | cnt_vel_findhome = cnt_vel_findhome + 1; |
Lightvalve | 29:69f3f5445d6d | 840 | } else { |
Lightvalve | 29:69f3f5445d6d | 841 | cnt_vel_findhome = 0; |
Lightvalve | 29:69f3f5445d6d | 842 | } |
Lightvalve | 19:23b7c1ad8683 | 843 | |
Lightvalve | 55:f4819de54e7a | 844 | if ((cnt_vel_findhome < 3*TMR_FREQ_5k) && cnt_findhome < 10*TMR_FREQ_5k) { // wait for 3sec |
Lightvalve | 29:69f3f5445d6d | 845 | //REFERENCE_MODE = MODE_REF_NO_ACT; |
Lightvalve | 57:f308b1656d9c | 846 | if (HOMEPOS_OFFSET > 0) pos.ref = pos.ref + 2.0f; |
Lightvalve | 57:f308b1656d9c | 847 | else pos.ref = pos.ref - 2.0f; |
Lightvalve | 59:bc8c8270f0ab | 848 | |
Lightvalve | 57:f308b1656d9c | 849 | // pos.err = pos.ref_home_pos - pos.sen; |
Lightvalve | 57:f308b1656d9c | 850 | // float VALVE_POS_RAW_POS_FB = 0.0f; |
Lightvalve | 57:f308b1656d9c | 851 | // VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * pos.err/(float) ENC_PULSE_PER_POSITION * 0.01f; |
Lightvalve | 57:f308b1656d9c | 852 | // valve_pos.ref = VALVE_POS_RAW_POS_FB + (float) VALVE_CENTER; |
Lightvalve | 57:f308b1656d9c | 853 | // VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 59:bc8c8270f0ab | 854 | |
Lightvalve | 57:f308b1656d9c | 855 | CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 57:f308b1656d9c | 856 | alpha_trans = 0.0f; |
Lightvalve | 59:bc8c8270f0ab | 857 | |
Lightvalve | 34:bb2ca2fc2a8e | 858 | |
Lightvalve | 29:69f3f5445d6d | 859 | } else { |
Lightvalve | 29:69f3f5445d6d | 860 | ENC_SET(HOMEPOS_OFFSET); |
Lightvalve | 29:69f3f5445d6d | 861 | INIT_REF_POS = HOMEPOS_OFFSET; |
Lightvalve | 29:69f3f5445d6d | 862 | REF_POSITION = 0; |
Lightvalve | 29:69f3f5445d6d | 863 | REF_VELOCITY = 0; |
Lightvalve | 29:69f3f5445d6d | 864 | FINDHOME_POSITION = 0; |
Lightvalve | 29:69f3f5445d6d | 865 | FINDHOME_POSITION_OLD = 0; |
Lightvalve | 29:69f3f5445d6d | 866 | FINDHOME_VELOCITY = 0; |
Lightvalve | 29:69f3f5445d6d | 867 | cnt_findhome = 0; |
Lightvalve | 29:69f3f5445d6d | 868 | cnt_vel_findhome = 0; |
Lightvalve | 29:69f3f5445d6d | 869 | FINDHOME_STAGE = FINDHOME_ZEROPOSE; |
Lightvalve | 29:69f3f5445d6d | 870 | } |
Lightvalve | 29:69f3f5445d6d | 871 | } else if (FINDHOME_STAGE == FINDHOME_ZEROPOSE) { |
Lightvalve | 29:69f3f5445d6d | 872 | int T_move = 2*TMR_FREQ_5k; |
Lightvalve | 57:f308b1656d9c | 873 | 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 | 57:f308b1656d9c | 874 | vel.ref = 0.0f; |
Lightvalve | 19:23b7c1ad8683 | 875 | |
Lightvalve | 29:69f3f5445d6d | 876 | // input for position control |
Lightvalve | 59:bc8c8270f0ab | 877 | |
Lightvalve | 57:f308b1656d9c | 878 | CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 57:f308b1656d9c | 879 | alpha_trans = 0.0f; |
Lightvalve | 57:f308b1656d9c | 880 | // pos.err = pos.ref - (float)pos.sen; |
Lightvalve | 57:f308b1656d9c | 881 | // float VALVE_POS_RAW_POS_FB = 0.0f; |
Lightvalve | 57:f308b1656d9c | 882 | // VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * 0.01f * pos.err/(float) ENC_PULSE_PER_POSITION; |
Lightvalve | 57:f308b1656d9c | 883 | // valve_pos.ref = VALVE_POS_RAW_POS_FB + (float) VALVE_CENTER; |
Lightvalve | 57:f308b1656d9c | 884 | // VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 29:69f3f5445d6d | 885 | |
Lightvalve | 29:69f3f5445d6d | 886 | cnt_findhome++; |
Lightvalve | 29:69f3f5445d6d | 887 | if (cnt_findhome >= T_move) { |
Lightvalve | 29:69f3f5445d6d | 888 | //REFERENCE_MODE = MODE_REF_DIRECT; |
Lightvalve | 29:69f3f5445d6d | 889 | cnt_findhome = 0; |
Lightvalve | 30:8d561f16383b | 890 | pos.ref = 0.0f; |
Lightvalve | 30:8d561f16383b | 891 | vel.ref = 0.0f; |
Lightvalve | 30:8d561f16383b | 892 | pos.ref_home_pos = 0.0f; |
Lightvalve | 30:8d561f16383b | 893 | vel.ref_home_pos = 0.0f; |
Lightvalve | 29:69f3f5445d6d | 894 | FINDHOME_STAGE = FINDHOME_INIT; |
Lightvalve | 55:f4819de54e7a | 895 | CONTROL_UTILITY_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 29:69f3f5445d6d | 896 | } |
Lightvalve | 13:747daba9cf59 | 897 | } |
Lightvalve | 19:23b7c1ad8683 | 898 | |
Lightvalve | 13:747daba9cf59 | 899 | break; |
Lightvalve | 13:747daba9cf59 | 900 | } |
Lightvalve | 14:8e7590227d22 | 901 | |
Lightvalve | 49:3c630b5eba9f | 902 | // case MODE_VALVE_GAIN_SETTING: { |
Lightvalve | 49:3c630b5eba9f | 903 | // if (TMR3_COUNT_FLOWRATE == 0) { |
Lightvalve | 49:3c630b5eba9f | 904 | // if (pos_plus_end == pos_minus_end) need_enc_init = true; |
Lightvalve | 49:3c630b5eba9f | 905 | // else { |
Lightvalve | 49:3c630b5eba9f | 906 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 49:3c630b5eba9f | 907 | // temp_time = (int) (0.5f * (float) TMR_FREQ_5k); |
Lightvalve | 49:3c630b5eba9f | 908 | // } |
Lightvalve | 49:3c630b5eba9f | 909 | // } |
Lightvalve | 49:3c630b5eba9f | 910 | // if (need_enc_init) { |
Lightvalve | 49:3c630b5eba9f | 911 | // if (TMR3_COUNT_FLOWRATE < (int) (0.5f * (float) TMR_FREQ_5k)) { |
Lightvalve | 49:3c630b5eba9f | 912 | // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 49:3c630b5eba9f | 913 | // pos_plus_end = pos.sen; |
Lightvalve | 49:3c630b5eba9f | 914 | // } else if (TMR3_COUNT_FLOWRATE < TMR_FREQ_5k) { |
Lightvalve | 49:3c630b5eba9f | 915 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 49:3c630b5eba9f | 916 | // pos_minus_end = pos.sen; |
Lightvalve | 49:3c630b5eba9f | 917 | // } else if (TMR3_COUNT_FLOWRATE == TMR_FREQ_5k) { |
Lightvalve | 49:3c630b5eba9f | 918 | // need_enc_init = false; |
Lightvalve | 49:3c630b5eba9f | 919 | // check_vel_pos_init = (int) (0.9f * (float) (pos_plus_end - pos_minus_end)); |
Lightvalve | 49:3c630b5eba9f | 920 | // check_vel_pos_fin = (int) (0.95f * (float) (pos_plus_end - pos_minus_end)); |
Lightvalve | 49:3c630b5eba9f | 921 | // check_vel_pos_interv = check_vel_pos_fin - check_vel_pos_init; |
Lightvalve | 49:3c630b5eba9f | 922 | // } |
Lightvalve | 49:3c630b5eba9f | 923 | // temp_time = TMR_FREQ_5k; |
Lightvalve | 49:3c630b5eba9f | 924 | // } |
Lightvalve | 49:3c630b5eba9f | 925 | // TMR3_COUNT_FLOWRATE++; |
Lightvalve | 49:3c630b5eba9f | 926 | // if (TMR3_COUNT_FLOWRATE > temp_time) { |
Lightvalve | 49:3c630b5eba9f | 927 | // if (flag_flowrate % 2 == 0) { // (+) |
Lightvalve | 49:3c630b5eba9f | 928 | // VALVE_VOLTAGE = 1000.0f * (float) (flag_flowrate / 2 + 1); |
Lightvalve | 49:3c630b5eba9f | 929 | // V_out = VALVE_VOLTAGE; |
Lightvalve | 49:3c630b5eba9f | 930 | // if (pos.sen > (pos_minus_end + check_vel_pos_init) && pos.sen < (pos_minus_end + check_vel_pos_fin)) { |
Lightvalve | 49:3c630b5eba9f | 931 | // fl_temp_cnt++; |
Lightvalve | 49:3c630b5eba9f | 932 | // } else if (pos.sen >= (pos_minus_end + check_vel_pos_fin) && CUR_VELOCITY == 0) { |
Lightvalve | 49:3c630b5eba9f | 933 | // 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 | 49:3c630b5eba9f | 934 | // // 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 | 49:3c630b5eba9f | 935 | // fl_temp_cnt2++; |
Lightvalve | 49:3c630b5eba9f | 936 | // } |
Lightvalve | 49:3c630b5eba9f | 937 | // } else if (flag_flowrate % 2 == 1) { // (-) |
Lightvalve | 49:3c630b5eba9f | 938 | // VALVE_VOLTAGE = -1. * (float) (flag_flowrate / 2 + 1); |
Lightvalve | 49:3c630b5eba9f | 939 | // V_out = VALVE_VOLTAGE; |
Lightvalve | 49:3c630b5eba9f | 940 | // if (pos.sen < (pos_plus_end - check_vel_pos_init) && pos.sen > (pos_plus_end - check_vel_pos_fin)) { |
Lightvalve | 49:3c630b5eba9f | 941 | // fl_temp_cnt++; |
Lightvalve | 49:3c630b5eba9f | 942 | // } else if (pos.sen <= (pos_plus_end - check_vel_pos_fin) && CUR_VELOCITY == 0) { |
Lightvalve | 49:3c630b5eba9f | 943 | // 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 | 49:3c630b5eba9f | 944 | // // 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 | 49:3c630b5eba9f | 945 | // fl_temp_cnt2++; |
Lightvalve | 49:3c630b5eba9f | 946 | // } |
Lightvalve | 49:3c630b5eba9f | 947 | // } |
Lightvalve | 49:3c630b5eba9f | 948 | // if (fl_temp_cnt2 == 100) { |
Lightvalve | 49:3c630b5eba9f | 949 | // |
Lightvalve | 49:3c630b5eba9f | 950 | // ROM_RESET_DATA(); |
Lightvalve | 49:3c630b5eba9f | 951 | // |
Lightvalve | 49:3c630b5eba9f | 952 | // //spi_eeprom_write(RID_VALVE_GAIN_PLUS_1 + flag_flowrate, (int16_t) (VALVE_GAIN_LPM_PER_V[flag_flowrate] * 100.0f)); |
Lightvalve | 49:3c630b5eba9f | 953 | // cur_vel_sum = 0; |
Lightvalve | 49:3c630b5eba9f | 954 | // fl_temp_cnt = 0; |
Lightvalve | 49:3c630b5eba9f | 955 | // fl_temp_cnt2 = 0; |
Lightvalve | 49:3c630b5eba9f | 956 | // flag_flowrate++; |
Lightvalve | 49:3c630b5eba9f | 957 | // } |
Lightvalve | 49:3c630b5eba9f | 958 | // if (flag_flowrate == 10) { |
Lightvalve | 49:3c630b5eba9f | 959 | // V_out = 0; |
Lightvalve | 49:3c630b5eba9f | 960 | // flag_flowrate = 0; |
Lightvalve | 49:3c630b5eba9f | 961 | // TMR3_COUNT_FLOWRATE = 0; |
Lightvalve | 49:3c630b5eba9f | 962 | // valve_gain_repeat_cnt++; |
Lightvalve | 49:3c630b5eba9f | 963 | // if (valve_gain_repeat_cnt >= 1) { |
Lightvalve | 49:3c630b5eba9f | 964 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 49:3c630b5eba9f | 965 | // valve_gain_repeat_cnt = 0; |
Lightvalve | 49:3c630b5eba9f | 966 | // } |
Lightvalve | 49:3c630b5eba9f | 967 | // |
Lightvalve | 49:3c630b5eba9f | 968 | // } |
Lightvalve | 49:3c630b5eba9f | 969 | // break; |
Lightvalve | 49:3c630b5eba9f | 970 | // } |
Lightvalve | 49:3c630b5eba9f | 971 | // |
Lightvalve | 49:3c630b5eba9f | 972 | // } |
Lightvalve | 14:8e7590227d22 | 973 | case MODE_PRESSURE_SENSOR_NULLING: { |
Lightvalve | 13:747daba9cf59 | 974 | // DAC Voltage reference set |
Lightvalve | 14:8e7590227d22 | 975 | if (TMR3_COUNT_PRES_NULL < TMR_FREQ_5k * 2) { |
Lightvalve | 14:8e7590227d22 | 976 | CUR_PRES_A_sum += pres_A.sen; |
Lightvalve | 14:8e7590227d22 | 977 | CUR_PRES_B_sum += pres_B.sen; |
Lightvalve | 14:8e7590227d22 | 978 | |
Lightvalve | 14:8e7590227d22 | 979 | if (TMR3_COUNT_PRES_NULL % 10 == 0) { |
Lightvalve | 30:8d561f16383b | 980 | CUR_PRES_A_mean = CUR_PRES_A_sum / 10.0f; |
Lightvalve | 30:8d561f16383b | 981 | CUR_PRES_B_mean = CUR_PRES_B_sum / 10.0f; |
Lightvalve | 13:747daba9cf59 | 982 | CUR_PRES_A_sum = 0; |
Lightvalve | 13:747daba9cf59 | 983 | CUR_PRES_B_sum = 0; |
Lightvalve | 14:8e7590227d22 | 984 | |
Lightvalve | 38:118df027d851 | 985 | float VREF_NullingGain = 0.0003f; |
Lightvalve | 56:2eade98630e2 | 986 | PRES_A_VREF = PRES_A_VREF + VREF_NullingGain * CUR_PRES_A_mean; |
Lightvalve | 56:2eade98630e2 | 987 | PRES_B_VREF = PRES_B_VREF + VREF_NullingGain * CUR_PRES_B_mean; |
Lightvalve | 14:8e7590227d22 | 988 | |
Lightvalve | 30:8d561f16383b | 989 | if (PRES_A_VREF > 3.3f) PRES_A_VREF = 3.3f; |
Lightvalve | 30:8d561f16383b | 990 | if (PRES_A_VREF < 0.0f) PRES_A_VREF = 0.0f; |
Lightvalve | 30:8d561f16383b | 991 | if (PRES_B_VREF > 3.3f) PRES_B_VREF = 3.3f; |
Lightvalve | 30:8d561f16383b | 992 | if (PRES_B_VREF < 0.0f) PRES_B_VREF = 0.0f; |
Lightvalve | 19:23b7c1ad8683 | 993 | |
Lightvalve | 30:8d561f16383b | 994 | dac_1 = PRES_A_VREF / 3.3f; |
Lightvalve | 30:8d561f16383b | 995 | dac_2 = PRES_B_VREF / 3.3f; |
Lightvalve | 13:747daba9cf59 | 996 | } |
Lightvalve | 13:747daba9cf59 | 997 | } else { |
Lightvalve | 55:f4819de54e7a | 998 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 14:8e7590227d22 | 999 | TMR3_COUNT_PRES_NULL = 0; |
Lightvalve | 13:747daba9cf59 | 1000 | CUR_PRES_A_sum = 0; |
Lightvalve | 13:747daba9cf59 | 1001 | CUR_PRES_B_sum = 0; |
Lightvalve | 13:747daba9cf59 | 1002 | CUR_PRES_A_mean = 0; |
Lightvalve | 13:747daba9cf59 | 1003 | CUR_PRES_B_mean = 0; |
Lightvalve | 14:8e7590227d22 | 1004 | |
Lightvalve | 16:903b5a4433b4 | 1005 | ROM_RESET_DATA(); |
Lightvalve | 19:23b7c1ad8683 | 1006 | |
Lightvalve | 30:8d561f16383b | 1007 | dac_1 = PRES_A_VREF / 3.3f; |
Lightvalve | 30:8d561f16383b | 1008 | dac_2 = PRES_B_VREF / 3.3f; |
Lightvalve | 17:1865016ca2e7 | 1009 | //pc.printf("nulling end"); |
Lightvalve | 13:747daba9cf59 | 1010 | } |
Lightvalve | 14:8e7590227d22 | 1011 | TMR3_COUNT_PRES_NULL++; |
Lightvalve | 13:747daba9cf59 | 1012 | break; |
Lightvalve | 13:747daba9cf59 | 1013 | } |
Lightvalve | 14:8e7590227d22 | 1014 | |
Lightvalve | 49:3c630b5eba9f | 1015 | // case MODE_PRESSURE_SENSOR_CALIB: { |
Lightvalve | 49:3c630b5eba9f | 1016 | // if (TMR3_COUNT_PRES_CALIB < 2 * TMR_FREQ_5k) { |
Lightvalve | 49:3c630b5eba9f | 1017 | // V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 49:3c630b5eba9f | 1018 | // if (TMR3_COUNT_PRES_CALIB >= TMR_FREQ_5k) { |
Lightvalve | 49:3c630b5eba9f | 1019 | // CUR_PRES_A_sum += CUR_PRES_A; |
Lightvalve | 49:3c630b5eba9f | 1020 | // } |
Lightvalve | 49:3c630b5eba9f | 1021 | // } else if (TMR3_COUNT_PRES_CALIB < 4 * TMR_FREQ_5k) { |
Lightvalve | 49:3c630b5eba9f | 1022 | // V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 49:3c630b5eba9f | 1023 | // if (TMR3_COUNT_PRES_CALIB >= 3 * TMR_FREQ_5k) { |
Lightvalve | 49:3c630b5eba9f | 1024 | // CUR_PRES_B_sum += CUR_PRES_B; |
Lightvalve | 49:3c630b5eba9f | 1025 | // } |
Lightvalve | 49:3c630b5eba9f | 1026 | // } else { |
Lightvalve | 49:3c630b5eba9f | 1027 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 49:3c630b5eba9f | 1028 | // TMR3_COUNT_PRES_CALIB = 0; |
Lightvalve | 49:3c630b5eba9f | 1029 | // V_out = 0; |
Lightvalve | 49:3c630b5eba9f | 1030 | // PRES_SENSOR_A_PULSE_PER_BAR = CUR_PRES_A_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_A_NULL; |
Lightvalve | 49:3c630b5eba9f | 1031 | // PRES_SENSOR_A_PULSE_PER_BAR = PRES_SENSOR_A_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f); |
Lightvalve | 49:3c630b5eba9f | 1032 | // PRES_SENSOR_B_PULSE_PER_BAR = CUR_PRES_B_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_B_NULL; |
Lightvalve | 49:3c630b5eba9f | 1033 | // PRES_SENSOR_B_PULSE_PER_BAR = PRES_SENSOR_B_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f); |
Lightvalve | 49:3c630b5eba9f | 1034 | // CUR_PRES_A_sum = 0; |
Lightvalve | 49:3c630b5eba9f | 1035 | // CUR_PRES_B_sum = 0; |
Lightvalve | 49:3c630b5eba9f | 1036 | // CUR_PRES_A_mean = 0; |
Lightvalve | 49:3c630b5eba9f | 1037 | // CUR_PRES_B_mean = 0; |
Lightvalve | 49:3c630b5eba9f | 1038 | // |
Lightvalve | 49:3c630b5eba9f | 1039 | // ROM_RESET_DATA(); |
Lightvalve | 49:3c630b5eba9f | 1040 | // |
Lightvalve | 49:3c630b5eba9f | 1041 | // //spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f)); |
Lightvalve | 49:3c630b5eba9f | 1042 | // //spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f)); |
Lightvalve | 49:3c630b5eba9f | 1043 | // } |
Lightvalve | 49:3c630b5eba9f | 1044 | // TMR3_COUNT_PRES_CALIB++; |
Lightvalve | 49:3c630b5eba9f | 1045 | // break; |
Lightvalve | 49:3c630b5eba9f | 1046 | // } |
Lightvalve | 19:23b7c1ad8683 | 1047 | |
Lightvalve | 49:3c630b5eba9f | 1048 | // case MODE_ROTARY_FRICTION_TUNING: { |
Lightvalve | 49:3c630b5eba9f | 1049 | // 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 | 49:3c630b5eba9f | 1050 | // V_out = PWM_out * sin(2 * 3.14159f * freq_fric_tune * TMR3_COUNT_ROTARY_FRIC_TUNE * 0.0001f); |
Lightvalve | 49:3c630b5eba9f | 1051 | // if (V_out > 0) V_out = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 49:3c630b5eba9f | 1052 | // else V_out = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 49:3c630b5eba9f | 1053 | // TMR3_COUNT_ROTARY_FRIC_TUNE++; |
Lightvalve | 49:3c630b5eba9f | 1054 | // if (TMR3_COUNT_ROTARY_FRIC_TUNE > TUNING_TIME * TMR_FREQ_5k) { |
Lightvalve | 49:3c630b5eba9f | 1055 | // TMR3_COUNT_ROTARY_FRIC_TUNE = 0; |
Lightvalve | 49:3c630b5eba9f | 1056 | // V_out = 0.0f; |
Lightvalve | 49:3c630b5eba9f | 1057 | // CONTROL_MODE = MODE_NO_ACT; |
Lightvalve | 49:3c630b5eba9f | 1058 | // } |
Lightvalve | 49:3c630b5eba9f | 1059 | // break; |
Lightvalve | 49:3c630b5eba9f | 1060 | // } |
Lightvalve | 14:8e7590227d22 | 1061 | |
Lightvalve | 14:8e7590227d22 | 1062 | case MODE_DDV_POS_VS_PWM_ID: { |
Lightvalve | 57:f308b1656d9c | 1063 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 13:747daba9cf59 | 1064 | VALVE_ID_timer = VALVE_ID_timer + 1; |
Lightvalve | 14:8e7590227d22 | 1065 | |
Lightvalve | 14:8e7590227d22 | 1066 | if(VALVE_ID_timer < TMR_FREQ_5k*1) { |
Lightvalve | 58:64181f1d3e60 | 1067 | Vout.ref = 3000.0f * sin(2.0f*3.14f*VALVE_ID_timer/TMR_FREQ_5k * 100.0f); |
Lightvalve | 14:8e7590227d22 | 1068 | } else if(VALVE_ID_timer < TMR_FREQ_5k*2) { |
Lightvalve | 57:f308b1656d9c | 1069 | Vout.ref = 1000.0f*(ID_index_array[ID_index]); |
Lightvalve | 14:8e7590227d22 | 1070 | } else if(VALVE_ID_timer == TMR_FREQ_5k*2) { |
Lightvalve | 13:747daba9cf59 | 1071 | VALVE_POS_TMP = 0; |
Lightvalve | 13:747daba9cf59 | 1072 | data_num = 0; |
Lightvalve | 14:8e7590227d22 | 1073 | } else if(VALVE_ID_timer < TMR_FREQ_5k*3) { |
Lightvalve | 13:747daba9cf59 | 1074 | data_num = data_num + 1; |
Lightvalve | 13:747daba9cf59 | 1075 | VALVE_POS_TMP = VALVE_POS_TMP + value; |
Lightvalve | 14:8e7590227d22 | 1076 | } else if(VALVE_ID_timer == TMR_FREQ_5k*3) { |
Lightvalve | 57:f308b1656d9c | 1077 | Vout.ref = 0.0f; |
Lightvalve | 57:f308b1656d9c | 1078 | } else { |
Lightvalve | 13:747daba9cf59 | 1079 | VALVE_POS_AVG[ID_index] = VALVE_POS_TMP / data_num; |
Lightvalve | 13:747daba9cf59 | 1080 | VALVE_ID_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1081 | ID_index= ID_index +1; |
Lightvalve | 13:747daba9cf59 | 1082 | } |
Lightvalve | 14:8e7590227d22 | 1083 | |
Lightvalve | 17:1865016ca2e7 | 1084 | if(ID_index>=25) { |
Lightvalve | 13:747daba9cf59 | 1085 | int i; |
Lightvalve | 13:747daba9cf59 | 1086 | VALVE_POS_AVG_OLD = VALVE_POS_AVG[0]; |
Lightvalve | 17:1865016ca2e7 | 1087 | for(i=0; i<25; i++) { |
Lightvalve | 13:747daba9cf59 | 1088 | VALVE_POS_VS_PWM[i] = (int16_t) (VALVE_POS_AVG[i]); |
Lightvalve | 14:8e7590227d22 | 1089 | if(VALVE_POS_AVG[i] > VALVE_POS_AVG_OLD) { |
Lightvalve | 13:747daba9cf59 | 1090 | VALVE_MAX_POS = VALVE_POS_AVG[i]; |
Lightvalve | 13:747daba9cf59 | 1091 | VALVE_POS_AVG_OLD = VALVE_MAX_POS; |
Lightvalve | 14:8e7590227d22 | 1092 | } else if(VALVE_POS_AVG[i] < VALVE_POS_AVG_OLD) { |
Lightvalve | 13:747daba9cf59 | 1093 | VALVE_MIN_POS = VALVE_POS_AVG[i]; |
Lightvalve | 13:747daba9cf59 | 1094 | VALVE_POS_AVG_OLD = VALVE_MIN_POS; |
Lightvalve | 13:747daba9cf59 | 1095 | } |
Lightvalve | 13:747daba9cf59 | 1096 | } |
Lightvalve | 57:f308b1656d9c | 1097 | ROM_RESET_DATA(); |
Lightvalve | 13:747daba9cf59 | 1098 | ID_index = 0; |
Lightvalve | 55:f4819de54e7a | 1099 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 13:747daba9cf59 | 1100 | } |
Lightvalve | 14:8e7590227d22 | 1101 | |
Lightvalve | 14:8e7590227d22 | 1102 | |
Lightvalve | 13:747daba9cf59 | 1103 | break; |
Lightvalve | 13:747daba9cf59 | 1104 | } |
Lightvalve | 14:8e7590227d22 | 1105 | |
Lightvalve | 14:8e7590227d22 | 1106 | case MODE_DDV_DEADZONE_AND_CENTER: { |
Lightvalve | 57:f308b1656d9c | 1107 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 13:747daba9cf59 | 1108 | VALVE_DZ_timer = VALVE_DZ_timer + 1; |
Lightvalve | 14:8e7590227d22 | 1109 | if(first_check == 0) { |
Lightvalve | 30:8d561f16383b | 1110 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1111 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 30:8d561f16383b | 1112 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1113 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1114 | pos_plus_end = pos.sen; |
Lightvalve | 30:8d561f16383b | 1115 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1116 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 30:8d561f16383b | 1117 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1118 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1119 | pos_minus_end = pos.sen; |
Lightvalve | 30:8d561f16383b | 1120 | } else if(VALVE_DZ_timer < (int) (3.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1121 | 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 | 1122 | } else if(VALVE_DZ_timer < (int) (4.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1123 | 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 | 1124 | data_num = data_num + 1; |
Lightvalve | 13:747daba9cf59 | 1125 | VALVE_POS_TMP = VALVE_POS_TMP + value; |
Lightvalve | 30:8d561f16383b | 1126 | } else if(VALVE_DZ_timer == (int) (4.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1127 | 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 | 1128 | DDV_POS_AVG = VALVE_POS_TMP / data_num; |
Lightvalve | 14:8e7590227d22 | 1129 | START_POS = pos.sen; |
Lightvalve | 13:747daba9cf59 | 1130 | VALVE_POS_TMP = 0; |
Lightvalve | 13:747daba9cf59 | 1131 | data_num = 0; |
Lightvalve | 14:8e7590227d22 | 1132 | |
Lightvalve | 30:8d561f16383b | 1133 | } else if(VALVE_DZ_timer < (int) (5.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1134 | valve_pos.ref = DDV_POS_AVG; |
Lightvalve | 14:8e7590227d22 | 1135 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 14:8e7590227d22 | 1136 | |
Lightvalve | 30:8d561f16383b | 1137 | } else if(VALVE_DZ_timer < (int) (6.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1138 | valve_pos.ref = DDV_POS_AVG; |
Lightvalve | 14:8e7590227d22 | 1139 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 58:64181f1d3e60 | 1140 | |
Lightvalve | 30:8d561f16383b | 1141 | } else if(VALVE_DZ_timer == (int) (6.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1142 | valve_pos.ref = DDV_POS_AVG; |
Lightvalve | 14:8e7590227d22 | 1143 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 14:8e7590227d22 | 1144 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1145 | |
Lightvalve | 58:64181f1d3e60 | 1146 | if((FINAL_POS - START_POS)>200) { |
Lightvalve | 13:747daba9cf59 | 1147 | DZ_case = 1; |
Lightvalve | 58:64181f1d3e60 | 1148 | } else if((FINAL_POS - START_POS)<-200) { |
Lightvalve | 13:747daba9cf59 | 1149 | DZ_case = -1; |
Lightvalve | 14:8e7590227d22 | 1150 | } else { |
Lightvalve | 13:747daba9cf59 | 1151 | DZ_case = 0; |
Lightvalve | 13:747daba9cf59 | 1152 | } |
Lightvalve | 59:bc8c8270f0ab | 1153 | |
Lightvalve | 58:64181f1d3e60 | 1154 | CAN_TX_PRES((int16_t) (DZ_case), (int16_t) (6)); |
Lightvalve | 49:3c630b5eba9f | 1155 | |
Lightvalve | 13:747daba9cf59 | 1156 | first_check = 1; |
Lightvalve | 13:747daba9cf59 | 1157 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1158 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1159 | Ref_Valve_Pos_Old = DDV_POS_AVG; |
Lightvalve | 13:747daba9cf59 | 1160 | DZ_NUM = 1; |
Lightvalve | 13:747daba9cf59 | 1161 | DZ_index = 1; |
Lightvalve | 14:8e7590227d22 | 1162 | |
Lightvalve | 13:747daba9cf59 | 1163 | } |
Lightvalve | 19:23b7c1ad8683 | 1164 | } else { |
Lightvalve | 14:8e7590227d22 | 1165 | if((DZ_case == -1 && DZ_NUM == 1) | (DZ_case == 1 && DZ_NUM == 1)) { |
Lightvalve | 30:8d561f16383b | 1166 | if(VALVE_DZ_timer < (int) (1.0 * (float) TMR_FREQ_5k)) { |
Lightvalve | 58:64181f1d3e60 | 1167 | 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 | 58:64181f1d3e60 | 1168 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 58:64181f1d3e60 | 1169 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1170 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1171 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1172 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1173 | valve_pos.ref = Ref_Valve_Pos_Old - DZ_case * DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1174 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1175 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1176 | } else if(valve_pos.ref >= VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1177 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 13:747daba9cf59 | 1178 | } |
Lightvalve | 14:8e7590227d22 | 1179 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 58:64181f1d3e60 | 1180 | |
Lightvalve | 30:8d561f16383b | 1181 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1182 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1183 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1184 | |
Lightvalve | 14:8e7590227d22 | 1185 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 14:8e7590227d22 | 1186 | DZ_DIRECTION = 1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1187 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 14:8e7590227d22 | 1188 | DZ_DIRECTION = -1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1189 | } else { |
Lightvalve | 13:747daba9cf59 | 1190 | DZ_DIRECTION = 1 * DZ_case; |
Lightvalve | 13:747daba9cf59 | 1191 | } |
Lightvalve | 14:8e7590227d22 | 1192 | |
Lightvalve | 13:747daba9cf59 | 1193 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1194 | DZ_index= DZ_index *2; |
Lightvalve | 14:8e7590227d22 | 1195 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1196 | FIRST_DZ = valve_pos.ref; |
Lightvalve | 13:747daba9cf59 | 1197 | DZ_NUM = 2; |
Lightvalve | 13:747daba9cf59 | 1198 | Ref_Valve_Pos_Old = FIRST_DZ; |
Lightvalve | 13:747daba9cf59 | 1199 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1200 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1201 | } |
Lightvalve | 13:747daba9cf59 | 1202 | } |
Lightvalve | 14:8e7590227d22 | 1203 | } else if((DZ_case == -1 && DZ_NUM == 2) | (DZ_case == 1 && DZ_NUM == 2)) { |
Lightvalve | 30:8d561f16383b | 1204 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 58:64181f1d3e60 | 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 | 58:64181f1d3e60 | 1206 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 58:64181f1d3e60 | 1207 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1208 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1209 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1210 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 58:64181f1d3e60 | 1211 | valve_pos.ref = Ref_Valve_Pos_Old - DZ_case * DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1212 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1213 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1214 | } else if(valve_pos.ref >= VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1215 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 13:747daba9cf59 | 1216 | } |
Lightvalve | 14:8e7590227d22 | 1217 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 59:bc8c8270f0ab | 1218 | |
Lightvalve | 30:8d561f16383b | 1219 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1220 | Vout.ref = 0.0f; |
Lightvalve | 57:f308b1656d9c | 1221 | } else if(VALVE_DZ_timer > (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1222 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1223 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1224 | |
Lightvalve | 14:8e7590227d22 | 1225 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 58:64181f1d3e60 | 1226 | DZ_DIRECTION = 1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1227 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 58:64181f1d3e60 | 1228 | DZ_DIRECTION = -1 * DZ_case; |
Lightvalve | 14:8e7590227d22 | 1229 | } else { |
Lightvalve | 58:64181f1d3e60 | 1230 | DZ_DIRECTION = -1 * DZ_case; |
Lightvalve | 13:747daba9cf59 | 1231 | } |
Lightvalve | 14:8e7590227d22 | 1232 | |
Lightvalve | 13:747daba9cf59 | 1233 | VALVE_DZ_timer = 0; |
Lightvalve | 58:64181f1d3e60 | 1234 | DZ_index= DZ_index * 2; |
Lightvalve | 14:8e7590227d22 | 1235 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1236 | SECOND_DZ = valve_pos.ref; |
Lightvalve | 55:f4819de54e7a | 1237 | VALVE_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ)); |
Lightvalve | 13:747daba9cf59 | 1238 | first_check = 0; |
Lightvalve | 33:91b17819ec30 | 1239 | VALVE_DEADZONE_MINUS = (float) FIRST_DZ; |
Lightvalve | 33:91b17819ec30 | 1240 | VALVE_DEADZONE_PLUS = (float) SECOND_DZ; |
Lightvalve | 19:23b7c1ad8683 | 1241 | |
Lightvalve | 16:903b5a4433b4 | 1242 | ROM_RESET_DATA(); |
Lightvalve | 34:bb2ca2fc2a8e | 1243 | |
Lightvalve | 58:64181f1d3e60 | 1244 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 13:747daba9cf59 | 1245 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1246 | } |
Lightvalve | 13:747daba9cf59 | 1247 | } |
Lightvalve | 14:8e7590227d22 | 1248 | } else if(DZ_case == 0 && DZ_NUM ==1) { |
Lightvalve | 30:8d561f16383b | 1249 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 58:64181f1d3e60 | 1250 | 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 | 58:64181f1d3e60 | 1251 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 58:64181f1d3e60 | 1252 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1253 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1254 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1255 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1256 | valve_pos.ref = Ref_Valve_Pos_Old - DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1257 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1258 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1259 | } else if(valve_pos.ref >= VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1260 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 13:747daba9cf59 | 1261 | } |
Lightvalve | 14:8e7590227d22 | 1262 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 59:bc8c8270f0ab | 1263 | |
Lightvalve | 30:8d561f16383b | 1264 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1265 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1266 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1267 | |
Lightvalve | 14:8e7590227d22 | 1268 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 14:8e7590227d22 | 1269 | DZ_DIRECTION = 1; |
Lightvalve | 14:8e7590227d22 | 1270 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 14:8e7590227d22 | 1271 | DZ_DIRECTION = -1; |
Lightvalve | 14:8e7590227d22 | 1272 | } else { |
Lightvalve | 13:747daba9cf59 | 1273 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1274 | } |
Lightvalve | 13:747daba9cf59 | 1275 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1276 | DZ_index= DZ_index *2; |
Lightvalve | 14:8e7590227d22 | 1277 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1278 | FIRST_DZ = valve_pos.ref; |
Lightvalve | 13:747daba9cf59 | 1279 | DZ_NUM = 2; |
Lightvalve | 13:747daba9cf59 | 1280 | Ref_Valve_Pos_Old = FIRST_DZ; |
Lightvalve | 13:747daba9cf59 | 1281 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1282 | DZ_DIRECTION = 1; |
Lightvalve | 13:747daba9cf59 | 1283 | } |
Lightvalve | 13:747daba9cf59 | 1284 | } |
Lightvalve | 14:8e7590227d22 | 1285 | } else { |
Lightvalve | 30:8d561f16383b | 1286 | if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 58:64181f1d3e60 | 1287 | 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 | 58:64181f1d3e60 | 1288 | //pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 58:64181f1d3e60 | 1289 | //CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1290 | } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1291 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1292 | } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1293 | valve_pos.ref = Ref_Valve_Pos_Old + DZ_DIRECTION * 64 / DZ_index; |
Lightvalve | 14:8e7590227d22 | 1294 | if(valve_pos.ref <= VALVE_MIN_POS) { |
Lightvalve | 14:8e7590227d22 | 1295 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 14:8e7590227d22 | 1296 | } else if(valve_pos.ref > VALVE_MAX_POS) { |
Lightvalve | 14:8e7590227d22 | 1297 | valve_pos.ref = VALVE_MAX_POS - 1; |
Lightvalve | 13:747daba9cf59 | 1298 | } |
Lightvalve | 14:8e7590227d22 | 1299 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 58:64181f1d3e60 | 1300 | |
Lightvalve | 30:8d561f16383b | 1301 | } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1302 | Vout.ref = 0.0f; |
Lightvalve | 57:f308b1656d9c | 1303 | } else if(VALVE_DZ_timer > (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1304 | Ref_Valve_Pos_Old = valve_pos.ref; |
Lightvalve | 14:8e7590227d22 | 1305 | FINAL_POS = pos.sen; |
Lightvalve | 59:bc8c8270f0ab | 1306 | |
Lightvalve | 58:64181f1d3e60 | 1307 | if((FINAL_POS - START_POS)>100) { |
Lightvalve | 13:747daba9cf59 | 1308 | DZ_DIRECTION = 1; |
Lightvalve | 58:64181f1d3e60 | 1309 | } else if((FINAL_POS - START_POS)<-100) { |
Lightvalve | 58:64181f1d3e60 | 1310 | DZ_DIRECTION = -1; |
Lightvalve | 58:64181f1d3e60 | 1311 | } else { |
Lightvalve | 13:747daba9cf59 | 1312 | DZ_DIRECTION = 1; |
Lightvalve | 58:64181f1d3e60 | 1313 | } |
Lightvalve | 14:8e7590227d22 | 1314 | |
Lightvalve | 13:747daba9cf59 | 1315 | VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1316 | DZ_index= DZ_index *2; |
Lightvalve | 14:8e7590227d22 | 1317 | if(DZ_index >= 128) { |
Lightvalve | 14:8e7590227d22 | 1318 | SECOND_DZ = valve_pos.ref; |
Lightvalve | 55:f4819de54e7a | 1319 | VALVE_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ)); |
Lightvalve | 13:747daba9cf59 | 1320 | first_check = 0; |
Lightvalve | 33:91b17819ec30 | 1321 | VALVE_DEADZONE_MINUS = (float) FIRST_DZ; |
Lightvalve | 33:91b17819ec30 | 1322 | VALVE_DEADZONE_PLUS = (float) SECOND_DZ; |
Lightvalve | 59:bc8c8270f0ab | 1323 | |
Lightvalve | 57:f308b1656d9c | 1324 | ROM_RESET_DATA(); |
Lightvalve | 34:bb2ca2fc2a8e | 1325 | |
Lightvalve | 55:f4819de54e7a | 1326 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 13:747daba9cf59 | 1327 | DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 1328 | } |
Lightvalve | 13:747daba9cf59 | 1329 | } |
Lightvalve | 13:747daba9cf59 | 1330 | } |
Lightvalve | 14:8e7590227d22 | 1331 | } |
Lightvalve | 13:747daba9cf59 | 1332 | break; |
Lightvalve | 13:747daba9cf59 | 1333 | } |
Lightvalve | 14:8e7590227d22 | 1334 | |
Lightvalve | 14:8e7590227d22 | 1335 | case MODE_DDV_POS_VS_FLOWRATE: { |
Lightvalve | 57:f308b1656d9c | 1336 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 13:747daba9cf59 | 1337 | VALVE_FR_timer = VALVE_FR_timer + 1; |
Lightvalve | 14:8e7590227d22 | 1338 | if(first_check == 0) { |
Lightvalve | 30:8d561f16383b | 1339 | if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1340 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 23:59218d4a256d | 1341 | //CAN_TX_PRES((int16_t) (VALVE_FR_timer), (int16_t) (6)); |
Lightvalve | 30:8d561f16383b | 1342 | } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1343 | Vout.ref = VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1344 | pos_plus_end = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1345 | // CAN_TX_PRES((int16_t) (V_out), (int16_t) (7)); |
Lightvalve | 30:8d561f16383b | 1346 | } else if(VALVE_FR_timer < (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1347 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 30:8d561f16383b | 1348 | } else if(VALVE_FR_timer == (int) (2.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1349 | // CAN_TX_PRES((int16_t) (V_out), (int16_t) (8)); |
Lightvalve | 57:f308b1656d9c | 1350 | Vout.ref = -VALVE_VOLTAGE_LIMIT * 1000.0f; |
Lightvalve | 14:8e7590227d22 | 1351 | pos_minus_end = pos.sen; |
Lightvalve | 13:747daba9cf59 | 1352 | first_check = 1; |
Lightvalve | 13:747daba9cf59 | 1353 | VALVE_FR_timer = 0; |
Lightvalve | 55:f4819de54e7a | 1354 | valve_pos.ref = (float) VALVE_CENTER; |
Lightvalve | 13:747daba9cf59 | 1355 | ID_index = 0; |
Lightvalve | 13:747daba9cf59 | 1356 | max_check = 0; |
Lightvalve | 13:747daba9cf59 | 1357 | min_check = 0; |
Lightvalve | 13:747daba9cf59 | 1358 | } |
Lightvalve | 14:8e7590227d22 | 1359 | } else { |
Lightvalve | 30:8d561f16383b | 1360 | if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 57:f308b1656d9c | 1361 | //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 | 57:f308b1656d9c | 1362 | pos.ref = 0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end; |
Lightvalve | 57:f308b1656d9c | 1363 | CONTROL_MODE = MODE_JOINT_CONTROL; |
Lightvalve | 30:8d561f16383b | 1364 | } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 13:747daba9cf59 | 1365 | data_num = 0; |
Lightvalve | 55:f4819de54e7a | 1366 | valve_pos.ref = 10.0f*((float) ID_index_array[ID_index]) + (float) VALVE_CENTER; |
Lightvalve | 14:8e7590227d22 | 1367 | |
Lightvalve | 14:8e7590227d22 | 1368 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 14:8e7590227d22 | 1369 | START_POS = pos.sen; |
Lightvalve | 30:8d561f16383b | 1370 | } else if(VALVE_FR_timer < (int) (5.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 55:f4819de54e7a | 1371 | valve_pos.ref = 10.0f*((float) ID_index_array[ID_index]) + (float) VALVE_CENTER; |
Lightvalve | 14:8e7590227d22 | 1372 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 13:747daba9cf59 | 1373 | data_num = data_num + 1; |
Lightvalve | 30:8d561f16383b | 1374 | if(abs(0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen) > 20000.0f) { |
Lightvalve | 14:8e7590227d22 | 1375 | FINAL_POS = pos.sen; |
Lightvalve | 14:8e7590227d22 | 1376 | one_period_end = 1; |
Lightvalve | 13:747daba9cf59 | 1377 | } |
Lightvalve | 30:8d561f16383b | 1378 | } else if(VALVE_FR_timer == (int) (5.0f * (float) TMR_FREQ_5k)) { |
Lightvalve | 14:8e7590227d22 | 1379 | FINAL_POS = pos.sen; |
Lightvalve | 13:747daba9cf59 | 1380 | one_period_end = 1; |
Lightvalve | 57:f308b1656d9c | 1381 | V_out = 0.0f; |
Lightvalve | 13:747daba9cf59 | 1382 | } |
Lightvalve | 14:8e7590227d22 | 1383 | |
Lightvalve | 14:8e7590227d22 | 1384 | if(one_period_end == 1) { |
Lightvalve | 14:8e7590227d22 | 1385 | if(valve_pos.ref > VALVE_MAX_POS) { |
Lightvalve | 13:747daba9cf59 | 1386 | max_check = 1; |
Lightvalve | 14:8e7590227d22 | 1387 | } else if(valve_pos.ref < VALVE_MIN_POS) { |
Lightvalve | 13:747daba9cf59 | 1388 | min_check = 1; |
Lightvalve | 13:747daba9cf59 | 1389 | } |
Lightvalve | 13:747daba9cf59 | 1390 | JOINT_VEL[ID_index] = (FINAL_POS - START_POS) / data_num * TMR_FREQ_5k; // pulse/sec |
Lightvalve | 19:23b7c1ad8683 | 1391 | |
Lightvalve | 13:747daba9cf59 | 1392 | VALVE_FR_timer = 0; |
Lightvalve | 13:747daba9cf59 | 1393 | one_period_end = 0; |
Lightvalve | 13:747daba9cf59 | 1394 | ID_index= ID_index +1; |
Lightvalve | 30:8d561f16383b | 1395 | V_out = 0.0f; |
Lightvalve | 13:747daba9cf59 | 1396 | } |
Lightvalve | 14:8e7590227d22 | 1397 | |
Lightvalve | 14:8e7590227d22 | 1398 | if(max_check == 1 && min_check == 1) { |
Lightvalve | 19:23b7c1ad8683 | 1399 | |
Lightvalve | 13:747daba9cf59 | 1400 | VALVE_POS_NUM = ID_index; |
Lightvalve | 57:f308b1656d9c | 1401 | ROM_RESET_DATA(); |
Lightvalve | 13:747daba9cf59 | 1402 | ID_index = 0; |
Lightvalve | 13:747daba9cf59 | 1403 | first_check = 0; |
Lightvalve | 13:747daba9cf59 | 1404 | VALVE_FR_timer = 0; |
Lightvalve | 55:f4819de54e7a | 1405 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 48:e7bcfc244d40 | 1406 | // CAN_TX_PRES((int16_t) (VALVE_FR_timer), (int16_t) (6)); |
Lightvalve | 13:747daba9cf59 | 1407 | } |
Lightvalve | 13:747daba9cf59 | 1408 | } |
Lightvalve | 13:747daba9cf59 | 1409 | break; |
Lightvalve | 13:747daba9cf59 | 1410 | } |
Lightvalve | 56:2eade98630e2 | 1411 | |
Lightvalve | 55:f4819de54e7a | 1412 | case MODE_SYSTEM_ID: { |
Lightvalve | 55:f4819de54e7a | 1413 | freq_sysid_Iref = (double) cnt_sysid * DT_TMR3 * 3.; |
Lightvalve | 55:f4819de54e7a | 1414 | valve_pos.ref = 2500.0f * sin(2.0f * 3.14159f * freq_sysid_Iref * (double) cnt_sysid * DT_TMR3); |
Lightvalve | 55:f4819de54e7a | 1415 | CONTROL_MODE = MODE_VALVE_OPEN_LOOP; |
Lightvalve | 55:f4819de54e7a | 1416 | cnt_sysid++; |
Lightvalve | 55:f4819de54e7a | 1417 | if (freq_sysid_Iref >= 300) { |
Lightvalve | 55:f4819de54e7a | 1418 | cnt_sysid = 0; |
Lightvalve | 55:f4819de54e7a | 1419 | CONTROL_UTILITY_MODE = MODE_NO_ACT; |
Lightvalve | 55:f4819de54e7a | 1420 | } |
Lightvalve | 55:f4819de54e7a | 1421 | break; |
Lightvalve | 55:f4819de54e7a | 1422 | } |
Lightvalve | 56:2eade98630e2 | 1423 | |
Lightvalve | 56:2eade98630e2 | 1424 | |
Lightvalve | 55:f4819de54e7a | 1425 | |
Lightvalve | 55:f4819de54e7a | 1426 | default: |
Lightvalve | 55:f4819de54e7a | 1427 | break; |
Lightvalve | 55:f4819de54e7a | 1428 | } |
Lightvalve | 55:f4819de54e7a | 1429 | |
Lightvalve | 55:f4819de54e7a | 1430 | // CONTROL MODE ------------------------------------------------------------ |
Lightvalve | 55:f4819de54e7a | 1431 | |
Lightvalve | 55:f4819de54e7a | 1432 | switch (CONTROL_MODE) { |
Lightvalve | 55:f4819de54e7a | 1433 | case MODE_NO_ACT: { |
Lightvalve | 55:f4819de54e7a | 1434 | V_out = 0.0f; |
Lightvalve | 55:f4819de54e7a | 1435 | break; |
Lightvalve | 55:f4819de54e7a | 1436 | } |
Lightvalve | 55:f4819de54e7a | 1437 | |
Lightvalve | 55:f4819de54e7a | 1438 | case MODE_VALVE_POSITION_CONTROL: { |
Lightvalve | 55:f4819de54e7a | 1439 | if (((OPERATING_MODE&0b110)>>1) == 0) { //Moog Valve |
Lightvalve | 55:f4819de54e7a | 1440 | I_REF = valve_pos.ref; |
Lightvalve | 55:f4819de54e7a | 1441 | } else if (((OPERATING_MODE&0b110)>>1) == 1) { //KNR Valve |
Lightvalve | 55:f4819de54e7a | 1442 | V_out = valve_pos.ref; |
Lightvalve | 55:f4819de54e7a | 1443 | } else { //SW Valve |
Lightvalve | 55:f4819de54e7a | 1444 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 57:f308b1656d9c | 1445 | V_out = Vout.ref; |
Lightvalve | 55:f4819de54e7a | 1446 | } |
Lightvalve | 56:2eade98630e2 | 1447 | |
Lightvalve | 55:f4819de54e7a | 1448 | break; |
Lightvalve | 55:f4819de54e7a | 1449 | } |
Lightvalve | 55:f4819de54e7a | 1450 | |
Lightvalve | 55:f4819de54e7a | 1451 | case MODE_JOINT_CONTROL: { |
Lightvalve | 55:f4819de54e7a | 1452 | double torq_ref = 0.0f; |
Lightvalve | 55:f4819de54e7a | 1453 | pos.err = (pos.ref - pos.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm] |
Lightvalve | 55:f4819de54e7a | 1454 | vel.err = (vel.ref - vel.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm/s] |
Lightvalve | 55:f4819de54e7a | 1455 | pos.err_sum += pos.err/(float) TMR_FREQ_5k; //[mm] |
Lightvalve | 55:f4819de54e7a | 1456 | torq_ref = torq.ref + (K_SPRING * pos.err * 0.01f + D_DAMPER * vel.err * 0.0001f) / ENC_PULSE_PER_POSITION; //[N] |
Lightvalve | 55:f4819de54e7a | 1457 | |
Lightvalve | 55:f4819de54e7a | 1458 | // torque feedback |
Lightvalve | 56:2eade98630e2 | 1459 | torq.err = (torq_ref)/(float)(TORQUE_SENSOR_PULSE_PER_TORQUE) - torq.sen; //[N] |
Lightvalve | 55:f4819de54e7a | 1460 | torq.err_sum += torq.err/(float) TMR_FREQ_5k; //[N] |
Lightvalve | 55:f4819de54e7a | 1461 | |
Lightvalve | 55:f4819de54e7a | 1462 | if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) { |
Lightvalve | 56:2eade98630e2 | 1463 | |
Lightvalve | 55:f4819de54e7a | 1464 | double I_REF_POS = 0.0f; |
Lightvalve | 55:f4819de54e7a | 1465 | double I_REF_FORCE_FB = 0.0f; // I_REF by Force Feedback |
Lightvalve | 55:f4819de54e7a | 1466 | double I_REF_VC = 0.0f; // I_REF for velocity compensation |
Lightvalve | 55:f4819de54e7a | 1467 | |
Lightvalve | 55:f4819de54e7a | 1468 | double temp_vel_pos = 0.0f; |
Lightvalve | 55:f4819de54e7a | 1469 | double temp_vel_torq = 0.0f; |
Lightvalve | 55:f4819de54e7a | 1470 | double wn_Pos = 2.0f * PI * 5.0f; // f_cut : 5Hz Position Control |
Lightvalve | 56:2eade98630e2 | 1471 | |
Lightvalve | 55:f4819de54e7a | 1472 | if ((OPERATING_MODE && 0x01) == 0) { // Rotary Mode |
Lightvalve | 55:f4819de54e7a | 1473 | 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 | 55:f4819de54e7a | 1474 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 55:f4819de54e7a | 1475 | } else if ((OPERATING_MODE && 0x01) == 1) { |
Lightvalve | 55:f4819de54e7a | 1476 | 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 | 55:f4819de54e7a | 1477 | // L when P-gain = 100, f_cut = 10Hz L feedforward velocity |
Lightvalve | 55:f4819de54e7a | 1478 | } |
Lightvalve | 55:f4819de54e7a | 1479 | 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 | 55:f4819de54e7a | 1480 | else I_REF_POS = temp_vel_pos * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f)))); |
Lightvalve | 55:f4819de54e7a | 1481 | |
Lightvalve | 55:f4819de54e7a | 1482 | // velocity compensation for torque control |
Lightvalve | 55:f4819de54e7a | 1483 | if ((OPERATING_MODE && 0x01) == 0) { // Rotary Mode |
Lightvalve | 55:f4819de54e7a | 1484 | I_REF_FORCE_FB = 0.001f * ((double) P_GAIN_JOINT_TORQUE * torq.err + (double) I_GAIN_JOINT_TORQUE * torq.err_sum); |
Lightvalve | 55:f4819de54e7a | 1485 | // temp_vel_torq = (0.01 * (double) VELOCITY_COMP_GAIN * (double) CUR_VELOCITY / (double) ENC_PULSE_PER_POSITION) * PI / 180.0; // rad/s |
Lightvalve | 55:f4819de54e7a | 1486 | temp_vel_torq = (0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / (double) ENC_PULSE_PER_POSITION) * PI / 180.0f; // rad/s |
Lightvalve | 55:f4819de54e7a | 1487 | // L feedforward velocity |
Lightvalve | 55:f4819de54e7a | 1488 | } else if ((OPERATING_MODE && 0x01) == 1) { |
Lightvalve | 55:f4819de54e7a | 1489 | 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 | 55:f4819de54e7a | 1490 | // temp_vel_torq = (0.01 * (double) VELOCITY_COMP_GAIN * (double) CUR_VELOCITY / (double) ENC_PULSE_PER_POSITION); // mm/s |
Lightvalve | 55:f4819de54e7a | 1491 | temp_vel_torq = (0.01f * (double) VELOCITY_COMP_GAIN * vel.ref / (double) ENC_PULSE_PER_POSITION); // mm/s |
Lightvalve | 55:f4819de54e7a | 1492 | // L feedforward velocity |
Lightvalve | 55:f4819de54e7a | 1493 | } |
Lightvalve | 55:f4819de54e7a | 1494 | 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 | 55:f4819de54e7a | 1495 | else I_REF_VC = temp_vel_torq * ((double) PISTON_AREA_B * 0.00006f / (K_v * sqrt(2.0f / (alpha3 + 1.0f)))); |
Lightvalve | 55:f4819de54e7a | 1496 | // L velocity(rad/s or mm/s) >> I_ref(mA) |
Lightvalve | 55:f4819de54e7a | 1497 | // Ref_Joint_FT_dot = (Ref_Joint_FT_Nm - Ref_Joint_FT_Nm_old) / TMR_DT_5k; |
Lightvalve | 55:f4819de54e7a | 1498 | // Ref_Joint_FT_Nm_old = Ref_Joint_FT_Nm; |
Lightvalve | 55:f4819de54e7a | 1499 | |
Lightvalve | 55:f4819de54e7a | 1500 | I_REF = (1.0f - alpha_trans) * I_REF_POS + alpha_trans * (I_REF_VC + I_REF_FORCE_FB); |
Lightvalve | 55:f4819de54e7a | 1501 | |
Lightvalve | 55:f4819de54e7a | 1502 | } else { |
Lightvalve | 55:f4819de54e7a | 1503 | float VALVE_POS_RAW_FORCE_FB = 0.0f; |
Lightvalve | 55:f4819de54e7a | 1504 | |
Lightvalve | 55:f4819de54e7a | 1505 | 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 | 55:f4819de54e7a | 1506 | + 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 | 55:f4819de54e7a | 1507 | |
Lightvalve | 55:f4819de54e7a | 1508 | if (VALVE_POS_RAW_FORCE_FB >= 0) { |
Lightvalve | 55:f4819de54e7a | 1509 | valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_PLUS; |
Lightvalve | 55:f4819de54e7a | 1510 | } else { |
Lightvalve | 55:f4819de54e7a | 1511 | valve_pos.ref = VALVE_POS_RAW_FORCE_FB + VALVE_DEADZONE_MINUS; |
Lightvalve | 55:f4819de54e7a | 1512 | } |
Lightvalve | 55:f4819de54e7a | 1513 | |
Lightvalve | 55:f4819de54e7a | 1514 | if(I_GAIN_JOINT_TORQUE != 0) { |
Lightvalve | 55:f4819de54e7a | 1515 | double Ka = 1.0f / (double) I_GAIN_JOINT_TORQUE * 100.0f; |
Lightvalve | 55:f4819de54e7a | 1516 | if(valve_pos.ref>VALVE_MAX_POS) { |
Lightvalve | 55:f4819de54e7a | 1517 | double valve_pos_rem = valve_pos.ref - VALVE_MAX_POS; |
Lightvalve | 55:f4819de54e7a | 1518 | valve_pos_rem = valve_pos_rem * Ka; |
Lightvalve | 55:f4819de54e7a | 1519 | valve_pos.ref = VALVE_MAX_POS; |
Lightvalve | 55:f4819de54e7a | 1520 | torq.err_sum = torq.err_sum - valve_pos_rem/(float) TMR_FREQ_5k; |
Lightvalve | 55:f4819de54e7a | 1521 | } else if(valve_pos.ref < VALVE_MIN_POS) { |
Lightvalve | 55:f4819de54e7a | 1522 | double valve_pos_rem = valve_pos.ref - VALVE_MIN_POS; |
Lightvalve | 55:f4819de54e7a | 1523 | valve_pos_rem = valve_pos_rem * Ka; |
Lightvalve | 55:f4819de54e7a | 1524 | valve_pos.ref = VALVE_MIN_POS; |
Lightvalve | 55:f4819de54e7a | 1525 | torq.err_sum = torq.err_sum - valve_pos_rem/(float) TMR_FREQ_5k; |
Lightvalve | 55:f4819de54e7a | 1526 | } |
Lightvalve | 55:f4819de54e7a | 1527 | } |
Lightvalve | 59:bc8c8270f0ab | 1528 | |
Lightvalve | 55:f4819de54e7a | 1529 | VALVE_POS_CONTROL(valve_pos.ref); |
Lightvalve | 59:bc8c8270f0ab | 1530 | |
Lightvalve | 64:a8e6799dbce3 | 1531 | //Vout.ref = (float) P_GAIN_JOINT_POSITION * 0.01f * ((float) pos.err); |
Lightvalve | 58:64181f1d3e60 | 1532 | V_out = (float) Vout.ref; |
Lightvalve | 55:f4819de54e7a | 1533 | |
Lightvalve | 55:f4819de54e7a | 1534 | } |
Lightvalve | 56:2eade98630e2 | 1535 | |
Lightvalve | 55:f4819de54e7a | 1536 | break; |
Lightvalve | 55:f4819de54e7a | 1537 | } |
Lightvalve | 56:2eade98630e2 | 1538 | |
Lightvalve | 55:f4819de54e7a | 1539 | case MODE_VALVE_OPEN_LOOP: { |
Lightvalve | 55:f4819de54e7a | 1540 | V_out = (float) Vout.ref; |
Lightvalve | 55:f4819de54e7a | 1541 | break; |
Lightvalve | 55:f4819de54e7a | 1542 | } |
Lightvalve | 14:8e7590227d22 | 1543 | |
Lightvalve | 12:6f2531038ea4 | 1544 | default: |
Lightvalve | 12:6f2531038ea4 | 1545 | break; |
Lightvalve | 12:6f2531038ea4 | 1546 | } |
Lightvalve | 14:8e7590227d22 | 1547 | |
Lightvalve | 55:f4819de54e7a | 1548 | |
Lightvalve | 55:f4819de54e7a | 1549 | if (((OPERATING_MODE&0b110)>>1) == 0 || ((OPERATING_MODE&0b110)>>1) == 1) { //Moog Valve or KNR Valve |
Lightvalve | 56:2eade98630e2 | 1550 | |
Lightvalve | 55:f4819de54e7a | 1551 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 55:f4819de54e7a | 1552 | //////////////////////////// CURRENT CONTROL ////////////////////////////// |
Lightvalve | 55:f4819de54e7a | 1553 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 55:f4819de54e7a | 1554 | if (CURRENT_CONTROL_MODE) { |
Lightvalve | 55:f4819de54e7a | 1555 | double alpha_update_Iref = 1.0f / (1.0f + TMR_FREQ_5k / (2.0f * 3.14f * 300.0f)); // f_cutoff : 500Hz |
Lightvalve | 55:f4819de54e7a | 1556 | I_REF_fil = (1.0f - alpha_update_Iref) * I_REF_fil + alpha_update_Iref*I_REF; |
Lightvalve | 55:f4819de54e7a | 1557 | |
Lightvalve | 55:f4819de54e7a | 1558 | I_ERR = I_REF_fil - cur.sen; |
Lightvalve | 55:f4819de54e7a | 1559 | I_ERR_INT = I_ERR_INT + (I_ERR) * DT_TMR3; |
Lightvalve | 55:f4819de54e7a | 1560 | |
Lightvalve | 55:f4819de54e7a | 1561 | |
Lightvalve | 55:f4819de54e7a | 1562 | // Moog Valve Current Control Gain |
Lightvalve | 55:f4819de54e7a | 1563 | double R_model = 539.0f; // ohm |
Lightvalve | 55:f4819de54e7a | 1564 | double L_model = 1.2f; |
Lightvalve | 55:f4819de54e7a | 1565 | double w0 = 2.0f * 3.14f * 150.0f; |
Lightvalve | 55:f4819de54e7a | 1566 | double KP_I = 0.1f * L_model*w0; |
Lightvalve | 55:f4819de54e7a | 1567 | double KI_I = 0.1f * R_model*w0; |
Lightvalve | 55:f4819de54e7a | 1568 | |
Lightvalve | 55:f4819de54e7a | 1569 | // KNR Valve Current Control Gain |
Lightvalve | 55:f4819de54e7a | 1570 | if (((OPERATING_MODE & 0b110)>>1) == 1) { // KNR Valve |
Lightvalve | 55:f4819de54e7a | 1571 | R_model = 163.0f; // ohm |
Lightvalve | 55:f4819de54e7a | 1572 | L_model = 1.0f; |
Lightvalve | 55:f4819de54e7a | 1573 | w0 = 2.0f * 3.14f * 80.0f; |
Lightvalve | 55:f4819de54e7a | 1574 | KP_I = 1.0f * L_model*w0; |
Lightvalve | 55:f4819de54e7a | 1575 | KI_I = 0.08f * R_model*w0; |
Lightvalve | 55:f4819de54e7a | 1576 | } |
Lightvalve | 55:f4819de54e7a | 1577 | |
Lightvalve | 55:f4819de54e7a | 1578 | double FF_gain = 1.0f; |
Lightvalve | 55:f4819de54e7a | 1579 | |
Lightvalve | 55:f4819de54e7a | 1580 | VALVE_PWM_RAW = KP_I * I_ERR + KI_I * I_ERR_INT; |
Lightvalve | 55:f4819de54e7a | 1581 | // VALVE_PWM_RAW = VALVE_PWM_RAW + FF_gain * (R_model*I_REF); // Unit : mV |
Lightvalve | 55:f4819de54e7a | 1582 | I_REF_fil_diff = I_REF_fil - I_REF_fil_old; |
Lightvalve | 55:f4819de54e7a | 1583 | I_REF_fil_old = I_REF_fil; |
Lightvalve | 55:f4819de54e7a | 1584 | VALVE_PWM_RAW = VALVE_PWM_RAW + FF_gain * (R_model * I_REF_fil + L_model * I_REF_fil_diff * TMR_FREQ_5k); // Unit : mV |
Lightvalve | 55:f4819de54e7a | 1585 | double V_MAX = 12000.; // Maximum Voltage : 12V = 12000mV |
Lightvalve | 55:f4819de54e7a | 1586 | |
Lightvalve | 55:f4819de54e7a | 1587 | double Ka = 3.0f / KP_I; |
Lightvalve | 55:f4819de54e7a | 1588 | if (VALVE_PWM_RAW > V_MAX) { |
Lightvalve | 55:f4819de54e7a | 1589 | V_rem = VALVE_PWM_RAW - V_MAX; |
Lightvalve | 55:f4819de54e7a | 1590 | V_rem = Ka*V_rem; |
Lightvalve | 55:f4819de54e7a | 1591 | VALVE_PWM_RAW = V_MAX; |
Lightvalve | 55:f4819de54e7a | 1592 | I_ERR_INT = I_ERR_INT - V_rem * DT_TMR3; |
Lightvalve | 55:f4819de54e7a | 1593 | } else if (VALVE_PWM_RAW < -V_MAX) { |
Lightvalve | 55:f4819de54e7a | 1594 | V_rem = VALVE_PWM_RAW - (-V_MAX); |
Lightvalve | 55:f4819de54e7a | 1595 | V_rem = Ka*V_rem; |
Lightvalve | 55:f4819de54e7a | 1596 | VALVE_PWM_RAW = -V_MAX; |
Lightvalve | 55:f4819de54e7a | 1597 | I_ERR_INT = I_ERR_INT - V_rem * DT_TMR3; |
Lightvalve | 55:f4819de54e7a | 1598 | } |
Lightvalve | 55:f4819de54e7a | 1599 | Cur_Valve_Open_pulse = cur.sen / mA_PER_pulse; |
Lightvalve | 55:f4819de54e7a | 1600 | } else { |
Lightvalve | 55:f4819de54e7a | 1601 | VALVE_PWM_RAW = I_REF * mV_PER_mA; |
Lightvalve | 55:f4819de54e7a | 1602 | Cur_Valve_Open_pulse = I_REF / mA_PER_pulse; |
Lightvalve | 55:f4819de54e7a | 1603 | } |
Lightvalve | 55:f4819de54e7a | 1604 | |
Lightvalve | 55:f4819de54e7a | 1605 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 55:f4819de54e7a | 1606 | ///////////////// Dead Zone Cancellation & Linearization ////////////////// |
Lightvalve | 55:f4819de54e7a | 1607 | //////////////////////////////////////////////////////////////////////////// |
Lightvalve | 55:f4819de54e7a | 1608 | // Dead Zone Cancellation (Mechanical Valve dead-zone) |
Lightvalve | 55:f4819de54e7a | 1609 | if (FLAG_VALVE_DEADZONE) { |
Lightvalve | 55:f4819de54e7a | 1610 | if (VALVE_PWM_RAW > 0) VALVE_PWM_RAW = VALVE_PWM_RAW + VALVE_DEADZONE_PLUS * mV_PER_pulse; // unit: mV |
Lightvalve | 55:f4819de54e7a | 1611 | else if (VALVE_PWM_RAW < 0) VALVE_PWM_RAW = VALVE_PWM_RAW + VALVE_DEADZONE_MINUS * mV_PER_pulse; // unit: mV |
Lightvalve | 55:f4819de54e7a | 1612 | |
Lightvalve | 55:f4819de54e7a | 1613 | VALVE_PWM_VALVE_DZ = VALVE_PWM_RAW + (double)VALVE_CENTER * mV_PER_pulse; // unit: mV |
Lightvalve | 55:f4819de54e7a | 1614 | |
Lightvalve | 55:f4819de54e7a | 1615 | } else { |
Lightvalve | 55:f4819de54e7a | 1616 | VALVE_PWM_VALVE_DZ = VALVE_PWM_RAW; |
Lightvalve | 55:f4819de54e7a | 1617 | } |
Lightvalve | 55:f4819de54e7a | 1618 | |
Lightvalve | 55:f4819de54e7a | 1619 | // Output Voltage Linearization |
Lightvalve | 55:f4819de54e7a | 1620 | double CUR_PWM_nonlin = VALVE_PWM_VALVE_DZ; // Unit : mV |
Lightvalve | 55:f4819de54e7a | 1621 | double CUR_PWM_lin = PWM_duty_byLT(CUR_PWM_nonlin); |
Lightvalve | 55:f4819de54e7a | 1622 | |
Lightvalve | 55:f4819de54e7a | 1623 | // Dead Zone Cancellation (Electrical dead-zone) |
Lightvalve | 55:f4819de54e7a | 1624 | if (CUR_PWM_lin > 0) V_out = (int) CUR_PWM_lin + 140; |
Lightvalve | 55:f4819de54e7a | 1625 | else if (CUR_PWM_lin < 0) V_out = (int) CUR_PWM_lin - 140; |
Lightvalve | 55:f4819de54e7a | 1626 | else V_out = CUR_PWM_lin; |
Lightvalve | 55:f4819de54e7a | 1627 | } |
Lightvalve | 56:2eade98630e2 | 1628 | |
Lightvalve | 56:2eade98630e2 | 1629 | |
Lightvalve | 14:8e7590227d22 | 1630 | |
jobuuu | 7:e9086c72bb22 | 1631 | /******************************************************* |
jobuuu | 7:e9086c72bb22 | 1632 | *** PWM |
jobuuu | 7:e9086c72bb22 | 1633 | ********************************************************/ |
Lightvalve | 48:e7bcfc244d40 | 1634 | if (V_out >= VALVE_VOLTAGE_LIMIT*1000.0f) { |
Lightvalve | 48:e7bcfc244d40 | 1635 | V_out = VALVE_VOLTAGE_LIMIT*1000.0f; |
Lightvalve | 48:e7bcfc244d40 | 1636 | } else if(V_out<=-VALVE_VOLTAGE_LIMIT*1000.0f) { |
Lightvalve | 48:e7bcfc244d40 | 1637 | V_out = -VALVE_VOLTAGE_LIMIT*1000.0f; |
Lightvalve | 27:a2254a485f23 | 1638 | } |
Lightvalve | 48:e7bcfc244d40 | 1639 | PWM_out= V_out/(SUPPLY_VOLTAGE*1000.0f); // Full duty : 12000.0mV |
Lightvalve | 13:747daba9cf59 | 1640 | |
Lightvalve | 19:23b7c1ad8683 | 1641 | // Saturation of output voltage to 12.0V |
Lightvalve | 30:8d561f16383b | 1642 | if(PWM_out > 1.0f) PWM_out=1.0f; |
Lightvalve | 30:8d561f16383b | 1643 | else if (PWM_out < -1.0f) PWM_out=-1.0f; |
Lightvalve | 13:747daba9cf59 | 1644 | |
Lightvalve | 30:8d561f16383b | 1645 | if (PWM_out>0.0f) { |
Lightvalve | 30:8d561f16383b | 1646 | dtc_v=0.0f; |
jobuuu | 1:e04e563be5ce | 1647 | dtc_w=PWM_out; |
jobuuu | 1:e04e563be5ce | 1648 | } else { |
jobuuu | 2:a1c0a37df760 | 1649 | dtc_v=-PWM_out; |
Lightvalve | 30:8d561f16383b | 1650 | dtc_w=0.0f; |
jobuuu | 1:e04e563be5ce | 1651 | } |
Lightvalve | 13:747daba9cf59 | 1652 | |
jobuuu | 1:e04e563be5ce | 1653 | //pwm |
Lightvalve | 30:8d561f16383b | 1654 | TIM4->CCR2 = (PWM_ARR)*(1.0f-dtc_v); |
Lightvalve | 30:8d561f16383b | 1655 | TIM4->CCR1 = (PWM_ARR)*(1.0f-dtc_w); |
Lightvalve | 59:bc8c8270f0ab | 1656 | |
Lightvalve | 59:bc8c8270f0ab | 1657 | |
Lightvalve | 55:f4819de54e7a | 1658 | if (TMR2_COUNT_CAN_TX % (int) ((int) TMR_FREQ_5k/CAN_FREQ) == 0) { |
Lightvalve | 20:806196fda269 | 1659 | |
Lightvalve | 52:647072f5307a | 1660 | // Position, Velocity, and Torque (ID:1200) |
Lightvalve | 54:6f50d9d3bfee | 1661 | if (flag_data_request[0] == HIGH) { |
Lightvalve | 55:f4819de54e7a | 1662 | if ((OPERATING_MODE & 0b01) == 0) { // Rotary Actuator |
Lightvalve | 52:647072f5307a | 1663 | if (SENSING_MODE == 0) { |
Lightvalve | 56:2eade98630e2 | 1664 | CAN_TX_POSITION_FT((int16_t) (pos.sen), (int16_t) (vel.sen/10.0f), (int16_t) (pres_A.sen*10.0f)); |
Lightvalve | 52:647072f5307a | 1665 | } else if (SENSING_MODE == 1) { |
Lightvalve | 56:2eade98630e2 | 1666 | 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 | 52:647072f5307a | 1667 | } |
Lightvalve | 55:f4819de54e7a | 1668 | } else if ((OPERATING_MODE & 0b01) == 1) { // Linear Actuator |
Lightvalve | 52:647072f5307a | 1669 | if (SENSING_MODE == 0) { |
Lightvalve | 58:64181f1d3e60 | 1670 | CAN_TX_POSITION_FT((int16_t) (pos.sen/4.0f), (int16_t) (vel.sen/100.0f), (int16_t) (pres_A.sen)); |
Lightvalve | 52:647072f5307a | 1671 | } else if (SENSING_MODE == 1) { |
Lightvalve | 56:2eade98630e2 | 1672 | CAN_TX_POSITION_PRESSURE((int16_t) (pos.sen/4.0f), (int16_t) (vel.sen/100.0f), (int16_t) ((pres_A.sen)*5.0f), (int16_t) ((pres_B.sen)*5.0f)); |
Lightvalve | 52:647072f5307a | 1673 | } |
Lightvalve | 51:8ea76864368a | 1674 | } |
Lightvalve | 51:8ea76864368a | 1675 | } |
Lightvalve | 54:6f50d9d3bfee | 1676 | if (flag_data_request[1] == HIGH) { |
Lightvalve | 52:647072f5307a | 1677 | //valve position |
Lightvalve | 52:647072f5307a | 1678 | double t_value = 0; |
Lightvalve | 55:f4819de54e7a | 1679 | // if(value>=(float) VALVE_CENTER) { |
Lightvalve | 55:f4819de54e7a | 1680 | // t_value = 10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); |
Lightvalve | 55:f4819de54e7a | 1681 | // } else { |
Lightvalve | 55:f4819de54e7a | 1682 | // t_value = -10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); |
Lightvalve | 64:a8e6799dbce3 | 1683 | // } |
Lightvalve | 64:a8e6799dbce3 | 1684 | |
Lightvalve | 56:2eade98630e2 | 1685 | if(OPERATING_MODE==5) { |
Lightvalve | 55:f4819de54e7a | 1686 | t_value = (double) value; |
Lightvalve | 56:2eade98630e2 | 1687 | } else if(CURRENT_CONTROL_MODE==1) { |
Lightvalve | 55:f4819de54e7a | 1688 | t_value = cur.sen; |
Lightvalve | 56:2eade98630e2 | 1689 | } else { |
Lightvalve | 55:f4819de54e7a | 1690 | t_value = V_out; |
Lightvalve | 52:647072f5307a | 1691 | } |
Lightvalve | 58:64181f1d3e60 | 1692 | CAN_TX_TORQUE((int16_t) (t_value), (int16_t) (V_out)); //1300 |
Lightvalve | 52:647072f5307a | 1693 | } |
Lightvalve | 56:2eade98630e2 | 1694 | |
Lightvalve | 56:2eade98630e2 | 1695 | |
Lightvalve | 54:6f50d9d3bfee | 1696 | if (flag_data_request[2] == HIGH) { |
Lightvalve | 54:6f50d9d3bfee | 1697 | //pressure A and B |
Lightvalve | 55:f4819de54e7a | 1698 | CAN_TX_PRES((int16_t) (pres_A.sen), (int16_t) (pres_B.sen)); // CUR_PRES_X : 0(0bar)~4096(210bar) //1400 |
Lightvalve | 53:b25725257569 | 1699 | } |
Lightvalve | 56:2eade98630e2 | 1700 | |
Lightvalve | 55:f4819de54e7a | 1701 | //If it doesn't rest, below can can not work. |
Lightvalve | 55:f4819de54e7a | 1702 | for (can_rest = 0; can_rest < 10000; can_rest++) { |
Lightvalve | 55:f4819de54e7a | 1703 | ; |
Lightvalve | 55:f4819de54e7a | 1704 | } |
Lightvalve | 56:2eade98630e2 | 1705 | |
Lightvalve | 54:6f50d9d3bfee | 1706 | if (flag_data_request[3] == HIGH) { |
Lightvalve | 52:647072f5307a | 1707 | //PWM |
Lightvalve | 55:f4819de54e7a | 1708 | CAN_TX_PWM((int16_t) cur.sen); //1500 |
Lightvalve | 52:647072f5307a | 1709 | } |
Lightvalve | 55:f4819de54e7a | 1710 | //for (i = 0; i < 10000; i++) { |
Lightvalve | 55:f4819de54e7a | 1711 | // ; |
Lightvalve | 55:f4819de54e7a | 1712 | // } |
Lightvalve | 54:6f50d9d3bfee | 1713 | if (flag_data_request[4] == HIGH) { |
Lightvalve | 52:647072f5307a | 1714 | //valve position |
Lightvalve | 55:f4819de54e7a | 1715 | CAN_TX_VALVE_POSITION((int16_t) (CAN_FREQ), (int16_t) (D_DAMPER), (int16_t) OPERATING_MODE); //1600 |
Lightvalve | 52:647072f5307a | 1716 | } |
Lightvalve | 20:806196fda269 | 1717 | |
Lightvalve | 52:647072f5307a | 1718 | // Others : Reference position, Reference FT, PWM, Current (ID:1300) |
Lightvalve | 51:8ea76864368a | 1719 | // if (flag_data_request[1] == HIGH) { |
Lightvalve | 51:8ea76864368a | 1720 | // CAN_TX_SOMETHING((int) (FORCE_VREF), (int16_t) (1), (int16_t) (2), (int16_t) (3)); |
Lightvalve | 51:8ea76864368a | 1721 | // } |
Lightvalve | 52:647072f5307a | 1722 | //if (flag_delay_test == 1){ |
Lightvalve | 56:2eade98630e2 | 1723 | //CAN_TX_PRES((int16_t) (0),(int16_t) torq_ref); |
Lightvalve | 52:647072f5307a | 1724 | //} |
Lightvalve | 51:8ea76864368a | 1725 | |
Lightvalve | 52:647072f5307a | 1726 | TMR2_COUNT_CAN_TX = 0; |
Lightvalve | 52:647072f5307a | 1727 | } |
Lightvalve | 52:647072f5307a | 1728 | TMR2_COUNT_CAN_TX++; |
Lightvalve | 51:8ea76864368a | 1729 | |
Lightvalve | 20:806196fda269 | 1730 | } |
Lightvalve | 51:8ea76864368a | 1731 | TIM3->SR = 0x0; // reset the status register |
Lightvalve | 51:8ea76864368a | 1732 | |
Lightvalve | 56:2eade98630e2 | 1733 | } |