def doSense(self): #update the dictionary to return your values return {"unix_time":rospy.get_time(), "midnight_time":time_since_midnight(rospy.get_time()), "light": self.light_level, "temp":self.temperature, "humid":self.humidity, "smoist":self.moisture, "level":self.wlevel, "light_raw": self.light_level_raw, "temp_raw":self.temperature_raw, "humid_raw":self.humidity_raw, "smoist_raw":self.moisture_raw, "level_raw":self.wlevel_raw}
def doSense(self): #update the dictionary to return your values return { "unix_time": rospy.get_time(), "midnight_time": time_since_midnight(rospy.get_time()), "light": self.light_level, "temp": self.temp_output, "humid": self.humid_output, "smoist": self.smoist_output, "level": self.level_output }
def activate(self, time): child = copy.deepcopy(self) child.parent = self # Update the timeout so it doesn't keep triggering if (self.abs_time != None): self.timeout += 24 * 60 * 60 # Add a day if (child.agenda.time0 == None): child.agenda.time0 = time - time_since_midnight(time) first_constraint = child.agenda.schedule[0] first_constraint.set_timeout(time, child.agenda.time0) #print("First timeout: %s for %s" %(clock_time(first_constraint.timeout), first_constraint)) return child
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 main(self): rospy.sleep(2) while rospy.get_time() == 0: rospy.sleep(1) #your code here if necessary last_ping = rospy.get_time() self.ping_behavior.act() while not rospy.core.is_shutdown(): t = time_since_midnight(self.sensors.getTime()) self.planning_layer.doStep(t) rospy.sleep(1) self.executive_layer.doStep(t) rospy.sleep(1) self.behavioral_layer.doStep() rospy.sleep(1)
def run_command(self, time): curr_cmd = self.schedule[self.index] if (self.time0 == None): self.time0 = time - time_since_midnight(time) curr_cmd.cmd_start = self.time0 # Set up the local variables: light = self.vars.get('light') temperature = self.vars.get('temp'); humidity = self.vars.get('humid'); smoist = self.vars.get('smoist'); current = self.vars.get('cur'); wlevel = self.vars.get('level'); wpump = self.vars.get('wpump'); led = self.vars.get('led'); fan = self.vars.get('fan'); if (curr_cmd != self.last_cmd): print(" %s" %curr_cmd.line_str()) self.last_cmd = curr_cmd if (curr_cmd.type == 'WAIT' and len(curr_cmd.constraint) == 0 ): if (time > curr_cmd.timeout): print("SUCCESS: %s"%curr_cmd.line_str()) self.next_cmd(time) return 1 elif (curr_cmd.type == 'WAIT'): res = eval(curr_cmd.constraint) if res: #success! print("SUCCESS: %s"%curr_cmd.line_str()) self.next_cmd(time) return 1 elif (time > curr_cmd.timeout): print("FAIL: %s"%curr_cmd.line_str()) self.next_cmd(time) return -1 elif (curr_cmd.type == 'ENSURE'): res = eval(curr_cmd.constraint) if (time > curr_cmd.timeout) and res: print("SUCCESS: %s"%curr_cmd.line_str()) self.next_cmd(time) return 1 elif not res: #fail print("FAIL: %s"%curr_cmd.line_str()) self.next_cmd(time) return -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 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])) if __name__ == '__main__': import sys, time if (len(sys.argv) == 2): now = time.time() time0 = now - time_since_midnight(now) baseline = Baseline(sys.argv[1], time0) baseline.display() #""" # Testing how baseline works t = baseline.time0; sensor_values = {} while not baseline.finished(): baseline.update(t, sensor_values) t += 1 #""" else: print("Need to provide baseline file to parse")
int(internal_vars['smoist'][1])] return s_array sensor_funcs = { 'cur': get_cur, 'light': get_light, 'level': get_level, 'temp': get_temp, 'humid': get_humid, 'smoist': get_smoist } now = int(time.time()) # Convert to midnight now += clock_start - time_since_midnight(now) try: baseline_schedule = baseline.Baseline(args.baseline, now) now = baseline_schedule.time0 except: print('baseline file %s not found or parse error' % args.baseline) exit() rospy.init_node('Simulator', anonymous=True) generate_publishers() generate_subscribers() #print("Now: %f %s" %(now, clock_time(now))) clock_pub.publish(rospy.Time.from_sec(now))