test

Dependencies:   MODDMA MODSERIAL mbed

Fork of IRIS_MBED by IRIS

Committer:
JonathanAshworth
Date:
Thu Apr 09 20:07:15 2015 +0000
Revision:
7:49aba2a2e847
Parent:
4:1017848d2fe1
latest version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonathanAshworth 4:1017848d2fe1 1 /*
JonathanAshworth 4:1017848d2fe1 2 * File: botStateHandler.cpp
JonathanAshworth 4:1017848d2fe1 3 * Author: jhudson
JonathanAshworth 4:1017848d2fe1 4 *
JonathanAshworth 4:1017848d2fe1 5 * Created on 25 March 2015, 13:31
JonathanAshworth 4:1017848d2fe1 6 */
JonathanAshworth 4:1017848d2fe1 7
JonathanAshworth 4:1017848d2fe1 8 /*
JonathanAshworth 4:1017848d2fe1 9 * The bot state handler essentially acts as a central storage facility holding
JonathanAshworth 4:1017848d2fe1 10 * all of the information about the robots sensors.
JonathanAshworth 4:1017848d2fe1 11 */
JonathanAshworth 4:1017848d2fe1 12
JonathanAshworth 4:1017848d2fe1 13 #include "botStateHandler.h"
JonathanAshworth 4:1017848d2fe1 14 botStateHandler::botStateHandler()
JonathanAshworth 4:1017848d2fe1 15 {
JonathanAshworth 4:1017848d2fe1 16 //This initialiser will not intialise data for stations 0 or 1
JonathanAshworth 4:1017848d2fe1 17 //because these are not sensors.
JonathanAshworth 4:1017848d2fe1 18
JonathanAshworth 4:1017848d2fe1 19 //This is a dirty hack.This data comes from the shared definition.
JonathanAshworth 4:1017848d2fe1 20 unsigned char fieldCounts[24] =
JonathanAshworth 4:1017848d2fe1 21 {3,3,3,3,3,3,3,1,1,3,3,3,3,1,1,1,1,1,1,1,1,1,1,1};
JonathanAshworth 4:1017848d2fe1 22
JonathanAshworth 4:1017848d2fe1 23 for(int i = 0; i < 24; i++)
JonathanAshworth 4:1017848d2fe1 24 {
JonathanAshworth 4:1017848d2fe1 25 sensors[i].fieldCount = fieldCounts[i];
JonathanAshworth 4:1017848d2fe1 26
JonathanAshworth 4:1017848d2fe1 27 //Initialise the fields to nowt.
JonathanAshworth 4:1017848d2fe1 28 for(int j = 0; j < 10; j++) sensors[i].fields[j] = 0.0f;
JonathanAshworth 4:1017848d2fe1 29 }
JonathanAshworth 4:1017848d2fe1 30 }
JonathanAshworth 4:1017848d2fe1 31
JonathanAshworth 4:1017848d2fe1 32 //Allows caller to retrieve values that represent the state of the machine.
JonathanAshworth 4:1017848d2fe1 33 int botStateHandler::getVal(unsigned char stationId, unsigned char fieldId, float* val)
JonathanAshworth 4:1017848d2fe1 34 {
JonathanAshworth 4:1017848d2fe1 35 if(stationId > 1)
JonathanAshworth 4:1017848d2fe1 36 {
JonathanAshworth 4:1017848d2fe1 37 *val = sensors[stationId - 2].fields[fieldId];
JonathanAshworth 4:1017848d2fe1 38 return 0;
JonathanAshworth 4:1017848d2fe1 39 } else return 1;
JonathanAshworth 4:1017848d2fe1 40 }
JonathanAshworth 4:1017848d2fe1 41
JonathanAshworth 4:1017848d2fe1 42 //Allows caller to set values that represent the state of the machine.
JonathanAshworth 4:1017848d2fe1 43 int botStateHandler::setVal(unsigned char stationId, unsigned char fieldId, float* val)
JonathanAshworth 4:1017848d2fe1 44 {
JonathanAshworth 4:1017848d2fe1 45 if(stationId > 1)
JonathanAshworth 4:1017848d2fe1 46 {
JonathanAshworth 4:1017848d2fe1 47 sensors[stationId - 2].fields[fieldId] = *val;
JonathanAshworth 4:1017848d2fe1 48 return 0;
JonathanAshworth 4:1017848d2fe1 49 } else return 1;
JonathanAshworth 4:1017848d2fe1 50 }