Welcome To Ajioz Tech...

Thursday, March 16, 2017



Simulation of Discrete‐Event Systems in MATLAB

By: Raul Campos‐Rodriguez, Mildreth           Alcaraz‐Mejia and Uriel Sanchez‐Ramirez

Originally published by: INTECH, 2016

Abstract The  discrete‐event  systems  (DES)  are  systems  guided  by  asynchronous  events  rather than  by  the  passage  of  the  time  as  in  traditional  systems.  There  exists  a  wide  set  of systems  that  could  be  considered  within  this  class,  such  as  communication  protocols, computer  and  microcontroller  operating  systems,  flexible  manufacturing  systems, communication  drivers  for  embedded  applications  and  logistic  systems,  among  others. Their  proper  study  is  a  requirement  for  a  suitable  implementation  of  embedded hardware  and  software,  for  example.  The  aim  of  this  chapter  is  to  approach  the simulation  of  this  class  of  systems  within  the  MATLAB/SIMULINK  framework.  A suitable  simulation  process,  allowing  the  injection  of  input  signals  to  the  system  and observing  its  output  response,  is  a  first  step  in  the  analysis  of  this  class  of  systems, which  may  lead  to  more  elaborated  analysis  such  as  reachability  and  deadlock avoidance.  The  advantage  of  the  approach  and  techniques  proposed  in  this  chapter  is the  application  of  the  set  of  tools,  algorithms  and  visualization  instruments  present  in the  MATLAB/SIMULINK  to  the  simulation  of  Discrete‐Event  Systems,  which  allows  a simple  integration  of  various  DES  by  utilizing  the  matrices  that  define  them.  The concluding  section  of  the  chapter  provides  a  link  for  downloading  all  the  code  for  the examples  developed  here. Keywords:  discrete‐event  systems,  analysis,  modelling,  simulation,  MATLAB/Simulink.


The discrete‐event  systems (DES)  are  systems guided  by  asynchronous events  rather  than  by the  passage  of  time  as  in  the  traditional  framework  of  Control  Theory,  for  example  [1].  There exists a wide set of systems that could be considered in the class of DES, such as operating systems.

of  microprocessors  and  embedded  microcontrollers,  communication  protocols  such  as  IPv4/ IPv6,  complex  software  architectures  such  as  database  management  systems,  production systems  and  flexible  manufacturing  systems  (FMSs),  delivering  and  logistic  systems,  among others.  Their  proper  study  is  a  requirement  for  the  fulfillment  of  performance  and  safety requirements, for example. The traceability of requirements and its satisfaction is simplified by using  a model that is suitable  for  a  rigorous  simulation  process  [2]. The  aim  of  this  chapter  is  to  approach  the  simulation  of  DES  within  the  MATLAB/SIMULINK framework.  Analysis  such  as  the  application  of  random  inputs  to  a  DES  and  the  visualization of  system’s  output  response  are  intended  to  be  covered  in  this  chapter.  The  overall  goal  is  to enable the application of the set of tools, algorithms and visualization instruments present in the  MATLAB/SIMULINK  to  the  analysis  of  DES.  There  exist  several  approaches  for  the analysis  of  this  class  of  systems.  On  the  one  hand,  for  example,  empirical  practices  are  used for  addressing  the  problems  that  arise  in  the  DES  field.  Most  of  these  practices  are  based  on experience  and  good  knowledge  among  engineers  in  the  daily  execution  of  a  system.  On  the other  hand,  in  the  formal  point  of  view,  scientists  and  engineers  typically  use  mathematical tools  based  on  automata  theory,  Petri  nets  (PN),  Markov  chains  and  Queue  theory  for  addressing main aspects in the design and implementation of DES. The aspects most studied in the  analysis  of  DES  are  the  reachability  and  deadlock  analysis,  fault  tolerance,  control  and observability schemes, to mention a few [3]. 2. Discrete‐event systems (DES) In  recent  years,  the  simulation  methods  have  taken  great  relevance  in  the  design  and  implementation  of  big  systems.  These  methods  allow  engineers  and  scientists  the  study  of  complex behaviours  by  simulating  in  the  lab  different  real‐world  scenarios.  Intensive  workload conditions,  parametric  variations,  environmental  changes  and  fault  scenarios  are  possible  to investigate by simulation methods. Statistical information, performance curves, and parameter optimization are some of the possible results obtained by a simulation process. As  mentioned  in  the  introduction,  within  a  DES  the  state  evolution  depends  on  the  occurrence of  events  that  are  asynchronous  in  time.  An  event  is  an  instantaneous  action  occurred  in  the context  of  the  DES  that  is  relevant  for  the  understanding  of  the  system.  An  occurrence  of  an event  may  cause  an  immediate  change  in  the  system  state.  For  example,  an  event  could  be  a package  arriving  by  the  network  connection,  a  button  pressed  by  the  user  at  a  control  panel, a  timer’s  overflow  within  an  embedded  device  driver,  a  change  in  a  Boolean  flag  within  an Interrupt  Service  Routine,  etc.  By  convention,  it  is  supposed  that  no  time  is  elapsed  between the event occurrence and the change of the state in a DES. Some examples of DES’s include communication protocols, supply chains, queue systems, task schedulers,  logistic  systems,  device  drivers,  memory  managers,  landing  and  take‐off  systems of  airplanes,  urban  rail  systems  and  subway,  and  line  of  manufacturing  and  production systems, among others. For a wide list of examples of DES, see [4]. For full material, visit :
 http://www.intechopen.com/books/applications-from-engineeringwith-matlab-concep



This Sketch is used to create Widget needed to control Gpio pins of Raspberry pi.

from Tkinter import *

import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO. setwarnings(False)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def ajiri_hi():
print "Lighting up LED"
GPIO.output(17, GPIO.HIGH)
time.sleep(5)
GPIO.output(17, GPIO.LOW)

def check_button():
if (GPIO.input(18) == GPIO.LOW):
labelText.set("Button Pressed.")
else:
labelText.set("")
root.after(10,check_button)

root = Tk()

button = Button(root, text="Quit.", fg="blue", command=quit)
button.pack(side=RIGHT, padx=10, pady=10, ipadx=10, ipady=10)

hi_there = Button(root, text="Light my LED!", command=ajiri_hi)
hi_there.pack(side=LEFT, padx=10, pady=10, ipadx=10, ipady=10)

labelText = StringVar()
labelText.set("Button Pressed.")
label1 = Label(root, textvariable=labelText, height=4)
label1.pack(side=LEFT)

root.title("LED Blinker")
root.geometry('500x300+200+200')

root.after(10,check_button)
root.mainloop()




This Tutorial is about the script for building a Digital Temperature  Sense Circuit.

In this tutorial we shall learn how to write a python mnemonic for Smart Temperature Reporter on Raspberry pi board platform and interfacing same to a cloud system.

import paho.mqtt.client as mqtt
import time
import sys
import Adafruit_DHT

time.sleep(30) #Sleep to allow wireless to connect before starting MQTT

ajiri = mqtt.Client(client_id="")
ajiri.username_pw_set("username", password="")
ajiri.connect("mqtt.mydevices.com", port=1883, keepalive=60)
topic_dht11_temp = "v1/username/things/clientid/data/1"
topic_dht11_humidity = "v1/username/things/clientid/data/2"
topic_dht22_temp = "v1/username/things/clientid/data/3"
topic_dht22_humidity = "v1/username/things/clientid/data/4"
while True:
    try:
        humidity11, temp11 = Adafruit_DHT.read_retry(11, 6) #11 is the sensor type, 6 is the GPIO pin number
        humidity22, temp22 = Adafruit_DHT.read_retry(22, 5) #22 is the sensor type, 5 is the GPIO pin number
    
        if temp11 is not None:
            temp11 = "temp,c=" + str(temp11)
            ajiri.publish(topic_dht11_temp, payload=temp11, retain=True)
        if humidity11 is not None:
            humidity11 = "rel_hum,rel_hum=" + str(humidity11)
            ajiri.publish(topic_dht11_humidity, payload=humidity11, retain=True)
        if temp22 is not None:
            temp22 = "temp,c=" + str(temp22)
            ajiri.publish(topic_dht22_temp, payload=temp22, retain=True)
        if humidity22 is not None:
            humidity22 = "rel_hum,rel_hum=" + str(humidity22)
            ajiri.publish(topic_dht22_humidity, payload=humidity22, retain=True)
        time.sleep(5)
    except (EOFError, SystemExit, KeyboardInterrupt):
        ajiri.disconnect()
        sys.exit()

Save this file to /home/pi/python/tempsensor.py and fill in your username, password, and client id wherever required (lines 8, 9, 12, 13, 14, 15). You can also delete the DHT11 or DHT22 lines based on which sensor you are using or add additional lines to check more than 1 sensor. The topic_dht lines will all need unique channels, so be sure the last digit in the string is unique "v1/username/things/clientid/data/ 1 "
For testing just run the file with "python /home/pi/python/tempsensor.py". After it is working correctly add the