//BACKUP
package controlPI;
import [Link];
import [Link].*;
import [Link].Arc2D;
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
public class controller extends JApplet {
public static ArrayList<OutputData> output_data = new
ArrayList<OutputData>();
public static int T = 3;
public static int T_log = 6;
public static double ref=0.0;
public String host, miInURL,miOutURL;
public [Link] myServer = null;
public [Link] myConx = null;
final int START = 1; // Starts operation (timer)
final int STOP = 2; // Stops operation (timer)
//final int IN = 3;
final int SP = 4;
final int PB = 5;
final int RESET = 6;
double level = 0.0; // Must be global
double valve_p = 0.0;
double sp = 0.0;
double pb = 0.0;
double reset = 0.0;
private static final long serialVersionUID = 1L;
Timer timer = new Timer("ReadData");
public static PI controlador = new PI();
public static Planta planta = new Planta();
public static Log historial = new Log();
public static [Link] Hist = new
[Link](23, 60);
Image I;
static Label l1=new Label("SP"),l2=new
Label("OUT"),l3=new Label("IN");
public void init(){
Toolkit tk = [Link]();
int xs = (int) [Link]().getWidth() - 200;
int ys = (int) [Link]().getHeight() -
200;
[Link](xs + " " + ys);
setSize(xs,ys);
URL base;
base =
[Link]("/controlPI/[Link]");
I=getImage([Link]("[Link]"));
BackGroundPanel bgp = new BackGroundPanel();
[Link](null);
[Link](I);
[Link]([Link](
"Image1"));
[Link] panelControl = new
[Link]();
[Link]([Link]
edBorder("ControlPanel"));
[Link]( new FlowLayout());
[Link] startButton = new
[Link]("Start");
TextField AAA = new
TextField("AAASSSSSSSSSSSSSSSSSAA");
[Link] stopButton = new
[Link]("Stop");
[Link] pidLabel = new
[Link](" || PID:");
[Link] pbButton = new
[Link]("PB");
[Link](startButton);
[Link](stopButton);
[Link](pidLabel);
[Link](pbButton);
[Link](new
[Link](START));
[Link](new
[Link](STOP));
[Link](new
[Link](PB));
[Link] contenedor = getContentPane();
[Link](new GridLayout(2,2));
[Link](panelControl);
[Link](l1);
[Link](l2);
[Link](l3);
[Link](678, 58);
[Link](675,92);
[Link](583,132);
[Link](40,18);
[Link](40,18);
[Link](40,18);
[Link](bgp);
[Link] panelHist = new
[Link]();
[Link]([Link]
order("Historial"));
[Link]( new FlowLayout());
[Link](false);
[Link](new Insets(5,5,5,5));
JScrollPane logScrollPane = new JScrollPane(Hist);
[Link](logScrollPane);
[Link]( panelHist);
}
// Class to handle events on the control panel
class ControlPanel implements
[Link] {
FilePermission filePermission = new
FilePermission("C:/Users/pc/Desktop/controlPI/[Link]",
"write");
int buttonID;
final double outs[] = {0.0, 0.0, 0.0};
public ControlPanel(int buttonID) {
[Link] = buttonID;
}
public void
actionPerformed([Link] actionEvent) {
switch (buttonID) {
case START:
// The name of the file to open.
String fileNameIn = "[Link]";
//InputStreamReader isr = ;
// This will reference one line at a
time
String sp = null;
try {
// FileReader reads text files in
the default encoding.
/*FileReader fileReaderIn =
new FileReader(fileNameIn);*/
InputStream is =
[Link](fileNameIn);
// Always wrap FileReader in
BufferedReader.
BufferedReader bufferedReaderIn =
new BufferedReader(new
InputStreamReader(is));
//String sp;
//line = sp;
ref = 0.0;
if((sp =
[Link]())!=null)
ref = [Link](sp);
[Link]("\nSet
point: %.2f\n",ref);
[Link]([Link]("\nSet
point: %.2f\n",ref));
// Always close files.
[Link]();
}
catch(FileNotFoundException ex) {
[Link](
"Unable to open file '" +
fileNameIn + "'");
}
catch(IOException ex) {
[Link](
"Error reading file '"
+ fileNameIn + "'");
// Or we could just do this:
// [Link]();
}
// tareas
controlador = new PI();
planta = new Planta();
historial = new Log();
[Link](planta, 0, T*1000);
[Link](controlador, 0, T*1000);
[Link](historial, 0,
T_log*1000);
break;
case STOP:
if ( [Link]() &&
[Link]() &&
[Link]() )
{
[Link]("The Monitoring
Process Timer was stopped!");
[Link]("The Monitoring Process
Timer was stopped!");
timer = new Timer("ReadData");
}else{
[Link]("The Monitoring
Process Timer was already stopped!");
[Link]("The Monitoring Process
Timer was already stopped!");
}
break;
case PB:
String fileNameOut =
"[Link]";
try {
// Assume default encoding.
File file = new
File("C:\\Users\\pc\\Desktop\\controlPI\\[Link]");
// creates the file
[Link]();
// creates a FileWriter Object
FileWriter writer = new
FileWriter(file);
// Writes the content to the file
// Always wrap FileWriter in
BufferedWriter.
// Note that
write() does not automatically
// append a newline character.
for(int
i=0;i<controller.output_data.size();++i){
OutputData data =
controller.output_data.get(i);
[Link]([Link]("%.2f %.2f %.2f\n",data.t,data.u
,[Link]));
[Link]("\r\n");
//
[Link]([Link]("%.2f %.2f %.2f\n",data.t,
data.u,[Link]));
[Link]();
}
[Link]("\nLog data
written in 'output' file.");
[Link]("\nLog data written in
'output' file.");
// Always close files.
[Link]();
}
catch(IOException ex) {
[Link](
"Error writing to file '"
+ fileNameOut + "'");
// Or we could just do this:
// [Link]();
}
break;
}
}
}
public static String getHoraActual() {
Date ahora = new Date();
SimpleDateFormat formateador = new
SimpleDateFormat("hh:mm:ss");
return [Link](ahora);
}
}
class PI extends TimerTask{
static int times=0;
static double Yn; // Referencia
private static double u=0.0, u_MAX=100.0, u_MIN=0.0;
private static double En, En_1=0.0, CE=0.0;
static double Kc = 2.0, tauI=0.4;
static double t=0.0;
static int T_sec = controller.T;
PI(){
}
public void run(){
[Link]("Ejecutando PI (%d) a
horas %s\n",times++,[Link]());
[Link]([Link]([Link]));
[Link]([Link]("Ejecutando PI
(%d) a horas %s\n",times++,[Link]()));
// start time
long startTime = [Link]();
// e(k) = r(k) - y(k)
En = [Link] - [Link]();
updateU(En);
//update values
CE = En - En_1;
En_1 = En;
// generate cpu usage
for(int i=0;i<10000000;++i);
// end time
long endTime = [Link]();
double intervalTicks = (endTime -
startTime)*1000.0;
[Link](" Execution time (PI): %.2f
milisegundos\n",intervalTicks);
[Link]([Link](" Execution
time (PI): %.2f milisegundos\n",intervalTicks));
double cpu_usage = intervalTicks * 100 /
(T_sec*1000);
[Link](" CPU Usage
(PI): %.2f\n\n",cpu_usage);
[Link]([Link](" CPU Usage
(PI): %.2f\n\n",cpu_usage));
}
public synchronized void updateU(double En){
// u(k) = u(k-1) + Kc*[e(k)-e(k-1)] + Kc*T/ti*e(k)
u = u + Kc*CE + Kc*T_sec/tauI*En;
// saturadores
u = [Link](u_MIN,u);
u = [Link](u_MAX,u);
}
public synchronized static double getU(){
return PI.u;
}
}
class Planta extends TimerTask {
static int times=0;
private static double xn, xn_1, yyn_1, yyn;
private static double Kp=0.60, tau=47.100; //
Process gain and constant time
private static double t=0.0; // initial time
(sec)
private static double Xn, Xn_1, Yn, Yn_1; // n:
Curent time, n_1: Previous past time
private static int T = controller.T; // Sampling
time, s
Planta(){
}
public void run(){
[Link]("Ejecutando Planta (%d) a
horas %s\n",times++,[Link]());
[Link]([Link]("Ejecutando
Planta (%d) a
horas %s\n",times++,[Link]()));
// start time
long startTime = [Link]();
// Planta
xn = [Link]();
Xn = xn - xn_1;
updateYn(Xn);
[Link]([Link](getYn()));
yyn = yyn_1 + Yn;
//update values
yyn = yyn_1;
Yn_1 = Yn; // xn = xn_1; // when online
t += T;
// generate cpu usage
for(int i=0;i<15000000;++i);
// end time
long endTime = [Link]();
double intervalTicks = (endTime -
startTime)*1000.0;
[Link](" Execution time (PI): %.2f
milisegundos\n",intervalTicks);
[Link]([Link](" Execution
time (PI): %.2f milisegundos\n",intervalTicks));
double cpu_usage = intervalTicks * 100 / (T*1000);
[Link](" CPU Usage
(PI): %.2f\n\n",cpu_usage);
[Link]([Link](" CPU Usage
(PI): %.2f\n\n",cpu_usage));
}
public synchronized void updateYn(double Xn){
Yn = (tau*Yn_1 + Kp*T*Xn)/(tau + T); // Output of
First order lag
}
public synchronized static double getYn(){
return [Link];
}
}
class Log extends TimerTask {
private double yn, u;
private static double t = 0.0;
private int T_sec=controller.T;
Log(){}
public void run(){
yn = [Link]();
u = [Link]();
OutputData data = new OutputData(t,u,yn);
controller.output_data.add(data);
[Link]([Link](u));
[Link]("Ejecutando Historial a
horas %s\n",[Link]());
[Link]([Link]("Ejecutando
Historial a horas %s\n",[Link]()));
[Link](" t: %.4f | u: %.2f |
yn: %.2f\n",t,u,yn);
[Link]([Link](" t: %.4f |
u: %.2f | yn: %.2f\n",t,u,yn));
t += T_sec;
}
}
class OutputData{
public double t,u,yn;
OutputData(double _t,double _u,double _yn){
this.t = _t;
this.u = _u;
[Link] = _yn;
}
}
class BackGroundPanel extends JPanel {
Image backGround;
BackGroundPanel() {
super();
}
public void paint(Graphics g) {
// get the size of this panel (which is the
size of the applet),
// and draw the image
[Link](getBackGroundImage(), 0, 0,
(int) getBounds().getWidth(), (int)
getBounds().getHeight(), this);
}
public void setBackGroundImage(Image backGround) {
[Link] = backGround;
}
private Image getBackGroundImage() {
return backGround;
}
}
EN UNA CARPETA: controlPI
C:\Program Files (x86)\Java\jre1.8.0_73\bin -------------> POLICY TOOL EXE
GUARDAR EN C:\Users\pc como .[Link]
Editar con:
grant {
permission [Link];
};