Advertisement
Eriknem

Untitled

Oct 17th, 2020
1,742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.45 KB | None | 0 0
  1. /*************************************************************
  2. Generated at 2016/05/18 23:15:42 CEST for board Arduino Uno
  3. **************************************************************/
  4.  
  5. // imports
  6. #include <Servo.h>
  7. #include "Helper.h"
  8. #include "Enums.h"
  9. #include "Place.h"
  10. #include "Transition.h"
  11. #include "Arc.h"
  12. #include "FiringScheduler.h"
  13.  
  14.  
  15.  
  16. // global variables
  17. // ====== places ======
  18. Place *p_13;
  19. Place *p_22;
  20. Place *p_28;
  21. Place *p_29;
  22. Place *p_3;
  23. Place *p_5;
  24. Place **allPlaces;
  25. int allPlacesCount;
  26.  
  27. // ====== transitions ======
  28. Transition *t_14;
  29. Transition *t_17;
  30. Transition *t_18;
  31. Transition *t_2;
  32. Transition *t_20;
  33. Transition *t_24;
  34. Transition *t_25;
  35. Transition *t_26;
  36. Transition *t_4;
  37. Transition *t_7;
  38. Transition **allTransitions;
  39. int allTransitionsCount;
  40.  
  41. // ====== arcs ======
  42. Arc *a_695326262;
  43. Arc *a_907867606;
  44. Arc *a_1446112315;
  45. Arc *a_1635923666;
  46. Arc *a_552332219;
  47. Arc *a_917921253;
  48. Arc *a_1795255508;
  49. Arc *a_1505050988;
  50. Arc *a_1372075858;
  51. Arc *a_983687677;
  52. Arc *a_23365127;
  53. Arc *a_237252993;
  54. Arc *a_979541003;
  55. Arc *a_547699660;
  56. Arc *a_1957008776;
  57. Arc *a_1813879408;
  58. Arc *a_713055406;
  59. Arc *a_533727422;
  60. Arc *a_1314008099;
  61. Arc *a_84401590;
  62. Arc *a_1266296143;
  63. Arc *a_2023601639;
  64. Arc *a_2128195109;
  65. Arc *a_770267990;
  66. Arc *a_1347483247;
  67. Arc *a_766308115;
  68. Arc **allArcs;
  69. int allArcsCount;
  70.  
  71. // ====== firing policy ======
  72. FiringScheduler *firingScheduler;
  73.  
  74. Helper *helper;
  75.  
  76.  
  77.  
  78. // initial setup
  79. void setup() {
  80. Serial.begin(9600);
  81.  
  82. // ====== general ======
  83. helper = new Helper(0);
  84. allPlacesCount = 6;
  85. allPlaces = (Place**) malloc(allPlacesCount*sizeof(Place*));
  86. allTransitionsCount = 10;
  87. allTransitions = (Transition**) malloc(allTransitionsCount*sizeof(Transition*));
  88. allArcsCount = 26;
  89. allArcs = (Arc**) malloc(allArcsCount*sizeof(Arc*));
  90.  
  91. // ====== places ======
  92. p_13 = new Place("p_rain F");
  93. p_13->setCapacity(2);
  94. p_13->setTokens(0);
  95. allPlaces[0] = p_13;
  96. p_13->setThresholdRange(-1, -1);
  97. p_13->setInverseLogic(false);
  98. p_13->setHelper(helper);
  99. p_22 = new Place("p_manual", 11, DIGITAL_OUT);
  100. p_22->setCapacity(2);
  101. p_22->setTokens(0);
  102. allPlaces[1] = p_22;
  103. p_22->setThresholdRange(-1, -1);
  104. p_22->setInverseLogic(false);
  105. p_22->setHelper(helper);
  106. p_28 = new Place("p_auto", 12, DIGITAL_OUT);
  107. p_28->setCapacity(2);
  108. p_28->setTokens(0);
  109. allPlaces[2] = p_28;
  110. p_28->setThresholdRange(-1, -1);
  111. p_28->setInverseLogic(false);
  112. p_28->setHelper(helper);
  113. p_29 = new Place("p_guard");
  114. p_29->setCapacity(1);
  115. p_29->setTokens(1);
  116. allPlaces[3] = p_29;
  117. p_29->setThresholdRange(-1, -1);
  118. p_29->setInverseLogic(false);
  119. p_29->setHelper(helper);
  120. p_3 = new Place("p_rain S");
  121. p_3->setCapacity(2);
  122. p_3->setTokens(0);
  123. allPlaces[4] = p_3;
  124. p_3->setThresholdRange(-1, -1);
  125. p_3->setInverseLogic(false);
  126. p_3->setHelper(helper);
  127. p_5 = new Place("p_servo", 9, SERVO);
  128. p_5->setCapacity(6);
  129. p_5->setTokens(0);
  130. allPlaces[5] = p_5;
  131. p_5->setThresholdRange(-1, -1);
  132. p_5->setInverseLogic(false);
  133. p_5->setHelper(helper);
  134.  
  135. // ====== transitions ======
  136. t_14 = new Transition("t_rain F trg", 0, ANALOG_IN);
  137. t_14->setThresholdRange(0, 449);
  138. t_14->setDelay(0, 0);
  139. t_14->setInverseLogic(false);
  140. t_14->setDelayOccurrenceType(NO);
  141. t_14->setPriority(1);
  142. t_14->setHelper(helper);
  143. allTransitions[0] = t_14;
  144. t_17 = new Transition("t_turnOff F");
  145. t_17->setDelay(700, 700);
  146. t_17->setInverseLogic(false);
  147. t_17->setDelayOccurrenceType(AFTER);
  148. t_17->setPriority(3);
  149. t_17->setHelper(helper);
  150. allTransitions[1] = t_17;
  151. t_18 = new Transition("t_turn on F");
  152. t_18->setDelay(700, 700);
  153. t_18->setInverseLogic(false);
  154. t_18->setDelayOccurrenceType(AFTER);
  155. t_18->setPriority(2);
  156. t_18->setHelper(helper);
  157. allTransitions[2] = t_18;
  158. t_2 = new Transition("t_rain S trg", 0, ANALOG_IN);
  159. t_2->setThresholdRange(450, 1000);
  160. t_2->setDelay(0, 0);
  161. t_2->setInverseLogic(false);
  162. t_2->setDelayOccurrenceType(NO);
  163. t_2->setPriority(1);
  164. t_2->setHelper(helper);
  165. allTransitions[3] = t_2;
  166. t_20 = new Transition("t_MANUAL", 4, DIGITAL_IN);
  167. t_20->setThresholdRange(-1, -1);
  168. t_20->setDelay(0, 0);
  169. t_20->setInverseLogic(false);
  170. t_20->setDelayOccurrenceType(NO);
  171. t_20->setPriority(0);
  172. t_20->setHelper(helper);
  173. allTransitions[4] = t_20;
  174. t_24 = new Transition("t_manual trgr");
  175. t_24->setDelay(0, 0);
  176. t_24->setInverseLogic(false);
  177. t_24->setDelayOccurrenceType(NO);
  178. t_24->setPriority(1);
  179. t_24->setHelper(helper);
  180. allTransitions[5] = t_24;
  181. t_25 = new Transition("t_OFF", 2, DIGITAL_IN);
  182. t_25->setThresholdRange(-1, -1);
  183. t_25->setDelay(0, 0);
  184. t_25->setInverseLogic(false);
  185. t_25->setDelayOccurrenceType(NO);
  186. t_25->setPriority(4);
  187. t_25->setHelper(helper);
  188. allTransitions[6] = t_25;
  189. t_26 = new Transition("t_AUTO", 3, DIGITAL_IN);
  190. t_26->setThresholdRange(-1, -1);
  191. t_26->setDelay(0, 0);
  192. t_26->setInverseLogic(false);
  193. t_26->setDelayOccurrenceType(NO);
  194. t_26->setPriority(0);
  195. t_26->setHelper(helper);
  196. allTransitions[7] = t_26;
  197. t_4 = new Transition("t_turnOn S");
  198. t_4->setDelay(700, 700);
  199. t_4->setInverseLogic(false);
  200. t_4->setDelayOccurrenceType(AFTER);
  201. t_4->setPriority(2);
  202. t_4->setHelper(helper);
  203. allTransitions[8] = t_4;
  204. t_7 = new Transition("t_turnOff S");
  205. t_7->setDelay(2000, 2000);
  206. t_7->setInverseLogic(false);
  207. t_7->setDelayOccurrenceType(AFTER);
  208. t_7->setPriority(3);
  209. t_7->setHelper(helper);
  210. allTransitions[9] = t_7;
  211.  
  212. // ====== arcs ======
  213. a_695326262 = new Arc(p_22, t_24, regular, + 1);
  214. allArcs[0] = a_695326262;
  215. a_907867606 = new Arc(t_18, p_5, regular, + 5);
  216. allArcs[1] = a_907867606;
  217. a_1446112315 = new Arc(p_3, t_4, regular, + 1);
  218. allArcs[2] = a_1446112315;
  219. a_1635923666 = new Arc(t_4, p_5, regular, + 5);
  220. allArcs[3] = a_1635923666;
  221. a_552332219 = new Arc(p_28, t_14, regular, + 1);
  222. allArcs[4] = a_552332219;
  223. a_917921253 = new Arc(t_2, p_3, regular, + 1);
  224. allArcs[5] = a_917921253;
  225. a_1795255508 = new Arc(p_3, t_7, regular, + 1);
  226. allArcs[6] = a_1795255508;
  227. a_1505050988 = new Arc(t_24, p_13, regular, + 1);
  228. allArcs[7] = a_1505050988;
  229. a_1372075858 = new Arc(t_18, p_13, regular, + 1);
  230. allArcs[8] = a_1372075858;
  231. a_983687677 = new Arc(t_25, p_29, regular, + 1);
  232. allArcs[9] = a_983687677;
  233. a_23365127 = new Arc(p_22, t_25, reset, + 1);
  234. allArcs[10] = a_23365127;
  235. a_237252993 = new Arc(t_26, p_28, regular, + 1);
  236. allArcs[11] = a_237252993;
  237. a_979541003 = new Arc(p_13, t_17, regular, + 1);
  238. allArcs[12] = a_979541003;
  239. a_547699660 = new Arc(t_14, p_28, regular, + 1);
  240. allArcs[13] = a_547699660;
  241. a_1957008776 = new Arc(p_5, t_7, regular, + 5);
  242. allArcs[14] = a_1957008776;
  243. a_1813879408 = new Arc(p_29, t_20, regular, + 1);
  244. allArcs[15] = a_1813879408;
  245. a_713055406 = new Arc(t_4, p_3, regular, + 1);
  246. allArcs[16] = a_713055406;
  247. a_533727422 = new Arc(p_29, t_26, regular, + 1);
  248. allArcs[17] = a_533727422;
  249. a_1314008099 = new Arc(p_28, t_25, reset, + 1);
  250. allArcs[18] = a_1314008099;
  251. a_84401590 = new Arc(p_13, t_18, regular, + 1);
  252. allArcs[19] = a_84401590;
  253. a_1266296143 = new Arc(t_24, p_22, regular, + 1);
  254. allArcs[20] = a_1266296143;
  255. a_2023601639 = new Arc(t_14, p_13, regular, + 1);
  256. allArcs[21] = a_2023601639;
  257. a_2128195109 = new Arc(p_28, t_2, regular, + 1);
  258. allArcs[22] = a_2128195109;
  259. a_770267990 = new Arc(t_2, p_28, regular, + 1);
  260. allArcs[23] = a_770267990;
  261. a_1347483247 = new Arc(p_5, t_17, regular, + 5);
  262. allArcs[24] = a_1347483247;
  263. a_766308115 = new Arc(t_20, p_22, regular, + 1);
  264. allArcs[25] = a_766308115;
  265.  
  266. // ====== wiring parts together ======
  267. Arc** ta_14 = (Arc**) malloc( 3*sizeof(Arc*));
  268. ta_14[0] = a_552332219;
  269. ta_14[1] = a_547699660;
  270. ta_14[2] = a_2023601639;
  271. t_14->setConnectedArcs(ta_14);
  272. t_14->setConnectedArcsCount(3);
  273. Arc** ta_17 = (Arc**) malloc( 2*sizeof(Arc*));
  274. ta_17[0] = a_979541003;
  275. ta_17[1] = a_1347483247;
  276. t_17->setConnectedArcs(ta_17);
  277. t_17->setConnectedArcsCount(2);
  278. Arc** ta_18 = (Arc**) malloc( 3*sizeof(Arc*));
  279. ta_18[0] = a_84401590;
  280. ta_18[1] = a_907867606;
  281. ta_18[2] = a_1372075858;
  282. t_18->setConnectedArcs(ta_18);
  283. t_18->setConnectedArcsCount(3);
  284. Arc** ta_2 = (Arc**) malloc( 3*sizeof(Arc*));
  285. ta_2[0] = a_917921253;
  286. ta_2[1] = a_2128195109;
  287. ta_2[2] = a_770267990;
  288. t_2->setConnectedArcs(ta_2);
  289. t_2->setConnectedArcsCount(3);
  290. Arc** ta_20 = (Arc**) malloc( 2*sizeof(Arc*));
  291. ta_20[0] = a_1813879408;
  292. ta_20[1] = a_766308115;
  293. t_20->setConnectedArcs(ta_20);
  294. t_20->setConnectedArcsCount(2);
  295. Arc** ta_24 = (Arc**) malloc( 3*sizeof(Arc*));
  296. ta_24[0] = a_1266296143;
  297. ta_24[1] = a_695326262;
  298. ta_24[2] = a_1505050988;
  299. t_24->setConnectedArcs(ta_24);
  300. t_24->setConnectedArcsCount(3);
  301. Arc** ta_25 = (Arc**) malloc( 3*sizeof(Arc*));
  302. ta_25[0] = a_1314008099;
  303. ta_25[1] = a_23365127;
  304. ta_25[2] = a_983687677;
  305. t_25->setConnectedArcs(ta_25);
  306. t_25->setConnectedArcsCount(3);
  307. Arc** ta_26 = (Arc**) malloc( 2*sizeof(Arc*));
  308. ta_26[0] = a_237252993;
  309. ta_26[1] = a_533727422;
  310. t_26->setConnectedArcs(ta_26);
  311. t_26->setConnectedArcsCount(2);
  312. Arc** ta_4 = (Arc**) malloc( 3*sizeof(Arc*));
  313. ta_4[0] = a_1635923666;
  314. ta_4[1] = a_1446112315;
  315. ta_4[2] = a_713055406;
  316. t_4->setConnectedArcs(ta_4);
  317. t_4->setConnectedArcsCount(3);
  318. Arc** ta_7 = (Arc**) malloc( 2*sizeof(Arc*));
  319. ta_7[0] = a_1795255508;
  320. ta_7[1] = a_1957008776;
  321. t_7->setConnectedArcs(ta_7);
  322. t_7->setConnectedArcsCount(2);
  323. // ====== firing policy ======
  324. firingScheduler = new FiringScheduler(BY_PRIORITY, allTransitions, allTransitionsCount, allPlaces, allPlacesCount);
  325. firingScheduler->setHelper(helper);
  326. firingScheduler->setHelper(helper);
  327. randomSeed(analogRead(0));
  328.  for (int i = 0; i < allPlacesCount; i++) {
  329.        allPlaces[i]->apply();
  330.    }
  331.  
  332. }
  333.  
  334. // main infinite loop
  335. void loop() {
  336.  Transition *nextToFire = firingScheduler->nextToFire();
  337.  if(nextToFire != NULL) nextToFire->fire();
  338.  
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement