Skip to content
Snippets Groups Projects
Commit 52657be7 authored by Sai Lakhan Ekal's avatar Sai Lakhan Ekal
Browse files

Introduce virtual_clock in climate_chamber_dummy

Added internal function for simulated temperature
parent 389df5d1
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python3
import virtual_time
import prototype
import time
import math
class ClimateChamberDummy:
def __init__(self, ip_address, target_accuracy):
......@@ -14,20 +18,38 @@ class ClimateChamberDummy:
self.__ip_address = ip_address
self.target_accuracy = target_accuracy
# we try to connect to the climate chamber just to see if there is an error
self.simulated_temperature = 25
self.virtual_time = virtual_time.get_clock('localhost')
# local when simulating self.deltaT = self.target_temperature - self.read_temperature()[0]
self.last_simulation_time = self.virtual_time.time()
self.simulated_temperature = 25 # + self.deltaT *"slope"* self.deltat
self.simulated_humidity = 35
self.simulated_mode = 'OFF'
self.target_temperature = 40
self.target_humidity = 50
self.target_temperature = 25
self.target_humidity = 35
self.temperature_slope = 0.1 # 0.1 degrees/second
def _simulate_temp(self):
max_delta_temp = self.target_temperature - self.simulated_temperature
if max_delta_temp < 0:
direction = -1
else:
direction = 1
new_time = self.virtual_time.time()
delta_time = new_time - self.last_simulation_time
max_temp_change_in_delta_time = self.temperature_slope * delta_time
if abs(max_delta_temp) < max_temp_change_in_delta_time:
self.simulated_temperature = self.target_temperature
else:
self.simulated_temperature = self.simulated_temperature + direction * self.temperature_slope * delta_time
self.last_simulation_time = new_time
# the communication section
def read_temperature(self):
if self.simulated_temperature < self.target_temperature:
self.simulated_temperature += 0.1
elif self.simulated_temperature > self.target_temperature:
self.simulated_temperature -= 0.1
self._simulate_temp()
# data format: [current temp, set temp, upper limit, lower limit]
return [self.simulated_temperature, self.target_temperature, 0., 100.]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment