Skip to content

Commit

Permalink
Add dynamic compression amplitude
Browse files Browse the repository at this point in the history
  • Loading branch information
noisymime committed May 16, 2024
1 parent 207c606 commit fe6cd5c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions UI/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,8 @@ input, select, textarea {
hr {
border: 0;
border-top: solid 1px #ddd;
padding: 1.5em 0 0 0;
margin: 1.75em 0 0 0;
padding: 0.5em 0 0 0;
margin: 0.75em 0 0 0;
}

sub {
Expand Down
11 changes: 9 additions & 2 deletions UI/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</div>
</div>
<div class="row">
<div class="col-5">RPM Sweep range: </div>
<div class="col-5">Sweep range: </div>
<div class="col-3">
<input type="number" id="rpmSweepMin" min="0" max="10000" step="1" value="100" onChange="sendConfig()" disabled>
</div>
Expand All @@ -74,17 +74,24 @@
</div>
</div>
<div class="row">
<div class="col-5">RPM Sweep speed: </div>
<div class="col-5">Sweep speed: </div>
<div class="col-2">
<input type="range" id="rpmSweepSpeed" min="200" max="4000" step="10" value="3000" onChange="sendConfig()" disabled>
</div>
</div>
<hr />
<div class="row">
<div class="col-7"><span class="tooltip">Enable compression: <span class="tooltiptext">When Enabled, this simulates RPM 'waves' that are common during cranking as each cylinder compresses. The effect will only be active below a set RPM value</span></span></div>
<div class="col-2">
<input type="checkbox" id="compressionEnable" onChange="toggleCompression()">
</div>
</div>
<div class="row">
<div class="col-7"><span class="tooltip">Dynamic amplitude: <span class="tooltiptext">When Enabled, the amplitude of the waves will change based on how far the RPM is below the compression RPM setting. If disabled, the wave amplitude will always be 100rpm</span></span></div>
<div class="col-2">
<input type="checkbox" id="compressionDynamic" onChange="sendConfig()" disabled>
</div>
</div>
<div class="row">
<div class="col-7">Configuration: </div>
<div class="col-2">
Expand Down
5 changes: 4 additions & 1 deletion UI/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ByteLengthParser = require('@serialport/parser-byte-length')
const {ipcRenderer} = require("electron")
var port = new serialport('/dev/tty-usbserial1', { autoOpen: false })

const CONFIG_SIZE = 17;
const CONFIG_SIZE = 18;
var onConnectIntervalConfig;
var onConnectIntervalWheels;
var isConnected=false;
Expand Down Expand Up @@ -236,6 +236,7 @@ function receiveConfig(data)
document.getElementById("compressionMode").value = data[12];
document.getElementById("compressionRPM").value = (((data[14] & 0xff) << 8) | (data[13] & 0xff));
document.getElementById("compressionOffset").value = (((data[16] & 0xff) << 8) | (data[15] & 0xff));
document.getElementById("compressionDynamic").value = data[17];

port.unpipe();

Expand All @@ -260,6 +261,7 @@ function sendConfig()
configBuffer[12] = parseInt(document.getElementById('compressionMode').value);
configBuffer.writeUInt16LE(parseInt(document.getElementById('compressionRPM').value), 13);
configBuffer.writeUInt16LE(parseInt(document.getElementById('compressionOffset').value), 15);
configBuffer[16] = document.getElementById('compressionDynamic').checked;

console.log("Sending full config: ", configBuffer);

Expand Down Expand Up @@ -568,6 +570,7 @@ function toggleCompression()
{
var state = document.getElementById('compressionEnable').checked

document.getElementById('compressionDynamic').disabled = !state
document.getElementById('compressionMode').disabled = !state
document.getElementById('compressionRPM').disabled = !state
document.getElementById('compressionOffset').disabled = !state
Expand Down
10 changes: 9 additions & 1 deletion ardustim/ardustim/ardustim.ino
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void loop()

uint16_t calculateCompressionModifier()
{
if( (currentStatus.rpm > config.compressionRPM) || (config.useCompression != true) ) { return 0; }
if( (currentStatus.base_rpm > config.compressionRPM) || (config.useCompression != true) ) { return 0; }
//if( currentStatus.base_rpm > 400 ) { return 0;}

uint16_t crankAngle = calculateCurrentCrankAngle();
Expand Down Expand Up @@ -359,6 +359,14 @@ uint16_t calculateCompressionModifier()
compressionModifier = pgm_read_byte(&sin_100_180[modAngle]);
break;
}

//RPM scaler - Varies the amplitude of the compression modifier based on how far below the compression RPM point we are. Eg:
//If the compression RPM value is 400
//At 300rpm the amplitude will be 75%
//At 200rpm the amplitude will be 50%
//At 100rpm the amplitude will be 25% etc
//Base RPM must be below 650 to prevent overflow
if(config.compressionDynamic && (currentStatus.base_rpm < 655U) ) { compressionModifier = (compressionModifier * currentStatus.base_rpm) / config.compressionRPM; }

return compressionModifier;
}
Expand Down
1 change: 1 addition & 0 deletions ardustim/ardustim/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct configTable
uint8_t compressionType = 0;
uint16_t compressionRPM = 400;
uint16_t compressionOffset = 0;
bool compressionDynamic = false;
} __attribute__ ((packed));
extern struct configTable config;

Expand Down

0 comments on commit fe6cd5c

Please sign in to comment.