kh

Dependencies:   mbed PinDetect Servo

Files at this revision

API Documentation at this revision

Comitter:
Sayak97
Date:
Sat Nov 10 19:30:54 2018 +0000
Child:
1:2c365f6da61d
Commit message:
k'k

Changed in this revision

README.md Show annotated file Show diff for this revision Revisions of this file
actuators.cpp Show annotated file Show diff for this revision Revisions of this file
actuators.h Show annotated file Show diff for this revision Revisions of this file
authentication.cpp Show annotated file Show diff for this revision Revisions of this file
authentication.h Show annotated file Show diff for this revision Revisions of this file
lock.cpp Show annotated file Show diff for this revision Revisions of this file
lock.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
moter.cpp Show annotated file Show diff for this revision Revisions of this file
motor.h Show annotated file Show diff for this revision Revisions of this file
open.cpp Show annotated file Show diff for this revision Revisions of this file
open.h Show annotated file Show diff for this revision Revisions of this file
parameters.h Show annotated file Show diff for this revision Revisions of this file
powerManagement.h Show annotated file Show diff for this revision Revisions of this file
powerMangement.cpp Show annotated file Show diff for this revision Revisions of this file
setup.cpp Show annotated file Show diff for this revision Revisions of this file
setup.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,2 @@
+# devilsafe
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/actuators.cpp	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,53 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the actuators of the safe
+* Language:  NBC
+*/
+#include "actuators.h"
+#include "parameters.h"
+#include "mbed.h"
+/*
+* Function:  turnsRcServosRight
+* --------------------
+*  Turns the servos to the right
+*
+*
+*/
+void turnsRcServosRight() {
+	rcServo1 = 1.0f;
+	rcServo2 = 1.0f;
+}
+
+/*
+* Function:  urnsRcServosLeft
+* --------------------
+*  Turns the servos to the right
+*
+*
+*/
+void turnsRcServosLeft() {
+	rcServo1 = -1.0f;
+	rcServo2 = -1.0f;
+}
+
+
+/*
+* Function:  openSafe
+* --------------------
+*  Opens the safe
+*/
+void openSafe() {
+	turnsRcServosRight();
+}
+
+/*
+* Function:  lockSafe
+* --------------------
+*  Locks the safe
+*/
+void lockSafe() {
+	turnsRcServosLeft();
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/actuators.h	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,41 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the actuators of the safe
+* Language:  NBC
+*/
+
+/*
+* Function:  turnsRcServosRight
+* --------------------
+*  Turns the servos to the right
+*
+*
+*/
+void turnsRcServosRight() ;
+
+/*
+* Function:  urnsRcServosLeft
+* --------------------
+*  Turns the servos to the right
+*
+*
+*/
+void turnsRcServosLeft() ;
+
+
+/*
+* Function:  openSafe
+* --------------------
+*  Opens the safe
+*/
+void openSafe() ;
+
+/*
+* Function:  lockSafe
+* --------------------
+*  Locks the safe
+*/
+void lockSafe() ;
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/authentication.cpp	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,83 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls Input and Output Data
+* Language: C
+*/
+#include "logging.h"
+#include "powerManagement.h"
+#include "parameters.h"
+
+int p1;
+int p2;
+int p3;
+int p4;
+
+int entryNum1;
+int entryNum2;
+int entryNum3;
+int entryNum4;
+
+/*
+* Function: setEntrySequence
+* --------------------
+*  Reads in user's entry sequence attempt
+*/
+void setEntrySequenceAttempt() {
+	entryNum1 = float(pot1) * 10;
+	entryNum2 = float(pot2) * 10;
+	entryNum3 = float(pot3) * 10;
+	entryNum4 = float(pot4) * 10;
+}
+
+/*
+* Function:  CorrectEntrySequenceAttempt
+* --------------------
+*  Checks whether the user's entry sequence attempt is correct
+*
+*  returns: true if the entry sequence attempt from the user matches
+*  the set entry sequence otherwise false
+*
+*/
+bool CorrectEntrySequenceAttempt() {
+	p1 = float(pot1) * 10;
+	p2 = float(pot2) * 10;
+	p3 = float(pot3) * 10;
+	p4 = float(pot4) * 10;
+
+	if(checkPot(p1,entryNum1) && checkPot(p2,entryNum2) && checkPot(p3,entryNum3) && checkPot(p3,entryNum3) ){
+		return true;
+	}
+}
+
+bool checkPot(int p1, int p2) {
+	return (p2 - p1) < 2 && (p1 - p2) > -2;
+
+}
+
+
+
+/*
+* Function:  bluetooth
+* --------------------
+*  bluetooth stuff EDIT LATER
+*
+*  returns:
+*
+*/
+void bluetooth() {
+
+}
+
+
+/*
+* Function:  sdCard
+* --------------------
+*  sdCard stuff EDIT LATER
+*
+*  returns:
+*
+*/
+void sdCard() {
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/authentication.h	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,56 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls Input and Output Data
+* Language: C
+*/
+#include "authentication.cpp"
+/*
+* Function: setEntrySequence
+* --------------------
+*  Reads in user's entry sequence attempt
+*/
+void setEntrySequenceAttempt() {
+}
+
+/*
+* Function:  CorrectEntrySequenceAttempt
+* --------------------
+*  Checks whether the user's entry sequence attempt is correct
+*
+*  returns: true if the entry sequence attempt from the user matches
+*  the set entry sequence otherwise false
+*
+*/
+bool CorrectEntrySequenceAttempt() {
+}
+
+bool checkPot(int p1, int p2) {
+}
+
+
+
+/*
+* Function:  bluetooth
+* --------------------
+*  bluetooth stuff EDIT LATER
+*
+*  returns:
+*
+*/
+void bluetooth() {
+
+}
+
+
+/*
+* Function:  sdCard
+* --------------------
+*  sdCard stuff EDIT LATER
+*
+*  returns:
+*
+*/
+void sdCard() {
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lock.cpp	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,39 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the LOCK state of the machine
+* Language: C
+*/
+#include "lock.h"
+#include "actuators.h"
+#include "powerManagement.h"
+#include "parameters.h"
+
+/*
+* Function:  lock
+* --------------------
+*  Locks safe
+*
+*  returns: the next state in the state machine
+*  Open: After it has been locked
+*
+*/
+enum states lock() {
+	if(authenticate()) {
+		openSafe();
+		wait(5000);
+		return OPEN;
+	} else {
+		return LOCK:
+	}
+}
+
+/*
+* Function: authenticate
+* ----------------------------
+*  Checks whether a cup was found through the sonar sensor
+*
+*  returns: true if cup found else false
+*/
+bool authenticate() {
+    return CorrectEntrySequenceAttempt();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lock.h	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,29 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the LOCK state of the machine
+* Language: C
+*/
+#include "lock.cpp"
+
+/*
+* Function:  lock
+* --------------------
+*  Locks safe
+*
+*  returns: the next state in the state machine
+*  Open: After it has been locked
+*
+*/
+enum states lock() {
+}
+
+/*
+* Function: authenticate
+* ----------------------------
+*  Checks whether a cup was found through the sonar sensor
+*
+*  returns: true if cup found else false
+*/
+bool authenticate() {
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,47 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the functions of the safe
+* Language: C
+*/
+#include "open.h"
+#include "lock.h"
+#include "setup.h"
+#include "sleep.h"
+#include "parameters.h"
+
+task main() {
+    SafeStateMachine();
+}
+
+/*
+* Function:  SafeStateMachine
+* --------------------
+*  Routine for the safe's basic functions.
+*
+*
+*
+*/
+void SafeStateMachine() {
+
+
+    enum states state = SETUP;
+
+    while (1) {
+        switch (state) {
+        case OPEN:/*state in which the the case is open*/
+            state = open();
+            break;
+        case LOCK:/*state in which the case us closed*/
+            state = lock();
+            break;
+        case SETUP:/*state in which the the case is changing its settings*/
+            state = setup();
+            break;
+        default:
+            state = locked();
+        }
+    }
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/moter.cpp	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,44 @@
+/* mbed simple H-bridge motor controller
+ * Copyright (c) 2007-2010, sford, http://mbed.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "Motor.h"
+
+#include "mbed.h"
+
+Motor::Motor(PinName pwm, PinName fwd, PinName rev):
+        _pwm(pwm), _fwd(fwd), _rev(rev) {
+
+    // Set initial condition of PWM
+    _pwm.period(0.001);
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+}
+
+void Motor::speed(float speed) {
+    _fwd = (speed > 0.0);
+    _rev = (speed < 0.0);
+    _pwm = abs(speed);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor.h	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,56 @@
+/* mbed simple H-bridge motor controller
+ * Copyright (c) 2007-2010, sford, http://mbed.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MBED_MOTOR_H
+#define MBED_MOTOR_H
+
+#include "mbed.h"
+
+/** Interface to control a standard DC motor 
+ *
+ * with an H-bridge using a PwmOut and 2 DigitalOuts
+ */
+class Motor {
+public:
+
+    /** Create a motor control interface    
+     *
+     * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
+     * @param fwd A DigitalOut, set high when the motor should go forward
+     * @param rev A DigitalOut, set high when the motor should go backwards
+     */
+    Motor(PinName pwm, PinName fwd, PinName rev);
+    
+    /** Set the speed of the motor
+     * 
+     * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
+     */
+    void speed(float speed);
+
+protected:
+    PwmOut _pwm;
+    DigitalOut _fwd;
+    DigitalOut _rev;
+
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open.cpp	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,42 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the OPEN state of the machine
+* Language:  C
+*/
+#include "open.h"
+#include "authentication.h"
+#include "actuators.h"
+#include "parameters.h"
+
+/*
+* Function:  OPEN
+* --------------------
+*  Calls the functions needed to for the open state
+*
+*
+*  returns: the next state in the state machine
+*  LOCK: if closed properly
+*  ALARM: if cup is not found after searching in a full circle
+*
+*/
+enum states open() {
+    if (authenticate()) {
+        return OPEN;
+    } else {
+        lockSafe();
+        wait(5000);
+        return LOCK;
+    }
+}
+
+/*
+* Function: authenticate
+* ----------------------------
+*  Checks whether a cup was found through the sonar sensor
+*
+*  returns: true if cup found else false
+*/
+bool authenticate() {
+    return CorrectEntrySequenceAttempt();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open.h	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,31 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the OPEN state of the machine
+* Language:  C
+*/
+#include "open.cpp"
+
+/*
+* Function:  OPEN
+* --------------------
+*  Calls the functions needed to for the open state
+*
+*
+*  returns: the next state in the state machine
+*  LOCK: if closed properly
+*  ALARM: if cup is not found after searching in a full circle
+*
+*/
+enum states open() {
+}
+
+/*
+* Function: authenticate
+* ----------------------------
+*  Checks whether a cup was found through the sonar sensor
+*
+*  returns: true if cup found else false
+*/
+bool authenticate() {
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/parameters.h	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+/*
+ * Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga 
+ * Purpose: Controls the parameters of the safe
+ * Language:  C
+ */
+enum state{OPEN, LOCK, SETUP};/*Name of the states in the Safe Cups State Machine*/
+#define  maxFailedAtttemps 6; /*number of max failed attemps entered before alarm is thrown*/
+DigitalIn button(p8);
+
+PwmOut rcServo1(p23); // pwm, fwd, rev
+PwmOut rcServo2(p24); // pwm, fwd, rev
+
+Serial blue(p28,p27);
+
+AnalogIn pot1(p20);
+AnalogIn pot2(p21);
+AnalogIn pot3(p22);
+AnalogIn pot4(p22);
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/powerManagement.h	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,27 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls Input and Output Data
+* Language: C
+*/
+#include "powerManagement.cpp"
+
+
+/*
+* Function: powerSavingMode
+* --------------------
+*  Controls what is on while the safe is on this mode
+*/
+void powerSavingMode() {
+//however we decide to implement 
+}
+
+/*
+* Function: getBatteryLevels
+* --------------------
+*  Get the battery level for the safe
+*
+*  returns: the battery level for the safe
+*
+*/
+void getBatteryLevels() {
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/powerMangement.cpp	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,31 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls Input and Output Data
+* Language: C
+*/
+#include "powerManagement.h"
+#include "parameters.h"
+
+int batteryLevels;
+
+/*
+* Function: powerSavingMode
+* --------------------
+*  Controls what is on while the safe is on this mode
+*/
+void powerSavingMode() {
+//however we decide to implement 
+}
+
+/*
+* Function: getBatteryLevels
+* --------------------
+*  Get the battery level for the safe
+*
+*  returns: the battery level for the safe
+*
+*/
+void getBatteryLevels() {
+	//EDIT LATER maybe have it send a notification in the future
+	return batteryLevels;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.cpp	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,34 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the SETUP state of the machine
+* Language: C
+*/
+#include "setup.h"
+#include "authentication.h"
+#include "parameters.h"
+#include "actuators.h"
+
+/*
+* Function:  setup
+* --------------------
+*  Calls the functions needed to setup the entry sequence for the safe.
+*
+*  returns: the next state in the state machine
+*  LOCK: after entry sequence has been entered
+*
+*/
+
+
+enum states setup() {
+	if(pb) {
+	setEntrySequence();
+	wait(5000);
+	lockSafe();
+	wait(5000);
+	return LOCK;
+	}
+	return SETUP;
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.h	Sat Nov 10 19:30:54 2018 +0000
@@ -0,0 +1,23 @@
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the SETUP state of the machine
+* Language: C
+*/
+#include "setup.cpp"
+
+/*
+* Function:  setup
+* --------------------
+*  Calls the functions needed to setup the entry sequence for the safe.
+*
+*  returns: the next state in the state machine
+*  LOCK: after entry sequence has been entered
+*
+*/
+
+
+enum states setup() {
+}
+
+
+