def export_inner(operation, useDart=False): """ Continues the export process on the specified operation """ print("Beginnning Export") joint_laminates = operation.bodies_generic project_name = "exported" #We can figure out a better way later. world_name = 'world' robot_name = 'default_body' global_root = etree.Element("sdf", version="1.5") world_object = etree.Element("world", name=world_name) global_root.append(world_object); model_object = etree.Element("model", name=robot_name) world_object.append(model_object) etree.SubElement(model_object, "static").text = "false" etree.SubElement(model_object, "pose").text = "0 0 0 0 0 0" etree.SubElement(model_object, "plugin", name="Model_Vel", filename="libmodel_vel.so") #world_object.append(createFloor()) include_floor = etree.SubElement(world_object, "include") etree.SubElement(include_floor, "uri").text = "model://ground_plane" include_sun = etree.SubElement(world_object, "include") etree.SubElement(include_sun, "uri").text = "model://sun" #Sorts them in the correct order #operation.connections.sort(key=lambda tup: tup[0], reverse=True) ordered_connection = [reorder_pair(connection[1], operation.get_laminate_generations()) for connection in operation.connections] tree = spawnTreefromList(ordered_connection, sort=True) assert(len(tree.decendents) == len(operation.bodies_generic) - 1) midpoints = [connect[0] for connect in operation.connections] print(midpoints) #This key function tells it to ignore the following special characters when sorting. link_sort = lambda string: str(string).replace('|', '\x02').replace('*','\x01') counter = 0 for joint_laminate in sorted(joint_laminates,key=link_sort): model_object.append(createRobotPart(joint_laminate, counter, tree, buildMesh=True, approxCollisions=(not useDart))) counter+=1 joint_names = [] joints = [] for joint_connection in zip(midpoints, ordered_connection): name = "hingejoint" name += tree.getNode(joint_connection[1][0]).getID() name += '|' name += tree.getNode(joint_connection[1][1]).getID() joints.append(craftJoint(operation, list(joint_connection), name, tree)) joint_names.append(name) joint_sort = lambda joint: link_sort(joint.get('name')) for joint in sorted(joints, key=joint_sort): print(joints) model_object.append(joint) joint_names.sort(key=link_sort) if useDart is True: physics_engine = 'dart' else: physics_engine = 'simbody' world_object.append(craftSimbodyPhysics()) #Saves the object file_output = popupcad.exportdir + os.path.sep + project_name + ".world" f = open(file_output,"wb") f.write(etree.tostring(global_root, pretty_print=True)) f.close() def stringify(s1): #For local use to generate default Python code return "'{}'".format(s1) #Experimental Python IDE and Control System #TODO Sandbox this from popupcad.widgets.userinput import UserInputIDE mw = UserInputIDE() mw.setWindowTitle('Internal Python IDE') mw.appendText('#This code will control your robot during the simulation') mw.appendText('from popupcad_gazebo.gazebo_controller import apply_joint_forces, apply_joint_pos') mw.appendText('world_name=' + stringify(world_name)) mw.appendText('robot_name=' + stringify(robot_name)) mw.appendText('joint_names=' + str(joint_names)) mw.te.setReadOnly(False) mw.exec_() print("Starting gazebo") user_input_code = compile(mw.te.toPlainText(), 'user_defined', 'exec')#Todo Sandbox this #TODO replace with Subprocess to prevent pollution of STDOUT #subprocess.Popen("killall -9 gazebo & killall -9 gzserver & killall -9 gzclient", shell=True) subprocess.Popen(['killall', 'gzserver']) gazebo = subprocess.Popen(["gazebo", "-e", physics_engine, file_output, '-u', '--verbose']) print("Gazebo is now open") #Even with wait net service we run into issues. wait_net_service('localhost', 11345) print("Gazebo is done waiting") def exec_(arg): #This is done for Python 2 and 3 compatibility exec(arg) from multiprocessing import Process code_process = Process(target=exec_, args=(user_input_code,)) time.sleep(5) #follow_model(robot_name) pause_simulation(world_name, pause=False) code_process.start() import PySide.QtGui as qg import PySide widget = qg.QMessageBox() widget.setText("Press Okay to Stop the Simulation and Close Gazebo") widget.setWindowModality(PySide.QtCore.Qt.NonModal) widget.exec_() code_process.terminate() gazebo.terminate()
def export_inner(operation, useDart=False): """ Continues the export process on the specified operation """ print("Beginnning Export") joint_laminates = operation.bodies_generic project_name = "exported" #We can figure out a better way later. world_name = 'world' robot_name = 'default_body' global_root = etree.Element("sdf", version="1.5") world_object = etree.Element("world", name=world_name) global_root.append(world_object) model_object = etree.Element("model", name=robot_name) world_object.append(model_object) etree.SubElement(model_object, "static").text = "false" etree.SubElement(model_object, "pose").text = "0 0 0 0 0 0" etree.SubElement(model_object, "plugin", name="Model_Vel", filename="libmodel_vel.so") #world_object.append(createFloor()) include_floor = etree.SubElement(world_object, "include") etree.SubElement(include_floor, "uri").text = "model://ground_plane" include_sun = etree.SubElement(world_object, "include") etree.SubElement(include_sun, "uri").text = "model://sun" #Sorts them in the correct order #operation.connections.sort(key=lambda tup: tup[0], reverse=True) ordered_connection = [ reorder_pair(connection[1], operation.get_laminate_generations()) for connection in operation.connections ] tree = tree_node.spawnTreefromList(ordered_connection, sort=True) assert (len(tree.decendents) == len(operation.bodies_generic) - 1) midpoints = [connect[0] for connect in operation.connections] print(midpoints) #This key function tells it to ignore the following special characters when sorting. link_sort = lambda string: str(string).replace('|', '\x02').replace( '*', '\x01') counter = 0 for joint_laminate in sorted(joint_laminates, key=link_sort): model_object.append( createRobotPart(joint_laminate, counter, tree, buildMesh=True, approxCollisions=(not useDart))) counter += 1 joint_names = [] joints = [] for joint_connection in zip(midpoints, ordered_connection): name = "hingejoint" name += tree.getNode(joint_connection[1][0]).getID() name += '|' name += tree.getNode(joint_connection[1][1]).getID() joints.append(craftJoint(operation, list(joint_connection), name, tree)) joint_names.append(name) joint_sort = lambda joint: link_sort(joint.get('name')) for joint in sorted(joints, key=joint_sort): print(joints) model_object.append(joint) joint_names.sort(key=link_sort) if useDart is True: physics_engine = 'dart' else: physics_engine = 'simbody' world_object.append(craftSimbodyPhysics()) #Saves the object file_output = popupcad.exportdir + os.path.sep + project_name + ".world" f = open(file_output, "wb") f.write(etree.tostring(global_root, pretty_print=True)) f.close() def stringify(s1): #For local use to generate default Python code return "'{}'".format(s1) #Experimental Python IDE and Control System #TODO Sandbox this from popupcad.widgets.userinput import UserInputIDE mw = UserInputIDE() mw.setWindowTitle('Internal Python IDE') mw.appendText('#This code will control your robot during the simulation') mw.appendText( 'from popupcad_gazebo.gazebo_controller import apply_joint_forces, apply_joint_pos' ) mw.appendText('world_name=' + stringify(world_name)) mw.appendText('robot_name=' + stringify(robot_name)) mw.appendText('joint_names=' + str(joint_names)) mw.te.setReadOnly(False) mw.exec_() print("Starting gazebo") user_input_code = compile(mw.te.toPlainText(), 'user_defined', 'exec') #Todo Sandbox this #TODO replace with Subprocess to prevent pollution of STDOUT #subprocess.Popen("killall -9 gazebo & killall -9 gzserver & killall -9 gzclient", shell=True) subprocess.Popen(['killall', 'gzserver']) gazebo = subprocess.Popen( ["gazebo", "-e", physics_engine, file_output, '-u', '--verbose']) print("Gazebo is now open") #Even with wait net service we run into issues. wait_net_service('localhost', 11345) print("Gazebo is done waiting") def exec_(arg): #This is done for Python 2 and 3 compatibility exec(arg) from multiprocessing import Process code_process = Process(target=exec_, args=(user_input_code, )) time.sleep(5) #follow_model(robot_name) pause_simulation(world_name, pause=False) code_process.start() import qt.QtCore as qc import qt.QtGui as qg widget = qg.QMessageBox() widget.setText("Press Okay to Stop the Simulation and Close Gazebo") widget.setWindowModality(qc.Qt.NonModal) widget.exec_() code_process.terminate() gazebo.terminate()
def buildeditdialog(self, design): mw = UserInputIDE() mw.setWindowTitle('Internal Python IDE') mw.te.setReadOnly(False) mw.te.setPlainText(self.code) return mw
def buildnewdialog(cls, design, currentop): mw = UserInputIDE() mw.setWindowTitle('Internal Python IDE') mw.te.setReadOnly(False) return mw