GroupA / Mbed 2 deprecated WaG_final

Dependencies:   mbed

Fork of Lab_6_WaG by GroupA

Committer:
phn10
Date:
Tue Apr 17 12:36:25 2018 +0000
Revision:
59:6b3a52d87465
Parent:
57:aef01bd9b3be
Child:
60:604c10531f58
Working on wag.cpp, not compiled yet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spm71 57:aef01bd9b3be 1 /******************************************************************************
spm71 57:aef01bd9b3be 2 * EECS 397
spm71 57:aef01bd9b3be 3 *
spm71 57:aef01bd9b3be 4 * Assignment Name: Lab 7: WaG
spm71 57:aef01bd9b3be 5 *
spm71 57:aef01bd9b3be 6 * Authors: Sam Morrison and Phong Nguyen
spm71 57:aef01bd9b3be 7 * File name: wag.cpp
spm71 57:aef01bd9b3be 8 * Purpose: Wag functions
spm71 57:aef01bd9b3be 9 *
spm71 57:aef01bd9b3be 10 * Created: 04/12/2018
spm71 57:aef01bd9b3be 11 * Last Modified: 04/12/2018
spm71 57:aef01bd9b3be 12 *
spm71 57:aef01bd9b3be 13 ******************************************************************************/
spm71 57:aef01bd9b3be 14
spm71 57:aef01bd9b3be 15 #include "mbed.h"
spm71 57:aef01bd9b3be 16 #include "io_pins.h"
spm71 57:aef01bd9b3be 17 #include "wag.h"
spm71 57:aef01bd9b3be 18 #include <stdlib.h>
spm71 57:aef01bd9b3be 19 #include <stdio.h>
phn10 59:6b3a52d87465 20 #include <string.h>
phn10 59:6b3a52d87465 21
phn10 59:6b3a52d87465 22 extern Timer t;
phn10 59:6b3a52d87465 23
phn10 59:6b3a52d87465 24 void whack(int sensor_no, float * sensor_values) {
phn10 59:6b3a52d87465 25 bool sensor_registered = false;
phn10 59:6b3a52d87465 26 int sensor_no = // --> need to specify sensor_no
phn10 59:6b3a52d87465 27
phn10 59:6b3a52d87465 28 // start timer for sensor reading
phn10 59:6b3a52d87465 29 t.start();
phn10 59:6b3a52d87465 30
phn10 59:6b3a52d87465 31 // keep reading until one of the sensor get laser pointed in
phn10 59:6b3a52d87465 32 while (!sensor_registered) {
phn10 59:6b3a52d87465 33 // read value of all gnoll sensor
phn10 59:6b3a52d87465 34 for (int i = 0; i < TGT_SENSOR_QUAN; i++) {
phn10 59:6b3a52d87465 35 // scan all 16 sensors into sensor_values array
phn10 59:6b3a52d87465 36 ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2);
phn10 59:6b3a52d87465 37 }
phn10 59:6b3a52d87465 38
phn10 59:6b3a52d87465 39 // detect which sensor get lasered on
phn10 59:6b3a52d87465 40 for (int i = 0; i < TGT_SENSOR_QUAN + sensor_no; i++) {
phn10 59:6b3a52d87465 41 if (sensor_values[i] > THRESHOLD_SIGNAL)
phn10 59:6b3a52d87465 42 sensor_registered = true;
phn10 59:6b3a52d87465 43 }
phn10 59:6b3a52d87465 44
phn10 59:6b3a52d87465 45 // if (reading sensor timer expired) display error and freeze
phn10 59:6b3a52d87465 46 t.stop();
phn10 59:6b3a52d87465 47 if (t.read() > EXPIRED_TIMER) {
phn10 59:6b3a52d87465 48 pc.printf("Error: Reading timer expired. See whack() function.\n");
phn10 59:6b3a52d87465 49 while (1);
phn10 59:6b3a52d87465 50 }
phn10 59:6b3a52d87465 51 }
phn10 59:6b3a52d87465 52
phn10 59:6b3a52d87465 53 // point whack’s laser to the corresponding sensor on it’s target array
phn10 59:6b3a52d87465 54
phn10 59:6b3a52d87465 55
phn10 59:6b3a52d87465 56
phn10 59:6b3a52d87465 57 // activate whacker’s laser
phn10 59:6b3a52d87465 58
phn10 59:6b3a52d87465 59 while (signal from corresponding sensor value > THRESHOLD_SIGNAL) {
phn10 59:6b3a52d87465 60 if (finding sensor timer expired) display error and freeze
phn10 59:6b3a52d87465 61 }
phn10 59:6b3a52d87465 62
phn10 59:6b3a52d87465 63 activate corresponding indicator
phn10 59:6b3a52d87465 64
phn10 59:6b3a52d87465 65 // waiting for gnoll laser to turn off to turn off
phn10 59:6b3a52d87465 66 while (gnoll’s laser turned on) {}
phn10 59:6b3a52d87465 67 // turn off laer gnoll
phn10 59:6b3a52d87465 68 lzr_off();
phn10 59:6b3a52d87465 69 }