rusEFI
The most advanced open source ECU
dynoview.cpp
Go to the documentation of this file.
1 /*
2  * @file dynoview.cpp
3  *
4  * @date Nov 29, 2020
5  * @author Alexandru Miculescu, (c) 2012-2020
6  */
7 
8 #include "pch.h"
9 
10 #if EFI_DYNO_VIEW
11 #include "dynoview.h"
12 
14 
16 
17  efitimeus_t timeNow, deltaTime = 0.0;
18  float speed,deltaSpeed = 0.0;
19  timeNow = getTimeNowUs();
21  if (src == ICU) {
22  speed = efiRound(speed,1.0);
23  } else {
24  //use speed with 0.001 precision from source CAN
25  speed = efiRound(speed,0.001);
26  }
27 
28  if(timeStamp != 0) {
29 
30  if (vss != speed) {
31  deltaTime = timeNow - timeStamp;
32  if (vss > speed) {
33  deltaSpeed = (vss - speed);
34  direction = 1; //decceleration
35  } else {
36  deltaSpeed = speed - vss;
37  direction = 0; //acceleration
38  }
39 
40  //save data
41  timeStamp = timeNow;
42  vss = speed;
43  }
44 
45  //updating here would display acceleration = 0 at constant speed
46  updateAcceleration(deltaTime, deltaSpeed);
47 #if EFI_TUNER_STUDIO
48  if (engineConfiguration->debugMode == DBG_LOGIC_ANALYZER) {
54  }
55 #endif /* EFI_TUNER_STUDIO */
56  updateHP();
57 
58  } else {
59  //ensure we grab init values
60  timeStamp = timeNow;
61  vss = speed;
62  }
63 }
64 
65 /**
66  * input units: deltaSpeed in km/h
67  * deltaTime in uS
68  */
69 void DynoView::updateAcceleration(efitimeus_t deltaTime, float deltaSpeed) {
70  if (deltaSpeed != 0.0) {
71  acceleration = ((deltaSpeed / 3.6) / (deltaTime / US_PER_SECOND_F));
72  if (direction) {
73  //decceleration
74  acceleration *= -1;
75  }
76  } else {
77  acceleration = 0.0;
78  }
79 }
80 
81 /**
82  * E = m*a
83  * ex. 900 (kg) * 1.5 (m/s^2) = 1350N
84  * P = F*V
85  * 1350N * 35(m/s) = 47250Watt (35 m/s is the final velocity)
86  * 47250 * (1HP/746W) = 63HP
87  * https://www.youtube.com/watch?v=FnN2asvFmIs
88  * we do not take resistence into account right now.
89  */
91 
92  //these are actually at the wheel
93  //we would need final drive to calcualte the correct torque at the wheel
94  if (acceleration != 0) {
96  enginePower = engineForce * (vss / 3.6);
97  engineHP = enginePower / 746;
100  }
101  } else {
102  //we should calculate static power
103  }
104 
105 }
106 
107 #if EFI_UNIT_TEST
109  acceleration = a;
110 }
111 #endif
112 
114  return acceleration;
115 }
116 
118  return engineForce;
119 }
120 
122  return (enginePower/1000);
123 }
124 
126  return engineHP;
127 }
128 
130  return (engineTorque/0.73756);
131 }
132 
133 
135  return dynoInstance.getAcceleration();
136 }
137 
139  return dynoInstance.getEnginePower();
140 }
141 
142 /**
143  * Periodic update function called from SlowCallback.
144  * Only updates if we have Vss from input pin.
145  */
150  }
151 }
152 
153 /**
154  * This function is called after every CAN msg received, we process it
155  * as soon as we can to be more acurate.
156  */
159  return;
160  }
161 
163 }
164 
165 #endif /* EFI_DYNO_VIEW */
int getEngineTorque()
Definition: dynoview.cpp:129
void updateHP()
Definition: dynoview.cpp:90
void updateAcceleration(efitimeus_t deltaTime, float deltaSpeed)
Definition: dynoview.cpp:69
int getEngineHP()
Definition: dynoview.cpp:125
int getEngineForce()
Definition: dynoview.cpp:117
float getAcceleration()
Definition: dynoview.cpp:113
float acceleration
Definition: dynoview.h:43
efitimeus_t timeStamp
Definition: dynoview.h:39
int engineHP
Definition: dynoview.h:49
int enginePower
Definition: dynoview.h:47
uint8_t direction
Definition: dynoview.h:53
int getEnginePower()
Definition: dynoview.cpp:121
int engineForce
Definition: dynoview.h:45
void update(vssSrc src)
Definition: dynoview.cpp:15
float vss
Definition: dynoview.h:41
int engineTorque
Definition: dynoview.h:51
void setAcceleration(float a)
Definition: dynoview.cpp:108
TunerStudioOutputChannels outputChannels
Definition: engine.h:96
static float getOrZero(SensorType type)
Definition: sensor.h:92
int getDynoviewPower()
Definition: dynoview.cpp:138
void updateDynoView()
Definition: dynoview.cpp:146
float getDynoviewAcceleration()
Definition: dynoview.cpp:134
static DynoView dynoInstance
Definition: dynoview.cpp:13
void updateDynoViewCan()
Definition: dynoview.cpp:157
vssSrc
Definition: dynoview.h:16
@ CAN
Definition: dynoview.h:18
@ ICU
Definition: dynoview.h:17
float efiRound(float value, float precision)
Definition: efilib.cpp:33
efitimeus_t getTimeNowUs()
Definition: efitime.cpp:26
Engine * engine
engine_configuration_s * engineConfiguration
bool isBrainPinValid(brain_pin_e brainPin)