def __init__(self): rospy.init_node('execute_program_node', anonymous=False) logging.config.fileConfig(get_full_path('config', 'logging.ini')) self._getdatsrv = rospy.ServiceProxy('/db_interface_node/getDatabase', GetDatabase) req = GetDatabaseRequest() req.write = False res = self._getdatsrv.call(req) # self.db = Database(res.path) self._addsrv = rospy.ServiceProxy('/db_interface_node/addObject', AddObject) self._senddatsrv = rospy.ServiceProxy('/db_interface_node/sendDatabase', SendDatabase) self.db_api = DatabaseAPI() # self.onto = self.db_api.get_onto() # path = '/home/algernon/ros_melodic_ws/base_ws/src/crow/database_com/nodes/saved_onto.owl' self.db = self.db_api.get_db() self.db.change_onto(res.path) obj = self.db.onto.search(type=self.db.onto.Cube) # exit_res = self.db.onto.__exit__() print('press a key to execute an action') self.robotProgram = 'grounded_1' self.listener = keyboard.Listener(on_press=self.on_press) self.listener.start()
def evaluate(self) -> None: db_api = DatabaseAPI() demonstration_templates = db_api.get_demonstration_templates() uim = UserInputManager() uim.say("Actions learned from demonstration:") uim.show([t.name for t in demonstration_templates])
def __init__(self, language='en'): self.logger = logging.getLogger(__name__) self.og = ObjectGrounder() self.lg = LocationGrounder() self.db_api = DatabaseAPI() self.lang = language
def __init__(self, language = 'en'): self.lang = language self.db_api = DatabaseAPI() self.cd = ColorDetector() self.ar = UserInputManager(language = self.lang) self.logger = logging.getLogger(__name__) self.templ_file = self.ar.load_file('templates_detection.json') self.guidance_file = self.ar.load_file('guidance_dialogue.json')
def __init__(self): self.logger = logging.getLogger(__name__) self.db_api = DatabaseAPI() self.class_map = { "screwdriver": db.onto.Screwdriver, "hammer": db.onto.Hammer, "pliers": db.onto.Pliers, "glue": db.onto.Glue, "panel": db.onto.Panel, "cube": db.onto.Cube }
def evaluate(self) -> None: is_default = False uim = UserInputManager() uim.say(f"Do you want to make {self.area_name} your default area? (y/n)") if uim.confirm_user(): is_default = True self.db_api = DatabaseAPI() self.db_api.add_area(area_name=self.area_name, corners=(self.corner_0, self.corner_1, self.corner_2, self.corner_3), is_default=is_default) self.db_api.set_state(State.DEFINE_AREA)
def __init__(self,language = 'en'): self.logger = logging.getLogger(__name__) self.lang = language self.db_api = DatabaseAPI() self.ui = UserInputManager(language = language) self.class_map = { "screwdriver": db.onto.Screwdriver, "hammer": db.onto.Hammer, "pliers": db.onto.Pliers, "glue" : db.onto.Glue, "panel" : db.onto.Panel, "cube" : db.onto.Cube } self.templ_det = self.ui.load_file('templates_detection.json') self.guidance_file = self.ui.load_file('guidance_dialogue.json')
def add_put_first_cube_task(self, program, cube_id): put_task = PutTask() top_cube = db.onto.ObjectPlaceholder() top_cube.is_a.append(db.onto.Cube) top_cube.id = cube_id put_task.object_to_put = top_cube db_api = DatabaseAPI() default_area = db_api.get_default_area() put_task.location = RelativeLocation() put_task.location.loc_type = "center" put_task.location.relative_to = default_area self.add_task(program, put_task)
def evaluate(self) -> None: self.db_api = DatabaseAPI() self.db_api.set_param("current_task_name", self.task_name) dl = DemonstrationLearner() program = dl.create_new_program() last_cube_positions = {} for cube_positions in dl.get_cube_positions(): for key, val in cube_positions.items(): val self.add_object('Cube', x=0.1, y=0.3, z=0, id=key, color='red') logging.debug(f"Position of cubes: {cube_positions}") overlapping = self.detect_overlapping(last_cube_positions, cube_positions) if overlapping: bottom_cube_id = overlapping[0] top_cube_id = overlapping[1] logging.debug( f"Overlapping cubes detected: cube id {top_cube_id} is on top of cube id {bottom_cube_id}" ) if not program.root.children: # beginning of the demonstration, place the first cube self.add_pick_task(program, bottom_cube_id) self.add_put_first_cube_task(program, bottom_cube_id) self.add_pick_task(program, top_cube_id) self.add_put_task(program, top_cube_id, bottom_cube_id) last_cube_positions = cube_positions # time.sleep(1) logging.debug("Demonstration finished, adding program to database") logging.debug("\n" + str(program)) self.db_api.add_custom_template(program) self.db_api.set_state(State.LEARN_FROM_DEMONSTRATION)
def process_text(self, sentence: str) -> RobotProgram: """ Turns an input text into a program template which can be used for creating instructions for the robot (after grounding). The program template is dependent only on the content of the sentence and not on the current state of the workspace. Parameters ---------- sentence an input sentence as string Returns ------- a program template - formalized instructions for the robot with placeholders for real objects and locations (right now, the behavior is undefined in case the sentence does not allow creating a valid program) """ parsed_text = self.gp.parse(sentence) root = parsed_text.parse_tree db_api = DatabaseAPI() state = db_api.get_state() if state == State.LEARN_FROM_INSTRUCTIONS: program = RobotCustomProgram() else: program = RobotProgram() # hardcoded program structure: all subprograms are located directly under the root node "AND" program.root = RobotProgramOperator(operator_type="AND") for subnode in root.subnodes: if type(subnode) is ParseTreeNode: # create a single robot instructon program_node = self.process_node(subnode) program.root.add_child(program_node) return program
def __init__(self): rospy.init_node('process_sentence_node', anonymous=False) logging.config.fileConfig(get_full_path('config', 'logging.ini')) self._getdatsrv = rospy.ServiceProxy('/db_interface_node/getDatabase', GetDatabase) req = GetDatabaseRequest() req.write = False res = self._getdatsrv.call(req) self.sub = rospy.Subscriber('/nl_input', SentenceProgram, queue_size=10, callback=self.callback) self.pub = rospy.Publisher('/sentence_output', SentenceProgram, queue_size=10) self._addsrv = rospy.ServiceProxy('/db_interface_node/addObject', AddObject) self._senddatsrv = rospy.ServiceProxy( '/db_interface_node/sendDatabase', SendDatabase) self.db_api = DatabaseAPI() self.db = self.db_api.get_db() self.ontoC = self.db.change_onto(res.path) #obj = self.db.onto.search(type = db.onto.Cube) #obj2 = self.ontoC.search(type = db.onto.Cube) #obj3 = self.db.onto.search(type = db.onto.Cube) #obj4 = self.ontoC.search(type = db.onto.Cube) #path = '/home/algernon/ros_melodic_ws/base_ws/src/crow_nlp/scripts/saved_updated_onto.owl' self.UngroundedID = 1 self.GroundedID = 1
def __init__(self): rospy.init_node('db_interface_node', anonymous=False) self._dbapi = DatabaseAPI() self.db = self._dbapi.get_db() self.sub_cubes = rospy.Subscriber('/averaged_markers', MarkersAvgList, self.update_object_position) # self.listener = keyboard.Listener(on_press=self.on_press) # self.listener.start() self.pub = rospy.Publisher('/database_update', DatabaseUpdate, queue_size=10) self.srv = {} # self.srv['groundProgram'] = rospy.Service('~groundProgram', GroundProgram, self.handle_ground_program) self.srv['addObject'] = rospy.Service('~addObject', AddObject, self.handle_add_object) self.srv['getDatabase'] = rospy.Service( '~getDatabase', GetDatabase, self.handle_get_database_request) self.srv['sendDatabase'] = rospy.Service( '~sendDatabase', SendDatabase, self.handle_send_database_request) self.database_locked = False
def __init__(self): self.db_api = DatabaseAPI() self.ar = UserInputManager() self.og = ObjectGrounder() self.logger = logging.getLogger(__name__)
def __init__(self): self.logger = logging.getLogger(__name__) self.db_api = DatabaseAPI()
def setUp(self): self.db = DatabaseAPI() self.onto = self.db.get_onto()
def __init__(self, serverAdress, gain: int = 1.0): # instantiate client object; make sure address and port are correct self.DEBUG_mode = False self.client = Client(serverAdress) self.shouldProcessInput = True self.LANG = 'en' self.recognizer = sr.Recognizer() self.fast_recognizer = sr.Recognizer() self.fast_recognizer.non_speaking_duration = 0.05 self.fast_recognizer.pause_threshold = 0.15 self.recText = RawNLParser(language=self.LANG) self.lastRecognitionFailed = False self.repeatChoices = False self.last_key = '' self.keys_pressed = set() if self.DEBUG_mode: self.keys_pressed = 's' self.ADD_OBJECTS = 1 self.kb_listener = Listener(on_press=self.on_press) self.kb_listener.start() self.play_sound("start_speech") """ SoX Effects http://sox.sourceforge.net/sox.html#EFFECTS gain -n normalize the audio to 0dB -b balance the audio, try to prevent clipping dither adds noise to mask low sampling rate vol changes volume: above 1 -> increase volume below 1 -> decrease volume pad adds silence to the begining (first argument) and the end (second argument) of the audio - attempt to mask sound cut-off but extends the audio duration """ self.sox_effects = ("gain", "-n", "-b", "vol", str(gain), "pad", "0", "0.5", "dither", "-a") SpeechCustom.MAX_SEGMENT_SIZE = 300 Speech.MAX_SEGMENT_SIZE = 300 self.hint_directive_re = re.compile(r"<([b-])>\s*$") rospy.init_node('process_sentence_node', anonymous=False) logging.config.fileConfig(get_full_path('config', 'logging.ini')) self._getdatsrv = rospy.ServiceProxy('/db_interface_node/getDatabase', GetDatabase) req = GetDatabaseRequest() req.write = False res = self._getdatsrv.call(req) self.sub = rospy.Subscriber('/nl_input', SentenceProgram, queue_size=10, callback=self.callback) self.pub = rospy.Publisher('/sentence_output', SentenceProgram, queue_size=10) self._addsrv = rospy.ServiceProxy('/db_interface_node/addObject', AddObject) self._senddatsrv = rospy.ServiceProxy( '/db_interface_node/sendDatabase', SendDatabase) self.db_api = DatabaseAPI() self.db = self.db_api.get_db() self.ontoC = self.db.change_onto(res.path) # obj = self.db.onto.search(type = db.onto.Cube) # obj2 = self.ontoC.search(type = db.onto.Cube) # obj3 = self.db.onto.search(type = db.onto.Cube) # obj4 = self.ontoC.search(type = db.onto.Cube) # path = '/home/algernon/ros_melodic_ws/base_ws/src/crow_nlp/scripts/saved_updated_onto.owl' self.UngroundedID = 1 self.GroundedID = 1
""" import json import os from typing import List from pkg_resources import resource_filename from nlp_crow.database.DatabaseAPI import DatabaseAPI from nlp_crow.modules.CrowModule import CrowModule from nlp_crow.structures.tagging.MorphCategory import POS from nlp_crow.structures.tagging.ParsedText import TaggedText from nlp_crow.structures.tagging.Tag import Tag from nlp_crow.templates.TemplateFactory import TemplateType as tt from nlp_crow.modules.UserInputManager import UserInputManager db_api = DatabaseAPI() db = db_api.get_db() # onto = db_api.get_onto() # with onto: class TemplateDetector(CrowModule): """ First part of the NL pipeline. Preliminary template detection in the text. """ namespace = db.onto def __init__(self, language='en'): self.lang = language self.ui = UserInputManager(language=language)
def __init__(self): self.db_api = DatabaseAPI() self.cd = ColorDetector() self.ar = UserInputManager() self.logger = logging.getLogger(__name__)