Robot Principal 26
Documentation du Club Robot INSA Rennes 2026
Chargement...
Recherche...
Aucune correspondance
Node.h
Aller à la documentation de ce fichier.
1//
2// Created by awing on 09/05/2026.
3//
9#ifndef TEAM2026_NODE_H
10#define TEAM2026_NODE_H
11#if !GRAFCET_DYNAMIC_FAMILY
12#ifndef GRAFCET_FAMILY_SIZE
13#define GRAFCET_FAMILY_SIZE 10
14#endif
15#endif
16
17#if GRAFCET_DYNAMIC_FAMILY
18#include <vector>
19#else
20#include <array>
21#include <stdexcept>
22#endif
23#include <string>
24
25namespace Grafcet {
26 class StateMachine;
27
34 class Node {
35 public:
36 Node() = default;
42 explicit Node(const auto &parents, const auto &children = {}) : parent(parents), children(children) {}
43 virtual ~Node() = default;
45 virtual bool enabled() = 0;
47 virtual void action() = 0;
48
53 constexpr void addChild(Node *child) {
54#if GRAFCET_DYNAMIC_FAMILY
55 this->children.push_back(child);
56 child->parent.push_back(this);
57#else
58 if (const auto childrenSize = children.size(); childrenSize >= children.max_size()) {
59 throw std::out_of_range("Node::addChild");
60 }
61 if (const auto parentSize = parent.size(); parentSize >= parent.max_size()) {
62 throw std::out_of_range("Node::addChild");
63 }
64 this->children[this->children.size()] = child;
65 child->parent[child->parent.size()] = this;
66#endif
67 }
68
73 [[nodiscard]] auto getChildren() const { return children; }
74
75 std::string name = "Node";
77 bool isTransition = false;
79 bool synchronize = false;
81 bool active = false;
82 protected:
83#if GRAFCET_DYNAMIC_FAMILY
85 std::vector<Node*> parent;
87 std::vector<Node*> children;
88#else
90 std::array<Node*, GRAFCET_FAMILY_SIZE> parent = {};
92 std::array<Node*, GRAFCET_FAMILY_SIZE> children = {};
93#endif
94
95 friend StateMachine;
96 };
97}
98#endif //TEAM2026_NODE_H
virtual bool enabled()=0
vérifie si le noeud est activé
std::array< Node *, GRAFCET_FAMILY_SIZE > parent
Liste des nœuds parents.
Definition Node.h:90
auto getChildren() const
retourne la liste des enfants
Definition Node.h:73
bool isTransition
true si le noeud est une transition, false sinon
Definition Node.h:77
virtual void action()=0
action à réaliser lorsque le noeud est actif
constexpr void addChild(Node *child)
attache un enfant au noeud
Definition Node.h:53
bool synchronize
true si le noeud est synchronisant
Definition Node.h:79
std::array< Node *, GRAFCET_FAMILY_SIZE > children
Liste des nœuds enfants.
Definition Node.h:92
Node(const auto &parents, const auto &children={})
Definition Node.h:42
bool active
true si le noeud est actif
Definition Node.h:81
La machine à état permettant de parcourir le grafcet.
Definition StateMachine.h:25
Contient les classes et fonctions nécessaires pour générer et parcourir le Grafcet.
Definition ActionNode.h:16