Sungwoo Kim
/
HydraulicControlBoard_Learning
for learning
Diff: main.cpp
- Revision:
- 169:645207e160ca
- Parent:
- 168:f05a45d5f318
- Child:
- 170:42c938a40313
diff -r f05a45d5f318 -r 645207e160ca main.cpp --- a/main.cpp Fri Oct 16 00:25:32 2020 +0000 +++ b/main.cpp Mon Nov 16 02:23:23 2020 +0000 @@ -1,4 +1,4 @@ -//201016_1 +//201116_1 #include "mbed.h" #include "FastPWM.h" #include "INIT_HW.h" @@ -8,7 +8,7 @@ #include "setting.h" #include "function_utilities.h" #include "stm32f4xx_flash.h" -#include "FlashWriter.h" +#include "FlashWriter.h" using namespace std; Timer t; @@ -136,52 +136,53 @@ MODE_DDV_DEADZONE_AND_CENTER, //31 MODE_DDV_POS_VS_FLOWRATE, //32 MODE_SYSTEM_ID, //33 + MODE_FREQ_TEST, //34 + MODE_SEND_BUFFER, //35 + MODE_SEND_OVER, //36 + MODE_STEP_TEST, //37 }; void SystemClock_Config(void) { - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - /** Configure the main internal regulator output voltage - */ - __HAL_RCC_PWR_CLK_ENABLE(); - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); - /** Initializes the CPU, AHB and APB busses clocks - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; - RCC_OscInitStruct.PLL.PLLM = 8;//8 - RCC_OscInitStruct.PLL.PLLN = 180; //180 - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = 2; - RCC_OscInitStruct.PLL.PLLR = 2; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - //Error_Handler(); - } - /** Activate the Over-Drive mode - */ - if (HAL_PWREx_EnableOverDrive() != HAL_OK) - { - //Error_Handler(); - } - /** Initializes the CPU, AHB and APB busses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; + /** Configure the main internal regulator output voltage + */ + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); + /** Initializes the CPU, AHB and APB busses clocks + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; + RCC_OscInitStruct.PLL.PLLM = 8;//8 + RCC_OscInitStruct.PLL.PLLN = 180; //180 + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 2; + RCC_OscInitStruct.PLL.PLLR = 2; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + //Error_Handler(); + } + /** Activate the Over-Drive mode + */ + if (HAL_PWREx_EnableOverDrive() != HAL_OK) { + //Error_Handler(); + } + /** Initializes the CPU, AHB and APB busses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) - { - //Error_Handler(); - } + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { + //Error_Handler(); + } } float u_past[num_array_u_past] = {0.0f}; @@ -192,62 +193,62 @@ float input_NN[num_input] = { 0.0f }; -const float h1[num_input][16] = { - {-1.3752100467681885f,0.9850414395332336f,0.12903714179992676f,-0.23237967491149902f,-1.5664141178131104f,0.36565715074539185f,-0.17472904920578003f,-0.3780243396759033f,-0.5318458676338196f,-0.6931207776069641f,-0.24376395344734192f,-3.9280478954315186f,-0.259793758392334f,-0.5339483022689819f,-0.2571594715118408f,-0.4960939884185791f}, -{-1.184814453125f,0.8704654574394226f,-0.3927857577800751f,-0.40050771832466125f,-1.4921096563339233f,0.5157514810562134f,-0.4054011106491089f,-0.3723553717136383f,-0.264297217130661f,-0.4598728120326996f,-0.2805407643318176f,-2.543855905532837f,0.24001067876815796f,-0.9143947958946228f,-0.20967772603034973f,-0.46271881461143494f}, -{-0.9112814664840698f,0.6714562773704529f,0.36391180753707886f,-0.6117674708366394f,-1.1069424152374268f,0.9712548851966858f,0.2872133255004883f,-0.059537652879953384f,-0.28272250294685364f,-0.4464949667453766f,-0.3544096052646637f,-1.0609019994735718f,0.0019771659281104803f,-0.2590618431568146f,0.05590221285820007f,-1.0201798677444458f}, -{-0.2895396053791046f,-0.01403216365724802f,0.39742106199264526f,0.20069332420825958f,-0.6715657114982605f,0.5361601710319519f,-0.11584559082984924f,0.3479021489620209f,-0.01779201813042164f,-0.017457854002714157f,0.08943979442119598f,0.845181941986084f,-0.15994226932525635f,-0.14522784948349f,-0.2961459457874298f,-0.7345172166824341f}, -{1.1968307495117188f,-0.8280011415481567f,-0.0051451027393341064f,0.39627134799957275f,0.3181920051574707f,-0.05303953215479851f,0.1294034719467163f,0.16528914868831635f,0.07129872590303421f,0.7101694941520691f,0.34140077233314514f,1.623598575592041f,-0.06323867291212082f,0.27155500650405884f,-0.3865056037902832f,-0.30631402134895325f}, -{3.009206533432007f,-3.122997522354126f,0.21773302555084229f,0.7692314386367798f,2.249300003051758f,-2.275317907333374f,0.16514194011688232f,0.11058115214109421f,0.17132356762886047f,2.417614459991455f,-0.25413116812705994f,2.2743594646453857f,-0.25959381461143494f,0.8003392219543457f,-0.4132833778858185f,1.4499995708465576f}, -{-0.7179104089736938f,0.8526995182037354f,-0.2501986622810364f,-0.875395655632019f,-0.5985659956932068f,2.8744397163391113f,0.06014183163642883f,-0.8439451456069946f,-0.05617062747478485f,-0.640657901763916f,0.14294663071632385f,3.381211519241333f,-0.1638868898153305f,-0.2370987981557846f,-0.15618428587913513f,-0.7710326910018921f}, -{-0.5504567623138428f,0.25199615955352783f,-0.26619744300842285f,-0.08971554040908813f,-0.3043712079524994f,0.903326153755188f,-0.17925891280174255f,-0.6943695545196533f,-0.25526830554008484f,0.20558907091617584f,0.09723648428916931f,2.3618743419647217f,0.38060376048088074f,-0.1769549399614334f,0.04303058981895447f,-0.12222103029489517f}, -{0.06810358166694641f,0.17962348461151123f,0.10248100757598877f,-0.30372604727745056f,0.4354613721370697f,-0.7276828289031982f,-0.07246989011764526f,-0.6118704676628113f,-0.42743170261383057f,1.453460693359375f,-0.30540645122528076f,1.6834946870803833f,0.23858578503131866f,0.21455851197242737f,-0.30555272102355957f,0.8063939213752747f}, -{-0.0713198110461235f,-0.4495846927165985f,0.18462657928466797f,0.05500239133834839f,0.7719969153404236f,-1.2848507165908813f,-0.2990540862083435f,-0.22474081814289093f,-0.1015893891453743f,0.7663454413414001f,-0.016399379819631577f,-0.03539150580763817f,0.38201630115509033f,-0.09081173688173294f,0.3484981060028076f,0.7820040583610535f}, -{0.33533185720443726f,0.13371603190898895f,0.37182438373565674f,0.39484986662864685f,0.35771995782852173f,-1.3015228509902954f,-0.20339298248291016f,-0.14145439863204956f,-0.5059540271759033f,0.8015591502189636f,0.34025880694389343f,-0.6485148072242737f,-0.05657690018415451f,0.09265313297510147f,0.26688337326049805f,0.2284013032913208f}, -{-0.4380135238170624f,-0.15535405278205872f,-0.40320003032684326f,0.0452105812728405f,0.23505118489265442f,-0.8950125575065613f,0.1533789038658142f,0.1997886300086975f,-0.24218705296516418f,0.45601460337638855f,-0.42232224345207214f,-0.5756524205207825f,0.15488487482070923f,-0.013335001654922962f,0.10493969917297363f,0.23898905515670776f}, -{-0.02198643982410431f,0.009633726440370083f,0.19847965240478516f,0.0860355794429779f,0.336037278175354f,-0.277248352766037f,-0.2404318004846573f,-0.07731665670871735f,-0.2765587270259857f,-0.1708865910768509f,-0.11712735891342163f,-0.7335506677627563f,0.10241620987653732f,-0.06552530825138092f,-0.22268100082874298f,-0.13819573819637299f}, -{0.020149538293480873f,-0.03840681165456772f,0.4127817749977112f,-0.2523573637008667f,-0.21765978634357452f,-0.4540342092514038f,-0.32001304626464844f,-0.5396589040756226f,-0.21919101476669312f,-0.2550864815711975f,-0.20302052795886993f,-0.2918916642665863f,-0.3021690249443054f,-0.19007131457328796f,0.0479682981967926f,0.28083792328834534f}, -{0.19955825805664062f,0.13080951571464539f,0.20282304286956787f,-0.21126452088356018f,0.15339018404483795f,-0.06708966940641403f,0.04202890396118164f,0.06752092391252518f,0.25217023491859436f,-0.20238792896270752f,-0.2873592674732208f,-0.42253321409225464f,0.11435109376907349f,-0.2376958578824997f,0.0668090283870697f,0.04261681064963341f}, -{-0.03747318685054779f,-0.29164087772369385f,-0.40439701080322266f,-0.3783135414123535f,-0.40124887228012085f,-0.026558339595794678f,-0.15568238496780396f,-0.08766567707061768f,0.21709603071212769f,-0.35802650451660156f,-0.4817592203617096f,-0.3809756338596344f,-0.2601439654827118f,-0.1273980438709259f,-0.08245879411697388f,0.014104350470006466f}, -{0.16147102415561676f,-0.5628581643104553f,0.16706281900405884f,-0.1172998696565628f,-0.03297983109951019f,-0.9104568362236023f,-0.041414469480514526f,0.1465616226196289f,0.04248951002955437f,0.007101915311068296f,-0.3614332377910614f,-0.48312774300575256f,0.12316523492336273f,0.3939219117164612f,0.29427415132522583f,0.3038717210292816f}, +const float h1[num_input][16] = { + {-1.3752100467681885f,0.9850414395332336f,0.12903714179992676f,-0.23237967491149902f,-1.5664141178131104f,0.36565715074539185f,-0.17472904920578003f,-0.3780243396759033f,-0.5318458676338196f,-0.6931207776069641f,-0.24376395344734192f,-3.9280478954315186f,-0.259793758392334f,-0.5339483022689819f,-0.2571594715118408f,-0.4960939884185791f}, + {-1.184814453125f,0.8704654574394226f,-0.3927857577800751f,-0.40050771832466125f,-1.4921096563339233f,0.5157514810562134f,-0.4054011106491089f,-0.3723553717136383f,-0.264297217130661f,-0.4598728120326996f,-0.2805407643318176f,-2.543855905532837f,0.24001067876815796f,-0.9143947958946228f,-0.20967772603034973f,-0.46271881461143494f}, + {-0.9112814664840698f,0.6714562773704529f,0.36391180753707886f,-0.6117674708366394f,-1.1069424152374268f,0.9712548851966858f,0.2872133255004883f,-0.059537652879953384f,-0.28272250294685364f,-0.4464949667453766f,-0.3544096052646637f,-1.0609019994735718f,0.0019771659281104803f,-0.2590618431568146f,0.05590221285820007f,-1.0201798677444458f}, + {-0.2895396053791046f,-0.01403216365724802f,0.39742106199264526f,0.20069332420825958f,-0.6715657114982605f,0.5361601710319519f,-0.11584559082984924f,0.3479021489620209f,-0.01779201813042164f,-0.017457854002714157f,0.08943979442119598f,0.845181941986084f,-0.15994226932525635f,-0.14522784948349f,-0.2961459457874298f,-0.7345172166824341f}, + {1.1968307495117188f,-0.8280011415481567f,-0.0051451027393341064f,0.39627134799957275f,0.3181920051574707f,-0.05303953215479851f,0.1294034719467163f,0.16528914868831635f,0.07129872590303421f,0.7101694941520691f,0.34140077233314514f,1.623598575592041f,-0.06323867291212082f,0.27155500650405884f,-0.3865056037902832f,-0.30631402134895325f}, + {3.009206533432007f,-3.122997522354126f,0.21773302555084229f,0.7692314386367798f,2.249300003051758f,-2.275317907333374f,0.16514194011688232f,0.11058115214109421f,0.17132356762886047f,2.417614459991455f,-0.25413116812705994f,2.2743594646453857f,-0.25959381461143494f,0.8003392219543457f,-0.4132833778858185f,1.4499995708465576f}, + {-0.7179104089736938f,0.8526995182037354f,-0.2501986622810364f,-0.875395655632019f,-0.5985659956932068f,2.8744397163391113f,0.06014183163642883f,-0.8439451456069946f,-0.05617062747478485f,-0.640657901763916f,0.14294663071632385f,3.381211519241333f,-0.1638868898153305f,-0.2370987981557846f,-0.15618428587913513f,-0.7710326910018921f}, + {-0.5504567623138428f,0.25199615955352783f,-0.26619744300842285f,-0.08971554040908813f,-0.3043712079524994f,0.903326153755188f,-0.17925891280174255f,-0.6943695545196533f,-0.25526830554008484f,0.20558907091617584f,0.09723648428916931f,2.3618743419647217f,0.38060376048088074f,-0.1769549399614334f,0.04303058981895447f,-0.12222103029489517f}, + {0.06810358166694641f,0.17962348461151123f,0.10248100757598877f,-0.30372604727745056f,0.4354613721370697f,-0.7276828289031982f,-0.07246989011764526f,-0.6118704676628113f,-0.42743170261383057f,1.453460693359375f,-0.30540645122528076f,1.6834946870803833f,0.23858578503131866f,0.21455851197242737f,-0.30555272102355957f,0.8063939213752747f}, + {-0.0713198110461235f,-0.4495846927165985f,0.18462657928466797f,0.05500239133834839f,0.7719969153404236f,-1.2848507165908813f,-0.2990540862083435f,-0.22474081814289093f,-0.1015893891453743f,0.7663454413414001f,-0.016399379819631577f,-0.03539150580763817f,0.38201630115509033f,-0.09081173688173294f,0.3484981060028076f,0.7820040583610535f}, + {0.33533185720443726f,0.13371603190898895f,0.37182438373565674f,0.39484986662864685f,0.35771995782852173f,-1.3015228509902954f,-0.20339298248291016f,-0.14145439863204956f,-0.5059540271759033f,0.8015591502189636f,0.34025880694389343f,-0.6485148072242737f,-0.05657690018415451f,0.09265313297510147f,0.26688337326049805f,0.2284013032913208f}, + {-0.4380135238170624f,-0.15535405278205872f,-0.40320003032684326f,0.0452105812728405f,0.23505118489265442f,-0.8950125575065613f,0.1533789038658142f,0.1997886300086975f,-0.24218705296516418f,0.45601460337638855f,-0.42232224345207214f,-0.5756524205207825f,0.15488487482070923f,-0.013335001654922962f,0.10493969917297363f,0.23898905515670776f}, + {-0.02198643982410431f,0.009633726440370083f,0.19847965240478516f,0.0860355794429779f,0.336037278175354f,-0.277248352766037f,-0.2404318004846573f,-0.07731665670871735f,-0.2765587270259857f,-0.1708865910768509f,-0.11712735891342163f,-0.7335506677627563f,0.10241620987653732f,-0.06552530825138092f,-0.22268100082874298f,-0.13819573819637299f}, + {0.020149538293480873f,-0.03840681165456772f,0.4127817749977112f,-0.2523573637008667f,-0.21765978634357452f,-0.4540342092514038f,-0.32001304626464844f,-0.5396589040756226f,-0.21919101476669312f,-0.2550864815711975f,-0.20302052795886993f,-0.2918916642665863f,-0.3021690249443054f,-0.19007131457328796f,0.0479682981967926f,0.28083792328834534f}, + {0.19955825805664062f,0.13080951571464539f,0.20282304286956787f,-0.21126452088356018f,0.15339018404483795f,-0.06708966940641403f,0.04202890396118164f,0.06752092391252518f,0.25217023491859436f,-0.20238792896270752f,-0.2873592674732208f,-0.42253321409225464f,0.11435109376907349f,-0.2376958578824997f,0.0668090283870697f,0.04261681064963341f}, + {-0.03747318685054779f,-0.29164087772369385f,-0.40439701080322266f,-0.3783135414123535f,-0.40124887228012085f,-0.026558339595794678f,-0.15568238496780396f,-0.08766567707061768f,0.21709603071212769f,-0.35802650451660156f,-0.4817592203617096f,-0.3809756338596344f,-0.2601439654827118f,-0.1273980438709259f,-0.08245879411697388f,0.014104350470006466f}, + {0.16147102415561676f,-0.5628581643104553f,0.16706281900405884f,-0.1172998696565628f,-0.03297983109951019f,-0.9104568362236023f,-0.041414469480514526f,0.1465616226196289f,0.04248951002955437f,0.007101915311068296f,-0.3614332377910614f,-0.48312774300575256f,0.12316523492336273f,0.3939219117164612f,0.29427415132522583f,0.3038717210292816f}, }; -const float h2[16][16] = { +const float h2[16][16] = { {0.33418041467666626f,2.9079723358154297f,-0.06966331601142883f,-0.009902028366923332f,2.812035322189331f,4.195849418640137f,-0.038234543055295944f,0.0904630720615387f,-0.43008196353912354f,-0.1415480375289917f,0.10707370936870575f,-0.20333009958267212f,-0.031739287078380585f,-3.289416551589966f,-1.172767996788025f,-0.6248859763145447f}, -{0.11070519685745239f,-2.3348469734191895f,0.057057321071624756f,-0.10134492069482803f,-5.252432346343994f,-1.3715343475341797f,-0.8426902890205383f,-0.2990124225616455f,-0.33757925033569336f,0.2895788848400116f,-7.361403465270996f,-0.858361005783081f,0.0845860168337822f,2.2169580459594727f,-3.0816471576690674f,-1.0190033912658691f}, -{-0.22745239734649658f,0.003037691116333008f,-0.061119019985198975f,0.35696902871131897f,0.05568113923072815f,0.011741191148757935f,-0.20225946605205536f,-0.08465918898582458f,0.3489862382411957f,0.0687277615070343f,0.31964078545570374f,0.3004753887653351f,0.36063823103904724f,-0.42892736196517944f,0.08652284741401672f,0.027493387460708618f}, -{-0.1391567885875702f,0.03293241187930107f,-0.2894435524940491f,0.25554025173187256f,0.08946844935417175f,0.1340968757867813f,-0.39087218046188354f,0.4122363030910492f,0.26211628317832947f,0.2953031361103058f,0.7025435566902161f,0.05798906087875366f,-0.5013425946235657f,-0.030901746824383736f,-0.06675297021865845f,-0.0446302704513073f}, -{-2.245600938796997f,1.6008015871047974f,-0.25313520431518555f,0.1469619870185852f,1.6072996854782104f,-1.3637473583221436f,-0.5957030653953552f,-0.08570799231529236f,-0.024399548768997192f,-0.39465832710266113f,-6.811410427093506f,-0.7977238893508911f,-0.022602174431085587f,-1.6454986333847046f,0.5441725850105286f,-0.7979243397712708f}, -{0.5210384130477905f,-0.11346126347780228f,-0.3519742488861084f,0.29306867718696594f,-0.3572634160518646f,1.75344979763031f,-0.744201123714447f,-0.019414573907852173f,-0.23047015070915222f,0.3579089343547821f,-2.398893117904663f,-0.48980283737182617f,-0.45957082509994507f,0.5487804412841797f,-0.7850930690765381f,-0.7663227319717407f}, -{-0.1828227937221527f,-0.02554568648338318f,-0.3260969817638397f,0.08422836661338806f,-0.38453540205955505f,-0.25432005524635315f,0.285016268491745f,0.12387624382972717f,-0.0982072651386261f,0.13111665844917297f,-0.03692615032196045f,-0.32796353101730347f,-0.21546880900859833f,0.049302369356155396f,-0.27088475227355957f,-0.4124959409236908f}, -{-0.007747650612145662f,0.3667842745780945f,0.33083590865135193f,-0.38213321566581726f,-0.14358049631118774f,-0.2546055316925049f,-0.09043094515800476f,-0.3003333508968353f,0.2600560486316681f,-0.37898191809654236f,0.49078798294067383f,-0.3058888614177704f,-0.31673234701156616f,0.44664251804351807f,-0.9339061975479126f,-0.1061311885714531f}, -{-0.17694538831710815f,0.1767565757036209f,-0.11379697918891907f,-0.07116051763296127f,0.041274964809417725f,-0.517110288143158f,-0.10284432768821716f,0.0019084513187408447f,0.06103590130805969f,-0.38046833872795105f,-0.3456110656261444f,-0.24793067574501038f,-0.4166972041130066f,-0.30618393421173096f,-0.33565962314605713f,-0.48154377937316895f}, -{0.5043365359306335f,0.1850307136774063f,-0.13502129912376404f,-0.25706031918525696f,-0.8451530337333679f,-0.9415315389633179f,-0.2777014970779419f,-0.3632148504257202f,-0.13619378209114075f,0.16938945651054382f,1.5622152090072632f,-0.19312366843223572f,0.1250869333744049f,-0.1843482404947281f,1.0270578861236572f,-0.5840676426887512f}, -{-0.25693249702453613f,-0.010147050023078918f,0.0457797646522522f,-0.3549601435661316f,-0.03321319818496704f,-0.4391511380672455f,0.17873415350914001f,-0.20421427488327026f,-0.050184011459350586f,0.12480869889259338f,-0.22192376852035522f,0.3545852601528168f,-0.3647043704986572f,0.4194667637348175f,-0.3910166025161743f,-0.2837793529033661f}, -{2.3816981315612793f,0.4564768075942993f,0.3954955041408539f,0.11254638433456421f,1.1973353624343872f,1.804193377494812f,-0.8583166599273682f,-0.11795541644096375f,0.3487861454486847f,-0.32520344853401184f,-1.3897980451583862f,-0.5921090841293335f,-0.14213289320468903f,-0.26851770281791687f,1.597784161567688f,-0.5877130031585693f}, -{-0.267646849155426f,-0.20429572463035583f,-0.15798500180244446f,0.3999568819999695f,-0.37393757700920105f,0.35770177841186523f,0.11292675137519836f,-0.2947862446308136f,-0.3764709532260895f,0.2424570620059967f,-0.10294663906097412f,-0.2837170362472534f,0.41839322447776794f,-0.02792874164879322f,-0.13706544041633606f,0.11999254673719406f}, -{0.2282707840204239f,-0.13254989683628082f,-0.2018718123435974f,-0.07019486278295517f,0.07545611262321472f,-0.33204764127731323f,-0.4035329520702362f,-0.21416273713111877f,-0.24509364366531372f,0.19522181153297424f,0.47974857687950134f,-0.8069085478782654f,-0.40297332406044006f,0.23708327114582062f,0.5259239673614502f,-0.3548051416873932f}, -{0.4138670265674591f,0.1604653298854828f,0.056746453046798706f,0.036025404930114746f,0.3228367865085602f,-0.07083973288536072f,0.018455177545547485f,0.0059362053871154785f,0.40515169501304626f,0.014240056276321411f,-0.07738298177719116f,0.1407785713672638f,-0.13024571537971497f,-0.29546058177948f,-0.11976784467697144f,-0.35825538635253906f}, -{-0.5818981528282166f,0.014110059477388859f,0.12081471085548401f,-0.2973254919052124f,0.5392167568206787f,0.3773144781589508f,-0.39351940155029297f,0.31089308857917786f,-0.3893685042858124f,-0.02222958207130432f,-6.493835926055908f,-0.12242847681045532f,-0.2689415514469147f,-0.2518419325351715f,-0.1694900244474411f,-0.652117908000946f}, + {0.11070519685745239f,-2.3348469734191895f,0.057057321071624756f,-0.10134492069482803f,-5.252432346343994f,-1.3715343475341797f,-0.8426902890205383f,-0.2990124225616455f,-0.33757925033569336f,0.2895788848400116f,-7.361403465270996f,-0.858361005783081f,0.0845860168337822f,2.2169580459594727f,-3.0816471576690674f,-1.0190033912658691f}, + {-0.22745239734649658f,0.003037691116333008f,-0.061119019985198975f,0.35696902871131897f,0.05568113923072815f,0.011741191148757935f,-0.20225946605205536f,-0.08465918898582458f,0.3489862382411957f,0.0687277615070343f,0.31964078545570374f,0.3004753887653351f,0.36063823103904724f,-0.42892736196517944f,0.08652284741401672f,0.027493387460708618f}, + {-0.1391567885875702f,0.03293241187930107f,-0.2894435524940491f,0.25554025173187256f,0.08946844935417175f,0.1340968757867813f,-0.39087218046188354f,0.4122363030910492f,0.26211628317832947f,0.2953031361103058f,0.7025435566902161f,0.05798906087875366f,-0.5013425946235657f,-0.030901746824383736f,-0.06675297021865845f,-0.0446302704513073f}, + {-2.245600938796997f,1.6008015871047974f,-0.25313520431518555f,0.1469619870185852f,1.6072996854782104f,-1.3637473583221436f,-0.5957030653953552f,-0.08570799231529236f,-0.024399548768997192f,-0.39465832710266113f,-6.811410427093506f,-0.7977238893508911f,-0.022602174431085587f,-1.6454986333847046f,0.5441725850105286f,-0.7979243397712708f}, + {0.5210384130477905f,-0.11346126347780228f,-0.3519742488861084f,0.29306867718696594f,-0.3572634160518646f,1.75344979763031f,-0.744201123714447f,-0.019414573907852173f,-0.23047015070915222f,0.3579089343547821f,-2.398893117904663f,-0.48980283737182617f,-0.45957082509994507f,0.5487804412841797f,-0.7850930690765381f,-0.7663227319717407f}, + {-0.1828227937221527f,-0.02554568648338318f,-0.3260969817638397f,0.08422836661338806f,-0.38453540205955505f,-0.25432005524635315f,0.285016268491745f,0.12387624382972717f,-0.0982072651386261f,0.13111665844917297f,-0.03692615032196045f,-0.32796353101730347f,-0.21546880900859833f,0.049302369356155396f,-0.27088475227355957f,-0.4124959409236908f}, + {-0.007747650612145662f,0.3667842745780945f,0.33083590865135193f,-0.38213321566581726f,-0.14358049631118774f,-0.2546055316925049f,-0.09043094515800476f,-0.3003333508968353f,0.2600560486316681f,-0.37898191809654236f,0.49078798294067383f,-0.3058888614177704f,-0.31673234701156616f,0.44664251804351807f,-0.9339061975479126f,-0.1061311885714531f}, + {-0.17694538831710815f,0.1767565757036209f,-0.11379697918891907f,-0.07116051763296127f,0.041274964809417725f,-0.517110288143158f,-0.10284432768821716f,0.0019084513187408447f,0.06103590130805969f,-0.38046833872795105f,-0.3456110656261444f,-0.24793067574501038f,-0.4166972041130066f,-0.30618393421173096f,-0.33565962314605713f,-0.48154377937316895f}, + {0.5043365359306335f,0.1850307136774063f,-0.13502129912376404f,-0.25706031918525696f,-0.8451530337333679f,-0.9415315389633179f,-0.2777014970779419f,-0.3632148504257202f,-0.13619378209114075f,0.16938945651054382f,1.5622152090072632f,-0.19312366843223572f,0.1250869333744049f,-0.1843482404947281f,1.0270578861236572f,-0.5840676426887512f}, + {-0.25693249702453613f,-0.010147050023078918f,0.0457797646522522f,-0.3549601435661316f,-0.03321319818496704f,-0.4391511380672455f,0.17873415350914001f,-0.20421427488327026f,-0.050184011459350586f,0.12480869889259338f,-0.22192376852035522f,0.3545852601528168f,-0.3647043704986572f,0.4194667637348175f,-0.3910166025161743f,-0.2837793529033661f}, + {2.3816981315612793f,0.4564768075942993f,0.3954955041408539f,0.11254638433456421f,1.1973353624343872f,1.804193377494812f,-0.8583166599273682f,-0.11795541644096375f,0.3487861454486847f,-0.32520344853401184f,-1.3897980451583862f,-0.5921090841293335f,-0.14213289320468903f,-0.26851770281791687f,1.597784161567688f,-0.5877130031585693f}, + {-0.267646849155426f,-0.20429572463035583f,-0.15798500180244446f,0.3999568819999695f,-0.37393757700920105f,0.35770177841186523f,0.11292675137519836f,-0.2947862446308136f,-0.3764709532260895f,0.2424570620059967f,-0.10294663906097412f,-0.2837170362472534f,0.41839322447776794f,-0.02792874164879322f,-0.13706544041633606f,0.11999254673719406f}, + {0.2282707840204239f,-0.13254989683628082f,-0.2018718123435974f,-0.07019486278295517f,0.07545611262321472f,-0.33204764127731323f,-0.4035329520702362f,-0.21416273713111877f,-0.24509364366531372f,0.19522181153297424f,0.47974857687950134f,-0.8069085478782654f,-0.40297332406044006f,0.23708327114582062f,0.5259239673614502f,-0.3548051416873932f}, + {0.4138670265674591f,0.1604653298854828f,0.056746453046798706f,0.036025404930114746f,0.3228367865085602f,-0.07083973288536072f,0.018455177545547485f,0.0059362053871154785f,0.40515169501304626f,0.014240056276321411f,-0.07738298177719116f,0.1407785713672638f,-0.13024571537971497f,-0.29546058177948f,-0.11976784467697144f,-0.35825538635253906f}, + {-0.5818981528282166f,0.014110059477388859f,0.12081471085548401f,-0.2973254919052124f,0.5392167568206787f,0.3773144781589508f,-0.39351940155029297f,0.31089308857917786f,-0.3893685042858124f,-0.02222958207130432f,-6.493835926055908f,-0.12242847681045532f,-0.2689415514469147f,-0.2518419325351715f,-0.1694900244474411f,-0.652117908000946f}, }; -const float h3[16][16] = { +const float h3[16][16] = { {-0.36079341173171997f,-1.5671656131744385f,-0.870830237865448f,-0.4786093831062317f,-0.5575059056282043f,-0.773746132850647f,0.29977259039878845f,0.1743643879890442f,-0.5892294645309448f,-0.19605471193790436f,-0.27379146218299866f,0.06893575936555862f,2.2012624740600586f,-2.7650468349456787f,-1.8527313470840454f,1.5724681615829468f}, -{0.047732532024383545f,-0.23476845026016235f,-2.8836917877197266f,-0.42602431774139404f,-2.397148370742798f,1.254254937171936f,-0.3198729455471039f,-0.25123724341392517f,0.013695899397134781f,-0.5729482173919678f,0.09775999933481216f,-0.5587971806526184f,-0.9381403923034668f,-1.532671570777893f,-0.6944977045059204f,1.4258947372436523f}, -{0.07903262972831726f,0.2790505588054657f,-0.07798504829406738f,0.04248586297035217f,-0.1963958442211151f,-0.19260792434215546f,-0.4038352966308594f,0.015906542539596558f,0.15353140234947205f,0.030178606510162354f,0.2488909661769867f,0.13805970549583435f,-0.0816211998462677f,-0.20733052492141724f,-0.3036302626132965f,0.054825395345687866f}, -{-0.30922991037368774f,-0.16969707608222961f,0.3056027889251709f,-0.380797415971756f,-0.17742466926574707f,0.10660405457019806f,0.20021501183509827f,0.07002416253089905f,-0.25412267446517944f,-0.365601509809494f,0.13192829489707947f,0.41021624207496643f,-0.13397035002708435f,0.0815882533788681f,0.15073642134666443f,0.10944337397813797f}, -{-0.39607733488082886f,-0.05481579899787903f,0.1976260244846344f,0.022423356771469116f,0.16892847418785095f,-0.6999471187591553f,0.16012099385261536f,0.21129152178764343f,-0.08640444278717041f,-0.11053556203842163f,-0.2634495496749878f,-0.31317979097366333f,-0.1530032455921173f,-0.24679358303546906f,0.22959044575691223f,-3.0342295169830322f}, -{-0.37449589371681213f,-0.10077743977308273f,-4.51036262512207f,-0.04963836818933487f,-0.8192825317382812f,-0.6951172947883606f,-0.19780586659908295f,-0.09049295634031296f,-0.9114404916763306f,-0.8623005151748657f,-0.4059421718120575f,-0.16295623779296875f,-5.017462730407715f,-1.1079373359680176f,0.34683844447135925f,0.6427209377288818f}, -{0.4110594093799591f,0.2715781033039093f,-0.38537508249282837f,0.37246426939964294f,-0.05490662157535553f,-0.009114405140280724f,-0.08670487999916077f,-0.25336313247680664f,-0.030661463737487793f,-0.06259563565254211f,-0.1344406008720398f,0.35313835740089417f,-0.13377737998962402f,0.25604528188705444f,0.3126353323459625f,-0.1528691202402115f}, -{-0.40892091393470764f,0.043769627809524536f,-0.3867315948009491f,0.25968697667121887f,0.3424709737300873f,-0.051169753074645996f,-0.23312048614025116f,-0.390264093875885f,0.28059282898902893f,-0.1559126079082489f,-0.14134526252746582f,-0.0003446042537689209f,-0.2742875814437866f,-0.36560842394828796f,0.07994696497917175f,0.005298197269439697f}, -{0.10697010159492493f,-0.12228584289550781f,-0.37870171666145325f,0.21184906363487244f,-0.37222859263420105f,-0.17138728499412537f,-0.1382003128528595f,0.3493293821811676f,-0.360889196395874f,-0.3875247836112976f,0.42142823338508606f,-0.3482915461063385f,-0.3289247751235962f,-0.2186824083328247f,0.09620395302772522f,-0.06898030638694763f}, -{0.2847062647342682f,0.018552124500274658f,0.11435768008232117f,0.36562982201576233f,-0.047046810388565063f,0.30447837710380554f,0.2430230677127838f,0.2909286320209503f,-0.2802048921585083f,0.18043199181556702f,0.41849127411842346f,-0.287167489528656f,0.24394884705543518f,-0.14084559679031372f,-0.10168051719665527f,0.010465055704116821f}, -{0.15459725260734558f,0.22762465476989746f,1.5232031345367432f,-0.2233445942401886f,1.524779200553894f,2.6997625827789307f,-0.08742031455039978f,0.05785742402076721f,-0.1277361363172531f,-0.37371426820755005f,-0.03133596479892731f,-0.30447322130203247f,-1.9101834297180176f,0.6954238414764404f,0.46117544174194336f,1.1762653589248657f}, -{-0.408692330121994f,0.07260357588529587f,-0.02147701010107994f,0.0922636091709137f,-0.1529182642698288f,-0.05657944083213806f,0.03285527229309082f,0.38763079047203064f,-0.20705322921276093f,-0.25883403420448303f,0.12809070944786072f,0.03996849060058594f,-0.6609845757484436f,-0.1087266057729721f,-0.10636871308088303f,-0.0133456289768219f}, -{-0.2991822361946106f,0.3794580399990082f,-0.08715943992137909f,-0.05932474136352539f,0.11478022485971451f,0.3007120192050934f,-0.11253207921981812f,0.34576353430747986f,0.04814547300338745f,-0.35770976543426514f,-0.044228196144104004f,-0.36229726672172546f,0.05380958318710327f,-0.13672849535942078f,0.35829514265060425f,-0.10585878044366837f}, -{-0.2675279378890991f,-0.1429223269224167f,-0.9267327189445496f,-0.1256239265203476f,0.49980443716049194f,-0.843601405620575f,-0.33532586693763733f,-0.31893211603164673f,-1.478386402130127f,-1.1926257610321045f,-0.5260127782821655f,-0.8384293913841248f,0.9772797226905823f,0.1813446283340454f,0.17612296342849731f,1.590701699256897f}, -{-0.015470266342163086f,-0.4976375699043274f,2.497199058532715f,0.14489558339118958f,0.11334121972322464f,0.3805958926677704f,0.02394937537610531f,-0.16103173792362213f,-0.677362859249115f,-0.8498573303222656f,-0.026575788855552673f,-0.427055299282074f,0.17177484929561615f,1.67837655544281f,0.08538639545440674f,-1.3552721738815308f}, -{0.1863725483417511f,0.13157431781291962f,-0.047772910445928574f,-0.49708226323127747f,0.7275430560112f,-0.145163431763649f,0.04860696196556091f,0.17769548296928406f,-0.050254471600055695f,0.19876523315906525f,-0.5504136085510254f,0.19592127203941345f,0.23928996920585632f,-0.12190091609954834f,-0.1250786930322647f,0.041962411254644394f}, + {0.047732532024383545f,-0.23476845026016235f,-2.8836917877197266f,-0.42602431774139404f,-2.397148370742798f,1.254254937171936f,-0.3198729455471039f,-0.25123724341392517f,0.013695899397134781f,-0.5729482173919678f,0.09775999933481216f,-0.5587971806526184f,-0.9381403923034668f,-1.532671570777893f,-0.6944977045059204f,1.4258947372436523f}, + {0.07903262972831726f,0.2790505588054657f,-0.07798504829406738f,0.04248586297035217f,-0.1963958442211151f,-0.19260792434215546f,-0.4038352966308594f,0.015906542539596558f,0.15353140234947205f,0.030178606510162354f,0.2488909661769867f,0.13805970549583435f,-0.0816211998462677f,-0.20733052492141724f,-0.3036302626132965f,0.054825395345687866f}, + {-0.30922991037368774f,-0.16969707608222961f,0.3056027889251709f,-0.380797415971756f,-0.17742466926574707f,0.10660405457019806f,0.20021501183509827f,0.07002416253089905f,-0.25412267446517944f,-0.365601509809494f,0.13192829489707947f,0.41021624207496643f,-0.13397035002708435f,0.0815882533788681f,0.15073642134666443f,0.10944337397813797f}, + {-0.39607733488082886f,-0.05481579899787903f,0.1976260244846344f,0.022423356771469116f,0.16892847418785095f,-0.6999471187591553f,0.16012099385261536f,0.21129152178764343f,-0.08640444278717041f,-0.11053556203842163f,-0.2634495496749878f,-0.31317979097366333f,-0.1530032455921173f,-0.24679358303546906f,0.22959044575691223f,-3.0342295169830322f}, + {-0.37449589371681213f,-0.10077743977308273f,-4.51036262512207f,-0.04963836818933487f,-0.8192825317382812f,-0.6951172947883606f,-0.19780586659908295f,-0.09049295634031296f,-0.9114404916763306f,-0.8623005151748657f,-0.4059421718120575f,-0.16295623779296875f,-5.017462730407715f,-1.1079373359680176f,0.34683844447135925f,0.6427209377288818f}, + {0.4110594093799591f,0.2715781033039093f,-0.38537508249282837f,0.37246426939964294f,-0.05490662157535553f,-0.009114405140280724f,-0.08670487999916077f,-0.25336313247680664f,-0.030661463737487793f,-0.06259563565254211f,-0.1344406008720398f,0.35313835740089417f,-0.13377737998962402f,0.25604528188705444f,0.3126353323459625f,-0.1528691202402115f}, + {-0.40892091393470764f,0.043769627809524536f,-0.3867315948009491f,0.25968697667121887f,0.3424709737300873f,-0.051169753074645996f,-0.23312048614025116f,-0.390264093875885f,0.28059282898902893f,-0.1559126079082489f,-0.14134526252746582f,-0.0003446042537689209f,-0.2742875814437866f,-0.36560842394828796f,0.07994696497917175f,0.005298197269439697f}, + {0.10697010159492493f,-0.12228584289550781f,-0.37870171666145325f,0.21184906363487244f,-0.37222859263420105f,-0.17138728499412537f,-0.1382003128528595f,0.3493293821811676f,-0.360889196395874f,-0.3875247836112976f,0.42142823338508606f,-0.3482915461063385f,-0.3289247751235962f,-0.2186824083328247f,0.09620395302772522f,-0.06898030638694763f}, + {0.2847062647342682f,0.018552124500274658f,0.11435768008232117f,0.36562982201576233f,-0.047046810388565063f,0.30447837710380554f,0.2430230677127838f,0.2909286320209503f,-0.2802048921585083f,0.18043199181556702f,0.41849127411842346f,-0.287167489528656f,0.24394884705543518f,-0.14084559679031372f,-0.10168051719665527f,0.010465055704116821f}, + {0.15459725260734558f,0.22762465476989746f,1.5232031345367432f,-0.2233445942401886f,1.524779200553894f,2.6997625827789307f,-0.08742031455039978f,0.05785742402076721f,-0.1277361363172531f,-0.37371426820755005f,-0.03133596479892731f,-0.30447322130203247f,-1.9101834297180176f,0.6954238414764404f,0.46117544174194336f,1.1762653589248657f}, + {-0.408692330121994f,0.07260357588529587f,-0.02147701010107994f,0.0922636091709137f,-0.1529182642698288f,-0.05657944083213806f,0.03285527229309082f,0.38763079047203064f,-0.20705322921276093f,-0.25883403420448303f,0.12809070944786072f,0.03996849060058594f,-0.6609845757484436f,-0.1087266057729721f,-0.10636871308088303f,-0.0133456289768219f}, + {-0.2991822361946106f,0.3794580399990082f,-0.08715943992137909f,-0.05932474136352539f,0.11478022485971451f,0.3007120192050934f,-0.11253207921981812f,0.34576353430747986f,0.04814547300338745f,-0.35770976543426514f,-0.044228196144104004f,-0.36229726672172546f,0.05380958318710327f,-0.13672849535942078f,0.35829514265060425f,-0.10585878044366837f}, + {-0.2675279378890991f,-0.1429223269224167f,-0.9267327189445496f,-0.1256239265203476f,0.49980443716049194f,-0.843601405620575f,-0.33532586693763733f,-0.31893211603164673f,-1.478386402130127f,-1.1926257610321045f,-0.5260127782821655f,-0.8384293913841248f,0.9772797226905823f,0.1813446283340454f,0.17612296342849731f,1.590701699256897f}, + {-0.015470266342163086f,-0.4976375699043274f,2.497199058532715f,0.14489558339118958f,0.11334121972322464f,0.3805958926677704f,0.02394937537610531f,-0.16103173792362213f,-0.677362859249115f,-0.8498573303222656f,-0.026575788855552673f,-0.427055299282074f,0.17177484929561615f,1.67837655544281f,0.08538639545440674f,-1.3552721738815308f}, + {0.1863725483417511f,0.13157431781291962f,-0.047772910445928574f,-0.49708226323127747f,0.7275430560112f,-0.145163431763649f,0.04860696196556091f,0.17769548296928406f,-0.050254471600055695f,0.19876523315906525f,-0.5504136085510254f,0.19592127203941345f,0.23928996920585632f,-0.12190091609954834f,-0.1250786930322647f,0.041962411254644394f}, }; const float hout[16] = { 0.45773375034332275f,0.5733839869499207f,-0.5152473449707031f,-0.035915032029151917f,-0.306951105594635f,0.30648893117904663f,-0.1005084440112114f,-0.08898112922906876f,-0.2034129500389099f,-0.05844772607088089f,-0.07081260532140732f,0.08596939593553543f,0.5426119565963745f,0.5678461194038391f,1.0715678930282593f,-0.25178417563438416f }; @@ -269,7 +270,7 @@ HAL_Init(); SystemClock_Config(); - + /********************************* *** Initialization *********************************/ @@ -346,7 +347,7 @@ else ID_index_array[i] = (i+1) * 0.5f; } - + /************************************ *** Program is operating! @@ -354,27 +355,27 @@ while(1) { // if(timer_while==1000 && OPERATING_MODE==5) { //if(timer_while==1000) { - //i2c - - read_field(i2c_slave_addr1); - if(DIR_VALVE_ENC < 0) value = 1023 - value; - // if(LED==1) { - // LED=0; - // } else - // LED = 1; - timer_while = 0; + //i2c + + read_field(i2c_slave_addr1); + if(DIR_VALVE_ENC < 0) value = 1023 - value; + // if(LED==1) { + // LED=0; + // } else + // LED = 1; + timer_while = 0; //} - + timer_while ++; - + //LED = 0; - + if(NN_Control_Flag == 0) { LED = 0; } - + else if(NN_Control_Flag == 1) { - + int ind = 0; for(int i=0; i<numpast_u; i++) { input_NN[ind] = u_past[time_interval*i]; @@ -387,7 +388,7 @@ } input_NN[ind] = (pos.sen / ENC_PULSE_PER_POSITION) / 60.0f; ind = ind + 1; - + // for(int i=0; i<numfuture_x; i++) { // input_NN[ind] = x_future[time_interval*i+time_interval] / 60.0f; // ind = ind + 1; @@ -404,7 +405,7 @@ input_NN[ind] = (f_future[time_interval*i+time_interval])/10000.0f+0.5f; ind = ind + 1; } - + float output1[16] = { 0.0f }; float output2[16] = { 0.0f }; float output3[16] = { 0.0f }; @@ -448,12 +449,12 @@ output = output + hout[index1] * output3[index1]; } output = output + bout[index2]; - + } output = 1.0f/(1.0f+exp(-output)); output_normalized = output; output = output * 20000.0f - 10000.0f; - + if(output>=0) { valve_pos.ref = output*0.0001f*((double)VALVE_MAX_POS - (double) VALVE_CENTER) + (double) VALVE_CENTER; } else { @@ -464,7 +465,7 @@ // torq.err = f_past[0] - torq.sen; //[N] //// torq.err_sum += torq.err/(float) TMR_FREQ_5k; //[N] // torq.err_sum += torq.err/(float) 1500.0f; //[N] -// +// // // valve_pos.ref = ((float) P_GAIN_JOINT_TORQUE * torq.err + (float) I_GAIN_JOINT_TORQUE * torq.err_sum) * 0.01f + DDV_JOINT_POS_FF(vel.sen) + valve_pos.ref * 0.01f; // @@ -482,17 +483,17 @@ // torq.err_sum = torq.err_sum - valve_pos_rem/(float) 1500.0f; // } // } - - + + if(LED==1) { LED=0; } else LED = 1; - + } - + //LED = 1; - + } } @@ -925,17 +926,17 @@ vel.ref_home_pos = 0.0f; //FINDHOME_STAGE = FINDHOME_INIT; //CONTROL_UTILITY_MODE = MODE_JOINT_CONTROL; - - + + } } else if (FINDHOME_STAGE == FINDHOME_ZEROPOSE) { int T_move = 2*TMR_FREQ_5k; 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; //pos.ref = 0.0f; vel.ref = 0.0f; - + // input for position control - + // CONTROL_MODE = MODE_JOINT_CONTROL; alpha_trans = 0.0f; @@ -985,8 +986,8 @@ } - - + + // pos.err = pos.ref - (float)pos.sen; // float VALVE_POS_RAW_POS_FB = 0.0f; // VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * 0.01f * pos.err/(float) ENC_PULSE_PER_POSITION; @@ -1520,7 +1521,7 @@ } case MODE_SYSTEM_ID: { - freq_sysid_Iref = (double) cnt_sysid * DT_TMR3 * 3.; + freq_sysid_Iref = (double) cnt_sysid * DT_TMR3 * 3.0f; valve_pos.ref = 2500.0f * sin(2.0f * 3.14159f * freq_sysid_Iref * (double) cnt_sysid * DT_TMR3); CONTROL_MODE = MODE_VALVE_OPEN_LOOP; cnt_sysid++; @@ -1531,7 +1532,96 @@ break; } + case MODE_FREQ_TEST: { + float valve_pos_ref = 2500.0f * sin(2.0f * 3.141592f * freq_test_valve_ref * (float) cnt_freq_test * DT_TMR3); + if(valve_pos_ref >= 0) { + valve_pos.ref = (double)VALVE_CENTER + (double)valve_pos_ref * ((double)VALVE_MAX_POS-(double)VALVE_CENTER)/10000.0f; + } else { + valve_pos.ref = (double)VALVE_CENTER - (double)valve_pos_ref * ((double)VALVE_MIN_POS-(double)VALVE_CENTER)/10000.0f; + } + ref_array[cnt_freq_test] = valve_pos_ref; + if(value>=(float) VALVE_CENTER) { + pos_array[cnt_freq_test] = 10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); + } else { + pos_array[cnt_freq_test] = -10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); + } + CONTROL_MODE = MODE_VALVE_POSITION_CONTROL; + cnt_freq_test++; + if (freq_test_valve_ref * (float) cnt_freq_test * DT_TMR3 > 2) { + buffer_data_size = cnt_freq_test; + cnt_freq_test = 0; + cnt_send_buffer = 0; + freq_test_valve_ref = freq_test_valve_ref * 1.05f; + if (freq_test_valve_ref >= 400) { + CONTROL_UTILITY_MODE = MODE_NO_ACT; + CONTROL_MODE = MODE_NO_ACT; + CAN_TX_PWM((int16_t) (1)); //1300 + } + CONTROL_MODE = MODE_NO_ACT; + CONTROL_UTILITY_MODE = MODE_SEND_OVER; + + } + break; + } + case MODE_SEND_BUFFER: { +// if (TMR2_COUNT_CAN_TX % (int) ((int) TMR_FREQ_5k/CAN_FREQ) == 0) { +// CAN_TX_PRES((int16_t) (pos_array[cnt_send_buffer]), (int16_t) (ref_array[cnt_send_buffer])); // 1400 +// if(cnt_send_buffer>=buffer_data_size) { +// CONTROL_UTILITY_MODE = MODE_FREQ_TEST; +// } +// cnt_send_buffer++; +// } + + break; + } + case MODE_SEND_OVER: { + CAN_TX_TORQUE((int16_t) (buffer_data_size)); //1300 + CONTROL_UTILITY_MODE = MODE_NO_ACT; + CONTROL_MODE = MODE_NO_ACT; + break; + } + + case MODE_STEP_TEST: { + float valve_pos_ref = 0.0f; + if (cnt_step_test < (int) (1.0f * (float) TMR_FREQ_5k)) + { + valve_pos_ref = 0.0f; + }else + { + valve_pos_ref = 10000.0f; + } + if(valve_pos_ref >= 0) { + valve_pos.ref = (double)VALVE_CENTER + (double)valve_pos_ref * ((double)VALVE_MAX_POS-(double)VALVE_CENTER)/10000.0f; + } else { + valve_pos.ref = (double)VALVE_CENTER - (double)valve_pos_ref * ((double)VALVE_MIN_POS-(double)VALVE_CENTER)/10000.0f; + } + ref_array[cnt_step_test] = valve_pos_ref; + if(value>=(float) VALVE_CENTER) { + pos_array[cnt_step_test] = 10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); + } else { + pos_array[cnt_step_test] = -10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); + } + + CONTROL_MODE = MODE_VALVE_POSITION_CONTROL; + cnt_step_test++; + if (cnt_step_test > (int) (2.0f * (float) TMR_FREQ_5k)) + { + buffer_data_size = cnt_step_test; + cnt_step_test = 0; + cnt_send_buffer = 0; + CONTROL_UTILITY_MODE = MODE_SEND_OVER; + CONTROL_MODE = MODE_NO_ACT; + } +// if (cnt_step_test > (int) (2.0f * (float) TMR_FREQ_5k)) +// { +// CONTROL_UTILITY_MODE = MODE_NO_ACT; +// CONTROL_MODE = MODE_NO_ACT; +// CAN_TX_PWM((int16_t) (1)); //1300 +// } + + break; + } default: break; @@ -1551,26 +1641,24 @@ V_out = Vout.ref; } else if (CURRENT_CONTROL_MODE == 0) { //PWM V_out = valve_pos.ref; - } else { + } else { I_REF = valve_pos.ref * 0.001f; } - break; } case MODE_JOINT_CONTROL: { - - + double torq_ref = 0.0f; pos.err = (pos.ref - pos.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm] vel.err = (0.0f - vel.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm/s] pos.err_sum += pos.err/(float) TMR_FREQ_5k; //[mm] - + //K & D Low Pass Filter float alpha_K_D = 1.0f/(1.0f + 5000.0f/(2.0f*3.14f*30.0f)); // f_cutoff : 30Hz K_LPF = K_LPF*(1.0f-alpha_K_D)+K_SPRING*(alpha_K_D); D_LPF = D_LPF*(1.0f-alpha_K_D)+D_DAMPER*(alpha_K_D); - + // torq_ref = torq.ref + K_LPF * pos.err - D_LPF * vel.sen / ENC_PULSE_PER_POSITION; //[N] torq_ref = torq.ref; @@ -1617,7 +1705,7 @@ // Ref_Joint_FT_Nm_old = Ref_Joint_FT_Nm; I_REF = (1.0f - alpha_trans) * I_REF_POS + alpha_trans * (I_REF_VC + I_REF_FORCE_FB); - + // Anti-windup for FT if (I_GAIN_JOINT_TORQUE != 0) { double I_MAX = 10.0f; // Maximum Current : 10mV @@ -1639,15 +1727,15 @@ float VALVE_POS_RAW_FORCE_FB = 0.0f; float VALVE_POS_RAW_FORCE_FF = 0.0f; float VALVE_POS_RAW = 0.0f; - + VALVE_POS_RAW_FORCE_FB = alpha_trans*(((float) P_GAIN_JOINT_TORQUE * torq.err + (float) I_GAIN_JOINT_TORQUE * torq.err_sum) * 0.01f + DDV_JOINT_POS_FF(vel.sen))+ (1.0f-alpha_trans) * (P_GAIN_JOINT_POSITION * 0.01f * pos.err + DDV_JOINT_POS_FF(vel.ref)); VALVE_POS_RAW_FORCE_FF = P_GAIN_JOINT_TORQUE_FF * torq_ref * 0.001f + D_GAIN_JOINT_TORQUE_FF * (torq_ref - torq_ref_past) * 0.0001f; - + VALVE_POS_RAW = VALVE_POS_RAW_FORCE_FB + VALVE_POS_RAW_FORCE_FF; - - + + if (VALVE_POS_RAW >= 0) { valve_pos.ref = VALVE_POS_RAW + VALVE_DEADZONE_PLUS; } else { @@ -1675,7 +1763,7 @@ V_out = (float) Vout.ref; } - + torq_ref_past = torq_ref; @@ -1686,29 +1774,29 @@ V_out = (float) Vout.ref; break; } - + case MODE_JOINT_ADAPTIVE_BACKSTEPPING: { - - + + float Va = (1256.6f + Amm * pos.sen/(float)(ENC_PULSE_PER_POSITION)) * 0.000000001f; // 4mm pipe * 100mm + (25mm Cylinder 18mm Rod) * x, unit : m^3 float Vb = (1256.6f + Amm * (79.0f - pos.sen/(float)(ENC_PULSE_PER_POSITION))) * 0.000000001f; // 4mm pipe * 100mm + (25mm Cylinder 18mm Rod) * (79.0mm-x), unit : m^3 - + // float Va = (1256.6f + Amm * 39.5f) * 0.000000001f; // 4mm pipe * 100mm + (25mm Cylinder 18mm Rod) * x, unit : m^3 // float Vb = (1256.6f + Amm * 39.5f) * 0.000000001f; // 4mm pipe * 100mm + (25mm Cylinder 18mm Rod) * (79.0mm-x), unit : m^3 V = 1.0f / (1.0f/Va + 1.0f/Vb); //initial 0.0000053f - - + + float f3 = -Amm*Amm*beta*0.000001f*0.000001f/V * vel.sen/(float)(ENC_PULSE_PER_POSITION)*0.001f; // unit : N/s //xdot=10mm/s일때 -137076 - + float g3_prime = 0.0f; - if (torq.sen > Amm*(Ps-Pt)*0.000001f){ + if (torq.sen > Amm*(Ps-Pt)*0.000001f) { g3_prime = 1.0f; } else if (torq.sen < -Amm*(Ps-Pt)*0.000001f) { g3_prime = -1.0f; } else { if ((value-VALVE_CENTER) > 0) { - g3_prime = sqrt(Ps-Pt-torq.sen/Amm*1000000.0f); -// g3_prime = sqrt(Ps-Pt); + g3_prime = sqrt(Ps-Pt-torq.sen/Amm*1000000.0f); +// g3_prime = sqrt(Ps-Pt); } else { g3_prime = sqrt(Ps-Pt+torq.sen/Amm*1000000.0f); // g3_prime = sqrt(Ps-Pt); @@ -1716,7 +1804,7 @@ } float tau = 0.01f; float K_valve = 0.0004f; - + float x_v = 0.0f; //x_v : -1~1 if(value>=VALVE_CENTER) { x_v = 1.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); @@ -1725,16 +1813,16 @@ } float f4 = -x_v/tau; float g4 = K_valve/tau; - + float torq_ref_dot = torq.ref_diff * 500.0f; - + pos.err = (pos.ref - pos.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm] vel.err = (0.0f - vel.sen)/(float)(ENC_PULSE_PER_POSITION); //[mm/s] pos.err_sum += pos.err/(float) TMR_FREQ_5k; //[mm] - + torq.err = torq.ref - torq.sen; //[N] torq.err_sum += torq.err/(float) TMR_FREQ_5k; //[N] - + float k3 = 20000.0f; //2000 float k4 = 10.0f; float rho3 = 3.2f; @@ -1742,23 +1830,23 @@ float x_4_des = (-f3 + torq_ref_dot - k3*(-torq.err))/(gamma_hat*g3_prime); if (x_4_des > 1) x_4_des = 1; else if (x_4_des < -1) x_4_des = -1; - + if (x_4_des > 0) { valve_pos.ref = x_4_des * (float)(VALVE_MAX_POS - VALVE_CENTER) + (float) VALVE_CENTER; } else { valve_pos.ref = x_4_des * (float)(VALVE_CENTER - VALVE_MIN_POS) + (float) VALVE_CENTER; } - - + + float x_4_des_dot = (x_4_des - x_4_des_old)*(float) TMR_FREQ_5k; x_4_des_old = x_4_des; - + V_out = (-f4 + x_4_des_dot - k4*(x_v-x_4_des)- rho3/rho4*gamma_hat*g3_prime*(-torq.err))/g4; - + float rho_gamma = 50000.0f;//5000 float gamma_hat_dot = rho3*(-torq.err)/rho_gamma*((-f3+torq_ref_dot-k3*(-torq.err))/gamma_hat + g3_prime*(x_v-x_4_des)); gamma_hat = gamma_hat + gamma_hat_dot / (float) TMR_FREQ_5k; - break; + break; } default: @@ -1845,8 +1933,7 @@ if (CUR_PWM_lin > 0) V_out = (float) (CUR_PWM_lin + 169.0f); else if (CUR_PWM_lin < 0) V_out = (float) (CUR_PWM_lin - 174.0f); else V_out = (float) (CUR_PWM_lin); - } - else { //////////////////////////sw valve + } else { //////////////////////////sw valve // Output Voltage Linearization // double CUR_PWM_nonlin = V_out; // Unit : mV // double CUR_PWM_lin = PWM_duty_byLT(CUR_PWM_nonlin); // -8000~8000 @@ -1860,18 +1947,18 @@ else if (V_out < 0) V_out = (V_out - 200.0f)/0.8651f; else V_out = 0.0f; } - + // if(V_out > 0.0f) V_out = (float) (V_out + 169.0f); // else if(V_out < 0.0f) V_out = (float) (V_out - 174.0f); // else V_out = V_out; - + /******************************************************* *** PWM ********************************************************/ - if(DIR_VALVE<0){ + if(DIR_VALVE<0) { V_out = -V_out; } - + if (V_out >= VALVE_VOLTAGE_LIMIT*1000.0f) { V_out = VALVE_VOLTAGE_LIMIT*1000.0f; } else if(V_out<=-VALVE_VOLTAGE_LIMIT*1000.0f) { @@ -1916,39 +2003,32 @@ } if (flag_data_request[1] == HIGH) { //valve position - double t_value = 0; + double t_value = 0.0f; if(valve_pos.ref>=(float) VALVE_CENTER) { t_value = 10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); } else { t_value = -10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); } -// if(OPERATING_MODE==5) { -// if(valve_pos.ref>=(float) VALVE_CENTER) { -// t_value = 10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); -// } else { -// t_value = -10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); -// } - //t_value = (double) value; -// } else if(CURRENT_CONTROL_MODE==1) { -// t_value = cur.sen * 1000.0f; -// } else { -// t_value = V_out; -// } CAN_TX_TORQUE((int16_t) (t_value)); //1300 - //CAN_TX_TORQUE((int16_t) (cur.sen * 1000.0f)); //1300 - //CAN_TX_TORQUE((int16_t) (I_REF * 1000.0f)); //1300 } if (flag_data_request[2] == LOW) { - //CAN_TX_PRES((int16_t) (pres_A.sen), (int16_t) (pres_B.sen)); // 1400 - double t_value = 0; + double t_value = 0.0f; if(valve_pos.ref>=(float) VALVE_CENTER) { t_value = 10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); } else { t_value = -10000.0f*((double)value - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); } - CAN_TX_PRES((int16_t) (t_value), (int16_t) (torq.ref)); // 1400 + double t_value_ref = 0.0f; + if(valve_pos.ref>=(float) VALVE_CENTER) { + t_value_ref = 10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MAX_POS - (double)VALVE_CENTER); + } else { + t_value_ref = -10000.0f*((double)valve_pos.ref - (double)VALVE_CENTER)/((double)VALVE_MIN_POS - (double)VALVE_CENTER); + } + + + CAN_TX_PRES((int16_t) (t_value), (int16_t) (t_value_ref)); // 1400 } //If it doesn't rest, below can can not work. @@ -1956,7 +2036,7 @@ ; } - if (flag_data_request[3] == LOW) { + if (flag_data_request[3] == HIGH) { //PWM //CAN_TX_PWM((int16_t) value); //1500 CAN_TX_PWM((int16_t) gamma_hat); //1500