Difference between revisions of "LIFT"

From ATI public wiki
Jump to: navigation, search
(Related Publications)
 
(75 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Lift Project is one of the projects designed in department of computer engineering at TTU as a lab project.  
+
[[File:Process.jpg|500px|thumb|right|alt=Alt text|Fig. 1: Laboratory Process]]
 +
Lift Project is one of the projects designed in department of computer engineering at TTU as a lab project.
 +
The main task in this lab is to design a controller for an elevator.
 +
Goals of this lab is to understand Finite State Machine (FSM) design.
 +
 
 +
The process of this lab is described in Fig. 1. Students first have to describe the controller by providing FSM diagrams and transition tables to
 +
the staff and then go through a process of implementation, synthesis and verification. In the end they are required to submit a report. 
 +
=GitHub repository=
 +
All the files and designs are accessible at: https://github.com/siavooshpayandehazad/TTU_ElevatorLab
 +
 
 
=Physical Model=
 
=Physical Model=
 +
[[File:ElevatorModel.jpg|300px|thumb|right|alt=Alt text|Fig. 2: Schematic of physical model]]
 +
This model has 5 floors but the last floor is reserved for security reasons.The schematic of the model is shown in Fig. 2.
 +
Each floor has a sensor and on the top floor there is an emergency break that stops the cabin from going through the roof.
 +
Before reaching the emergency break, there is an emergency sensor that is connected to a safety monitoring mechanism that
 +
is responsible of preventing hardware breaks. The thread is being pulled by a stepper motor which is placed at the first floor.
 +
There are no elevator doors included in the model at the time of writing this document.  The following physical models
 +
have been made for the project:
 +
 +
*[[Lego structure]]
 +
*[[3D printable structure]] (under development)
  
==Lego Construction==
 
A lego model has been built for this lab. you can see the schematic of the model in Fig. 1.
 
 
[[File:ElevatorModel.jpg|400px|thumb|right|alt=Alt text|Fig. 1: Schematic of physical model]]
 
 
=Controller circuit=
 
=Controller circuit=
==first prototype==
+
The controller circuit is monitoring sensor behaviour and issuing control signals to motor driver circuit based on the calls it gets from inner and outer cabin buttons. There are two main controller board classes prepared for this model.
In the first verion of control board, a XULA fpga board has been used. Pin configuration of this board has been shown in Fig. 2.
+
[[File:Schematic.png|400px|thumb|right|alt=Alt text|Fig. 2: Schematic of control board]]
+
+
The first prototype control board provides the following functionalities:
+
* Seven segment display
+
* Inner and outer cabin push buttons
+
* Motor state indicator LEDs
+
* software reset button
+
=== Signal Names and Description ===
+
The first prototype board has the following signals:
+
{| class="wikitable"
+
|-
+
! Name !! Port !! type
+
|-
+
| clk || in || STD_LOGIC
+
|-
+
| sensors || in || STD_LOGIC_VECTOR (4 DOWNTO 0)
+
|-
+
| calls || in || STD_LOGIC_VECTOR (4 DOWNTO 0)
+
|-
+
| menu || in || STD_LOGIC_VECTOR (4 DOWNTO 0)
+
|-
+
| motor || out || STD_LOGIC_VECTOR (1 DOWNTO 0)
+
|-
+
| sleep || out || STD_LOGIC
+
|-
+
| Seven segment || out || STD_LOGIC_VECTOR (6 DOWNTO 0)
+
|}
+
  
====Description====
+
FPGA controller boards:
*Sensors should be designed according to the following functionality:
+
*[[FPGA Controller prototype]]
**Sensors are prone to bouncing because of vibrations in the lift which might not be visible to the naked eye but is visible to the sensors. Hence the sensors need to be de-bounced by a three bit shift register with 19th bit of counter slowing the de-bouncing circuit.
+
*[[FPGA Controller PC-Board]] (under development...ver 1 will be released soon)
**The lift has five ray cut Infra-Red (IR) sensors.
+
Micro-Controller Boards (side project):
**When ever a sensors ray is cut by the lift it sends a signal '1' to the FPGA. Otherwise the sensor sends a '0'
+
*[[Micro-Controller prototype]] (under development...ver 1 will be released soon))
**Each sensor is placed between floors and there can be blind spots between each sensor. When the lift is in a blind spot all sensors send "00000" to the FPGA. This is the time when the lift is moving between two sensors. At this point sensors can also recieve value from two sensors as well. (e.g. on the second floor sensors can either have a value "00000" or "00110".) It is recommended that both cases should be handled by the designer. (hint: rather then looking for sensor ="00100" look for sensor(2)= "1".)
+
*Motor Signals
+
** Motor(0) controls the direction of the motor. Where '1' is DOWN '0' is up
+
** Motor(1) generates a clock signal which controls the speed of the motor. The speed is specified by a clk like signal by changing its frequency. The recommended speed of Motor can be given by sending 10th bit of the counter.
+
** A sleep signal turns off the motor. In idle state the motor should be kept turned off. where '1' is ON and '0' is OFF
+
** Motor FSM should also shares its Status with Floor FSM ( i.e. idle, going up, going down, blinking Seven segment)
+
*Seven segment should work as follows
+
**Seven segment decoder decodes the current floor into seven segment output.
+
**Each segment is turned on by logic value 1. Seven segment should also be able to blink 5 times after it reaches a floor.
+
**Seven segment the pin orientation (i-e. seven segment <= "abcdefg";)
+
  
===Sensor System===
+
=Functional Verification=
 
+
After students finished their design they are required to perform tests on their designs firs by simulating it and then try it on the physical model.
===Safty Monitoring System===
+
== Simuation ==
Since this model is designed to be controled remotely, it should be able to maintain its functionality even if it is programmed with a faulty design. For this reason we need some monitoring system to guarantee
+
===VHDL Simulation===
the functionality.
+
A VHDL testbench has been designed to be used for verifying the functionality of the lift.  
====hardware break====
+
<source lang="javascript" collapse="true" first-line="2">
A physical switch has been installed on the top floor to prevent faulty designs to go through the roof.
+
LIBRARY ieee;
====behaviour monitor====
+
USE ieee.std_logic_1164.ALL;
Since reaching hardware break will require human intervention and it would not always possible (in times that an operator is not present etc.), a behavior monitor system has been added to the lift.
+
USE ieee.numeric_std.ALL;
Motor control signals goes through the monitoring system and if it detects a suspicious behaviour (being on first floor and unwinding the thread or being on the top floor and trying to move up) it
+
takes over the control and brings the lift to the initial position and sends a reset signal to the control board.
+
 
   
 
   
 +
ENTITY lift_tb IS
 +
END lift_tb;
 +
 +
RCHITECTURE behavior OF lift_tb IS
 +
 +
    -- Component Declaration for the Unit Under Test (UUT)
 +
    -- fix this component for your design
 +
    COMPONENT lift
 +
    PORT(
 +
        clk : IN  std_logic;
 +
        sensors : IN  std_logic_vector(4 downto 0);
 +
        calls : IN  std_logic_vector(4 downto 0);
 +
        menu : IN  std_logic_vector(4 downto 0);
 +
        motor : OUT  std_logic_vector (1 downto 0);
 +
        sleep : OUT  std_logic;
 +
        ss : OUT  std_logic_vector(6 downto 0)
 +
        );
 +
    END COMPONENT;
 +
   
 +
  --Inputs
 +
  signal clk : std_logic := '0';
 +
  signal sensor : std_logic_vector(4 downto 0) := (others => '0');
 +
  signal call : std_logic_vector(4 downto 0) := (others => '0');
 +
 +
--Outputs
 +
  signal motor : std_logic_vector(1 downto 0);
 +
  signal menu  : std_logic_vector(4 downto 0);
 +
  signal sleep : std_logic;
 +
  signal ss : std_logic_vector(6 downto 0);
 +
 +
  -- internal signals and types
 +
  signal counter : integer:=0 ;
 +
  type state is (f1,f12,f2,f23,f3,f34,f4);
 +
  signal current_floor : state;
 +
 +
  -- Clock period definitions
 +
  constant clk_period : time := 2 ns;
 +
 +
BEGIN
 +
 +
  -- Instantiate the Unit Under Test (UUT)
 +
  uut: lift PORT MAP (
 +
          clk => clk,
 +
          sensors => sensor,
 +
          calls => call,
 +
          menu => menu,
 +
          motor => motor,
 +
          sleep => sleep,
 +
          ss => ss
 +
        );
 +
 +
  -- Clock process definitions
 +
  clk_process :process
 +
  begin
 +
        clk <= '0';
 +
        wait for clk_period/2;
 +
        clk <= '1';
 +
        wait for clk_period/2;
 +
  end process;
 +
 
 +
  -- Stimulus process
 +
  stim_proc: process
 +
  begin
 +
                call  <= "00000";
 +
                menu <= "00000";
 +
 +
      -- hold reset state for 100 ns.
 +
      wait for 100 ns;
 +
      wait for clk_period*10;
 +
 +
      -- insert stimulus here
 +
                call  <= "00001";
 +
                wait for clk_period;
 +
                call  <= "00000";
 +
 
 +
                wait for clk_period*50;
 +
 +
                call  <= "00010";
 +
                wait for clk_period;
 +
                call  <= "00000";
 +
                wait for clk_period*50;
 +
 +
                call  <= "00100";
 +
                wait for clk_period;
 +
                call  <= "00000";
 +
                wait until sensor(2)= '1';
 +
                wait for clk_period*40;
 +
                call  <= "01000";
 +
                wait for clk_period;
 +
                call  <= "00000";
 +
                wait until sensor(3)= '1';
 +
                wait for clk_period*40;
 +
 +
                call  <= "00010";
 +
                wait for clk_period;
 +
                call  <= "00000";
 +
                wait until sensor(1)= '1';
 +
                wait for clk_period*40;
 +
                call  <= "00001";
 +
                wait for clk_period;
 +
                call  <= "00000";
 +
                wait until sensor(0) = '1';
 +
                wait for clk_period*40;
 +
                wait;
 +
    end process;
 +
        --  simple/stupid lift emulator
 +
        process (motor(1)) begin
 +
                if rising_edge(motor(1)) then
 +
                        if sleep = '1' then
 +
                                if motor(0) = '0' then
 +
                                        counter <= counter +1;
 +
                                elsif motor(0) = '1' then
 +
                                        counter <= counter -1;
 +
                                else
 +
                                        assert false report "The motor feels lonely and ignored why are you not driving it properly" severity warning;
 +
                                end if;
 +
                        end if; -- sleep
 +
                end if;-- motor)1)
 +
        end process;
 +
        --  Assert based on state on lift
 +
        process (counter) begin
 +
                if counter < 2 and counter >=0 then -- floor 1 ( last chance to stop for 1st floor)
 +
                        sensor <="00001";
 +
                        assert false report " 1st Floor "severity note;
 +
                elsif counter < 3 and counter >=2 then -- between floor 1 and 2 sensors ( good place to stop either way for 1nd floor)
 +
                        sensor <="00000";
 +
                        if sleep = '1'  then --check if we are awake
 +
                                  assert motor(0) /= '1' report " BLIND SPOT "severity note;
 +
                                  assert motor(0) /= '0' report " BLIND SPOT  "severity note;
 +
                        end if;
 +
 +
                elsif counter < 4 and counter >=3 then -- between floor 1 and 2 sensors ( good place to stop either way for 1nd floor)
 +
                        sensor <="00011";
 +
                        if sleep = '1'  then --check if we are awake
 +
                                assert motor(0) /= '1' report " Just cut the bottom sensor for 1st floor, this is a good place to stop "severity note;
 +
                                assert motor(0) /= '0' report " Just cut the bottom sensor for 2nd floor, keep going up  "severity note;
 +
                        end if;
 +
 +
                elsif counter < 9 and counter >=4 then -- floor 2: for up : 1st cut of bottom 
 +
                                                      -- floor 2: for down:  stop
 +
                        assert motor(0) /= '1' report " 2nd Floor "severity note;
 +
                        assert motor(0) /= '0' report " floor 2: for up : 1st cut of sensor 1"severity note;
 +
                        sensor <="00010";
 +
 +
                elsif counter < 10 and counter >=9 then -- between the 2 and 3 sensors ( good place to stop either way for 2nd floor)
 +
                        sensor <="00000";
 +
                        if sleep = '1'  then --check if we are awake
 +
                              assert motor(0) /= '1' report " BLIND SPOT "severity note;
 +
                              assert motor(0) /= '0' report " BLIND SPOT  "severity note;
 +
                        end if;
 +
 +
                elsif counter < 11 and counter >=10 then -- between the 2 and 3 sensors ( good place to stop either way for 2nd floor)
 +
                        sensor <="00110";
 +
                        if sleep = '1'  then --check if we are awake
 +
                              assert motor(0) /= '1' report " Just cut the bottom sensor for 2nd floor, this is a good place to stop "severity note;
 +
                              assert motor(0) /= '0' report " Just cut the bottom sensor for 3rd floor, keep going up  "severity note;
 +
                        end if;
 +
 +
                elsif counter < 16 and counter >=11 then -- floor 3: for up : 1st cut of bottom 
 +
                                                        -- floor 3: for down:  stop
 +
                        assert motor(0) /= '1' report " 3nd Floor "severity note;
 +
                        assert motor(0) /= '0' report " floor 3: for up : 1st cut of sensor 2"severity note;
 +
                        sensor <="00100";
 +
                elsif counter < 17 and counter >=16 then -- between the 3 and 4 sensors ( good place to stop either way for 3nd floor)
 +
                        sensor <="00000";
 +
                        if sleep = '1'  then --check if we are awake
 +
                              assert motor(0) /= '1' report " BLIND SPOT "severity note;
 +
                              assert motor(0) /= '0' report " BLIND SPOT  "severity note;
 +
                        end if;
 +
                elsif counter < 18 and counter >=17 then -- between the 3 and 4 sensors ( good place to stop either way for 3nd floor)
 +
                        sensor <="01100";
 +
                        if sleep = '1'  then --check if we are awake
 +
                              assert motor(0) /= '1' report " Just cut the bottom sensor for 3rd floor, this is a good place to stop "severity note;
 +
                              assert motor(0) /= '0' report " Just cut the bottom sensor for 4th floor, keep going up  "severity note;
 +
                        end if;
 +
                elsif counter < 23 and counter >=18 then -- floor 4: for up : 1st cut of bottom 
 +
                                                        -- floor 4: for down:  stop
 +
                        assert motor(0) /= '1' report " 4nd Floor "severity note;
 +
                        assert motor(0) /= '0' report " floor 4: for up : 1st cut of sensor 3"severity note;
 +
                        sensor <="01000";
 +
                elsif counter < 24 and counter >=23 then -- between the 4 and 5 sensors ( good place to stop either way for 4nd floor)
 +
                        sensor <="00000";
 +
                        if sleep = '1'  then --check if we are awake
 +
                                assert motor(0) /= '1' report " BLIND SPOT "severity note;
 +
                                assert motor(0) /= '0' report " BLIND SPOT  "severity note;
 +
                        end if;
 +
                elsif counter < 25 and counter >=24 then -- between the 4 and 5 sensors ( good place to stop either way for 4nd floor)
 +
                        sensor <="11000";
 +
                        if sleep = '1'  then --check if we are awake
 +
                                assert motor(0) /= '1' report " Just cut the bottom sensor for 4th floor, this is a good place to stop "severity note;
 +
                                assert motor(0) /= '0' report " Getting  too close to the roof, 5th sensor is cut "severity warning;
 +
                        end if;
 +
                elsif counter < 30 and counter >=25 then -- floor 5: for up : 1st cut of bottom 
 +
                                                        -- floor 5: for down:  stop
 +
                        assert motor(0) /= '1' report " 5nd Floor "severity note;
 +
                        assert motor(0) /= '0' report " ITS THE 5TH FLOOR ALREADY!!! STOP GOING UP "severity warning;
 +
                        sensor <="10000";
 +
                elsif counter >33  then
 +
                        assert false report "Hold on mi lord! this is an elevator not a Nazgûl, Elevators cant fly P.s. by now your passenger will be halfway through the roof saying hi to the seagulls " severity error;
 +
                elsif counter < 0 then
 +
                        assert false report "Trying to go below 1st floor P.S. leave the Journey to the center of the earth to Jules Verne" severity error;
 +
                end if;
 +
      end process;
 +
END;
 +
</source>
 +
===Verilog Simulation===
 +
Students are required to write a Verilog testbench to test their designs.
  
= Lab Reports =  
+
== Testing on Physical Model (Remote Lab) ==
A lab report template has been provided for students.
+
[[File:Webpage.png|500px|thumb|right|alt=Alt text|Fig. 3: Screenshot of remote lab page]]
 
+
in this project, a remote lab was designed for students (see Fig. 3) to access the controlling hardware from any remote place inside the department INTERA network.
= Remote Lab =
+
in this project, a remote lab was designed for students to access the controlling hardware from any remote place inside the department INTERA network.
+
 
The server is running on a raspberry pi and students can see a view of the working lift using an internet camera.
 
The server is running on a raspberry pi and students can see a view of the working lift using an internet camera.
 
A working sample of the controller is provided to the students as a demo in order to get them accustomed to the functionality of the Lift.
 
A working sample of the controller is provided to the students as a demo in order to get them accustomed to the functionality of the Lift.
you can access this lab from this link: [[cherry.pld.ttu.ee]]
 
== Web Server ==
 
*server on Raspberry Pi
 
*username and password for restrictions on access
 
*internet webcam
 
  
== Push button emulator ==
+
=== Web Server ===
*using Raspberry Pi GPIO for emulating push button behaviour
+
Apache is used for web server, which runs on a Raspberry Pi. Web server's task is to provide the video stream of the elevator via an internet webcam along with virtual buttons for controling the board. In the remote lab page, students can test the lift with a bit file provided to them or they can upload their own bit fils. A Username and password pair has been added for restrictions on access to reduce any inconvinience. Raspberry Pi GPIO's have been used for emulating push button behaviour. All the Server files can be found in here: [[:File:Elevator.zip|server files]].
  
=Future Work=
+
When user clicks on buttons on the web page, cgi scripts are called out. Therefore web server has to have cgi-bin enabled and scripts have to have rights to execute. To control the elevator through GPIO, 3rd party application was compiled for this purpose and bash scripts simply call out the program with the corresponding arguments. The physical GPIO connections were wired so, that sending out signal ''gpio write 2 1'' for example, would move the elevator to second floor. More about using GPIO on linux in [https://sites.google.com/site/semilleroadt/raspberry-pi-tutorials/gpio here].
 +
 
 +
'''Note1:''' a schematic of all the connections for GPIO is needed here.
 +
=== Raspberry PI setup guide ===
 +
<ol>
 +
<!-- 1 -->
 +
<li> '''Install Raspbian OS on the SD card'''
 +
<ol>
 +
<li> Download the NOOBS installer from https://www.raspberrypi.org/downloads/
 +
<li> Copy it on SD card
 +
<li> Plug in the SD card to the Raspberry PI and turn it on
 +
<li> Select Raspbian OS installer and follow the instructions
 +
<li> When the installation finishes it is recommended to enable SSH server, so the following steps can be executed remotely through internet. From the Raspberry Pi Software Configuration Tool: '''Advanced Options > SSH > Enable'''. After that to figure out ip address of PI, use for example
 +
<source lang="bash" collapse="false">ifconfig | grep inet</source>
 +
</li>
 +
</ol>
 +
</li>
 +
 
 +
<!-- 2 -->
 +
<li> '''Install XSTOOLS'''
 +
<source lang="bash" collapse="false">
 +
sudo apt-get -y install python-pip
 +
sudo pip install xstools intelhex
 +
</source>
 +
Next add udev rule so that webserver user ''www-data'' can access usb to program boards. <br/>
 +
''/etc/udev/rules.d/81-xstools-sb.rules''
 +
SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="ff8c", MODE="0666", GROUP="www-data"
 +
or use bash command:
 +
<source lang="bash" collapse="true">
 +
sudo sh -c "echo 'SUBSYSTEM==\"usb\", ATTR{idVendor}==\"04d8\", \
 +
ATTR{idProduct}==\"ff8c\", MODE=\"0666\", GROUP=\"www-data\"'\
 +
> /etc/udev/rules.d/81-xstools-usb.rules"
 +
</source>
 +
Test XSTOOLS with ''xstest.py''. It should respond with ''Success: XuLA-200 passed diagnostic test!''. If it does not, upgrading the firmware of Xula-200 might help. For upgrading firmware use command ''xsusbprg.py''. From our experience it is also possible that USB port does not provide enough power for successful firmware upgrade. In that case using a USB hub with external power adapter might help.
 +
</li>
 +
 
 +
<!-- 3 -->
 +
<li> '''Webserver setup'''
 +
<ol>
 +
<li> Install webserver (Apache2 in this example)
 +
<source lang="bash" collapse="false">
 +
sudo apt-get -y install apache2 php5
 +
</source>
 +
<li> download and extract [[:File:Elevator.zip|server files]]
 +
<source lang="bash" collapse="false">
 +
wget http://ati.ttu.ee/~hkinks/lift/www.zip
 +
sudo unzip -o -d /var/www/ www.zip
 +
 
 +
#by default cgi-bin folder will be located at /usr/lib/cgi-bin
 +
#therefore we need to move the cgi scripts to there. Another option would be to change the apache config
 +
sudo mv /var/www/cgi-bin/* /usr/lib/cgi-bin
 +
sudo rm /var/www/cgi-bin -rf
 +
# make them executable and change owner
 +
sudo chmod +x /var/www/cgi-bin/*
 +
sudo chown www-data:www-data /var/www/cgi-bin/*
 +
</source>
 +
</li>
 +
</ol>
 +
</li>
 +
 
 +
<!-- 4 -->
 +
<li>
 +
'''GPIO setup''' <br/>
 +
To move the elevator using GPIO, wiringPi GPIO access library is used
 +
<source lang="bash" collapse="false">
 +
git clone git://git.drogon.net/wiringPi
 +
cd wiringPi
 +
./build
 +
</source>
 +
</li>
 +
<li>
 +
'''Testing and debugging''' <br>
 +
Try connecting to raspberry PI through web browser to see if webpage is available. If not , try restarting apache webserver ''sudo service apache2''. <br>
 +
 
 +
 
 +
If webpage is available but buttons don't work, start debugging by running cgi scripts in ''/usr/lib/cgi-bin'' and make sure they work from the shell. If they do work from the shell, webserver probably can not execute them. To verify it is indeed the problem, you could try executing the scripts as www-data users and check the permissions of the scripts. For example ''sudo su -c "./usr/lib/cgi-bin/move.cgi" www-data''.
 +
</li>
 +
</ol>
 +
 
 +
= Lab Reports =
 +
Students are required to submit a report in the beginning before starting their designs to describe the process of what they are planning to do and one at the end of the lab along with their codes. A lab report template has been provided for students (You can find it here: [[:File:lab6_template.pdf]]) and all the reports should be submitted in the same format.
 +
 
 +
=Plans for future improvements=
 +
The following improvements are on our todo list:
 
* queueing system for login in remote lab
 
* queueing system for login in remote lab
* checking the bitfile for malicious code
+
* checking the bitfile for malicious codes
* making a 3D model for printing
+
* making a 3D model for printing (under development)
 
* providing access for students outside ATI interanet
 
* providing access for students outside ATI interanet
* PCB design for control board
+
* adding a micro-controller based control board (under development)
* adding a micro-controller based control board
+
* checking if the motor is turned of with switching clock off: this will cause motor to get locked and warm up
* monitoring all the sensors in monitoring system
+
 
+
[[LIFT/About | About]]
+
  
.
+
=Related Publications=
 +
*Muhammad Adeel Tajammul, Siavoosh Payandeh Azad, Peeter Ellervee: "Digital system Modeling and synthesis as an introduction to computer systems engineering", IEEE International Conference on Microelectronic Systems Education (MSE), 2015
 +
*Siavoosh Payandeh Azad, Hannes Kinks, Muhammed Adeel Tajammul and Peeter Ellervee: "An Ad-hoc Implementation of a Remote Laboratory",IEEE International Conference on Microelectronic Systems Education (MSE), 2015

Latest revision as of 11:26, 29 May 2015

Alt text
Fig. 1: Laboratory Process

Lift Project is one of the projects designed in department of computer engineering at TTU as a lab project. The main task in this lab is to design a controller for an elevator. Goals of this lab is to understand Finite State Machine (FSM) design.

The process of this lab is described in Fig. 1. Students first have to describe the controller by providing FSM diagrams and transition tables to the staff and then go through a process of implementation, synthesis and verification. In the end they are required to submit a report.

GitHub repository

All the files and designs are accessible at: https://github.com/siavooshpayandehazad/TTU_ElevatorLab

Physical Model

Alt text
Fig. 2: Schematic of physical model

This model has 5 floors but the last floor is reserved for security reasons.The schematic of the model is shown in Fig. 2. Each floor has a sensor and on the top floor there is an emergency break that stops the cabin from going through the roof. Before reaching the emergency break, there is an emergency sensor that is connected to a safety monitoring mechanism that is responsible of preventing hardware breaks. The thread is being pulled by a stepper motor which is placed at the first floor. There are no elevator doors included in the model at the time of writing this document. The following physical models have been made for the project:

Controller circuit

The controller circuit is monitoring sensor behaviour and issuing control signals to motor driver circuit based on the calls it gets from inner and outer cabin buttons. There are two main controller board classes prepared for this model.

FPGA controller boards:

Micro-Controller Boards (side project):

Functional Verification

After students finished their design they are required to perform tests on their designs firs by simulating it and then try it on the physical model.

Simuation

VHDL Simulation

A VHDL testbench has been designed to be used for verifying the functionality of the lift.

 LIBRARY ieee;
 USE ieee.std_logic_1164.ALL;
 USE ieee.numeric_std.ALL;
 
 ENTITY lift_tb IS
 END lift_tb;
 
 RCHITECTURE behavior OF lift_tb IS 
 
    -- Component Declaration for the Unit Under Test (UUT)
    -- fix this component for your design 
    COMPONENT lift
    PORT(
         clk : IN  std_logic;
         sensors : IN  std_logic_vector(4 downto 0);
         calls : IN  std_logic_vector(4 downto 0);
         menu : IN  std_logic_vector(4 downto 0);
         motor : OUT  std_logic_vector (1 downto 0);
         sleep : OUT  std_logic;
         ss : OUT  std_logic_vector(6 downto 0)
        );
    END COMPONENT;
    
   --Inputs
   signal clk : std_logic := '0';
   signal sensor : std_logic_vector(4 downto 0) := (others => '0');
   signal call : std_logic_vector(4 downto 0) := (others => '0');
 
 	--Outputs
   signal motor : std_logic_vector(1 downto 0);
   signal menu  : std_logic_vector(4 downto 0);
   signal sleep : std_logic;
   signal ss : std_logic_vector(6 downto 0);
 
   -- internal signals and types
   signal counter : integer:=0 ; 
   type state is (f1,f12,f2,f23,f3,f34,f4); 
   signal current_floor : state; 
 
   -- Clock period definitions
   constant clk_period : time := 2 ns;
 
 BEGIN
 
   -- Instantiate the Unit Under Test (UUT)
   uut: lift PORT MAP (
          clk => clk,
          sensors => sensor,
          calls => call,
          menu => menu,
          motor => motor,
          sleep => sleep,
          ss => ss
        );
 
   -- Clock process definitions
   clk_process :process
   begin
        clk <= '0';
        wait for clk_period/2;
        clk <= '1';
        wait for clk_period/2;
   end process;
  
   -- Stimulus process
   stim_proc: process
   begin		
                call   <= "00000";
                menu <= "00000";
 
      -- hold reset state for 100 ns.
      wait for 100 ns;	
      wait for clk_period*10;
 
      -- insert stimulus here 
                call   <= "00001";
                wait for clk_period;
                call   <= "00000";
  
                wait for clk_period*50;
 
                call   <= "00010";
                wait for clk_period;
                call   <= "00000";
                wait for clk_period*50;
 
                call   <= "00100";
                wait for clk_period;
                call   <= "00000";
                wait until sensor(2)= '1';
                wait for clk_period*40;
                call   <= "01000";
                wait for clk_period;
                call   <= "00000";
                wait until sensor(3)= '1';
                wait for clk_period*40;
 
                call   <= "00010";
                wait for clk_period;
                call   <= "00000";
                wait until sensor(1)= '1';
                wait for clk_period*40;
                call   <= "00001";
                wait for clk_period;
                call   <= "00000";
                wait until sensor(0) = '1';
                wait for clk_period*40;
                wait;
     end process;
        --  simple/stupid lift emulator
        process (motor(1)) begin
                if rising_edge(motor(1)) then
                        if sleep = '1' then
                                if motor(0) = '0' then
                                        counter <= counter +1;
                                elsif motor(0) = '1' then
                                        counter <= counter -1;
                                else
                                        assert false report "The motor feels lonely and ignored why are you not driving it properly" severity warning;
                                end if;
                        end if; -- sleep
                end if;-- motor)1)
        end process;
        --  Assert based on state on lift
        process (counter) begin
                if counter < 2 and counter >=0 then -- floor 1 ( last chance to stop for 1st floor)
                        sensor <="00001";
                        assert false report " 1st Floor "severity note;
                elsif counter < 3 and counter >=2 then -- between floor 1 and 2 sensors ( good place to stop either way for 1nd floor)			
                        sensor <="00000";	
                        if sleep = '1'  then --check if we are awake
                                  assert motor(0) /= '1' report " BLIND SPOT "severity note;
                                  assert motor(0) /= '0' report " BLIND SPOT  "severity note;
                        end if;
 
                elsif counter < 4 and counter >=3 then -- between floor 1 and 2 sensors ( good place to stop either way for 1nd floor)
                        sensor <="00011";
                        if sleep = '1'  then --check if we are awake
                                assert motor(0) /= '1' report " Just cut the bottom sensor for 1st floor, this is a good place to stop "severity note;
                                assert motor(0) /= '0' report " Just cut the bottom sensor for 2nd floor, keep going up  "severity note;
                        end if;
 
                elsif counter < 9 and counter >=4 then -- floor 2: for up : 1st cut of bottom   
                                                       -- floor 2: for down:  stop 
                        assert motor(0) /= '1' report " 2nd Floor "severity note;
                        assert motor(0) /= '0' report " floor 2: for up : 1st cut of sensor 1"severity note;										
                        sensor <="00010";
 
                elsif counter < 10 and counter >=9 then -- between the 2 and 3 sensors ( good place to stop either way for 2nd floor)
                        sensor <="00000";	
                        if sleep = '1'  then --check if we are awake
                               assert motor(0) /= '1' report " BLIND SPOT "severity note;
                               assert motor(0) /= '0' report " BLIND SPOT  "severity note;
                        end if;
 
                elsif counter < 11 and counter >=10 then -- between the 2 and 3 sensors ( good place to stop either way for 2nd floor)
                        sensor <="00110";			
                        if sleep = '1'  then --check if we are awake
                               assert motor(0) /= '1' report " Just cut the bottom sensor for 2nd floor, this is a good place to stop "severity note;
                               assert motor(0) /= '0' report " Just cut the bottom sensor for 3rd floor, keep going up  "severity note;
                        end if;
 
                elsif counter < 16 and counter >=11 then -- floor 3: for up : 1st cut of bottom   
                                                         -- floor 3: for down:  stop 
                        assert motor(0) /= '1' report " 3nd Floor "severity note;
                        assert motor(0) /= '0' report " floor 3: for up : 1st cut of sensor 2"severity note;										
                        sensor <="00100";
                elsif counter < 17 and counter >=16 then -- between the 3 and 4 sensors ( good place to stop either way for 3nd floor)
                        sensor <="00000";	
                        if sleep = '1'  then --check if we are awake
                               assert motor(0) /= '1' report " BLIND SPOT "severity note;
                               assert motor(0) /= '0' report " BLIND SPOT  "severity note;
                        end if;
                elsif counter < 18 and counter >=17 then -- between the 3 and 4 sensors ( good place to stop either way for 3nd floor)
                        sensor <="01100";	
                        if sleep = '1'  then --check if we are awake
                               assert motor(0) /= '1' report " Just cut the bottom sensor for 3rd floor, this is a good place to stop "severity note;
                               assert motor(0) /= '0' report " Just cut the bottom sensor for 4th floor, keep going up  "severity note;
                        end if;
                elsif counter < 23 and counter >=18 then -- floor 4: for up : 1st cut of bottom   
                                                         -- floor 4: for down:  stop 
                        assert motor(0) /= '1' report " 4nd Floor "severity note;
                        assert motor(0) /= '0' report " floor 4: for up : 1st cut of sensor 3"severity note;										
                        sensor <="01000";
                elsif counter < 24 and counter >=23 then -- between the 4 and 5 sensors ( good place to stop either way for 4nd floor)
                        sensor <="00000";	
                        if sleep = '1'  then --check if we are awake
                                assert motor(0) /= '1' report " BLIND SPOT "severity note;
                                assert motor(0) /= '0' report " BLIND SPOT  "severity note;
                        end if;
                elsif counter < 25 and counter >=24 then -- between the 4 and 5 sensors ( good place to stop either way for 4nd floor)
                        sensor <="11000";			
                        if sleep = '1'  then --check if we are awake
                                assert motor(0) /= '1' report " Just cut the bottom sensor for 4th floor, this is a good place to stop "severity note;
                                assert motor(0) /= '0' report " Getting  too close to the roof, 5th sensor is cut "severity warning;
                        end if;
                elsif counter < 30 and counter >=25 then -- floor 5: for up : 1st cut of bottom   
                                                         -- floor 5: for down:  stop 							 
                        assert motor(0) /= '1' report " 5nd Floor "severity note;
                        assert motor(0) /= '0' report " ITS THE 5TH FLOOR ALREADY!!! STOP GOING UP "severity warning;										
                        sensor <="10000";
                elsif counter >33  then
                        assert false report "Hold on mi lord! this is an elevator not a Nazgûl, Elevators cant fly P.s. by now your passenger will be halfway through the roof saying hi to the seagulls " severity error;
                elsif counter < 0 then 
                        assert false report "Trying to go below 1st floor P.S. leave the Journey to the center of the earth to Jules Verne" severity error;
                end if;
       end process;
 END;

Verilog Simulation

Students are required to write a Verilog testbench to test their designs.

Testing on Physical Model (Remote Lab)

Alt text
Fig. 3: Screenshot of remote lab page

in this project, a remote lab was designed for students (see Fig. 3) to access the controlling hardware from any remote place inside the department INTERA network. The server is running on a raspberry pi and students can see a view of the working lift using an internet camera. A working sample of the controller is provided to the students as a demo in order to get them accustomed to the functionality of the Lift.

Web Server

Apache is used for web server, which runs on a Raspberry Pi. Web server's task is to provide the video stream of the elevator via an internet webcam along with virtual buttons for controling the board. In the remote lab page, students can test the lift with a bit file provided to them or they can upload their own bit fils. A Username and password pair has been added for restrictions on access to reduce any inconvinience. Raspberry Pi GPIO's have been used for emulating push button behaviour. All the Server files can be found in here: server files.

When user clicks on buttons on the web page, cgi scripts are called out. Therefore web server has to have cgi-bin enabled and scripts have to have rights to execute. To control the elevator through GPIO, 3rd party application was compiled for this purpose and bash scripts simply call out the program with the corresponding arguments. The physical GPIO connections were wired so, that sending out signal gpio write 2 1 for example, would move the elevator to second floor. More about using GPIO on linux in here.

Note1: a schematic of all the connections for GPIO is needed here.

Raspberry PI setup guide

  1. Install Raspbian OS on the SD card
    1. Download the NOOBS installer from https://www.raspberrypi.org/downloads/
    2. Copy it on SD card
    3. Plug in the SD card to the Raspberry PI and turn it on
    4. Select Raspbian OS installer and follow the instructions
    5. When the installation finishes it is recommended to enable SSH server, so the following steps can be executed remotely through internet. From the Raspberry Pi Software Configuration Tool: Advanced Options > SSH > Enable. After that to figure out ip address of PI, use for example
      ifconfig | grep inet
      
  2. Install XSTOOLS
     
    sudo apt-get -y install python-pip
    sudo pip install xstools intelhex
    

    Next add udev rule so that webserver user www-data can access usb to program boards.
    /etc/udev/rules.d/81-xstools-sb.rules

    SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="ff8c", MODE="0666", GROUP="www-data"
    

    or use bash command:

    sudo sh -c "echo 'SUBSYSTEM==\"usb\", ATTR{idVendor}==\"04d8\", \
    ATTR{idProduct}==\"ff8c\", MODE=\"0666\", GROUP=\"www-data\"'\
     > /etc/udev/rules.d/81-xstools-usb.rules"
    

    Test XSTOOLS with xstest.py. It should respond with Success: XuLA-200 passed diagnostic test!. If it does not, upgrading the firmware of Xula-200 might help. For upgrading firmware use command xsusbprg.py. From our experience it is also possible that USB port does not provide enough power for successful firmware upgrade. In that case using a USB hub with external power adapter might help.

  3. Webserver setup
    1. Install webserver (Apache2 in this example)
       
      sudo apt-get -y install apache2 php5
      
    2. download and extract server files
       
      wget http://ati.ttu.ee/~hkinks/lift/www.zip
      sudo unzip -o -d /var/www/ www.zip
      
      #by default cgi-bin folder will be located at /usr/lib/cgi-bin
      #therefore we need to move the cgi scripts to there. Another option would be to change the apache config
      sudo mv /var/www/cgi-bin/* /usr/lib/cgi-bin
      sudo rm /var/www/cgi-bin -rf
      # make them executable and change owner
      sudo chmod +x /var/www/cgi-bin/*
      sudo chown www-data:www-data /var/www/cgi-bin/*
      
  4. GPIO setup
    To move the elevator using GPIO, wiringPi GPIO access library is used
    git clone git://git.drogon.net/wiringPi 
    cd wiringPi
    ./build
    
  5. Testing and debugging
    Try connecting to raspberry PI through web browser to see if webpage is available. If not , try restarting apache webserver sudo service apache2.
    If webpage is available but buttons don't work, start debugging by running cgi scripts in /usr/lib/cgi-bin and make sure they work from the shell. If they do work from the shell, webserver probably can not execute them. To verify it is indeed the problem, you could try executing the scripts as www-data users and check the permissions of the scripts. For example sudo su -c "./usr/lib/cgi-bin/move.cgi" www-data.

Lab Reports

Students are required to submit a report in the beginning before starting their designs to describe the process of what they are planning to do and one at the end of the lab along with their codes. A lab report template has been provided for students (You can find it here: File:lab6_template.pdf) and all the reports should be submitted in the same format.

Plans for future improvements

The following improvements are on our todo list:

  • queueing system for login in remote lab
  • checking the bitfile for malicious codes
  • making a 3D model for printing (under development)
  • providing access for students outside ATI interanet
  • adding a micro-controller based control board (under development)
  • checking if the motor is turned of with switching clock off: this will cause motor to get locked and warm up

Related Publications

  • Muhammad Adeel Tajammul, Siavoosh Payandeh Azad, Peeter Ellervee: "Digital system Modeling and synthesis as an introduction to computer systems engineering", IEEE International Conference on Microelectronic Systems Education (MSE), 2015
  • Siavoosh Payandeh Azad, Hannes Kinks, Muhammed Adeel Tajammul and Peeter Ellervee: "An Ad-hoc Implementation of a Remote Laboratory",IEEE International Conference on Microelectronic Systems Education (MSE), 2015