Original Version of STM Board

Dependencies:   FastPWM mbed

Revision:
213:3e7bee70a0b4
Parent:
212:ec41f1449ef9
diff -r ec41f1449ef9 -r 3e7bee70a0b4 main.cpp
--- a/main.cpp	Wed Dec 23 11:22:31 2020 +0000
+++ b/main.cpp	Wed Dec 23 15:20:09 2020 +0000
@@ -1,4 +1,4 @@
-//201223_4
+//201223_5
 #include "mbed.h"
 #include "FastPWM.h"
 #include "INIT_HW.h"
@@ -85,7 +85,7 @@
 extern int CID_TX_VALVE_POSITION;
 
 
-
+float V_output = 0.0f;
 
 // =============================================================================
 // =============================================================================
@@ -199,72 +199,72 @@
 float input_NN[num_input] = { 0.0f };
 
 const float h1[num_input][16] = {
-    {-1.6070621013641357f,1.4444793462753296f,0.12903714179992676f,0.45971256494522095f,-1.8895007371902466f,1.5912665128707886f,-0.17472904920578003f,1.3318427801132202f,-2.261326551437378f,-0.03385619446635246f,-0.23437689244747162f,-1.2534494400024414f,-0.26408806443214417f,-1.1718051433563232f,-0.2571594715118408f,-1.0255193710327148f},
-{-1.0846422910690308f,0.8761099576950073f,-0.3927857577800751f,0.10885071754455566f,-1.2603814601898193f,0.7932608127593994f,-0.4054011106491089f,0.5438631772994995f,-1.546224594116211f,0.22130662202835083f,-0.27116647362709045f,-0.7526845335960388f,0.23553097248077393f,-1.0961291790008545f,-0.20967772603034973f,-0.659416675567627f},
-{-0.8406979441642761f,0.5655145645141602f,0.36391180753707886f,-0.2829425036907196f,-0.6366292238235474f,0.6242642402648926f,0.2872133255004883f,0.39269590377807617f,-1.4623386859893799f,0.22947895526885986f,-0.34503698348999023f,-0.4441416561603546f,-0.00272137182764709f,-0.3268943130970001f,0.05590221285820007f,-1.1436342000961304f},
-{-0.35294806957244873f,-0.09107200056314468f,0.39742106199264526f,0.33738622069358826f,-0.11074129492044449f,-0.19795556366443634f,-0.11584559082984924f,0.2239270806312561f,-1.016740083694458f,0.367963969707489f,0.09880797564983368f,0.34261059761047363f,-0.16485224664211273f,-0.02963976189494133f,-0.2961459457874298f,-0.9800482988357544f},
-{1.1172692775726318f,-0.881708025932312f,-0.0051451027393341064f,0.24785789847373962f,0.949159562587738f,-0.8879446387290955f,0.1294034719467163f,-1.1183830499649048f,-0.18216757476329803f,0.18784251809120178f,0.35077041387557983f,0.5736857056617737f,-0.06842327117919922f,1.0481723546981812f,-0.3865056037902832f,-0.9325311183929443f},
-{3.2859668731689453f,-3.373445987701416f,0.21773302555084229f,0.23583510518074036f,3.153277635574341f,-3.0842037200927734f,0.16514194011688232f,-3.330359697341919f,1.6308770179748535f,0.20284788310527802f,-0.24478337168693542f,1.4629696607589722f,-0.26506540179252625f,3.084402084350586f,-0.4132833778858185f,0.3235807716846466f},
-{-0.16239909827709198f,0.652294397354126f,-0.2501986622810364f,-0.7905404567718506f,-0.6188644766807556f,0.8528907299041748f,0.06014183163642883f,-0.4905660152435303f,1.5433074235916138f,-0.1533675193786621f,0.15192021429538727f,-0.10490059852600098f,-0.1730978935956955f,0.015356072224676609f,-0.15618428587913513f,0.5344299077987671f},
-{-0.8749822974205017f,0.6992738246917725f,-0.26619744300842285f,-0.08359992504119873f,-1.2196704149246216f,0.7197252511978149f,-0.17925891280174255f,0.24655599892139435f,0.32290568947792053f,0.030707592144608498f,0.10629666596651077f,-0.48497965931892395f,0.37155985832214355f,-0.5724732875823975f,0.04303058981895447f,0.5185656547546387f},
-{0.44704651832580566f,0.0694582387804985f,0.10248100757598877f,-0.6408140659332275f,0.08685804158449173f,-0.24289385974407196f,-0.07246989011764526f,-0.8823809623718262f,0.975390613079071f,0.2915976345539093f,-0.2963060140609741f,0.3272884786128998f,0.22921693325042725f,0.7061342597007751f,-0.30555272102355957f,1.1997355222702026f},
-{0.10269708186388016f,-0.4119151830673218f,0.18462657928466797f,-0.4237739145755768f,0.28614145517349243f,-0.0384453721344471f,-0.2990540862083435f,-0.3690754175186157f,1.0338808298110962f,-0.506875216960907f,-0.007301787845790386f,-0.4488030672073364f,0.372331827878952f,0.18725666403770447f,0.3484981060028076f,0.7741178274154663f},
-{0.4530973434448242f,0.06094556301832199f,0.37182438373565674f,-0.03273813799023628f,0.0016666745068505406f,-0.13683553040027618f,-0.20339298248291016f,0.0006952928379178047f,0.36829644441604614f,0.007492598611861467f,0.3493041396141052f,-0.34462884068489075f,-0.06654797494411469f,0.2495005875825882f,0.26688337326049805f,0.2787923216819763f},
-{-0.41628196835517883f,-0.34683796763420105f,-0.40320003032684326f,-0.26510435342788696f,0.01427370309829712f,-0.12881697714328766f,0.1533789038658142f,0.6213264465332031f,0.43982186913490295f,0.1924997866153717f,-0.41328826546669006f,-0.0027057332918047905f,0.14470605552196503f,0.13542859256267548f,0.10493969917297363f,0.358428418636322f},
-{-0.09863808006048203f,-0.15524423122406006f,0.19847965240478516f,-0.08667934685945511f,0.2108737826347351f,0.0608486607670784f,-0.2404318004846573f,0.5305993556976318f,0.29834941029548645f,-0.20526979863643646f,-0.10813693702220917f,-0.45609328150749207f,0.09201034903526306f,0.16512572765350342f,-0.22268100082874298f,-0.07933637499809265f},
-{-0.1803528368473053f,-0.07565825432538986f,0.4127817749977112f,-0.29987478256225586f,-0.3406386971473694f,-0.3658057749271393f,-0.32001304626464844f,0.18756037950515747f,0.23431532084941864f,-0.23265855014324188f,-0.19404397904872894f,-0.44801175594329834f,-0.31276315450668335f,0.09663949906826019f,0.0479682981967926f,0.23482243716716766f},
-{0.09787440299987793f,0.05535588413476944f,0.20282304286956787f,-0.1285126656293869f,0.21852988004684448f,-0.23995305597782135f,0.04202890396118164f,0.899287223815918f,0.4933943748474121f,0.07827243953943253f,-0.2784428298473358f,-0.7169914841651917f,0.10353262722492218f,0.041469767689704895f,0.0668090283870697f,0.10634815692901611f},
-{-0.17166218161582947f,-0.24739637970924377f,-0.40439701080322266f,-0.278349369764328f,-0.34712228178977966f,-0.047724951058626175f,-0.15568238496780396f,0.7170681357383728f,0.2422538846731186f,-0.006808132864534855f,-0.47287464141845703f,-0.4041852056980133f,-0.2711547017097473f,0.0345175676047802f,-0.08245879411697388f,-0.017156904563307762f},
-{0.10945872962474823f,-0.3796606957912445f,0.16706281900405884f,-0.1058274433016777f,0.09715140610933304f,-0.6114601492881775f,-0.041414469480514526f,0.459582656621933f,0.15684588253498077f,0.09002777934074402f,-0.35252657532691956f,0.13107328116893768f,0.11200001835823059f,0.6847966313362122f,0.29427415132522583f,-0.10886158049106598f},
+    {-1.5377649068832397f,1.2348084449768066f,0.12903714179992676f,-0.7775466442108154f,-1.7313402891159058f,1.1328696012496948f,-0.17472904920578003f,-0.31568053364753723f,-1.6451395750045776f,0.08867859095335007f,-0.23520143330097198f,-1.8044253587722778f,-0.2673356235027313f,-0.7325633764266968f,-0.2571594715118408f,1.472490906715393f},
+{-1.1286786794662476f,0.7839595675468445f,-0.3927857577800751f,-0.6969871520996094f,-1.2280852794647217f,0.48096179962158203f,-0.4054011106491089f,-0.3208436667919159f,-1.0162376165390015f,0.3468303382396698f,-0.2720212936401367f,-1.157413363456726f,0.232293039560318f,-0.9538101553916931f,-0.20967772603034973f,1.1393009424209595f},
+{-0.81263667345047f,0.40442758798599243f,0.36391180753707886f,-0.7410301566123962f,-0.5623536705970764f,0.26899170875549316f,0.2872133255004883f,-0.01752573810517788f,-0.8192043304443359f,0.35837459564208984f,-0.3459203839302063f,-0.7548978924751282f,-0.0059507424011826515f,-0.33420637249946594f,0.05590221285820007f,0.33579739928245544f},
+{-0.29265180230140686f,-0.27822574973106384f,0.39742106199264526f,0.2536725103855133f,-0.03869828209280968f,-0.5511156320571899f,-0.11584559082984924f,0.37218543887138367f,-0.2952747344970703f,0.5005717277526855f,0.09789774566888809f,0.15287092328071594f,-0.1680694818496704f,-0.221437469124794f,-0.2961459457874298f,0.03926409035921097f},
+{0.9285116791725159f,-0.8077948093414307f,-0.0051451027393341064f,0.6920914649963379f,0.7559896111488342f,-0.9459089040756226f,0.1294034719467163f,0.15902996063232422f,0.3258247375488281f,0.32459303736686707f,0.3498339056968689f,0.6136358380317688f,-0.07163341343402863f,0.4614284634590149f,-0.3865056037902832f,-1.0294679403305054f},
+{2.3463828563690186f,-2.5303292274475098f,0.21773302555084229f,1.477303147315979f,2.240800619125366f,-2.3303043842315674f,0.16514194011688232f,0.05813070386648178f,1.3986808061599731f,0.34440353512763977f,-0.24573767185211182f,1.9037261009216309f,-0.268279105424881f,1.7655072212219238f,-0.4132833778858185f,-1.9700273275375366f},
+{-0.4369703531265259f,0.7387278079986572f,-0.2501986622810364f,-0.9271978139877319f,-1.1423627138137817f,1.097220540046692f,0.06014183163642883f,-1.050276517868042f,0.13420486450195312f,-0.2703655958175659f,0.15077415108680725f,-0.04091700538992882f,-0.17465755343437195f,-1.6798783540725708f,-0.15618428587913513f,-1.5135868787765503f},
+{-0.13573184609413147f,0.13010674715042114f,-0.26619744300842285f,-0.0794379785656929f,-0.70912104845047f,0.31772083044052124f,-0.17925891280174255f,-0.7659602761268616f,0.01908610202372074f,-0.16886766254901886f,0.10512365400791168f,-0.2623549699783325f,0.3695131838321686f,-0.7335740327835083f,0.04303058981895447f,-1.0657305717468262f},
+{0.7555938363075256f,-0.021008117124438286f,0.10248100757598877f,-0.00994115136563778f,0.31521323323249817f,-0.2205902636051178f,-0.07246989011764526f,-0.5589467883110046f,0.3382551074028015f,0.11823058128356934f,-0.29748186469078064f,0.6377660036087036f,0.22716356813907623f,1.0021276473999023f,-0.30555272102355957f,-0.732044517993927f},
+{0.3232681155204773f,-0.40787485241889954f,0.18462657928466797f,0.12388432025909424f,0.49224865436553955f,0.06522741168737411f,-0.2990540862083435f,-0.13266541063785553f,0.48252439498901367f,-0.6622780561447144f,-0.008490024134516716f,-0.3987669348716736f,0.3702549934387207f,0.7228370904922485f,0.3484981060028076f,-0.32474222779273987f},
+{0.5499926209449768f,0.16501271724700928f,0.37182438373565674f,0.2804836630821228f,0.1178550198674202f,0.07621731609106064f,-0.20339298248291016f,-0.033771634101867676f,-0.12858600914478302f,-0.13823570311069489f,0.34812381863594055f,-0.4757518470287323f,-0.0686570256948471f,0.7044376134872437f,0.26688337326049805f,-0.16891999542713165f},
+{-0.32638248801231384f,-0.2681056559085846f,-0.40320003032684326f,-0.0554439052939415f,0.13748574256896973f,0.08285294473171234f,0.1533789038658142f,0.3311554193496704f,0.001971070421859622f,0.052262917160987854f,-0.41445285081863403f,-0.10799311101436615f,0.14259445667266846f,0.46168866753578186f,0.10493969917297363f,0.2548428475856781f},
+{-0.027842355892062187f,-0.08303984254598618f,0.19847965240478516f,0.09461163729429245f,0.32331663370132446f,0.2865959703922272f,-0.2404318004846573f,0.08309822529554367f,-0.1785000115633011f,-0.3414570987224579f,-0.10929234325885773f,-0.48389771580696106f,0.08989179879426956f,0.35135433077812195f,-0.22268100082874298f,0.014733131974935532f},
+{-0.06475397944450378f,-0.0561961904168129f,0.4127817749977112f,-0.10577572137117386f,-0.17697541415691376f,-0.1849510818719864f,-0.32001304626464844f,-0.36673668026924133f,-0.21330887079238892f,-0.3657089173793793f,-0.1951775997877121f,-0.3619512915611267f,-0.31488466262817383f,0.26527494192123413f,0.0479682981967926f,0.45723286271095276f},
+{0.10058767348527908f,0.18761076033115387f,0.20282304286956787f,-0.08738672733306885f,0.2697560787200928f,0.0342223234474659f,0.04202890396118164f,0.20938999950885773f,0.05025419965386391f,-0.052940960973501205f,-0.27958524227142334f,-0.7458251714706421f,0.10142271965742111f,0.16368134319782257f,0.0668090283870697f,0.6141231656074524f},
+{-0.1128726527094841f,-0.1546522080898285f,-0.40439701080322266f,-0.30092698335647583f,-0.24299722909927368f,0.15388551354408264f,-0.15568238496780396f,-0.037944644689559937f,0.05713915079832077f,-0.13745471835136414f,-0.47403645515441895f,-0.43296101689338684f,-0.27326998114585876f,0.4320793151855469f,-0.08245879411697388f,0.5419437885284424f},
+{0.04264898970723152f,-0.14219117164611816f,0.16706281900405884f,-0.06084718555212021f,0.0778137817978859f,-0.31440258026123047f,-0.041414469480514526f,0.07056988030672073f,0.15166155993938446f,-0.038817811757326126f,-0.3537028133869171f,0.07804109901189804f,0.10987777262926102f,1.3651574850082397f,0.29427415132522583f,0.09650146216154099f},
 };
 
 const float h2[16][16] = {
-    {-0.2100285440683365f,0.5450449585914612f,-0.06966331601142883f,-0.16327691078186035f,-0.21907491981983185f,-0.7174352407455444f,-0.08997400104999542f,0.03496444225311279f,-0.43008196353912354f,-0.1415480375289917f,-1.024130940437317f,-0.43296945095062256f,0.12968102097511292f,-1.543792724609375f,-0.4490607678890228f,-4.010191440582275f},
-{0.09335885941982269f,-2.328054904937744f,0.057057321071624756f,-0.4136889576911926f,-0.35503754019737244f,-1.8548954725265503f,-0.5476264953613281f,-0.3163917064666748f,-0.33757925033569336f,0.2895788848400116f,-3.989751100540161f,-0.2958875000476837f,0.33698758482933044f,2.3762283325195312f,-0.10209953784942627f,-1.2367063760757446f},
+    {-0.30360984802246094f,2.638908863067627f,-0.06966331601142883f,-2.1284985542297363f,-0.21907491981983185f,1.5969719886779785f,-0.11378823220729828f,0.0904630720615387f,-0.43008196353912354f,-0.1415480375289917f,0.2562443017959595f,-0.4410564601421356f,-0.013608419336378574f,-2.052125930786133f,-0.3983412981033325f,-1.9826109409332275f},
+{0.04869420453906059f,-0.9130892157554626f,0.057057321071624756f,-0.5089913010597229f,-0.35503754019737244f,-1.2973040342330933f,-1.0162988901138306f,-0.2990124225616455f,-0.33757925033569336f,0.2895788848400116f,-1.071617841720581f,-0.8869436383247375f,0.23050862550735474f,1.0951136350631714f,1.5778846740722656f,-1.7874358892440796f},
 {-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.05469902977347374f,-0.25110578536987305f,-0.2894435524940491f,0.5345750451087952f,0.08946844935417175f,0.4574865400791168f,-0.23805393278598785f,0.4122363030910492f,0.26211628317832947f,0.2953031361103058f,0.3205234110355377f,0.3810727894306183f,-0.404754102230072f,-0.2590928077697754f,0.2257760912179947f,0.16342028975486755f},
-{-0.25391754508018494f,0.49998918175697327f,-0.25313520431518555f,0.0678805261850357f,0.036378175020217896f,-0.5025586485862732f,-0.58262699842453f,-0.12088710814714432f,-0.024399548768997192f,-0.39465832710266113f,-1.5418189764022827f,-0.7374540567398071f,0.10077962279319763f,-0.42483294010162354f,-0.49100643396377563f,-0.64886075258255f},
-{0.34239134192466736f,-1.3530895709991455f,-0.3519742488861084f,0.014243300072848797f,-0.3015052080154419f,-1.4964323043823242f,-0.6469179391860962f,-0.04728340730071068f,-0.23047015070915222f,0.3579089343547821f,-2.080329179763794f,-0.22948884963989258f,-0.20959392189979553f,1.1190712451934814f,0.13593792915344238f,-2.15841007232666f},
+{0.0389205701649189f,-0.2350102663040161f,-0.2894435524940491f,0.6463852524757385f,0.08946844935417175f,0.02936168573796749f,-0.504420280456543f,0.4122363030910492f,0.26211628317832947f,0.2953031361103058f,0.22434934973716736f,0.036702197045087814f,-0.5147730708122253f,-0.26475679874420166f,-0.012437191791832447f,0.2709595263004303f},
+{-0.40975338220596313f,0.9070354104042053f,-0.25313520431518555f,0.48267850279808044f,0.036378175020217896f,1.1078479290008545f,-0.5186612010002136f,-0.08570799231529236f,-0.024399548768997192f,-0.39465832710266113f,-0.4139823019504547f,-0.9831398129463196f,-0.03532028570771217f,-2.3388190269470215f,0.6467065215110779f,-0.33112117648124695f},
+{0.24459777772426605f,0.1711728870868683f,-0.3519742488861084f,-1.8791543245315552f,-0.3015052080154419f,-1.0918842554092407f,-1.0872746706008911f,-0.019414573907852173f,-0.23047015070915222f,0.3579089343547821f,-0.936398446559906f,-0.4908921718597412f,-0.32434627413749695f,0.8514059782028198f,1.6185284852981567f,-3.258086919784546f},
 {-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.1319282501935959f,-1.5630793571472168f,0.33083590865135193f,-0.6722083687782288f,-0.14358049631118774f,-1.5424034595489502f,-0.5113024115562439f,-0.32745271921157837f,0.2600560486316681f,-0.37898191809654236f,-2.461042642593384f,-0.40288063883781433f,-0.31673234701156616f,1.4697182178497314f,0.17047874629497528f,-0.9254405498504639f},
-{-0.2827617824077606f,-0.5835872888565063f,-0.11379697918891907f,-0.2174888700246811f,0.041274964809417725f,-1.1300400495529175f,-0.5878999829292297f,-0.08471067994832993f,0.06103590130805969f,-0.38046833872795105f,-2.1991589069366455f,-0.5746544599533081f,-0.37024784088134766f,-1.505262017250061f,-0.564139187335968f,-0.7886471748352051f},
-{-0.16934998333454132f,0.5294079184532166f,-0.13502129912376404f,0.6688047051429749f,0.12987366318702698f,0.48973479866981506f,0.2711336314678192f,-0.3632148504257202f,-0.13619378209114075f,0.16938945651054382f,0.5563372373580933f,0.3686026632785797f,0.3811538517475128f,-0.608641505241394f,-0.3150292634963989f,-0.07790349423885345f},
-{-0.290787935256958f,0.008599113672971725f,0.0457797646522522f,-0.3533823788166046f,-0.03321319818496704f,-0.4156119227409363f,0.17873415350914001f,-0.20421427488327026f,-0.050184011459350586f,0.12480869889259338f,-0.2018822431564331f,0.3545852601528168f,-0.3647043704986572f,0.40289223194122314f,-0.40987616777420044f,-0.2687363028526306f},
-{0.31293871998786926f,0.514428973197937f,0.3954955041408539f,0.03152908384799957f,0.0033026933670043945f,0.11348362267017365f,-0.25357672572135925f,-0.1509854942560196f,0.3487861454486847f,-0.32520344853401184f,0.08041279017925262f,-0.32230615615844727f,0.0820283591747284f,-0.3886100947856903f,0.11279337108135223f,-0.043686479330062866f},
-{-0.26997238397598267f,-0.21165083348751068f,-0.15798500180244446f,0.37889501452445984f,-0.37393757700920105f,0.3643323481082916f,0.11292675137519836f,-0.2947862446308136f,-0.3764709532260895f,0.2424570620059967f,-0.11038123071193695f,-0.2837170362472534f,0.41839322447776794f,-0.016996487975120544f,-0.12759913504123688f,0.10896846652030945f},
-{-0.2488415539264679f,0.5050635933876038f,-0.2018718123435974f,0.4112447202205658f,0.07545611262321472f,0.41179272532463074f,-0.39304429292678833f,-0.21989363431930542f,-0.24509364366531372f,0.19522181153297424f,0.8638243079185486f,-0.5810434818267822f,-0.16718891263008118f,-0.8570426106452942f,-0.6993795037269592f,0.26117852330207825f},
+{0.14612844586372375f,0.26144781708717346f,0.33083590865135193f,0.18728496134281158f,-0.14358049631118774f,-0.14802397787570953f,-0.09043094515800476f,-0.3003333508968353f,0.2600560486316681f,-0.37898191809654236f,0.28126513957977295f,-0.3191148042678833f,-0.31673234701156616f,0.0378720797598362f,0.2110089659690857f,0.5294160842895508f},
+{-0.4464441239833832f,-0.37462499737739563f,-0.11379697918891907f,0.015016188845038414f,0.041274964809417725f,0.9448469281196594f,-0.27324017882347107f,0.0019084513187408447f,0.06103590130805969f,-0.38046833872795105f,-0.44487905502319336f,-0.5847339034080505f,-0.37024784088134766f,-0.3508826792240143f,-2.5958049297332764f,-1.0934983491897583f},
+{0.3172138035297394f,0.8529412746429443f,-0.13502129912376404f,1.3385112285614014f,0.12987366318702698f,1.0381544828414917f,0.2711336314678192f,-0.3632148504257202f,-0.13619378209114075f,0.16938945651054382f,0.891782820224762f,0.36860278248786926f,0.3811538517475128f,-0.8146499395370483f,-0.4384280741214752f,0.393382728099823f},
+{-0.2874368727207184f,0.0053735338151454926f,0.0457797646522522f,-0.3544918894767761f,-0.03321319818496704f,-0.4190075397491455f,0.17873415350914001f,-0.20421427488327026f,-0.050184011459350586f,0.12480869889259338f,-0.2065037190914154f,0.3545852601528168f,-0.3647043704986572f,0.405265748500824f,-0.406197190284729f,-0.2715927064418793f},
+{0.1931207925081253f,0.7604777812957764f,0.3954955041408539f,0.20387306809425354f,0.0033026933670043945f,0.5029672980308533f,-0.7109203338623047f,-0.11795541644096375f,0.3487861454486847f,-0.32520344853401184f,0.15682469308376312f,-0.6898894309997559f,-0.052492406219244f,0.25462016463279724f,0.20089516043663025f,-0.00925449188798666f},
+{-0.2629387378692627f,-0.21474134922027588f,-0.15798500180244446f,0.38661113381385803f,-0.37393757700920105f,0.358870267868042f,0.11292675137519836f,-0.2947862446308136f,-0.3764709532260895f,0.2424570620059967f,-0.11385586112737656f,-0.2837170362472534f,0.41839322447776794f,-0.01518807839602232f,-0.12482608109712601f,0.1076495498418808f},
+{-0.2209693342447281f,-0.22651943564414978f,-0.2018718123435974f,-0.08468649536371231f,0.07545611262321472f,-1.134768009185791f,-0.6247013211250305f,-0.21416273713111877f,-0.24509364366531372f,0.19522181153297424f,-0.2526063024997711f,-0.8176553249359131f,-0.16718891263008118f,-1.0407229661941528f,-0.7605361342430115f,-0.17334645986557007f},
 {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.4079033434391022f,0.0030517925042659044f,0.12081471085548401f,-0.5565865635871887f,0.29976895451545715f,-1.0711815357208252f,-0.3759289085865021f,0.23442097008228302f,-0.3893685042858124f,-0.02222958207130432f,-3.00561785697937f,-0.32067564129829407f,-0.19991017878055573f,-0.5698347091674805f,0.07654765248298645f,-2.1375231742858887f},
+{-0.516390323638916f,-0.9803458452224731f,0.12081471085548401f,-1.280253529548645f,0.29976895451545715f,-0.15804079174995422f,-0.17698705196380615f,0.31089308857917786f,-0.3893685042858124f,-0.02222958207130432f,-0.5123834609985352f,-0.2791821360588074f,-0.12851779162883759f,-0.46627044677734375f,0.16254712641239166f,-1.2184544801712036f},
 };
 
 const float h3[16][16] = {
-    {-0.36079341173171997f,-0.08991171419620514f,-0.07854580879211426f,-0.3761775493621826f,-0.19077321887016296f,0.04002965986728668f,0.3332441747188568f,0.3036012351512909f,-0.2405819296836853f,0.04891335964202881f,-0.11870327591896057f,0.4001283347606659f,0.023342788219451904f,0.3089201748371124f,-0.3160521388053894f,0.14951297640800476f},
-{0.047732532024383545f,-0.09652574360370636f,0.8443890810012817f,-0.2737945318222046f,-0.6023720502853394f,0.0635899230837822f,-0.3198729455471039f,0.06247803568840027f,-0.14267313480377197f,-0.025146597996354103f,0.22248788177967072f,-0.3128277659416199f,-0.1967906951904297f,2.094522714614868f,-0.3103681206703186f,-0.29817160964012146f},
+    {-0.36079341173171997f,0.0360223725438118f,-0.2051449418067932f,-0.39598140120506287f,-0.3172777593135834f,0.1664893478155136f,0.3332441747188568f,0.3036012351512909f,-0.2405819296836853f,0.04891335964202881f,-0.11870327591896057f,0.4001283347606659f,-0.09934001415967941f,0.4381318688392639f,-0.18075375258922577f,0.14712423086166382f},
+{0.047732532024383545f,0.8276740908622742f,-2.895641326904297f,-0.7189748883247375f,-0.8473038673400879f,-1.5547460317611694f,-0.3198729455471039f,0.06247803568840027f,-0.15339034795761108f,-0.6566473841667175f,0.10441755503416061f,-0.37812095880508423f,1.0550841093063354f,1.1523609161376953f,-1.7321557998657227f,-0.29818227887153625f},
 {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.09327439963817596f,0.05971873924136162f,-0.3845849633216858f,-0.5093491673469543f,0.33769017457962036f,0.20021501183509827f,0.07002416253089905f,-0.33915144205093384f,-0.365601509809494f,-0.03443625569343567f,0.41021624207496643f,-0.2978057265281677f,0.35003378987312317f,0.26804131269454956f,-0.023121735081076622f},
+{-0.30922991037368774f,1.5714359283447266f,-1.248551607131958f,-0.7984899878501892f,-2.37579083442688f,2.149235486984253f,0.20021501183509827f,0.07002416253089905f,-0.28455856442451477f,-0.21670381724834442f,0.13192829489707947f,0.41021624207496643f,-0.6988661289215088f,2.150631904602051f,1.689864158630371f,-0.02943922020494938f},
 {-0.39607733488082886f,-0.05481579899787903f,0.1976260244846344f,0.022423356771469116f,0.16892847418785095f,-0.27518749237060547f,0.16012099385261536f,0.3626593053340912f,-0.08640444278717041f,-0.11053556203842163f,-0.10529157519340515f,-0.31317979097366333f,-0.1530032455921173f,-0.1336749792098999f,0.22959044575691223f,0.19986507296562195f},
-{-0.37449589371681213f,1.8457472324371338f,-1.8165240287780762f,0.09289615601301193f,-1.1789792776107788f,1.3625030517578125f,-0.18732719123363495f,0.22384825348854065f,-0.5127489566802979f,-1.1904394626617432f,-0.154531329870224f,0.19005391001701355f,-0.5971469283103943f,-0.36133918166160583f,0.4544094502925873f,-0.4715000092983246f},
-{0.4110594093799591f,0.2230953872203827f,-0.48654863238334656f,0.37246426939964294f,-0.24602459371089935f,0.1548190414905548f,-0.08670487999916077f,-0.25336313247680664f,-0.030661463737487793f,0.22344467043876648f,-0.1344406008720398f,0.35313835740089417f,0.21155259013175964f,0.10930821299552917f,0.3126353323459625f,-0.3391006588935852f},
-{-0.40892091393470764f,0.04582450911402702f,-0.3875610828399658f,0.25968697667121887f,0.3424709737300873f,-0.05059037357568741f,-0.23312048614025116f,-0.390264093875885f,0.28059282898902893f,-0.15431912243366241f,-0.14134526252746582f,-0.0003446042537689209f,-0.2742875814437866f,-0.3649594783782959f,0.07994696497917175f,0.005298197269439697f},
+{-0.37449589371681213f,1.4197392463684082f,0.9165111780166626f,-1.0427320003509521f,-0.05542439967393875f,0.43611469864845276f,-0.18732719123363495f,0.22384825348854065f,-0.5186166167259216f,-0.46416231989860535f,-0.37602612376213074f,0.08064482361078262f,0.9774999022483826f,-0.96781325340271f,0.7397663593292236f,-0.348768025636673f},
+{0.4110594093799591f,0.5826829075813293f,-0.21363244950771332f,0.3347121477127075f,0.08417744934558868f,0.2202162891626358f,-0.08670487999916077f,-0.25336313247680664f,-0.030661463737487793f,-0.06259563565254211f,-0.1344406008720398f,0.35313835740089417f,0.21155259013175964f,0.06360813230276108f,0.3126353323459625f,-0.3391006588935852f},
+{-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.8427432179450989f,0.679609477519989f,-0.1838339865207672f,-0.8048290014266968f,1.4805269241333008f,-0.08742031455039978f,0.05785742402076721f,-0.4665476381778717f,0.49658796191215515f,-0.08510879427194595f,-0.309722363948822f,-0.2896781861782074f,-0.9483605027198792f,0.4396055340766907f,0.17858834564685822f},
-{-0.408692330121994f,0.15604840219020844f,-0.11896948516368866f,0.0922636091709137f,-0.1451295167207718f,0.10412421077489853f,0.03285527229309082f,0.38763079047203064f,-0.20705322921276093f,-0.07742909342050552f,0.12809070944786072f,0.03996849060058594f,-0.4220041334629059f,-0.2886850833892822f,-0.3350064158439636f,0.3153386116027832f},
-{-0.2991822361946106f,0.3794580399990082f,-0.07897943258285522f,-0.05932474136352539f,0.08582660555839539f,0.24227938055992126f,-0.11253207921981812f,0.34576353430747986f,0.04814547300338745f,-0.35770976543426514f,-0.044228196144104004f,-0.36229726672172546f,0.015840977430343628f,-0.13475483655929565f,0.36124154925346375f,-0.16869547963142395f},
-{-0.2675279378890991f,0.4225318431854248f,-1.3180500268936157f,0.011379898525774479f,1.3076831102371216f,0.03549259528517723f,-0.32875844836235046f,-0.31893211603164673f,-0.9009249806404114f,-0.3250093460083008f,-0.5623511672019958f,-0.42054229974746704f,0.48087817430496216f,2.155684232711792f,0.3168305456638336f,0.050804875791072845f},
-{-0.015470266342163086f,-0.5833328366279602f,0.6117988228797913f,0.3354269862174988f,0.33325907588005066f,-0.5840275883674622f,0.05196094512939453f,-0.008358269929885864f,-0.5232630372047424f,-0.37522807717323303f,0.06831542402505875f,-0.11511552333831787f,0.5202909708023071f,-0.2629256248474121f,-0.06220770627260208f,-0.4585099518299103f},
-{0.1863725483417511f,1.084182858467102f,-1.0181115865707397f,-0.4724007248878479f,-0.33689597249031067f,0.9457219839096069f,0.04860696196556091f,0.17769548296928406f,-0.12625347077846527f,0.3378079831600189f,-0.4645434319972992f,0.19592127203941345f,-0.12818381190299988f,1.0687506198883057f,-0.028336618095636368f,-0.11500971764326096f},
+{0.15459725260734558f,0.8423792719841003f,-0.08067841827869415f,-0.6714912056922913f,-0.44800329208374023f,0.3429917097091675f,-0.08742031455039978f,0.05785742402076721f,-0.19653022289276123f,-0.34943631291389465f,-0.009556683711707592f,-0.30447322130203247f,-0.12912006676197052f,-0.036994293332099915f,0.5005905032157898f,0.3082493841648102f},
+{-0.408692330121994f,0.00016882641648408026f,0.07694726437330246f,-0.20951619744300842f,-0.07695908844470978f,-0.13925538957118988f,0.03285527229309082f,0.38763079047203064f,-0.20705322921276093f,-0.25883403420448303f,0.12809070944786072f,0.03996849060058594f,-0.4803943336009979f,-0.1641838550567627f,-0.133147731423378f,0.31533604860305786f},
+{-0.2991822361946106f,0.379294216632843f,-0.07897943258285522f,-0.09465082734823227f,0.08582660555839539f,0.2713330388069153f,-0.11253207921981812f,0.34576353430747986f,0.04814547300338745f,-0.35770976543426514f,-0.044228196144104004f,-0.36229726672172546f,0.004417163785547018f,-0.10467953234910965f,0.36124154925346375f,-0.16869547963142395f},
+{-0.2675279378890991f,-0.34640875458717346f,-0.44033652544021606f,0.997279942035675f,0.1495940089225769f,0.5893060564994812f,-0.32875844836235046f,-0.31893211603164673f,-0.8021053075790405f,-0.7621317505836487f,-0.5216618776321411f,-0.5296260714530945f,1.14543616771698f,-0.7926355600357056f,0.11776287108659744f,0.18698225915431976f},
+{-0.015470266342163086f,-1.1242914199829102f,-1.333337664604187f,0.5949698090553284f,-1.0383976697921753f,-2.408407688140869f,0.05196094512939453f,-0.008358269929885864f,-0.6119314432144165f,-0.6426531076431274f,0.13179203867912292f,-0.04501182585954666f,-1.284587025642395f,2.8592796325683594f,-0.5470286011695862f,-0.4591246545314789f},
+{0.1863725483417511f,2.1868832111358643f,-0.9707214832305908f,-0.549004316329956f,-0.573555052280426f,1.7018946409225464f,0.04860696196556091f,0.17769548296928406f,-0.08241094648838043f,0.22327333688735962f,-0.3929237127304077f,0.19592127203941345f,0.30913761258125305f,1.387982726097107f,0.10862469673156738f,-0.1303754299879074f},
 };
 
-const float hout[16] = { 0.45773375034332275f,1.3250397443771362f,-0.4248747229576111f,-0.16762784123420715f,-0.8701521158218384f,-0.003051317995414138f,0.0030125975608825684f,0.15066689252853394f,-0.0765313059091568f,0.410363107919693f,0.11355479061603546f,-0.2710728645324707f,-1.0137888193130493f,0.31872233748435974f,0.46201157569885254f,-0.1275034099817276f };
-
-const float b1[16] = { 0.34279701113700867f,1.5129735469818115f,-1.7145336866378784f,0.27451324462890625f,0.7754346132278442f,1.2727166414260864f,-0.058932315558195114f,0.9473782777786255f,1.5622917413711548f,-1.0377662181854248f,0.5732393264770508f,1.2818049192428589f,-0.37127330899238586f,-1.0851714611053467f,-1.087764859199524f,2.291581153869629f };
-
-const float b2[16] = { -0.1286313831806183f,-1.2512075901031494f,-1.4564176797866821f,-0.8030261397361755f,-0.6939148902893066f,-0.16376319527626038f,0.1311706006526947f,-0.3665841221809387f,-1.20063054561615f,-1.912178635597229f,-0.45517241954803467f,0.411864310503006f,-0.07918518036603928f,1.8873447179794312f,-0.0411815345287323f,0.7242259383201599f };
-
-const float b3[16] = { -1.963319182395935f,-0.7351341247558594f,0.32978370785713196f,-0.1386529505252838f,0.019260885193943977f,-0.056516703218221664f,-0.45353031158447266f,-0.6562485098838806f,-0.015211169607937336f,0.6103503704071045f,-0.34831100702285767f,-0.014407366514205933f,-0.753882646560669f,-1.2588518857955933f,-1.226777195930481f,-0.5482154488563538f };
-
-const float bout[1] = { 0.2236381620168686f };
+const float hout[16] = { 0.45773375034332275f,0.6198812127113342f,3.075077533721924f,-0.6007036566734314f,0.24847236275672913f,1.247266173362732f,0.0030125975608825684f,0.15066689252853394f,0.05033086612820625f,0.0533946268260479f,0.11185391992330551f,-0.1749655306339264f,-1.0110498666763306f,1.219071388244629f,1.8872015476226807f,-0.16191136837005615f };
+
+const float b1[16] = { 0.5638260245323181f,1.1806942224502563f,-1.7145336866378784f,0.24818021059036255f,0.8975874781608582f,1.2844585180282593f,-0.058932315558195114f,0.825614333152771f,1.6077704429626465f,-1.1153591871261597f,0.5720832943916321f,1.1545846462249756f,-0.3732912540435791f,-1.3868684768676758f,-1.087764859199524f,0.9789383411407471f };
+
+const float b2[16] = { -0.2617855966091156f,-0.8839436173439026f,-1.4564176797866821f,-0.6468855738639832f,-0.6939148902893066f,0.16817186772823334f,0.09135577827692032f,-0.30969977378845215f,-1.20063054561615f,-1.912178635597229f,-0.1662583202123642f,0.14832311868667603f,-0.23087339103221893f,1.7029191255569458f,0.10706561803817749f,0.5922772884368896f };
+
+const float b3[16] = { -1.963319182395935f,-0.13796980679035187f,-0.907817006111145f,0.09013273566961288f,-0.1457054167985916f,0.9321498870849609f,-0.45353031158447266f,-0.6562485098838806f,-0.01854712702333927f,-0.023044707253575325f,-0.4521785378456116f,-0.06036800891160965f,-1.33890962600708f,0.4787708818912506f,-1.2732046842575073f,-0.41846638917922974f };
+
+const float bout[1] = { -1.3581293821334839f };
 
 /////////////////////////////////////////////////////////////////////////////////////////////RL
 float input_RL[num_input_RL] = { 0.0f };
@@ -576,7 +576,7 @@
 ///////////////////////////Softplus//////////////////////////////////
 void update_Actor_Networks(float (*arr)[num_input_RL])
 {
-    
+
 
     float G_ha1[num_input_RL][num_hidden_unit1] = {0.0f};
     float G_ba1[num_hidden_unit1] = {0.0f};
@@ -803,9 +803,8 @@
 {
     float add = 0.0f;
     float result;
-    
-    for (int i=0; i<size; i++)
-    {
+
+    for (int i=0; i<size; i++) {
         add += x[i];
     }
     result = (float) add/size;
@@ -815,15 +814,14 @@
 {
     float sigma = 0.0f;
     float resultDeb = 0.0f;
-    
-    for (int k=0; k<size; k++)
-    {
+
+    for (int k=0; k<size; k++) {
         sigma = pow((float)x[k]-mean_adv(x,size), (float)2.0f)/(size-1);
         resultDeb += sqrt(sigma);
     }
     return resultDeb;
-}    
-     
+}
+
 
 void Overwirte_Critic_Networks()
 {
@@ -2493,11 +2491,12 @@
 
                 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
-                
+
                 V_adapt = 1.0f / (1.0f/Va + 1.0f/Vb); //initial 0.0000053f
-
-
-                float f3 = -Amm*Amm*beta*0.000001f*0.000001f/V_adapt * vel.sen/(float)(ENC_PULSE_PER_POSITION)*0.001f; // unit : N/s    //xdot=10mm/s일때 -137076
+                
+//                float f3 = -Amm*Amm*beta*0.000001f*0.000001f/V_adapt * vel.sen/(float)(ENC_PULSE_PER_POSITION)*0.001f; // unit : N/s    //xdot=10mm/s일때 -137076
+                a_hat = -Amm*Amm*beta*0.000001f*0.000001f/V_adapt;             //-13707631
+                float f3 = a_hat * vel.sen/(float)(ENC_PULSE_PER_POSITION)*0.001f; 
 
                 float g3_prime = 0.0f;
                 if (torq.sen > Amm*(Ps-Pt)*0.000001f) {
@@ -2551,18 +2550,35 @@
                 float x_4_des_dot = (x_4_des - x_4_des_old)*(float) TMR_FREQ_5k;
                 x_4_des_old = x_4_des;
                 float V_input = 0.0f;
-                V_out = (-f4 + x_4_des_dot - k4*(x_v-x_4_des)- rho3/rho4*gamma_hat*g3_prime*(-torq.err))/g4;
-//                //V_out LPF
-//                float alpha_V_out = 1.0f/(1.0f + 5000.0f/(2.0f*3.14f*50.0f)); // f_cutoff : 50Hz
-//                V_out = V_out*(1.0f-alpha_V_out)+V_input*(alpha_V_out);
-
-                float rho_gamma = 5000.0f;//5000 for change //50000 for not change
-                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;
+                
+                V_input = (-f4 + x_4_des_dot - k4*(x_v-x_4_des)- rho3/rho4*gamma_hat*g3_prime*(-torq.err))/g4;
                 
-                if(gamma_hat > 10000.0f) gamma_hat = 10000.0f;
-                else if(gamma_hat < 100.0f) gamma_hat = 100.0f;
+                //V_out LPF
+                float alpha_V_out = 1.0f/(1.0f + 5000.0f/(2.0f*3.14f*5.0f)); // f_cutoff : 5Hz
+                V_output = V_output*(1.0f-alpha_V_out) + V_input*(alpha_V_out);
+                if (V_output >= VALVE_VOLTAGE_LIMIT*1000.0f) {
+                    V_output = VALVE_VOLTAGE_LIMIT*1000.0f;
+                } else if(V_output<=-VALVE_VOLTAGE_LIMIT*1000.0f) {
+                    V_output = -VALVE_VOLTAGE_LIMIT*1000.0f;
+                }
+                V_out = V_output;
+
+//              // 1999 paper
+//                float rho_gamma = 5000.0f;//5000 for change //50000 for not change
+//                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;
+//
+//                if(gamma_hat > 10000.0f) gamma_hat = 10000.0f;
+//                else if(gamma_hat < 100.0f) gamma_hat = 100.0f;
+        
+                // 2000 paper
+                float rho_a = 1.0f;
+                float a_hat_dot = -rho3/rho_a * vel.sen/(float)(ENC_PULSE_PER_POSITION) * 0.001f * (-torq.err);
+                //a_hat = a_hat + a_hat_dot / (float) TMR_FREQ_5k;
                 
+                if(a_hat > -1000000.0f) a_hat = -1000000.0f;
+                else if(a_hat < -100000000.0f) a_hat = -100000000.0f;
+
                 break;
             }
 
@@ -2600,7 +2616,7 @@
                     virt_pos = virt_pos + (action_array[RL_timer] - 5.0f) * 1000.0f * 0.0002f;
                     if (virt_pos > 70 ) {
                         virt_pos = 70.0f;
-                    }else if(virt_pos < -70) {
+                    } else if(virt_pos < -70) {
                         virt_pos = -70.0f;
                     }
 
@@ -2643,7 +2659,7 @@
                     virt_pos = virt_pos + (action-5.0f) * 1000.0f * 0.0002f;
                     if (virt_pos > 70) {
                         virt_pos = 70.0f;
-                    }else if(virt_pos < -70) {
+                    } else if(virt_pos < -70) {
                         virt_pos = -70.0f;
                     }
 
@@ -2845,7 +2861,7 @@
             if (flag_data_request[4] == HIGH) {
                 //valve position
                 //CAN_TX_VALVE_POSITION((int16_t) pos.sen/(float)(ENC_PULSE_PER_POSITION), (int16_t) virt_pos, (int16_t) (logging2*1000.0f), (int16_t) (logging4*1000.0f)); //1600
-                CAN_TX_VALVE_POSITION((int16_t) gamma_hat, (int16_t) 0, (int16_t) 0, (int16_t) 0); //1600
+                CAN_TX_VALVE_POSITION((int16_t) (a_hat*0.0001f), (int16_t) 0, (int16_t) 0, (int16_t) 0); //1600
             }
 
             // Others : Reference position, Reference FT, PWM, Current  (ID:1300)