controller - Matlab .txt file read error -


i'm using matlab pi (proportional integral) controller. i'm trying control "virtual robot" agent via .txt files. simulated agent writes errors in .txt file. run through matlab , set speed via second .txt file, agent reads, in realtime.

the problem matlab tries read error file while agent using (at least that's think happening) , error message:

??? error using ==> rfinputs>localtimerespcheck @ 421 final time must positive number.  error in ==> pi_reg @ 42 [v,t]=lsim(pid_d,e,t); 

is there way avoid , have synchronized perfect every time? here code i'm using (e.txt error file, v.txt speed file):

clc, clear all, close  kp=1.3;                          ki=0.32;                        kd=0;                            ts=0.008;                         pid_c = tf([kd kp ki],[1 0]);    pid_d = c2d(pid_c,ts);            fid=fopen('e.txt'); r=textscan(fid,'%f','\r\r'); fclose(fid); e=r{1};  while length(e)<2464  s = dir('c:\robot_1\e.txt');  if s.bytes == 0 pause(0.003)  else fid=fopen('e.txt'); r=textscan(fid,'%f','\r\r'); fclose(fid);  e=r{1};                         %e error in mm  t=[0:ts:(length(e)-1)*ts];  [v,t]=lsim(pid_d,e,t);  v;  v=v(length(e))                  %v speed in mm/s  fid=fopen('v.txt','w'); fprintf(fid,'%v6.4f\n',v);       fclose(fid);  end end 

you using text files establish comm between robot , matlab?

your question not correctly stated not "where" robot: remote mcu, or code running in own/another pc?

in first case, recommend using serial interface.

in second case, use socket(more robust/flexible , plenty of code it) or pipes (no idea how cleanly in matlab). using files communication bad practice.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -