GroupA / Mbed 2 deprecated WaG_final

Dependencies:   mbed

Fork of Lab_6_WaG by GroupA

wag.cpp

Committer:
phn10
Date:
2018-04-17
Revision:
60:604c10531f58
Parent:
58:69f9a4607a16
Parent:
59:6b3a52d87465
Child:
61:778e7e30e370
Child:
62:b73067127fd6

File content as of revision 60:604c10531f58:

/******************************************************************************
* EECS 397
*
* Assignment Name: Lab 7: WaG
* 
* Authors: Sam Morrison and Phong Nguyen 
* File name: wag.cpp
* Purpose: Wag functions
*
* Created: 04/12/2018
* Last Modified: 04/12/2018
*
******************************************************************************/

#include "mbed.h"
#include "io_pins.h"
#include "wag.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <timer.h>

extern Timer t;

void gnoll() {
    int hit, miss;
    int a_num;
    int led_command;
    int sensor_no = 0 //change to match station

    for (int i = 0; i < 15; i++) {
        a_num = rand() % 8;
        turn_to_target(stp_sensor_pos[a_num]);
        lzr_on();
        wait(LASER_DELAY);
        if (sensor_values[sensor_no + a_num] > PTHRESH) {
            led_command = 0x0500 + a_num;
            spi_send(as1107, led_command);

        }
        
        clock_t start = clock();
        clock_t finish = clock();
        
        do {
            // check for whacker sensors
            finish = clock();
        } while (finish - start < VOLLEY_DELAY)
    }
}

void whack(int sensor_no, float * sensor_values) {
    bool sensor_registered = false;
    int sensor_no = // --> need to specify sensor_no

    // start timer for sensor reading
    t.start();
    
    // keep reading until one of the sensor get laser pointed in
    while (!sensor_registered) {
        // read value of all gnoll sensor
        for (int i = 0; i < TGT_SENSOR_QUAN; i++) {
            // scan all 16 sensors into sensor_values array
            ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2);
        }
                    
        // detect which sensor get lasered on
        for (int i = 0; i < TGT_SENSOR_QUAN + sensor_no; i++) {
            if (sensor_values[i] > THRESHOLD_SIGNAL)
                sensor_registered = true;
        }

        // if (reading sensor timer expired) display error and freeze
        t.stop();
        if (t.read() > EXPIRED_TIMER) {
            pc.printf("Error: Reading timer expired. See whack() function.\n");
            while (1);
        } 
    }

    // point whack’s laser to the corresponding sensor on it’s target array
    
    // activate whacker’s laser

    while (signal from corresponding sensor value > THRESHOLD_SIGNAL) {
        if (finding sensor timer expired) display error and freeze
    }

    activate corresponding indicator

    // waiting for gnoll laser to turn off to turn off
    while (gnoll’s laser turned on) {}
    // turn off laer gnoll
    lzr_off();
}