From ac6015cf65f52bd9b621084838d0fcafce2b229c Mon Sep 17 00:00:00 2001 From: Fisch Date: Tue, 10 Jul 2018 23:18:48 +0200 Subject: [PATCH] fix physics calculation. move wagon mass back to their corresponding terms --- achterbahn.ino | 4 ++-- .../achterbahnconfig/achterbahnconfig.pde | 10 +++++----- ...nconfig.pde => backup_achterbahnconfig.pde} | 0 wagon.cpp | 18 ++++++++++-------- 4 files changed, 17 insertions(+), 15 deletions(-) rename achterbahnconfig/{achterbahnconfig.pde => backup_achterbahnconfig.pde} (100%) diff --git a/achterbahn.ino b/achterbahn.ino index 27b5fb4..b82dd67 100644 --- a/achterbahn.ino +++ b/achterbahn.ino @@ -226,7 +226,7 @@ void spawnWagon(){ // pos, wagonlength, startvel , startacc, trainmass, wagoncolor //Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, random(0, 20), _randomlength, random(map(_randomlength,3,40,1,1), map(_randomlength,3,40, 13,40))/10.0 , 0 , 5 , Wheel((uint8_t)random(0,255))); //spawn new wagon - Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, NUMPIXELS+_randomlength, _randomlength, -random(map(_randomlength,3,40,10,20), map(_randomlength,3,40, 22,60))/10.0 , 0 , 5 , Wheel((uint8_t)random(0,255))); //spawn new wagon + Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, NUMPIXELS+_randomlength, _randomlength, -random(map(_randomlength,3,40,10,20), map(_randomlength,3,40, 22,60))/10.0 , 0 , 2.0 , Wheel((uint8_t)random(0,255))); //spawn new wagon //special spawns if (random(0,50)==0){ @@ -313,7 +313,7 @@ void checkSerial(){ int spawnstartacc=rest.substring(0,rest.indexOf(',')).toInt(); //part to next , rest=rest.substring(rest.indexOf(',')+1); //part after , - int spawnmass=rest.substring(0,rest.indexOf(',')).toInt(); //part to next , + float spawnmass=rest.substring(0,rest.indexOf(',')).toInt()/1000.0; //part to next , //mass in gramm rest=rest.substring(rest.indexOf(',')+1); //part after , int spawncolor=rest.substring(0).toInt(); //part to next , diff --git a/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde b/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde index 077b791..85ff540 100644 --- a/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde +++ b/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde @@ -29,7 +29,7 @@ int spawnstartacc; int maxspawnstartacc=100; Slider slSpawnMass; int spawnmass; -int maxspawnmass=200; +int maxspawnmass=10000; Slider slSpawnColor; int spawncolor; int maxspawncolor=255; @@ -91,7 +91,7 @@ void setup() { slSpawnPos = cp5.addSlider("spawnpos") .setRange(0,numpixels-1) - .setValue(0) + .setValue(590) .setPosition(220,80) .setSize(300,10); @@ -103,7 +103,7 @@ void setup() { slSpawnStartvel = cp5.addSlider("spawnstartvel") .setRange(-maxspawnstartvel,maxspawnstartvel) - .setValue(70) + .setValue(-20) .setPosition(220,80+15*2) .setSize(maxspawnstartvel*2,10); @@ -115,9 +115,9 @@ void setup() { slSpawnMass = cp5.addSlider("spawnmass") .setRange(1,maxspawnmass) - .setValue(10) + .setValue(1000) .setPosition(220,80+15*4) - .setSize(maxspawnmass-1,10); + .setSize(maxspawnmass/100-1,10); slSpawnColor = cp5.addSlider("spawncolor") .setRange(0,maxspawncolor) diff --git a/achterbahnconfig/achterbahnconfig.pde b/achterbahnconfig/backup_achterbahnconfig.pde similarity index 100% rename from achterbahnconfig/achterbahnconfig.pde rename to achterbahnconfig/backup_achterbahnconfig.pde diff --git a/wagon.cpp b/wagon.cpp index eeb2aa5..66f935a 100644 --- a/wagon.cpp +++ b/wagon.cpp @@ -77,10 +77,10 @@ void Wagon::updatePhysics(float updatedelayms) }*/ #define CONST_G 9.81 #define PIXELDISTANCE 1.6666667 // 1/60.0 * 100 - #define C_ROLL 0.001 // = Croll * G https://de.wikipedia.org/wiki/Rollwiderstand 0.001 (zug) - #define AIRRESFIRST 0.18 //C_w*A*0.5*rho Air resistance: C_w * A * 0.5 * rho (.... *v^2) - #define AIRRES 0.01 //for slipstream at second wagon - #define AIRRESMUL 0.7 //how much of air resistance the next wagon has + #define C_ROLL 0.001 // = Croll https://de.wikipedia.org/wiki/Rollwiderstand 0.001 (zug) + #define AIRRESFIRST 0.018 //C_w*A*0.5*rho Air resistance: C_w * A * 0.5 * rho (.... *v^2) 0.18 + #define AIRRES 0.001 //for slipstream at second wagon + #define AIRRESMUL 0.2 //how much of air resistance the next wagon has //http://www.kfz-tech.de/Biblio/Formelsammlung/Luftwiderstand.htm C_w 0.6 //rho Massendichte luft 1,2041 //A = 1m^2 @@ -105,10 +105,10 @@ void Wagon::updatePhysics(float updatedelayms) //_acc += CONST_G * cos(beta) - C_ROLLG*sin(beta) - AIRRES/m*_vel*_vel; - float aa=CONST_G * cos(beta) *updatedelayms/1000; //Gravity and m/s^2 time correction + float aa=CONST_G *m* cos(beta) *updatedelayms/1000; //Gravity and m/s^2 time correction //Roll Resistance - float bb=C_ROLL*CONST_G*updatedelayms/1000*sin(beta); //roll resistance + float bb=C_ROLL*m*CONST_G*updatedelayms/1000*sin(beta); //roll resistance if (_vel<0){ bb*=-1; @@ -117,9 +117,11 @@ void Wagon::updatePhysics(float updatedelayms) //Air Resistance float cc=0; if (wagonnumber==0){ //first wagon - cc=AIRRESFIRST/m*pow(_vel,2); //air resistance for first wagon + //cc=AIRRESFIRST/m*pow(_vel,2); //air resistance for first wagon + cc=AIRRESFIRST*pow(_vel,2); //air resistance for first wagon }else { - cc=AIRRES/m*pow(_vel,2) *pow(AIRRESMUL,wagonnumber-1); //air resistance + //cc=AIRRES/m*pow(_vel,2) *pow(AIRRESMUL,wagonnumber-1); //air resistance + cc=AIRRES*pow(_vel,2) *pow(AIRRESMUL,wagonnumber-1); //air resistance } if (_vel<0){