void get_sensors ( void ) { char i; mLeftLine = 0; mRightLine = 0; mCenterRange = 0; for ( i = 0; i < 8; i++ ) { //mLeftLine += read_a2d(FL_SENSOR); //mRightLine += read_a2d(FR_SENSOR); mCenterRange += read_a2d(OL_SENSOR); } //mLeftLine >>= 3; //mRightLine >>= 3; mCenterRange >>= 3; //Sumo.atLeftEdge = (mLeftLine < mLeftEdgeThreshold); //Sumo.atRightEdge = (mRightLine < mRightEdgeThreshold); Sumo.atLeftEdge = 0; Sumo.atRightEdge = 0; rangeDifference = mCenterRange; // - mRightRange; rangeAverage = mCenterRange; // + mRightRange) >> 1; return; }
void main(void) { //OPTION = (GPWU | GPPU | PS0 | PS1 | PS2);//1:256 TMR prescale rate OPTION = (nGPWU | nGPPU); //1:1 TMR prescale rate //TODO: check these init_a2d(); // initialise the A2D module TRIS = 0b1010; //gp0 out, gp1 in, gp2 out, gp3 in BACKLIGHT = 1; delay_s(1); read_a2d(); if (ADRES < VIDLE) { mode = FIXED; } else if (ADRES > VDISABLED) { mode = DISABLED; } else { mode = CP; } active = 0; last_roller = ROLLER; for (; mode == DISABLED;) { //DEAD } for (;;) { if (mode == FIXED) { if (ADRES < VIDLE) { if (active) { toggle_active = 1; } } else { if (!active) { toggle_active = 1; } } } else { //COLLECTIVE PITCH MODE if (ADRES > (VMDL_LOW) && ADRES < (VMDL_HIGH)) {//TODO: overflow check if (active) { toggle_active = 1; } } else { if (!active) { toggle_active = 1; } } } if (toggle_active) { active = !active; pulse_trainer(); toggle_active = 0; idle_time = 0; } else if (last_roller != ROLLER) { last_roller = ROLLER; idle_time = 0; BACKLIGHT = 1; } else if (!active){ //crude way of ensuring a cycle takes 100ms since that is a lot longer than all other operations __delay_ms(OPERATIONAL_DELAY); idle_time++; } if (idle_time >= BACKLIGHT_TIME) { BACKLIGHT = 0; } if (idle_time >= IDLE_TIME_WARNING) { idle_time = 0; pulse_trainer();pulse_trainer(); } read_a2d(); //takes 13Tad so time is 13/(4Mhz/4) = 13us } }