Alle Libraries eingefügt.

This commit is contained in:
2024-07-18 11:59:36 +02:00
parent d62c0e58a9
commit 80b797ab6c
5 changed files with 430 additions and 0 deletions

View File

@@ -1,45 +0,0 @@
#include <Arduino.h>
#include "Datalogger.h"
Datalogger logger;
void setup() {
Serial.begin(9600);
// Beispielkonfigurationen hinzufügen
logger.addConfig("Sample Rate", "1Hz");
logger.addConfig("Sensor Type", "Temperature");
// Beispieldaten hinzufügen
std::map<String, String> data1;
data1["Time"] = "0.1";
data1["Input"] = "1";
data1["Output"] = "5";
logger.addData(data1);
std::map<String, String> data2;
data2["Time"] = "0.2";
data2["Input"] = "2";
data2["Output"] = "10";
logger.addData(data2);
std::map<String, String> data3;
data3["Time"] = "0.3";
data3["Input"] = "3";
data3["Output"] = "15";
logger.addData(data3);
// Daten und Konfigurationen über die serielle Schnittstelle ausgeben
logger.logToSerial();
// Inhalte leeren
logger.clear();
// Überprüfen, ob die Inhalte geleert wurden
Serial.println("After clearing:");
logger.logToSerial();
}
void loop() {
// Hier könnte weitere Logik stehen
}

View File

@@ -1,71 +0,0 @@
#include "PID.h"
#include <Arduino.h>
PID::PID(float kp, float ki, float kd) {
this->kp = kp;
this->ki = ki;
this->kd = kd;
this->minOutput = 0;
this->maxOutput = 255;
this->lastOutput = 0;
this->sampleTime = 100; // Default sample time in milliseconds
this->lastTime = millis();
this->integral = 0;
this->lastInput = 0;
}
void PID::setTunings(float kp, float ki, float kd) {
this->kp = kp;
this->ki = ki;
this->kd = kd;
}
void PID::setOutputLimits(float min, float max) {
this->minOutput = min;
this->maxOutput = max;
}
void PID::setSampleTime(int sampleTime) {
this->sampleTime = sampleTime;
}
void PID::reset() {
this->integral = 0;
this->lastInput = 0;
this->lastTime = millis();
}
float PID::compute(float setpoint, float input) {
unsigned long now = millis();
unsigned long timeChange = now - lastTime;
if (timeChange >= sampleTime) {
// Calculate error
float error = setpoint - input;
// Proportional term
float Pout = kp * error;
// Integral term
integral += (ki * error * timeChange / 1000.0);
integral = constrain(integral, minOutput, maxOutput);
// Derivative term
float derivative = (input - lastInput) / (timeChange / 1000.0);
float Dout = kd * derivative;
// Compute output
float output = Pout + integral - Dout;
output = constrain(output, minOutput, maxOutput);
// Remember some variables for next time
lastInput = input;
lastTime = now;
lastOutput = output
return output;
}
return lastOutput;
}

View File

@@ -1,32 +0,0 @@
#ifndef PID_H
#define PID_H
class PID {
public:
PID(float kp, float ki, float kd);
void setTunings(float kp, float ki, float kd);
void setOutputLimits(float min, float max);
void setSampleTime(int sampleTime);
void reset();
float compute(float setpoint, float input);
private:
float kp;
float ki;
float kd;
float minOutput;
float maxOutput;
float lastOutput;
int sampleTime;
unsigned long lastTime;
float integral;
float lastInput;
};
#endif