def print_status(self, res, time): if (res == 1): print("SUCCESS (%s): %s" % (clock_time(time), self.brief())) pass elif (res == -1): curr_constraint = self.agenda.schedule[self.agenda.index] print("FAILURE (%s): at %s in %s" % (clock_time(time), curr_constraint, self.brief()))
def __init__(self, filename, time0): # time0 is midnight of the first day self.time0 = time0 last_time = time0 if (not filename): return with open(filename) as f: for line in f.readlines(): l = line.split('#')[0].strip(' \n') if (l.find('START AT') == 0) : dtime = datetime.strptime(l, "START AT %d-%H:%M:%S") time = clock_to_seconds(dtime) + time0 actions = [] self.add_to_schedule([time, actions]) self.time0 = time print("START: %s" %clock_time(time)) last_time = time elif (l.find('AT') == 0): dtime = datetime.strptime(l, "AT %d-%H:%M:%S") time = clock_to_seconds(dtime) + time0 if (time < last_time): print("Time must run forward: %s" %l) quit() last_time = time actions = [] self.add_to_schedule([time, actions]) elif (len(l) > 0): # Should be "sensor = value(s)" sensor = l[:l.find(" ")] if (not sensor in sensor_names): print("%s not a legal baseline sensor name" %sensor) quit() sensor_val = l[l.find("=")+1:] actions.append([sensor, sensor_val])
def display(self): for s in self.schedule: # Not sure why this prints right - but it does print("%sAT %s" %("START " if (self.time0 == s[0]) else "", clock_time(s[0]))) for sv in s[1]: print(" %s = %s" %(sv[0], sv[1]))
def update(self, time, sensor_values): if (not self.finished() and (time >= self.schedule[self.index][0])): print("Updating baseline at %s:" %clock_time(time)) for a in self.schedule[self.index][1]: sensor_values[a[0]] = eval(a[1]) #print(" %s: %s" %(a[0], sensor_values[a[0]])) self.index += 1 return True else: return False
def processImage(self, image): foliage_mask = classifyFoliage(image) size = image.shape[0] * image.shape[1] percentage = cv2.countNonZero(foliage_mask) / size height = measureHeight(foliage_mask) print( "As of %s, %.1f%% of pixels are foliage; plant height is %.1fcm" % (clock_time(self.time), 100 * percentage, (0 if not height else height)))
def next_cmd(self, time): self.index += 1 if (not self.finished()): next_cmd = self.schedule[self.index] if (next_cmd.rel_time != None): next_cmd.timeout = time + next_cmd.rel_time else: dtime = datetime.strptime(next_cmd.abs_time, "%d-%H:%M:%S") next_cmd.timeout = self.time0 + clock_to_seconds(dtime) print(" Next timeout: %s" %clock_time(next_cmd.timeout))
def update(self, time): if (not self.finished() and (time >= self.schedule[self.index][0])): print("Updating interferences at %s" % clock_time(time)) for ifs in self.schedule[self.index][1]: if (type(ifs[1]) == list): funcs = [get_interf_funcs(i) for i in ifs[1]] else: funcs = get_interf_funcs(ifs[1]) self.interf_funcs[ifs[0]] = funcs self.index += 1 return True else: return False
def amb_light(time): global morning_hour, evening_hour, light_level_day, light_level_night dl = light_level_night if (is_daylight(time)): dt = time_since_midnight(time) dl += ((light_level_day - light_level_night) * sqrt(1 - abs(1 - ((dt - 3600 * morning_hour) / (3600 * (evening_hour - morning_hour) / 2))))) if is_logging: global last_print, clock_start if (time - last_print > 1800): last_print = time print(" Ambient: %.1f (%s)" % (dl, clock_time(time))) return dl
def update_env_params(self, params, speedup, light): self.setWater(params['volume']) #Reservoir update self.setLights(params['led']) #LED update self.setFans(params['fan']) #Fan Update self.setTankWater(params['tankwater']) #Tankwater update self.setSoilColor(params['soilwater']) self.setAmbient(params['time']) for plant in self.plants: plant.grow(params, params['time'] - self.lastTime, light) self.lastTime = params['time'] if not self.shown: return self.reRenderPlants() #Stats panel : healths = [p.health for p in self.plants] avgH = sum(healths)/len(healths) avgH = int(avgH * 100) self.textpanel.text = \ ''' Pump: {} Fans: {} LEDs: {} Plant Health: {}% '''.format('ON' if params['wpump'] else 'off', \ 'ON' if params['fan'] else 'off', \ params['led'], avgH) self.textpanel2.text = \ ''' Time : {:s} Light level: {:01.0f} Temperature : {:04.1f} C Soil moisture : {:03.1f} Humidity : {:02.0f}% Volume : {:04.2f} ml Speedup : {}x '''.format(clock_time(self.start_time + params['time']), light, \ params['temperature'], 2*params['soilwater'], \ params['humidity'], params['volume'], speedup) self.fansound(params['fan']) self.pumpsound(params['wpump'])
def display(self): for interf in self.schedule: print("AT %s" % clock_time(interf[0])) for iv in interf[1]: print(" %s = %s" % (iv[0], iv[1]))
global morning_hour, evening_hour, light_level_day, light_level_night dl = light_level_night if (is_daylight(time)): dt = time_since_midnight(time) dl += ((light_level_day - light_level_night) * sqrt(1 - abs(1 - ((dt - 3600 * morning_hour) / (3600 * (evening_hour - morning_hour) / 2))))) if is_logging: global last_print, clock_start if (time - last_print > 1800): last_print = time print(" Ambient: %.1f (%s)" % (dl, clock_time(time))) return dl if is_logging: print(" Clock start: %s" % clock_time(clock_start)) ### INTERNAL UPDATE FUNCTIONS ### def light_update(cur_interval): for i in range(2): val = led_rate * actuator_vars['led'] + amb_light(rospy.get_time()) internal_vars['light'][i] = min(600, max(0, val)) def volume_update(cur_interval): if actuator_vars['wpump']: internal_vars['volume'] -= cur_interval * flow_rate internal_vars['volume'] = max(0, internal_vars['volume'])
def __init__(self, shown, t0, initTime, leafDroop, lankiness, plant_health): loadPrcFileData('', 'win-size 1024 768') loadPrcFileData("", "window-type none") ShowBase.__init__(self) if shown: self.openMainWindow(type = "onscreen") props = WindowProperties() props.setTitle('TerraBot Simulator') self.win.requestProperties(props) else: self.openMainWindow(type = "offscreen") base.disableMouse() # Allow manual positioning of the camera #camera.setPosHpr(-20, 0, -3, -90, 12, 0) # Under camera.setPosHpr(-20, 0, 7, -90, -12, 0) # Normal #camera.setPosHpr(0, 0, 30, 0, -90, 0) #TOP self.pic = False self.loc = None self.shown = shown self.start_time = t0; atexit.register(self.userExit) self.BASE_TEXT = ''' Pump: OFF Fans: OFF LEDs: 255 ''' self.BASE_TEXT2 = \ ''' Time : {:s} Light level: 0 Temperature : 20 C Soil moisture : 0 Humidity : 50% Volume : 3000 ml Speedup : 1x '''.format(clock_time(t0 + initTime)) self.lastTime = initTime self.droop = leafDroop self.lankiness = lankiness self.plant_health = plant_health #self.accept('escape', self.userExit) self.accept('r', self.resetCam) self.loadModels() self.setupLights() self.setupText() self.setupText2() self.setupSensorCam() self.setTankWater(0) self.setBackgroundColor(.8, .8, .8, 1) self.keys = {} for key in ['arrow_left', 'arrow_right', 'arrow_up', 'arrow_down', 'a', 'd', 'w', 's']: self.keys[key] = 0 self.accept(key, self.push_key, [key, 1]) self.accept('shift-%s' % key, self.push_key, [key, 1]) self.accept('%s-up' % key, self.push_key, [key, 0]) self.fanonSound = loader.loadSfx('sounds/fanon.wav') self.pumponSound = loader.loadSfx('sounds/pumpon.wav') self.fanonSound.setLoop(True) self.pumponSound.setLoop(True) #SetupCamera self.heading = -90.0 self.pitch = -12.0 self.camera.setPos(-20, 0, 7) self.picNextFrame = False self.taskMgr.add(self.update, 'main loop')
def ping(): global last_ping print("PING! %s" %clock_time(sensorsG.time)) last_ping = sensorsG.time ping_pub.publish(True)
print( "Updating %s to frequency %s (every %.1f seconds)" % (sensor, freq, 1 / float(freq))) freq_pub.publish(msg) elif input[0] == 'e': sensor, period = input[2:-1].split(" ") msg = tomsg(sensor, 1 / float(period)) if msg is not None: print( "Updating %s to period of %s seconds (frequency of %f)" % (sensor, period, 1 / float(period))) freq_pub.publish(msg) elif input[0] == 's': speedup_pub.publish(int(input[1:])) elif input[0] == 'v': print("Sensor values at %s" % clock_time(sensorsG.time)) print(" Light level: %.1f (%.1f, %.1f)" % (sensorsG.light_level, sensorsG.light_level_raw[0], sensorsG.light_level_raw[1])) print(" Temperature: %.1f (%.1f, %.1f)" % (sensorsG.temperature, sensorsG.temperature_raw[0], sensorsG.temperature_raw[1])) print(" Humidity: %.1f (%.1f, %.1f)" % (sensorsG.humidity, sensorsG.humidity_raw[0], sensorsG.humidity_raw[1])) print(" Soil moisture: %.1f (%.1f, %.1f)" % (sensorsG.moisture, sensorsG.moisture_raw[0], sensorsG.moisture_raw[1])) print(" Reservoir level: %.1f" % sensorsG.water_level) else: print(