PID in ThingSpeak code

조회 수: 1 (최근 30일)
mostafa mousa
mostafa mousa 2021년 1월 23일
답변: Christopher Stapels 2021년 1월 25일
I tried to write pid code in thingspeak app matlab analysis, but I faced some problem. Can anyone help?
sensed_output = thingSpeakRead(readChannelID), control_signal;
setpoint=23;
Kp = 1;
Ki = 1;
Kd = 1;
T= 5000;
double total_error, last_error;
int max_control=100;
int min_control=0
double error = setpoint - sensed_output;
total_error += error;
if total_error >= max_control
total_error = max_control;
elseif total_error <= min_control
total_error = min_control;
else
total_error = total_error;
end
double delta_error = error - last _error;
control_signal = Kp*error + (Ki*T)*total_error + (Kd/T)*delta_error;
if control_signal >= max_control
control_signal = max_control;
elseif control_signal <= min_control
control_signal = min_control;
else
control_signal = control_signal;
end
last_error = error;
analyzedData = control_signal;00
%% Write Data %%
thingSpeakWrite(writeChannelID, analyzedData, 'WriteKey', writeAPIKey);
  댓글 수: 1
Image Analyst
Image Analyst 2021년 1월 23일
Do not use double or int before the lines where you assign values.

댓글을 달려면 로그인하십시오.

답변 (1개)

Christopher Stapels
Christopher Stapels 2021년 1월 25일
I'd suggest you have a look at the MATLAB onramp. Its a two hour introduction to MATLAB fundamentals, I think you would find it really helpful. Once you have that down, I think writing the PID code will be much easier.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 Prepare and Analyze Data에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by