Actions GreenHouseMiddleLayer:: handleThresholds(float value, int min, int max, int minPin, int maxPin) {
	Actions action = NONE;
	//check max threshold
	if (value >= max)
		action = actuate(maxPin,true);
	//check min threshold
	else if (value <= min) {
		//if its the light threshold, we dont want to actuate in intervals,we want on,or off.
		//TODO check time of light
		action = actuate(minPin, true);
	}
	return action; //no action performed
}
Exemple #2
0
void noreturn main(void)
{
   init();
   initSensors();

   for(;;)
   {
      while(!loopActive)
      {
         ; // wait for next loop
      }

      readSensors();
      attitudeCalculation();
      control();
      actuate();
      triggerSonar();
      input();
      output();
      leds();

      ATOMIC_BLOCK(ATOMIC_FORCEON)
      {
         lastLoopTicks = ticksSinceLoopStart;
         loopActive = false;
      }
   }
}
Exemple #3
0
	void Proc::run() {
		assert(inited_);

		assert(hasValidObjects());
		assert(hasValidScenarioId());

		if (interactive_) {
			std::cout << std::endl << "running simulation..." << std::endl;
		}

		do {
			control();
			if (isSimulationOver()) {
				if (interactive_) {
					std::cout << std::endl << "*** TIME: " << t_ <<
							" FUEL: " << (*outp_)[fuelOutPort] <<
							" SCORE: " << (*outp_)[scoreOutPort] << " ***" <<
							std::endl << std::endl;
				}
				break;
			}
			actuate();
			tick();
		} while(true);

		if (interactive_) {
			std::cout << std::endl << "simulation complete." << std::endl;
		}
	}
    void
    BasicRemoteOperation::task(void)
    {
      fp64_t delta = Time::Clock::get() - m_last_action;

      // Check for connection timeouts.
      if (delta > m_connection_timeout)
        updateConnectionState(false);

      if (isActive() && m_connection)
        actuate();
    }
void DevicesConfigsLoader::continueLoading()
{
    if (component->isError()) {
        qWarning() << component->errors();
    } else {
        object = component->create();
        // TODO: driversList:
        // FIXME: driverName to moduleName
        if (object->property("driverName")==_udpDriver->getModuleName()) {
            QObject::connect(_udpDriver,SIGNAL(newDataReady(QVariant)),object,SIGNAL(newDataPacketReceived(QVariant)));
            QObject::connect(this,SIGNAL(newRequestReceived(QVariant)),object,SIGNAL(newRequestReceived(QVariant)));
            QObject::connect(object,SIGNAL(newDataReady(QString,QString)),this,SIGNAL(newDataReady(QString,QString)));
            QObject::connect(object,SIGNAL(addDriverDataSource(QVariant)),_udpDriver,SLOT(addDriverDataSource(QVariant)));
            QObject::connect(object,SIGNAL(actuate(QVariant)),_udpDriver,SLOT(actuate(QVariant)));
            DeviceConfig* device_object = dynamic_cast<DeviceConfig*>(object);
            if (true) {// TODO: if connect success
                emit device_object->driverConnected();
            }
        }
        // TODO: connect DataServer here
    }
}
Exemple #6
0
void actuateTask(void) {
	while (true) {
		if (actuateDivider == 0)
		{
			actuate();
		}

		actuateDivider++;

		if (actuateDivider >= 4)
		{
			actuateDivider = 0;
		}

		Task_Next();
	}
}
void GreenHouseMiddleLayer::decodeMessage(Message& msg) {	
	Serial.print(msg.source);

	if (CommonValues::emptyMessage == msg.messageType) {
		//do nothing the message is empty
		return;
	}
	DateTime dateTime;
	clock.createDateTime(dateTime);
	msg.dateTime = dateTime;	 //add time to message
	if (msg.dest != CommonValues::middleLayerAddress) {		 //check if the message is for me
		sendMessage(msg);			// if so, pass it on
		return;
	}
	//the message is from higer layer
	 if (msg.source >= CommonValues::highLayerMinAddress && msg.source < CommonValues::highLayerMaxAddress) {   
		switch (msg.messageType) {
			case CommonValues::policyChange:
				switch (msg.sensorType) {
					case CommonValues::soilHumidityType:
						//if it's soil Humidity policy changes, send it to the lower layers
						for (int i = 0; i<lowersIds.size() ; ++i) {
							if (lowersIds.get(i) != CommonValues::lowerLayerConsumptionAdress) {
								prepareMessage(msg, lowersIds.get(i));
								if (!sendMessage(msg)) {
									//unsentImportantMessages.add(msg);
								}
							}
						}			
					break;
					case CommonValues::temperatureType:
						CommonValues::temperatureThresholdMin = msg.data;
						CommonValues::temperatureThresholdMax = msg.additionalData;
					break;
					case CommonValues::humidityType:
						CommonValues::airHumidityThresholdMin = msg.data;
						CommonValues::airHumidityThresholdMax = msg.additionalData;
					break;
					case CommonValues::lightType:
						CommonValues::lightThresholdMin = msg.data;
						CommonValues::lightThresholdMax = msg.additionalData;
					break;
				}
			case CommonValues::loopTimeChange:
				
			break;
			case CommonValues::myAddressChange:
				
			break;
			case CommonValues::yourAddressChange:
			break;
			case CommonValues::ACTION_TYPE:
				switch (msg.action) {
					case PUMP1:
						prepareMessage(msg, lowersIds.get(0));
						if (!sendMessage(msg)) {
							//unsentImportantMessages.add(msg);
						}
						break;
					case PUMP2:
						prepareMessage(msg, lowersIds.get(1));
						if (!sendMessage(msg)) {
							//unsentImportantMessages.add(msg);
						}
						break;
					case FAN:
						msg.messageType = CommonValues::dataType;
						msg.action = actuate(CommonValues::fanPin,msg.data);
						prepareMessage(msg, CommonValues::highLayerAddress);
						if (!sendMessage(msg)) {
							//unsentImportantMessages.add(msg);
						}
					break;
					case LIGHT:
						msg.messageType = CommonValues::dataType;
						msg.action = actuate(CommonValues::lampPin, msg.data);
						prepareMessage(msg, CommonValues::highLayerAddress);
						if (!sendMessage(msg)) {
							//unsentImportantMessages.add(msg);
						}
						break;
					case HEATER:
						msg.messageType = CommonValues::dataType;
						msg.action = actuate(CommonValues::heatPin,msg.data);
						prepareMessage(msg, CommonValues::highLayerAddress);
						if (!sendMessage(msg)) {
							//unsentImportantMessages.add(msg);
						}
						break;
					case VENT:
						msg.messageType = CommonValues::dataType;
						msg.action = actuate(CommonValues::ventPin,msg.data);
						prepareMessage(msg, CommonValues::highLayerAddress);
						if (!sendMessage(msg)) {
							//unsentImportantMessages.add(msg);
						}
					break;
					case STEAMER:
						msg.messageType = CommonValues::dataType;
						msg.action = actuate(CommonValues::steamPin,msg.data);
						prepareMessage(msg, CommonValues::highLayerAddress);
						if (!sendMessage(msg)) {
							//unsentImportantMessages.add(msg);
						}
					break;
					case NONE:
						//TODO
					break;
					default:
						//TODO
					break;
				}
					
			break;
			case CommonValues::arduinoMalfunction: 

			break;			 
		}
	}
	//if the meesgae came from bottom layer
	//the layer should act/send up the hirarchy if needed
	else if (msg.source >= CommonValues::lowerLayerMinAddress && msg.source < CommonValues::lowerLayerMaxAddress) {
		switch (msg.messageType) {
			//first check if it's an emergency message
			case CommonValues::emergencyType:
				actuate(CommonValues::fanPin, true);
				actuate(CommonValues::ventPin, true);
				prepareMessage(msg, CommonValues::highLayerAddress); // prepare to send to high
				if (!sendMessage(msg)) {
					//unsentImportantMessages.add(msg);
				}
				break;
			case CommonValues::dataType:
				switch (msg.sensorType) {
					case CommonValues::soilHumidityType:
						//if it's soil Humidity data, send it to the high layer
						msg.additionalData = getMyAddress(); // the higher needs to know which pot it is.
						msg.dest = CommonValues::highLayerAddress;
						 //check if the message is important (action performed),and add to unsentImportantMessages if not sent
						 if (NONE != msg.action) {
							 if (!sendMessage(msg)) {
								// unsentImportantMessages.add(msg);
							 }
						 }
						 else
							sendMessage(msg); 
					break;
					case CommonValues::currentType:
						//if it's current consumption data, send it to the high layer
						prepareMessage(msg, CommonValues::highLayerAddress); // prepare to send to high
						sendMessage(msg);
					break;
					case CommonValues::waterType:
						//if it's water consumption data, send it to the high layer
						prepareMessage(msg, CommonValues::highLayerAddress);
						sendMessage(msg);
					break;
					case CommonValues::temperatureType:						
						isTemperatureReadyToAnalyze = ((updateDataAndCheckIfFull(temperatureData,msg,plantsLowerLayers)) && isTimeConsistency(temperatureData, CommonValues::minutesInInterval));
					break;
					case CommonValues::humidityType:
						isHumidityReadyToAnalyze = ((updateDataAndCheckIfFull(humidityData,msg, plantsLowerLayers)) && isTimeConsistency(humidityData, CommonValues::minutesInInterval));
					break;
					case CommonValues::lightType:
						isLightReadyToAnalyze = ((updateDataAndCheckIfFull(lightData,msg, plantsLowerLayers)) && isTimeConsistency(lightData, CommonValues::minutesInInterval));
					break;
				
				}
			break;
		//TODO think maybe handle with more messageTypes	
			//TODO action type
			//TODO what happens if we are not erady to analyze??
		}//end of switch (msg.messageType)
		analyze();
	}//end of if (msg.source >= CommonValues::lowerLayerMinAddress && msg.source < CommonValues::lowerLayerMaxAddress)
}
Exemple #8
0
int periodic_task_1(void)
{
    //static int previous_calibration_status = CALIBRATION_NOT_RUNNING;
    //int current_calibration_status; // Used to detect lowering edge
    static int previous_datalogger_status = DATALOGGER_NOT_RUNNING;
    int current_datalogger_status; // Used to detect rising edge
    char user =0;
   /* int buff_i=0; //i of buffer
    int i, j, k, equal=0;
    short int buff[3][3][3]; //{acc,gyr,mag}{x,y,z}{i=1,2,3}
*/

    // Main communication/control thread

    //Acquire
    total++;
    if( read_all_data(imu_param.i2c_dev, spi_param.spi_dev, &imu_data, &eff_data, &mra_data, &enc_data) != SUCCESS)
      failure++;
        
    // Calibrate and Estimate
    calibrate_all(&imu_data);
    //calibration_calibrate_all(&pwm_read_data, &scp1000_data, &battery_data, &gps_data, &imu_data, &pitot_data, &sonar_data, &calibration_local_coordinate_system_data, &calibration_altimeter_data, &calibration_local_fields_data, &gps_measure, &imu_measure, &magnetometer_measure);
    //estimation_update_state_estimate(&estimation_data, &gps_measure, &imu_measure, &magnetometer_measure, &sonar_measure, &calibration_local_fields_data, task_1_period_us/(double)1e6);

    // Control
    mra_data.v_ctl=1275+(uint8_t)(800*cosf(t_task_1_global*1000));
    //control_main_task(t_task_1_global, &pwm_write_data, &pwm_read_data, &control_data, &estimation_data);

    // Actuate
    actuate(spi_param.spi_dev, &mra_data);
    //protocol_send_actuation_data(&pwm_write_data);

    // Log
    /*user=getch();
    switch(user){
      case 'e': 
	exit_program();
	break;
      case 'a':
	acquire=1;
	break;
      case 's':
	acquire=0;
	break;
      default:
	break;
    }*/
    current_datalogger_status = datalogger_status();
    if( (current_datalogger_status == DATALOGGER_RUNNING))
    {
        if(previous_datalogger_status == DATALOGGER_NOT_RUNNING) // Rising edge
        {
            datalogger_set_Ts(task_1_period_us/1e6);
            reset_timer();
        }
        datalogger_update(t_task_1_global, T_task_1_exec_global, T_task_2_exec_global, t0, &imu_data, &eff_data, &mra_data /*&imu_measure, &magnetometer_measure, &estimation_data, &control_data*/);
  //printf("\n    %d\t|",i);
 /* printw("%d\t|",eff_data.F.x);
    printw("\t%d\t%d\t%d\t|",imu_data.acc.x,imu_data.acc.y,imu_data.acc.z);
    printw("\t%d\t%d\t%d\t|",imu_data.mag.x,imu_data.mag.y,imu_data.mag.z);
    printw("\t%d\t%d\t%d\t%d",imu_data.gyr.x,imu_data.gyr.y,imu_data.gyr.z, imu_data.temp);
    printw("\t%d\t%d",eff_data.new_data,imu_data.new_data);
    printw("\t%d\t%d",mra_data.Out_0, mra_data.Read_0);
    printw("\n");
    refresh();*/
    }
    previous_datalogger_status = current_datalogger_status;

/*    current_calibration_status = calibration_get_status();
    if(current_calibration_status == CALIBRATION_RUNNING)
    {
        calibration_imu_add_sample_bias_estimate(&imu_data);
        calibration_altimeter_add_sample_initial_pressure(&scp1000_data, &calibration_altimeter_data);
    }
    else // Calibration not running
    {
        if(previous_calibration_status == CALIBRATION_RUNNING) // Lowering edge
        {
            calibration_imu_finish_bias_estimate(&imu_data);
            calibration_altimeter_finish_initial_pressure_estimate(&calibration_altimeter_data);
        }
    }
    previous_calibration_status = current_calibration_status;
*/
    return SUCCESS;
}