Tuesday, December 21, 2010

Security and Access Control Project

Summary: A project for young students of robotics

Access Control System

Assignment:

You are asked to create a security system for a top secret research facility. This facility has one access door through which authorized personnel can gain entry. The only security is a regular locked which can opened and closed with a key. This is not sufficient security for such a top secret facility.
Figure 1
Figure 1 (graphics2.jpg)

Technology available:

The following technology and equipment are given to you to use in your system:

Outputs:

  • Electromagnetic door latch
  • Indicator light
  • 23’’ External monitor

Inputs:

  • Keyboard or keypad for entering access information
  • Press button
  • RF ID reader
  • Magnetic reed switches
  • PIR motion detectors
  • Bluetooth receiver for cell phone connection
  • Webcam

Computing:

  • Laptop computer
  • Internet connection

Hardware interface:

  • Fischertechnik Robo Controller

Software:

  • Python programming language
  • Python libraries to interface with the Fischertechnik controller, cell phone, RF IF reader and webcam
Figure 2
Figure 2 (graphics1.jpg)

Write the specification of your system.

The first step to creating your system is writing out the specification of what your system will be able to do using the technology listed above. Your specifications can include things you don’t yet know how to do but think will be useful or cool, such as allow the user to send an SMS with a password to open the door or e-mail a picture of the user if he gets the password wrong. This is a wish-list which we will later inspect to see what is actually possible. Your specification should be in the following format:
My system will be able to:
  • Allow a user to enter his name and password on the keyboard outside the room and open the door if the password is correct
  • Allow the user to swipe his RF ID access card and allow him access if he is a registered user
  • Etc.

Draw a diagram of your system

This drawing should show how the different part are connected to one another.
Scan of sketch...

Steps in developing your system

You will not be able to building this system in one lesson. It will likely take you a number of lessons. Therefore we need to decide what want to do first and what we want to leave for last. It helps to start with the simplest possible form of the system you can think of and get that to work. Once that works you can add a small new feature and get that to work. This will mean that you always have a working system. The opposite would be to sit down and keep on building your system without testing it until you are finished. The problem with this approach is that when you finally test it, it may be very hard to find the problems in the large system.
I suggest approaching it in the following way:
  • Test the remote, motions sensor, buttons and lights connected to the Fischertechnik controller
  • Write a Robo Pro program to control these inputs and outputs
  • Wire the magnetic door latch into the system
  • Write a basic Python program without touching the hardware
  • Test the Fischertechnik hardware with Python
  • Write a Python program to do what you did with the Robo Pro program
  • Add some functionality

Step1: Testing the hardware

Connecting to the Fischertechnik controller

Plug the following hardware into the Fischertechnik controller:
  • red indicator light
  • green indicator light
  • buzzer
  • RF remote control receiver
  • PIR motion sensors
Figure 3
Figure 3 (graphics16.png)
Figure 4
Figure 4 (graphics17.png)
Figure 5
Figure 5 (graphics10.jpg)

Reading input from the sensors

The simplest way to see whether the Fischertechnik controller picks up the new hardware connected to it and correctly registers motion on the motion sensors and button presses on the remote control is to open the test interface in the Robo Pro software. Once you have tested the remote and motion sensor you can open up IDLE and test it in the shell. Look at the previous step to import the library and open the interface to read the status of the sensors.
If you are unsure how to do this, watch the following video tutorials:
  • plugging the Fischertechnik controller to power and USB
  • connecting lights and motors to the Fischertechnik controller
  • connecting buttons to the Fischertechnik controller

Step2: Writing a Robo Pro program

Before we write the program in Python to control our system, we will write it in Robo Pro. If we are happy with the system in Robo Pro then we will take it and repeat it in Python add more complex hardware and functionality like the webcam, RF ID, etc.
If you are not familiar with how to write programs in Robo Pro, I suggest that you watch the following introductory videos or do the 'Introduction to Visual Programming' course.
  • Starting out in Robo Pro

First attempt:

Write a Visual Program for your system to do the following:
  • have the green light on when the system is unarmed
  • arm the system by clicking the RF remote
  • once armed turn the red light on
  • wait to be either triggered by the motion sensor or dis-armed with the remote
  • when triggered by the motion sensor sound the buzzer
  • continue to sound the buzzer until the system is disarmed with the RF remote
  • once disarmed stop the buzzing, turn the indicator light green and be ready for arming again
Hint:
Remember that you have to power the PIR motion sensors before they will give an output when triggered and allow them a few seconds to 'boot up' before they are ready. Don't look at a suggested solution until you have made your own attempt.
Figure 6
Figure 6 (graphics8.jpg)

Second attempt:

  • If this works then you can build in some more functionality. Add the following to your system:
  • When arming the system give the user 10 seconds before the sensors can be triggered.
  • while arming flash the red light and make short buzzes with the buzzer.
  • the user should be able to disarm the system while it is in the process of arming.
  • once the 10 seconds arming is done, stop the blinking and short buzzes and permanently shine
  • the red indicator light.
  • when triggered by the motion sensors start ringing the alarm in longer bursts and flashing the red light
Hint:
You can take a look at the suggested solution below. The three images are the main program and the two sub-programs.
Figure 7
Figure 7 (graphics18.jpg)
Figure 8
Figure 8 (graphics19.jpg)
Figure 9
Figure 9 (graphics20.jpg)
Step 3: Single user access with a password
Write a program running on the PC or laptop that asks a user to enter his name and password using the keyboard. If he enters his password correctly the program tells him that access has been granted and the door will be opened. In this step we don’t yet connect any of the hardware to the computer.
Sample program:
Figure 10
Figure 10 (graphics3.png)
Figure 11
Figure 11 (graphics4.png)
Figure 12
Figure 12 (graphics5.png)
Figure 13
Figure 13 (graphics6.png)

Step 4: Multiple user access with password

We still don’t connect any hardware yet. The previous program are now changed to allow many users to type their usernames and unique passwords. If the user enters his username and his own password the system displays on the screen that he has been allowed access.
You will need to use:
  • Use the elif command to check for multiple valid usernames with corresponding passwords

Step5 : Testing the hardware with Python

At this point we test some of our hardware and see how we can read inputs from sensors outside the computer and control outputs such as lights through the Fischertechnik controller. The plan is to get a working prototype of the system which reads the user's name and password, and if correct prompts him to press his remote. If the remote is read by the system, a light connected to the system switches on and remains on for 5 seconds.

Plugging in the hardware

Connect the Fischertechnik controller to the 9V DC power supply and to the computer with a USB cable. Plug a 9V lamp into the M1 motor port and the output from the remote control receiver into the I1 digital input port. Press the remote and listen for the audible 'click' of the relay to make sure it is on and workd. Then I suggest opening up Robo Pro or another program to make sure your light works and the input from the remote registers. If you are satisfied then close Robo Pro and open up IDLE.

Getting Python to talk to the Fischertechnik controller

Installing the library
Assuming that the Fischertechnik controller already works with Robo Pro on your computer and the drivers required for that has been installed. To get Python to talk the Fischertechnik controller you will need two files – FishFa40.py and umFish40.dll. FishFa40 can be copied anywhere in the Python folder on your compute and umFish40.dll inside the DLL folder of your Python directory.
I suggest open the Python shell and see whether you can communicate to the controller. Punch in the following commands one at a time and see if they run without an error:
from FishFa40 import*
ff = FishFace()
ff.OpenInterface()
Then try some of the following commands:
ff.SetMotor(1,1) # For run the motor connected to M1 port cw
ff.SetMotor(1,0) # Switch the motor connected to M1 port off
ff.SetMotor(4,2) # Run the motor connected to M4 ccw
ff.GetInput(1) # Read the status of the I1 port.
ff.WaitForInput(1) # Waits for I1 to triggered
ff.Pause(1000) # Wait for 1 second or 1000 milliseconds
ff.CloseInterface() # Remember to close the interface before terminating the program
Play around with these commands in shell until you are comfortable that you can read the sensors and control the outputs.
Sample program
Now lets create a new file and combine a number of these commands into a simple program:
Figure 14
Figure 14 (graphics7.jpg)

Step: Looping your program

Up until now the programs we have written only repeats once and then they end. We want out security system to be able to run continuously, to be armed and disarmed without having to restart it. In Robo Pro it was easy to this by creating a loop. In python there are few ways of doing it. Lets start by running a loop which will repeat forever. Every time the loop repeats is asks the user for his name and greets him.
Continuous loop with the while statement
Figure 15
Figure 15 (graphics9.jpg)
Loop a number of times
We can change this program so that it only repeats as long as the counter is smaller than 3. Every time the loop repeats it adds one to the counter and when it repeats the next time is checks to see whether the counter is still smaller than 3.
Figure 16
Figure 16 (graphics11.png)
Here is the loop used in a program:
Figure 17
Figure 17 (graphics13.png)
Breaking out of a while loop
We know how to do a while loop which runs forever. We have also seen how to run a while loop for a fixed number of times. We can break out of a continuous loop with the break command.
Figure 18
Figure 18 (graphics14.png)
Repeating with a for loop
There is another way of repeating a loop a certain number of times. We can do it with the for loop, which will repeat as long as the counter is within the range of 0 to 3.
Figure 19
Figure 19 (graphics12.png)
Using the loops in our program
Here is a sample program which uses the while loop to allow the user three guesses to get his password right.
Figure 20
Figure 20 (graphics15.png)

Step: Keeping a log of all activity

In this step we will keep the existing hardware but improve our software. Security logs are important because it lets us see what has happened on our system when we were not watching. Whenever someone tries to access the system by typing in a username and password we need to record this information and the time it happened in a file. This file should be separate from our program so we can easily open it, copy it and analyse it without the risk of accidentally changing our software.
You will need to use:
  • Use definitions to create a clean and ordered program
  • Creating a file
  • Working with directories
  • Writing to a file
  • Using the time function to get the date and time of events
  • Combine the information in a string and formatting it before writing to the file

Step: Arming and unarming the system

Our system can allow access to a select group of users with the right passwords. It doesn’t yet help us to detect unauthorized access by some other way. We would like the system to be alert for any movement inside the room once the system has been armed. A user should be able to arm the system from the keyboard outside the room. This would require you to change the system so that once the user has entered his username and password, the system asks him whether he would like to open the door or arm the system. When armed the system should display on the screen that it is armed.
You will need to use:
  • a loop running and acting a menu to select from

Step: Adding the magnetic door latch

In this step we will connect the computer to the magnetic door latch. Again we will use a simpler version that our final design. Instead of a real 12V magnetic door latch installed in a real door, we will use Fischertechnik model of a door with a 9V motor acting as a door latch. We will use a Fischertechnik controller to control the power to the door latch that will make it open. To talk to the Fischertechnik controller we need to successfully import the software libraries and also find out how to instruct the controller to give power to the door latch.
Our previous program we will adapt to instead of just showing on the screen that access has been granted also power the latch to open. This is our first basic prototype. We can plug an external monitor and external keyboard into the laptop and hide the laptop from the user. The user can now see the request for a password on the screen, enter his password on the keyboard and the door will be buzzed open if he gets it correct.
You will need to use:
  • The FishFa40 library to talk to the controller

Step: Detecting motion and triggering the alarm

In this step add both new hardware and functionality to the system. We plug a single Passive Infra Red (PIR) sensor and a alarm buzzer into the Fischertechnik controller. The PIR can sense movement, even in the dark and allow the system to detect when someone is moving around inside the room. After connecting the PIR and alarm buzzer to the Fischretechnik controller you will need update your program. Once the system is armed it needs to keep on looking for any feedback from the PIR which shows movement. If the PIR is triggered the system needs to display on the screen that there is an intruder and sound the alarm. This should continue until the system is unarmed by someone logging in with their username and password and opening the door.
You will need to:

Step: Access by remote control

An additional way of access can now be added to the system. You will connect a RF (Radio Frequency) receiver as an input to the Fischertechnik controller which will register someone pressing their remote as if a button connected to the controller has been pressed. Your program needs to be changed so that when the remote is activated, the alarm gets deactivated and the door gets opened.

Step: Text to Speech

We will connect external speakers to the computer and speak out all the commands from the computer to the user.

Step: Notification of activity over e-mail and SMS

In this step will add additional functionality to the system. Should a user enter his password incorrectly more than three times an e-mail and SMS gets sent to the system administrator. The e-mail will be sent using the computer’s internet connection and the SMS by using an existing e-mail to SMS service. The e-mail to SMS service converts an e-mail you send into an SMS.

Step: Display photo of the user on the screen when access is granted

Up until now the screen has only been used to print text. In this step we will display the messages on the screen in large letters and also put an image on the screen of the user when he has successfully logged in.

Content actions

GIVE FEEDBACK:


No comments:

Post a Comment