Simulink close loop System control with Arduino and serial
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to make a control system using Simulink and Arduino.
I am trying to install a system model in Simulink and a PID controller in Arduino like this pic

For this I made serial communication of Simulink and Arduino.

also Arduino code is this just for you check (I haven't designed a PID controller yet.)
double Setpoint, Input, Output;
float MyValue = 0;
typedef union{
float number;
uint8_t bytes[4];
} FLOATUNION_t;
FLOATUNION_t myValue;
void setup() {
Serial.begin(115200);
}
void loop(){
myValue.number = getFloat();
Input = double(myValue.number);
Send2Matlab();
}
void Send2Matlab(){
Serial.write('A');
for (int i=0; i<4; i++){
Serial.write(myValue.bytes[i]);
}
Serial.print('\n');
delay(100);
}
float getFloat(){
int cont = 0;
FLOATUNION_t f;
while (cont < 4 ){
f.bytes[cont] = Serial.read() ;
cont = cont +1;
}
return f.number;
}
When there is no system or PID controller, the serial communication works fine, although sometimes the communication is lost.

However, a problem arises when the signal from serial communication enters the transfer function or PID block.

To solve the problem, I tried various methods such as using the discrete transfer function or changing the solver by putting a constant such as 0 in the middle of the signal, but
Using the discrete transform outputs nan values, and the other method didn't work either.
Finally, I tried to use the PIL block supported by the embedded coder to solve this problem, but it failed too.
Please can someone tell me what is the problem?
Thank you for reading this long article.
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Arduino Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!