def test_add_instance(self, mock_initialize_kb_service, mock_services): kb.initialize() def _update_knowledge_base(kb_operation, kb_item): return KnowledgeUpdateServiceResponse(True) services = {"update_knowledge_base": _update_knowledge_base} mock_services.__getitem__.side_effect = lambda key: services[key] self.assertTrue(kb.add_instance('v1', 'videotape')) self.assertTrue(kb.add_instance('v2', 'videotape')) self.assertTrue(kb.add_instance('c', 'container')) self.assertTrue(kb.add_instance('b1', 'box')) self.assertTrue(kb.add_instance('b2', 'box')) def _get_current_instances(type_name): return GetInstanceServiceResponse(['v1', 'v2', 'c', 'b1', 'b2']) services = {"get_current_instances": _get_current_instances} mock_services.__getitem__.side_effect = lambda key: services[key] instances = kb.list_instances() success = True for instance in instances: if instance not in ['v1', 'v2', 'c', 'b1', 'b2']: success = False self.assertTrue(success, 'Returned not correct instances')
def __init__(self): """ This will derive knowledge when an alarm bell rings """ kb.initialize(prefix="/rosplan_knowledge_base") rospy.init_node('hectic_knowledge_deriving', anonymous=True) rospy.Subscriber('sound_recognised', RecognisedSounds, self.sound_recognised) self.notified = False rospy.spin()
def __init__(self): kb.initialize(prefix="/rosplan_knowledge_base") rospy.init_node('loud_sounds_knowledge_deriving', anonymous=True) rospy.Subscriber('sound_volume', String, self.sound_volume_detected) self.count_high_volume = 0 self.high_volume_limit = 60 self.launch_helper_limit = 3 self.loud_noise = False self.noise_place = "" rospy.spin()
def main(): rospy.init_node("pytools_ask_for_instance") kb.initialize() kb.reset() sdb.initialize() sdb.reset() prepare_instances() retrieve_instances()
def __init__(self): kb.initialize(prefix="/rosplan_knowledge_base") rospy.init_node('hectic_knowledge_deriving', anonymous=True) rospy.Subscriber('sound_recognised', RecognisedSounds, self.sound_recognised) # min number of times at least one sound was heard self.min_sound_history_required = 8 # min number of different sounds self.min_diff_sounds_required = 5 # the sliding window self.sounds_history = [0 for i in range(14)] self.location_bot = "" self.published = False rospy.spin()
def __init__(self, ip, port): rospy.init_node('robot_interface', anonymous=True) session = qi.Session() try: session.connect("tcp://" + ip + ":" + str(port)) except RuntimeError: print("Can't connect to Naoqi at ip \"" + ip + "\" on port " + str(port) + ".\n") self.motion_service = session.service("ALMotion") self.posture_service = session.service("ALRobotPosture") self.motion_service.wakeUp() self.posture_service.goToPosture("StandInit", 0.5) time.sleep(2) kb.initialize(prefix="/rosplan_knowledge_base") self.go_to_init_location() rospy.Subscriber('robot_command', String, self.handle_robot_command) rospy.spin()
def main(): kb.initialize() print("Predicates ---") for predicate in kb.list_predicates(): print("[" + str(predicate) + "]") print("\nInstances ---") print(str(kb.list_instances()) + "\n") for instance in kb.list_instances(): print("[" + str(instance) + ", " + str(kb.get_instance_type(instance)) + "]") print("\nGoals ---") for goal in kb.list_goals(): print("[" + str(goal) + "]")
def main(): kb.initialize() kb.reset()
def main(): kb.initialize() kb.remove_all_predicates() kb.remove_all_goals()
[robot, tolocation])) rospy.loginfo("Reporting succes") super(MoveRobot, self)._report_success() class PickupTreat(act_int.SimpleAction): name = "robottaketreataction" def _start(self, robot, treatlocation, treat): """ Grasp the treat """ rospy.loginfo("Picking up treat") # The messages are used for creating the emotional model self.pub = rospy.Publisher('robot_command', String, queue_size=10) self.pub.publish(String("grasp")) rospy.sleep(2) kb.add_predicate( pytools_utils.predicate_maker("robot-holds", ["robot", "holdingobject"], [robot, treat])) super(PickupTreat, self)._report_success() if __name__ == "__main__": rospy.init_node("dog_reactor") act_int.initialize_actions() kb.initialize(prefix="/rosplan_knowledge_base") act_int.start_actions("rosplan_plan_dispatcher/action_dispatch", "rosplan_plan_dispatcher/action_feedback") rospy.spin()
#!/usr/bin/env python import rospy import rosplan_pytools import rosplan_pytools import rosplan_pytools.controller.knowledge_base as kb import rosplan_pytools.controller.scene_database as sdb import rosplan_pytools.controller.planning_system as ps rospy.init_node("teste") #rosplan_pytools.init() kb.initialize("/rosplan_knowledge_base") print("OLAR") kb.reset() # Using the KB kb.add_instance("rover1", "rover") kb.list_instances() # You can store stuff into the scene database with a third arg # kb.add_instance("msg1", "msg_type") # sdb.add_element("msg1", sdb.Element(std_msgs.msg.String("Be sure to drink your ovaltine"), "msg_type")) # kb.add_goal("robot-at", loc="loc1") # kb.add_goal("has-received-message", msg="msg1", loc="loc1") # # Then, plan and execute! using PS
def __init__(self): rospy.init_node('emotional_reasoner', anonymous=True) kb.initialize(prefix="/rosplan_knowledge_base") self.valence = 0 self.arousal = 0 self.publish_as_param() self.pub = rospy.Publisher('emotional_reasoner', Emotion, queue_size=10) self.service = rospy.Service('emotion_service', EmotionService, self.service_respond_emotion) rospy.Subscriber('voice_emotion_recognised', RecognisedSounds, self.adapt_model_speech) rospy.Subscriber('sound_recognised', RecognisedSounds, self.adapt_model_sounds) self.numbers_to_kb_emotion = [[-1, -1, "lowv-lowa"], [1, -1, "highv-lowa"], [1, 1, "highv-higha"], [-1, 1, "lowv-higha"]] self.map_emotion_to_quantity = { "Neutral": { "valence": 0, "arousal": 0 }, "Happy": { "valence": 0.5, "arousal": 0.2 }, "Sad": { "valence": -0.5, "arousal": -0.2 }, "Angry": { "valence": -0.5, "arousal": 0.4 }, "Fear": { "valence": -0.30, "arousal": 0.3 }, } self.map_sound_to_quantity = { "an Alarm bell ringing": { "valence": -0.295, "arousal": 0.387 }, "Speech": { "valence": 0.0, "arousal": 0.0 }, "a Dog": { "valence": -0.023, "arousal": 0.182 }, "a Cat": { "valence": 0.535, "arousal": 0.067 }, "Dishes": { "valence": -0.192, "arousal": -0.285 }, "Frying": { "valence": 0.0, "arousal": 0.0 }, "an Electric_shaver or a toothbrush": { "valence": -0.437, "arousal": 0.178 }, "a Blender": { "valence": -0.668, "arousal": 0.27 }, "Running_water": { "valence": -0.137, "arousal": -0.045 }, "a Vacuum_cleaner": { "valence": 0, "arousal": 0 } }