WindRose 1.0
Custom Hardware , Firmware and Software for Robotic Cellular Automata Experiments
Being.h
Go to the documentation of this file.
1
8#ifndef Being_h
9#define Being_h
10
11#include "Directions.h"
12#include "Sensing.h"
13
22class Being
23{
24 private:
25
26 public:
28 boolean alive = 0; //It doesn't born yet
30 uint32_t age = 0; //It just borns (0)
35 SensingData sensors; //Sensing Data Struct
37 byte NGS =0x00; //Neigborhood Status Map
39 long ASBM = 0x00; //Active Sensor Byte Maps starts unset (32 bit total)
40
44 void born(){
45 this->alive = 1;
46 }
47
51 void dye(){
52 this->alive = 0;
53 }
54
58 void activate(uint8_t idx){ //Activate a sensor
59 this->ASBM |= 0x01<<idx; //Set sense bit at idx (maches with the bit in the ASBM)
60 }
64 void deactivate(uint8_t idx){ //Deactivate a sensor
65 this->ASBM &= ~(0x01<<idx); //Unset sense bit at idx (matches with the bit in the ASBM)
66 }
70 boolean isactive(uint8_t bit_pos){ //Check if a sensor is active
71 //Check bit on ASBM at bit_pos
72 if((this->ASBM>>bit_pos) & 0x01){
73 return true;//It's up
74 }
75 else return false;//It's down
76 }
78 void updateAge(){ //Update age (uptime)
79 this->age = millis();
80 }
81
86 void updateNGS(Being * _ng){ //Update Neighborhood Status Map
87 this->NGS = 0x00; //Reset ngstatus
88 for(uint8_t i=0;i<4;i++){
89 if(_ng[i].alive){
90 this->NGS |= 0x01<<i; //Set sense bit at idx
91 }
92 }
93 }
94
99 void calcDNGS(Being * _ng){ //Infer Neighborhood Status Map
100 uint8_t DNGS = 0x00; //Inferred Neighborhood Status Map
101 for(uint8_t i=0;i<4;i++){
102 switch (i){
103 case N:
104 if(_ng[N].alive){
105 DNGS |= (_ng[N].NGS >> W & 0x01) << N_W; //Inferring North_West neighbor
106 DNGS |= (_ng[N].NGS >> E & 0x01) << N_E; //Inferring North_East neighbor
107 }
108 break;
109 case E:
110 if(_ng[E].alive){
111 DNGS |= (_ng[E].NGS >> N & 0x01) << N_E; //Inferring North_East neighbor
112 DNGS |= (_ng[E].NGS >> S & 0x01) << S_E; //Inferring South_East neighbor
113 }
114 break;
115 case S:
116 if(_ng[S].alive){
117 DNGS |= (_ng[S].NGS >> E & 0x01) << S_E; //Inferring South_East neighbor
118 DNGS |= (_ng[S].NGS >> W & 0x01) << S_W; //Inferring South_West neighbor
119 }
120 break;
121 case W:
122 if(_ng[W].alive){
123 DNGS |= (_ng[W].NGS >> S & 0x01) << S_W; //Inferring South_West neighbor
124 DNGS |= (_ng[W].NGS >> N & 0x01) << N_W; //Inferring North_West neighbor
125 }
126 break;
127 default:
128 break;
129 }
130 }
131 this->NGS |= DNGS; //Update NGS with inferred diagonal neighbors
132 }
133};
134
135#endif
This file defines cardinal and relative directions enumerations.
This file contains the Sensing types, the sensors enumeration, and defines the sensing holder Sensing...
The base class (the soul) for all the beings in the simulation.
Definition: Being.h:23
void dye()
Sets the cell's state to dead.
Definition: Being.h:51
uint32_t age
The age of the being, since the board is up.
Definition: Being.h:30
boolean isactive(uint8_t bit_pos)
Checks if a sensor is active in the 32bit Active Sensor Bit Map (ASBM)
Definition: Being.h:70
void updateNGS(Being *_ng)
Updates the 8bit Neighborhood State Map (NGS) by setting it's four less significant bits to dead(0) o...
Definition: Being.h:86
boolean alive
The state of the being (dead = 0, alive = 1)
Definition: Being.h:28
void deactivate(uint8_t idx)
Deactivates a sensor in the 32bit Active Sensor Bit Map (ASBM)
Definition: Being.h:64
SensingData sensors
Sensor dada holder It has all the sensor types defined in the Sensing.h file. Think of it as a holde...
Definition: Being.h:35
void born()
Sets the cell's state to alive.
Definition: Being.h:44
void calcDNGS(Being *_ng)
Calculates the Diagonal neighbors of the being and sets the four most significant bits of the 8bit Ne...
Definition: Being.h:99
byte NGS
The neighborhood state mapping (NGS)
Definition: Being.h:37
void activate(uint8_t idx)
Activates a sensor in the 32bit Active Sensor Bit Map (ASBM)
Definition: Being.h:58
void updateAge()
Updates the Age of the being by seting it to the current time.
Definition: Being.h:78
long ASBM
The active sensor mapping (ASBM)
Definition: Being.h:39
Sensing holder structure with all the sensor types, ordered by the ASBM bits from its least significa...
Definition: Sensing.h:130