static void SensorSlave() {
    SensorRequest_t t;
    int status, byte;
    unsigned int i, j, index, parent;
    volatile uint32_t sensors[TRAIN_SENSOR_COUNT * TRAIN_MODULE_COUNT] = {0};

    parent = MyParentTid();

    debug("SensorSlave: Tid %d", MyTid());
    t.type = SENSOR_RETURNED;
    t.sensor = (uint32_t)sensors;

    while (true) {
        pollSensors();
        for (i = 0; i < TRAIN_MODULE_COUNT; ++i) {
            index = i * TRAIN_SENSOR_COUNT;

            byte = trgetchar();
            for (j = 0; j < TRAIN_SENSOR_COUNT / 2; ++j) {
                sensors[index++] = EXTRACT_BIT(byte, (TRAIN_SENSOR_COUNT / 2) - j - 1) & 1;
            }

            byte = trgetchar();
            for (; j < TRAIN_SENSOR_COUNT; ++j) {
                sensors[index++] = EXTRACT_BIT(byte, TRAIN_SENSOR_COUNT - j - 1) & 1;
            }
        }
        Send(parent, &t, sizeof(t), &status, sizeof(status));
    }

    Exit();
}
Exemple #2
0
// Declare Global variables
int main(void) {
  // Set up Create and module
  initializeCommandModule();

  powerOnRobot();
    // Is the Robot on
  byteTx(CmdStart);
    // Start the create
  baud(Baud57600);
    // Set the baud rate for the Create and Command Module
  defineSongs();
    // Define some songs so that we know the robot is on.
  byteTx(CmdControl);
    // Deprecated form of safe mode. I use it because it will
    // turn of all LEDs, so it's essentially a reset.
  byteTx(CmdFull);
    // We are operating in FULL mode.

  // Play the reset song and wait while it plays.
  byteTx(CmdPlay);
  byteTx(RESET_SONG);
  delayMs(750);

  // Turn the power button on to something.
  turnOnPowerButtonLight();
  delayMs(20);


  // Infinite operation loop
  int timerLoop = 0; 
  const int timerLimit = 15;
  
  initializeUSBBuffer();
  initializeRobotBuffer();
  initializeSensorArray();
  
  setLEDs(BOTHLED, FULL);
  enableReports();
  enableSensors();
  
  while(1) {
	pollSensors();
	if(timerLoop == timerLimit){
		compileReport();
		sendUSBBuffer();
		timerLoop = 0;
		delayMs(1);
  	}
	timerLoop++;
	pollRemoteSensors();
	pollRemote();
	executeCommand();
	delayMs(5);
	}
}
void DHT22Controller_loop()
{
	unsigned long currentMillies = millis();
	unsigned long elapsedTime = currentMillies - _lastMillies;

	if (elapsedTime > POLL_INTERVAL)
	{
		_lastMillies = currentMillies;
		pollSensors();
	}
}
Exemple #4
0
// Declare Global variables
int main(void) {
  // Set up Create and module
  initializeCommandModule();

  powerOnRobot();
    // Is the Robot on
  byteTx(CmdStart);
    // Start the create
  baud(Baud57600);
    // Set the baud rate for the Create and Command Module
  defineSongs();
    // Define some songs so that we know the robot is on.
  byteTx(CmdControl);
    // Deprecated form of safe mode. I use it because it will
    // turn of all LEDs, so it's essentially a reset.
  byteTx(CmdFull);
    // We are operating in FULL mode.

  // Play the reset song and wait while it plays.
  byteTx(CmdPlay);
  byteTx(RESET_SONG);
  delayMs(750);

  // Turn the power button on to something.
  delayMs(20);
  
  initializeUSBBuffer();
  initializeRobotBuffer();
  initializeSensorArray();
  
  setLEDs(BOTHLED, FULL);
  enableReports();
  enableSensors();
  
  int fakeTimer = 0;

  // Infinite operation loop
  while(1) {
	  
	  if (fakeTimer == 4) {
		  compileReport();
		  sendUSBBuffer();
		  fakeTimer = 0;
	  }
	  
	  pollSensors();
	  delayMs(250);
	  
	  fakeTimer++;
	  
  }
}
void GameLogicController::pollLogic() {
	//Check the instantiated MAO's
	checkInstMAO();

	//Evaluate the sensors
	pollSensors();

	//Evaluate the controllers
	std::vector<MLBController*>& activeControllers = pollControllers();
	MPYWrapper::getInstance()->runScripts(); //Running scripts!

	cleanupSensors(); //Clean up sensors first! To make MLBSensorActuators work! ;)
	cleanupControllers();

	//Activate actuators
	activateActuators(activeControllers);

	//Cleaning up!
	delete &activeControllers;

}
int main() {
    #ifdef DEBUG
        /* TODO: implement debugging
        Debug debug(DEBUG_FREQ);
        */
    #endif

    // Set output pins: B0 (indicator), B1 (motor), B2 (lamp)
    DDRB |= BV(DDB0) | BV(DDB1) | BV(DDB2);

    // Initialize non-inverted pwm in pin OC0B (PB1)
    TCCR0A |= BV(WGM01) | BV(WGM00);
    TCCR0A |= BV(COM0B1);
    Attiny13::setTimer0Prescaler(Attiny13::PSV_64);

    // Initialize human as not doing anything.
    OCR0B = 0xff;

    bool indicatorLit = false;
    uint16_t counter = 0;
    while(true) {
        counter += 1;
        _delay_ms(LOOP_DELAY);

        // Read sensors and re-activate human if pig is detected
        if(pollSensors()) {
            humanInactivityDelay = HUMAN_DELAY;
        }

        runHuman();

        if(counter % INDICATOR_HALF_PERIOD == 0) {
            indicatorLit = !indicatorLit;
            setIndicator(indicatorLit);
        }
    }
}
Exemple #7
0
void GRWHallway() {
    if (direction == 1) {

        // Set up distance counting
        int lCount, rCount;
        int lostL = 0;
        int lostR = 0;
        double wallL, wallR;

        pollSensors(&lCount, &rCount);
        position = 0.0;
        lostL = lostR = 0;
        currentRoom = -1;
        int roomCount = 0;

        // Move to center
        moveToCenter(0.0);

        pollSensors(&lCount, &rCount);
        position = position + ((lCount + rCount) / 2.0) * ticks2inches;

        correctAngle('B');
        pollSensors(&lCount, &rCount);

        urgStart(&urg);
        // Keep going until both walls are lost or room found
        while (!lostL || !lostR) {
            if (scan_center(0.0, &wallL, &wallR, &lostL, &lostR, 1) != -10) {
                lCount = rCount = 0;
                pollSensors(&lCount, &rCount);
                position = position + ((lCount + rCount) / 2.0) * ticks2inches;
                char string[70];
                sprintf(string, "Going Straight. Pos: %lf\n", position);
                Xprintf(string);
            }
            if (position > array[current].roomDist[roomCount]*12) {
                currentRoom++;
                roomCount++;
            }
            if (current == destination && currentRoom == destinationRoom) return;
        }
        urgStop(&urg);

        straightBlind(1.5 * 12);
        turn90('L');
        sendSpeed(0.0, 0.0);
        current++;
        currentRoom = -1;
        return;
    }
    if (direction == -1) {
        straightBlind(6);
        correctAngle('B');
        moveToCenter(0.0);
        correctAngle('B');

        // Keep going down center of hall until wall both disappear
        int lostL, lostR;
        double wallL, wallR;
        lostL = lostR = 0;
        wallL = wallR = 1;
        urgStart(&urg);
        while(!(lostR || lostL || ((wallL > 5 * feet2mm) && (wallR > 5 * feet2mm)))) {
            scan_center(0.0, &wallL, &wallR, &lostL, &lostR, 1);
            Xprintf("Scan centering until both walls further than 5ft or either is lost\n");
        }
        urgStop(&urg);
        current--;
        currentRoom  = -1;
        return;
    }
}
Exemple #8
0
// Deprecated.
void doSensors() {
	pollSensors();
	compileSensors();
}