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

Added internal function for simulated_humidity and use it in climate_chamber_dummy

parent 04f6d56f
No related branches found
No related tags found
No related merge requests found
......@@ -27,8 +27,14 @@ class ClimateChamberDummy:
self.target_temperature = 25
self.target_humidity = 35
self.temperature_slope = 0.1 # 0.1 degrees/second
self.humidity_slope = 0.5 # degrees/second
def _simulate_temp(self):
def simulation(self):
self.simulate_temp()
self.simulate_hum()
self.last_simulation_time = self.virtual_time.time()
def simulate_temp(self):
max_delta_temp = self.target_temperature - self.simulated_temperature
if max_delta_temp < 0:
direction = -1
......@@ -44,24 +50,39 @@ class ClimateChamberDummy:
else:
self.simulated_temperature = self.simulated_temperature + direction * self.temperature_slope * delta_time
self.last_simulation_time = new_time
def simulate_hum(self):
max_delta_hum = self.target_humidity - self.simulated_humidity
if max_delta_hum < 0:
direction = -1
else:
direction = 1
new_time = self.virtual_time.time()
delta_time = new_time - self.last_simulation_time
max_hum_change_in_delta_time = self.humidity_slope * delta_time
if abs(max_delta_hum) < max_hum_change_in_delta_time:
self.simulated_humidity = self.target_humidity
else:
self.simulated_humidity = self.simulated_humidity + direction * self.humidity_slope * delta_time
# the communication section
def read_temperature(self):
self._simulate_temp()
self.simulation()
# data format: [current temp, set temp, upper limit, lower limit]
return [self.simulated_temperature, self.target_temperature, 0., 100.]
def read_humidity(self):
if self.simulated_humidity < self.target_humidity:
self.simulated_humidity += 0.1
elif self.simulated_humidity > self.target_humidity:
self.simulated_humidity -= 0.1
self.simulation()
# data format: [current temp, set temp, upper limit, lower limit]
return [self.simulated_humidity, self.target_humidity, 0., 100.]
def set_temperature(self, temperature):
# simulate everything that has happened until now, before we store the new setpoint
self.simulation()
# sets the temp of the chamber(float)
self.target_temperature = temperature
print('ChamberDummy: target temperature now is ' + str(self.target_temperature))
......@@ -69,6 +90,9 @@ class ClimateChamberDummy:
return response
def set_humidity(self, humidity):
# simulate everything that has happened until now, before we store the new setpoint
self.simulation()
# sets the humidity of the chamber(float)
self.target_humidity = humidity
print('ChamberDummy: target humidity now is ' + str(self.target_humidity))
......
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