def run_rosrun(self, data): rosrun_commands = utils.list_rosorun_commands() if data.get('command') in rosrun_commands: cmd = 'PYTHONUNBUFFERED=false rosrun ' + data.get('command') + ' ' + data.get('args') process = Popen(cmd, shell=True, stdout=PIPE) # Note: The launched rosnode-name does not appear the soon after roslaunch is executed. # Therefore, sleep is neccessary to wait it finishes to launch. time.sleep(2) msg = { 'uuid': self.id, 'rosnodes': rosnode.get_node_names(), 'rostopics': utils.list_rostopics() } self.sio.emit('update_rosnodes', json.dumps(msg), namespace=self.nms) while True: output = process.stdout.readline() if output == '' and process.poll() is not None: break if output: msg = { "cmd": data.get('command').replace(" ", "-"), "robotUuid": self.id, "log": output.strip(), } self.sio.emit('rosrun_log', json.dumps(msg), namespace=self.nms) print(output.strip()) process.poll()
def connect(self): ros_root = rospkg.get_ros_root() r = rospkg.RosPack() manifest = r.get_manifest('rowma_ros') rowma_ros_version = manifest.version launch_commands = utils.list_launch_commands() rosrun_commands = utils.list_rosorun_commands() rostopics = utils.list_rostopics() uuid = os.environ.get('UUID', self.id) msg = { 'uuid': uuid, 'launch_commands': launch_commands, 'rosnodes': rosnode.get_node_names(), 'rosrun_commands': rosrun_commands, 'rowma_ros_version': rowma_ros_version, 'rostopics': rostopics, 'reconnection': self.reconnecting } api_key = os.environ.get('API_KEY') if api_key: msg['api_key'] = api_key self.sio.emit('register_robot', json.dumps(msg), namespace=self.nms) utils.print_success('connection established')
def connect(self): print('connection established') launch_commands = utils.list_launch_commands() rosrun_commands = utils.list_rosorun_commands() uuid = os.environ.get('UUID') or self.id msg = { 'uuid': uuid, 'launch_commands': launch_commands, 'rosnodes': rosnode.get_node_names(), 'rosrun_commands': rosrun_commands } api_key = os.environ.get('API_KEY') if api_key: msg['api_key'] = api_key self.sio.emit('register_robot', json.dumps(msg), namespace=self.nms)
def run_rosrun(self, data): rosrun_commands = utils.list_rosorun_commands() print(rosrun_commands) if data.get('command') in rosrun_commands: cmd = 'rosrun ' + data.get('command') + ' ' + data.get('args') print(cmd) self.launched_nodes = self.launched_nodes.append( Popen(cmd.split()) or []) # Note: The launched rosnode-name does not appear the soon after roslaunch is executed. # Therefore, sleep is neccessary to wait it finishes to launch. time.sleep(2) msg = {'uuid': self.id, 'rosnodes': rosnode.get_node_names()} self.sio.emit('update_rosnodes', json.dumps(msg), namespace=self.nms) print('run_rosrun') print(data)
def add_script(self, data): enable_script_download = os.environ.get('ENABLE_SCRIPT_DOWNLOAD', False) if enable_script_download: script = data.get('script') name = data.get('name') current_path = os.path.dirname(os.path.realpath(__file__)) file_path = os.path.join(current_path, "../" + name) file = open(file_path, 'w') file.write(script) file.close() cmd = 'chmod +x ' + file_path process = Popen(cmd, shell=True, stdout=PIPE) msg = { 'uuid': self.id, 'rosrunCommands': utils.list_rosorun_commands() } self.sio.emit('update_rosnodes', json.dumps(msg), namespace=self.nms) else: utils.print_error("You have to set ENABLE_SCRIPT_DOWNLOAD if you use script download.")
def test_list_rosrun_commands(): rosrun_commands = utils.list_rosorun_commands() expected = ['rowma_ros rowma', 'ros_package_template ros_package_template'] assert rosrun_commands.sort() == expected.sort()