LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Hardware in the loop simulation with Arduino

Hello and thank you for your attention.

I have a transfer function in labview and i want to design a PI controller for that, in Arduino.I used VISA to connect labview to Arduino. i attached my VI and  this is my arduino code:

#include <PID_v1.h>
double Setpoint, Input, Output;
double Kp = 36, Ki = 19, Kd = 0;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
void setup()
{
  Serial.begin(115200);
  while (!Serial) {}
  Setpoint = 30;
  myPID.SetMode(AUTOMATIC);
}
int bytesToRead = 0;
char msg[64];
void loop()
{

  if (Serial.available())
  {

    getMessage();
    float feedback = atof (msg);
    Input = (double) feedback;
    myPID.Compute();
    Serial.println (Output);
  }
}

void getMessage()
{
  int i;

  bytesToRead = Serial.available();

  for (i = 0; i < bytesToRead; i++)
  {
    msg[i] = (Serial.read());

  }
  msg[i] = '\0';
}

the Set point is 30 and the output of the transfer function should be 30 but it stop on 25 and when i change the Kp and Ki and set point nothing change and the output of transfer function is 25... 

So what is the problem??

I realy need this....thanx for your help...

0 Kudos
Message 1 of 1
(2,258 Views)