-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRAFCETExample.cpp
More file actions
97 lines (79 loc) · 2.51 KB
/
GRAFCETExample.cpp
File metadata and controls
97 lines (79 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "GRAFCETExample.h"
GRAFCETExample::GRAFCETExample()
{
//Crear los estados
GRAFCETStep *s1 = new GRAFCETStep("s1", 500, std::bind(&GRAFCETExample::func_s1, this), std::bind(&GRAFCETExample::entry_s1, this));
GRAFCETStep *s2 = new GRAFCETStep("s2", 500, std::bind(&GRAFCETExample::func_s2, this), nullptr, std::bind(&GRAFCETExample::exit_s2, this));
GRAFCETStep *s3 = new GRAFCETStep("s3", 500, std::bind(&GRAFCETExample::func_s3, this));
//enlaza las transiciones
s1->addTransition(this, SIGNAL(goToS2()), s2);
s2->addTransition(this, SIGNAL(goToS3()), s3);
s2->addTransition(this, SIGNAL(goToS1()), s1);
s3->addTransition(this, SIGNAL(goToS1()), s1);
// Configuración de la Máquina de Estado
machine.addState(s1);
machine.addState(s2);
machine.addState(s3);
machine.setChildMode(QState::ExclusiveStates); // Maquina en serie sin estados paralelos
machine.setInitialState(s1); // Estado inicial
//Arranca la maquina
machine.start();
auto error = machine.errorString();
if (error.length() > 0){
qWarning() << error;
throw error;
}
}
//Función de visualización de estados activos
void GRAFCETExample::transition(){
QSet<QAbstractState*> activeStates = machine.configuration();
for(QAbstractState* state : activeStates)
qDebug() << "Estado activo:" << state->objectName();
}
/////////////////////Funciones de ejecución de estados////////////////////
/////////////////////Función de entrada a estado////////////////////////////
void GRAFCETExample::entry_s1(){
qInfo() << "///////Entrando al estado s1 desde la función de entrada///////////////////";
transition();
}
///////////////////Función de salida a estado////////////////////////////
void GRAFCETExample::exit_s2(){
qInfo() << "///////Salida del estado s2 desde la función de salida///////////////////";
}
///////////////////////////Como si fueran computes///////////////////////
void GRAFCETExample::func_s1() {
qInfo()<<"s1"<<i;
i++;
if (i>5){
i = 0;
emit goToS2();
}
}
void GRAFCETExample::func_s2() {
if (check)
{
qInfo()<<"s2"<<n;
n--;
}
else{
qInfo()<<"s2"<<n;
n++;
}
if (n>5){
n = 0;
check=true;
emit goToS3();
}
if (n<-5){
n = 0;
emit goToS1();
}
}
void GRAFCETExample::func_s3() {
qInfo()<<"s3"<<j;
j++;
if (j>10){
j = 0;
emit goToS1();
}
}