def execute(self): while not self.should_pause(): playful.console("robot", Playful_tutorial_robot.get_representation()) self.spin(15)
def execute(self): while not self.should_pause(): playful.console("exit_instructions", "to exit press 'q'") self.spin(5) playful.unconsole("exit_instructions")
def execute(self): while not self.should_pause(): current = datetime.datetime.now() playful.console("current_time", "current date and time: " + str(current)) self.spin(50) playful.unconsole("current_time")
def execute(self): # spinning while the node execution is required while not self.should_pause(): # printing on the console playful.console("hello", "hello " + str(self._hello_to) + " !") # running at 5Hz self.spin(5) # removing text from console playful.unconsole("hello")
def execute(self): while not self.should_pause(): # the targeting keyword in the playful script associated this instance of # 'ball_display' with one of the ball, that is retrieved here with the get_target # method ball = self.get_target() if ball is not None: position = ball.position color = ball.color if position and color: playful.console(str(id(self)), " " * int(position) + str(color)) self.spin(10)
def execute(self): # looping for as long the engine does not require this # node to stop while not self.should_pause(): # asking to use the "console" resource if self.ask_for_resource("console"): # access to resource was granted: displaying "value". # the console function prints strings in terminal during runtime. # it takes an arbitrary string id as first argument # and the string to print as second argument. playful.console(str(id(self)), "\n" + str(self.value) + "\n") else: # 'ask_for_resource' returned false: # access to the "console" resource was revoked, so we should # free it # removing what this node was displaying (if anything) playful.unconsole(str(id(self))) # freeing the resource (if taken). # not doing so would # prevent other nodes to access the resource self.release_all_resources() # note: code here may be called even if the resource has not # been taken by this node or when the node already # released the resource. This is fine. # operating at 10Hz self.spin(10) # leaving execution of the node, # removing what the node was displaying # (if anything) playful.unconsole(str(id(self)))
def execute(self): # returns the last digit of current time, # i.e. if current time is 162363.7 # returns 3 def _time_digit(): t = int(time.time()) last_number = str(t)[-1] return int(last_number) # evaluates if value between # min and max def _in_range(value, min_, max_): if value < min_: return False if value > max_: return False return True while not self.should_pause(): # alternates sequentially the mood between "happy", # "do not care" and "amused" digit = _time_digit() current_mood = None if _in_range(digit, 0, 3): current_mood = "happy" elif _in_range(digit, 4, 6): current_mood = "do_not_care" else: current_mood = "amused" # setting value of the "mood" memory key playful.Memory.set("mood", current_mood) # displaying to user current mood playful.console("mood_manager", "current mood: " + current_mood) self.spin(10)