Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:9a3416ed85c5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jun 10 23:52:30 2020 +0000 @@ -0,0 +1,158 @@ +#include "mbed.h" +#include "math.h" + + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +LocalFileSystem name("local"); + +int main() { + + + int i; + + FILE *fp1; + FILE *fp2; + + double x1[12]; + double y; + + int k; + double xp1[12]; + static const double b[12] = { 59.2416243584351, 24.103961890679, + 63.4731009187792, -9.08514665942534, -3.86282962493564, 122.259339815578, + -148.551741335807, -234.042011064834, -218.150614064212, -178.372006088071, + -79.8002107262464, -22.9908912361887 }; + + double av[12]; + static const double b_b[12] = { 0.0222700738481074, 0.024480398867528, + 0.0186350414013812, 0.563696802229006, 0.301008803773329, 0.0498977136859748, + 0.0237224002500299, 0.0119627362185442, 0.0130796528084212, + 0.0143258173123321, 0.0427784133116736, 0.0192108403250562 }; + + double d0; + double d1; + int i0; + static const double a[10] = { 0.92433029820093249, -0.3345867138763971, + -0.23333077480468864, 0.13014131784959329, 0.048717948404529608, + 0.24281549170723096, -0.64871794667151328, 0.44213469232645786, + 0.64165334547277764, 0.36575442779109313 }; + + static const double b_a[10] = { -1.19781806109026, -1.1597255659428132, + 1.005219361066259, -0.634053805018023, 0.12631479418148664, + 0.17828154855915918, -0.69740669316647219, -1.2169235750768683, + 1.383828465876682, 2.17344582115821 }; + + static const double c_a[120] = { 0.48355582888350035, 0.85707032397910687, + -0.44207212254628891, 0.17135665377441642, -0.25354242342266875, + 0.81450398829778614, 0.29117094693530787, -0.10028050520473253, + -0.26039721113382869, 0.47069972990590536, -0.07413178296216047, + 0.92854489436365428, -0.61763252505744348, 0.51077938571868753, + 0.21054817525259542, 0.83424269835988429, -0.035916552207017192, + -0.13548897182947406, -0.85379784602865327, -0.18885317899657586, + 0.79171895110745416, -0.82212731842148867, -0.38054797341298785, + -0.66808853453803874, 0.45470821947295548, -0.080864698221751935, + 1.0880690033295386, -0.78885223895632151, 0.31400507806575267, + -0.20737077574810134, 0.82598024431809369, 0.43985998841353191, + 0.27917303287100742, -0.95229848661889138, 1.0868383136558781, + -0.96099521606795923, -0.43523805960587919, -0.73155363743475976, + -0.923573716805755, -0.011453221497649043, 0.12539239659604834, + 1.4375851805255453, -0.37501731515261, -0.28542081189092572, + 0.17194386745399773, -0.22128998745880674, -0.6898582608476197, + -0.766795346177828, -0.085486270452420646, 0.20034996430438637, + -0.460479448080081, 0.4326023456325549, -0.29146270118839152, + 0.55556653263883016, -0.10325707758457579, -0.015664709642016942, + -0.87011531653393948, 0.26793494597704209, 0.60749881234398417, + -0.31553966309287373, -0.98599252193599018, -0.36677805226651228, + -0.54926552794703, 0.22754557092563496, 0.14408769744619623, + 0.61044304379287928, -0.27841266594812497, 0.30448747500877926, + -0.53711646738071361, 0.065184591776874662, 0.605636387298372, + 0.36538774818686026, 0.74635454846147442, -0.50499651014497315, + -0.027227925616738206, 0.26217058891409661, 0.37284054201746919, + 0.70996815304192329, 1.1316281637673793, -0.8600491837737525, + -0.19137728684927338, -1.0492295456481362, -0.25128613584947551, + -0.52207055717309314, -0.42561931630701311, -0.5730267232670827, + -0.32382068587578033, -0.41785103063976786, 0.054543500732962928, + 0.023513063044081437, -0.43267626341388643, -0.21366844104122562, + 0.963448238348314, 0.0069656372347315643, -0.581799812324173, + 0.13380943979545332, 0.33606721542768986, -0.6743130715487835, + -0.38829027889138973, -0.27280245816167964, 0.066008465744948078, + -1.1658570708081857, 0.045369243615443131, -0.039196766607316934, + 0.30896481175160356, 0.53939852662600685, 0.48599208973123892, + -1.0191291094627282, -0.10765289836638596, -0.96741775250215079, + 0.71995343139068924, 0.42567713558664166, -0.43197850145312766, + 0.023887388370709754, 0.68706865048047894, -0.39810041287391279, + 0.39021321157335626, -0.16684488417050469, -0.3128703452540143, + 0.12293296480165818 }; + + + + fp1=fopen("/local/InputCt.csv","r"); + fp2=fopen("/local/OutputCt.csv","w"); + + + myled1 = 1; + myled2 = 1; + myled3 = 1; + myled4 = 1; + wait(0.2); + myled2 = 0; + wait(0.2); + + +for(i=0;i<10;++i){ + + myled2 = 1; + wait(0.2); + + + fscanf(fp1,"%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",&x1[0],&x1[1],&x1[2],&x1[3],&x1[4],&x1[5],&x1[6],&x1[7],&x1[8],&x1[9],&x1[10],&x1[11]); + + + for (k = 0; k < 12; k++) { + xp1[k] = x1[k] - b[k]; + } + + for (k = 0; k < 12; k++) { + av[k] = xp1[k] * b_b[k]; + } + + memcpy(&xp1[0], &av[0], 12U * sizeof(double)); + for (k = 0; k < 12; k++) { + av[k] = xp1[k] + -1.0; + } + + memcpy(&xp1[0], &av[0], 12U * sizeof(double)); + + d0 = 0.0; + for (k = 0; k < 10; k++) { + d1 = 0.0; + for (i0 = 0; i0 < 12; i0++) { + d1 += c_a[k + 10 * i0] * xp1[i0]; + } + + d0 += a[k] * (2.0 / (1.0 + exp(-2.0 * (b_a[k] + d1))) - 1.0); + } + + y=((-0.23019776988546564 + d0) - -1.0) / 0.025 + 20.0; + + fprintf(fp2,"%lf\n",y); + + myled2 = 0; + wait(0.1); + + + } + myled2 = 1; + myled3 = 1; + wait(0.2); + + fclose(fp1); + fclose(fp2); + + myled4 = 1; + wait(0.2); +}