Commit ac14e145 authored by Wouter Klop's avatar Wouter Klop

Noise insertion implementation

parent ae3d39de
......@@ -45,9 +45,10 @@ Signals to plot<br />
<fieldset style="width:300px">
<legend>Signal generation</legend>
Amplitude
On / off
Location
<button id="noiseOn" onclick="sendCommand('pn',1)">Start</button>
<button id="noiseOff" onclick="sendCommand('pn',0)">Stop</button><br />
<input id="noiseAmplitude" type="range" min="0.1" max="10" step="0.1" oninput="sendCommand('pa',this.value);document.getElementById('noiseAmplitude_value').value = this.value;">
<input type="text" id="noiseAmplitude_value" readonly value="" style="width:40px"><br />
</fieldset>
</body>
......@@ -182,8 +183,8 @@ var plotStartStop = function (x) {
prescaler /= 2;
}
sendCommand('h', x);
sendCommand('i', prescaler);
sendCommand('pe', x);
sendCommand('pp', prescaler);
// Toggle user input disable/enable
var b = x==1;
......
......@@ -126,6 +126,10 @@ float speedFilterConstant = 0.9;
// -- WiFi
const char host[] = "balancingrobot";
// Noise source (for system identification)
boolean noiseSourceEnable = 0;
float noiseSourceAmplitude = 1;
// ----- Parameter definitions -----
// void updatePIDParameters() {
// pidAngle.updateParameters();
......@@ -435,7 +439,14 @@ void loop() {
pidAngle.setpoint = pidSpeedOutput;
}
pidAngle.input = filterAngle;
// Optionally, add some noise to angle for system identification purposes
if (noiseSourceEnable) {
pidAngle.input = filterAngle + noiseSourceAmplitude*((random(1000)/1000.0)-0.5);
} else {
pidAngle.input = filterAngle;
}
pidAngleOutput = pidAngle.calculate();
avgMotSpeedSum += pidAngleOutput/2;
......@@ -627,12 +638,29 @@ void parseCommand(char* data, uint8_t length) {
case 'g':
gyroGain = atof(data+1);
break;
case 'h':
plot.enable = atoi(data+1);
break;
case 'i':
plot.prescaler = atoi(data+1);
case 'p': {
switch (data[1]) {
case 'e':
plot.enable = atoi(data+2);
break;
case 'p':
plot.prescaler = atoi(data+2);
break;
case 'n': // Noise source enable
noiseSourceEnable = atoi(data+2);
break;
case 'a': // Noise source amplitude
noiseSourceAmplitude = atof(data+2);
break;
}
break;
}
// case 'h':
// plot.enable = atoi(data+1);
// break;
// case 'i':
// plot.prescaler = atoi(data+1);
// break;
case 'j':
gyroGain = atof(data+1);
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment