You are viewing an older revision! See the latest version

Locker

Table of Contents

    Task

    The locker team is tasked with securing the locker, following the instructions of the user via the interface, setting the battery to charge and relaying information between the battery and the interface.

    Overview

    The locker is secured by a solenoid controlled latch. There is also an alarm system which can be armed or disarmed. The armed alarm sounds off if a metal contact is disconnected while the alarm is armed. The locking mechanism and the alarm only unlocks when instructed to by the interface.

    <battery systems have yet to be implemented>

    Securing the locker

    The locker is secured via a solenoid controlled latch. When an unlock pulse is sent from the interface, the mbed turns off the alarm(sets alarmflag = 0), then activates the solenoid to pull the latch to unlock the door(function unlock() ). To prevent overheating, the solenoid only activates for a limited time, within which the user must open the door/springs will force the door to open. The solenoid is also controlled via a relay as the mbed cannot supply the power the solenoid needs.

    There is a electrical contact surface where contact is established when the door is locked and disconnected if the door is opened. This allows the locker system to know if the door is open(via setting flag doorclosed=0). If the door is opened while the alarm is activated(alarmflag==1&&doorclosed==0), the loss of electrical contact sets off the alarm. This contact also allows the locker system to inform the interface system if the door is opened.

    Build (v3.2)

    mbed:

    2 digital-in pins on the mbed:

    1) "lock" on pin D1 is the flag from the interface to unlock the door. (logic 0 to unlock)

    2) "doorclosed" on pin D2 is connected to a pull-down resistor and the metal contacts on the door.(logic 1 for closed door)

    2 digital-out pins on the mbed:

    1) "latch" on pin D0 controls the solenoid via a relay.(logic 0 to activate solenoid)

    2)"flagdoor" on pin D3 to the interface, informing it if the door is open(logic 1 for opened door)

    1 PWMOut on the mbed: "alarm" on pin PTE20, powers speaker for alarm on demand.

    Code(v3.2) The mbed continuously runs two threads, the main thread which monitors the status of the system and external flags, and the Tunlock thread which controls the entire unlock process.

    Thread main()

    This thread runs continuously , checking if a signal to unlock has been received, if the door is open, and whether the locker is broken into.

    Main cycle:

    1) If unlock signal(lock ==0) and that a unlock cycle is not running already(alarmflag == 1) or just been run(justarmed ==0), run the unlock cycle in thread Tunlock. Else if an unlock cycle has just been completed(alarmflag ==1 && justarmed ==1), reset just armed and wait to prevent double-running from the same unlock pulse.

    2) Detect if door is opened/closed and inform interface. If door is open(doorclosed ==0), send out flag to interface(flagdoor = 1).

    3) Sets off alarm if the alarm is armed and the door is opened. If door is open(doorclosed==0), no unlock signal(lock==1) and alarm armed(alarmflag ==1), set off the alarm(alarm ==0.5).

    Thread Tunlock:

    The thread Tunlock runs function unlock() continuously but does nothing if unlockflag ==0. If unlockflag ==1, the program runs through an unlock cycle, deactivating the alarm, .

    Unlock cycle:

    1) Deactivate the alarm by setting alarmflag=0.

    2) Activates the solenoid via a relay, then sets the thread to wait for 5s, allowing other threads to run and giving enough time for the door to open. After 5s it deactivates the solenoid.

    3) Sets unlockflag =0.

    4) Runs other threads while waiting for door to close.

    5) If door is closed, activate alarm (set alarmflag =1). The unlock cycle then ends and the thread now waits for the next instance of unlockflag ==1.


    All wikipages