def rosbag_command_callback(rosbag_command): rospy.loginfo("rosbag_command_callback()") # start recording if rosbag_command.command == 'start': global filename0 filename0 = create_file_name(rosbag_command.filename) rospy.loginfo("start recording rosbag") p = subprocess.Popen(["rosbag","record","-a","-O",filename0]) # stop recording and save log elif rosbag_command.command == 'stop': rospy.loginfo("stop recording rosbag") subprocess.Popen(["pkill","rosbag","-2"]) subprocess.Popen(["pkill","record","-2"]) global filename1 if rosbag_command.filename != "": filename1 = create_file_name(rosbag_command.filename) else: filename1 = filename0 # move bagfile if rosbag_command.path != "": os.system("mkdir -p " + rosbag_command.path) while not os.path.exists(os.path.join(rospkg.get_ros_home(),filename0) + ".bag"): time.sleep(0.001) os.system("mv " + os.path.join(rospkg.get_ros_home(),filename0) + ".bag " + os.path.join(rosbag_command.path,filename1) + ".bag") else : rospy.loginfo("invalid command") return True
def rosbag_command_callback(rosbag_command): rospy.loginfo("rosbag_command_callback()") # start recording if rosbag_command.command == 'start': global filename0 filename0 = create_file_name(rosbag_command.filename) rospy.loginfo("start recording rosbag") p = subprocess.Popen(["rosbag", "record", "-a", "-O", filename0]) # stop recording and save log elif rosbag_command.command == 'stop': rospy.loginfo("stop recording rosbag") subprocess.Popen(["pkill", "rosbag", "-2"]) subprocess.Popen(["pkill", "record", "-2"]) global filename1 if rosbag_command.filename != "": filename1 = create_file_name(rosbag_command.filename) else: filename1 = filename0 # move bagfile if rosbag_command.path != "": os.system("mkdir -p " + rosbag_command.path) while not os.path.exists( os.path.join(rospkg.get_ros_home(), filename0) + ".bag"): time.sleep(0.001) os.system("mv " + os.path.join(rospkg.get_ros_home(), filename0) + ".bag " + os.path.join(rosbag_command.path, filename1) + ".bag") else: rospy.loginfo("invalid command") return True
def get_rocon_home(): ''' Retrieve the location of the rocon home directory for using rocon components. If it is not existed, create new directory and return this path @return the service manager home directory (path object). @type str ''' rocon_home = os.path.join(rospkg.get_ros_home(), 'rocon') if not os.path.isdir(rocon_home): os.makedirs(rocon_home) return os.path.join(rospkg.get_ros_home(), 'rocon')
def get_rocon_home(): ''' Retrieve the location of the rocon home directory for using rocon compoenets. If it is not existed, create new directory and return this path @return the service manager home directory (path object). @type str ''' rocon_home = os.path.join(rospkg.get_ros_home(), 'rocon') if not os.path.isdir(rocon_home): os.makedirs(rocon_home) return os.path.join(rospkg.get_ros_home(), 'rocon')
def test_get_ros_home(): from rospkg import get_ros_root, get_ros_home base = tempfile.gettempdir() ros_home_dir = os.path.join(base, 'ros_home_dir') home_dir = os.path.expanduser('~') # ROS_HOME has precedence env = {'ROS_ROOT': get_ros_root(), 'ROS_HOME': ros_home_dir } assert ros_home_dir == get_ros_home(env=env) env = {'ROS_ROOT': get_ros_root()} assert os.path.join(home_dir, '.ros') == get_ros_home(env=env) # test default assignment of env. Don't both checking return value assert get_ros_home() is not None
def test_get_ros_home(): from rospkg import get_ros_root, get_ros_home base = tempfile.gettempdir() ros_home_dir = os.path.join(base, 'ros_home_dir') home_dir = os.path.expanduser('~') # ROS_HOME has precedence env = {'ROS_ROOT': get_ros_root(), 'ROS_HOME': ros_home_dir} assert ros_home_dir == get_ros_home(env=env) env = {'ROS_ROOT': get_ros_root()} assert os.path.join(home_dir, '.ros') == get_ros_home(env=env) # test default assignment of env. Don't both checking return value assert get_ros_home() is not None
def configure_logging(logname, level=logging.INFO, filename=None, env=None): """ Configure Python logging package to send log files to ROS-specific log directory :param logname str: name of logger, ``str`` :param filename: filename to log to. If not set, a log filename will be generated using logname, ``str`` :param env: override os.environ dictionary, ``dict`` :returns: log file name, ``str`` :raises: :exc:`LoggingException` If logging cannot be configured as specified """ if env is None: env = os.environ logname = logname or 'unknown' log_dir = rospkg.get_log_dir(env=env) # if filename is not explicitly provided, generate one using logname if not filename: log_filename = os.path.join(log_dir, '%s-%s.log'%(logname, os.getpid())) else: log_filename = os.path.join(log_dir, filename) logfile_dir = os.path.dirname(log_filename) if not os.path.exists(logfile_dir): try: makedirs_with_parent_perms(logfile_dir) except OSError: # cannot print to screen because command-line tools with output use this sys.stderr.write("WARNING: cannot create log directory [%s]. Please set %s to a writable location.\n"%(logfile_dir, ROS_LOG_DIR)) return None elif os.path.isfile(logfile_dir): raise LoggingException("Cannot save log files: file [%s] is in the way"%logfile_dir) if 'ROS_PYTHON_LOG_CONFIG_FILE' in os.environ: config_file = os.environ['ROS_PYTHON_LOG_CONFIG_FILE'] else: # search for logging config file in /etc/. If it's not there, # look for it package-relative. fname = 'python_logging.conf' rosgraph_d = rospkg.RosPack().get_path('rosgraph') for f in [os.path.join(rospkg.get_ros_home(), 'config', fname), '/etc/ros/%s'%(fname), os.path.join(rosgraph_d, 'conf', fname)]: if os.path.isfile(f): config_file = f break else: config_file = None if config_file is None or not os.path.isfile(config_file): # logging is considered soft-fail sys.stderr.write("WARNING: cannot load logging configuration file, logging is disabled\n") logging.getLogger(logname).setLevel(logging.CRITICAL) return log_filename # pass in log_filename as argument to pylogging.conf os.environ['ROS_LOG_FILENAME'] = log_filename # #3625: disabling_existing_loggers=False logging.config.fileConfig(config_file, disable_existing_loggers=False) return log_filename
def __init__(self, root): """ Initialise the tree with a root. :param root: root node of the tree. :type root: instance or descendant of :py:class:`Behaviour <py_trees.behaviours.Behaviour>` :raises AssertionError: if incoming root variable is not the correct type. """ super(BehaviourTree, self).__init__(root) self.snapshot_visitor = visitors.SnapshotVisitor() self.logging_visitor = visitors.LoggingVisitor() self.visitors.append(self.snapshot_visitor) self.visitors.append(self.logging_visitor) self._bag_closed = False now = datetime.datetime.now() topdir = rospkg.get_ros_home() + '/behaviour_trees' subdir = topdir + '/' + now.strftime('%Y-%m-%d') if not os.path.exists(topdir): os.makedirs(topdir) if not os.path.exists(subdir): os.makedirs(subdir) # opens in ros home directory for the user self.bag = rosbag.Bag(subdir + '/behaviour_tree_' + now.strftime("%H-%M-%S") + '.bag', 'w') self.last_tree = py_trees_msgs.BehaviourTree() self.lock = threading.Lock() # delay the publishers so we can instantiate this class without connecting to ros (private names need init_node) self.publishers = None # _cleanup must come last as it assumes the existence of the bag rospy.on_shutdown(self._cleanup)
def main(): rospy.init_node('cdrm_welding_tutorial_generate_node') client = actionlib.SimpleActionClient( '/cdrm_welding_node/generate_welding_cdrm', GenerateWeldingCdrmAction) client.wait_for_server() print 'Generating welding CDRM...' goal = GenerateWeldingCdrmGoal(filename=rospkg.get_ros_home() + '/m10ia_on_gantry.welding-cdrm', group_name='robot_with_gantry', end_effector_name='welding_torch', nozzle_link_name='nozzle_link', tool_roadmap_size=2000, robot_roadmap_size=100000, roadmap_k=10, rx=Interval(min=-0.261799, max=0.261799), ry=Interval(min=-0.610865, max=0.610865), ctwd=Interval(min=0, max=0.015), tool_resolution=0.002, robot_resolution=0.2) client.send_goal(goal) client.wait_for_result() print client.get_result()
def test_get_cwd(self): test_path = '/this/is/path/to' result_path = get_cwd('node', '%s/bin' % test_path) self.assertEqual( test_path, result_path, "wrong get_cwd from 'node' type, expected: %s, got: %s" % (test_path, result_path)) test_path = os.getcwd() result_path = get_cwd('cwd', '') self.assertEqual( test_path, result_path, "wrong get_cwd from 'cwd' type, expected: %s, got: %s" % (test_path, result_path)) test_path = rospkg.get_ros_root() result_path = get_cwd('ros-root', '') self.assertEqual( test_path, result_path, "wrong get_cwd from 'ros-root' type, expected: %s, got: %s" % (test_path, result_path)) test_path = rospkg.get_ros_home() result_path = get_cwd('', '') self.assertEqual( test_path, result_path, "wrong get_cwd from empty type, expected: %s, got: %s" % (test_path, result_path))
def image_cb(self, msg): """ Identifies red lights in the incoming camera image and publishes the index of the waypoint closest to the red light to /traffic_waypoint Args: msg (Image): image from car-mounted camera """ if self.base_waypoints is None or self.car_index is None: return #----------------------------------------------------------------------- # Create the classifier and download the models if necessary #----------------------------------------------------------------------- if self.classifier is None: self.classifier = Classifier(rospkg.get_ros_home()) if self.classifier.need_models(): rospy.logwarn('Need to download models, it may take a while.') if self.classifier.download_models(): rospy.logwarn('Finished downloading!') else: rospy.logerr('Unable to download models! ' 'Please try downloading by hand!') self.classifier_broken = True if not self.classifier_broken: self.classifier.initialize() rospy.logwarn('Classifier initialized!') self.classifier_initialized = True if self.classifier_broken: rospy.logerr('Cannot detect traffic lights, the TensorFlow models ' 'were not downloaded properly.') if not self.classifier_initialized: return #----------------------------------------------------------------------- # Get the next stop line and detect the state of the traffic light # if necessary #----------------------------------------------------------------------- stop_wp = self.get_next_stop_wp() if stop_wp is None: self.best_stop_line_index = None return img = self.bridge.imgmsg_to_cv2(msg, "rgb8") state = self.classifier.classify(img) if self.state != state: self.state_count = 0 self.state = state self.best_stop_line_index = None elif self.state_count >= STATE_COUNT_THRESHOLD: if state == Classifier.RED: self.best_stop_line_index = stop_wp self.time_received = rospy.get_time() self.state_count += 1
def CloseDatabase(file_path): global CoffeeDatabase numberUsers = GetNumberUsers() try: CoffeeDatabase.close() if numberUsers == 0: os.remove(os.path.join(rospkg.get_ros_home(), file_path)) except Exception, e: print e
def get_home(): ''' Retrieve the location of the home directory for the rocon remocon's temporary storage needs @return the rocon remocon home directory (path object). @type str ''' return os.path.join(rospkg.get_ros_home(), 'rocon', 'remocon')
def main(): global path rospy.init_node("factory_settings", anonymous=True) rospy.Service('/factory_settings/set_param', KVPair, set_param) path = os.path.join(rospkg.get_ros_home(), "factory_settings.yaml") rospy.loginfo("path: %s", path) file_init() read_all_params() rospy.spin()
def start(self): """ Start the process. @raise pmon.FatalProcessLaunch: if process cannot be started and it is not likely to ever succeed """ super(LocalProcess, self).start() try: self.lock.acquire() if self.started: _logger.info("process[%s]: restarting os process", self.name) else: _logger.info("process[%s]: starting os process", self.name) self.started = self.stopped = False full_env = self.env # _configure_logging() can mutate self.args try: logfileout, logfileerr = self._configure_logging() except Exception, e: _logger.error(traceback.format_exc()) printerrlog("[%s] ERROR: unable to configure logging [%s]"%(self.name, str(e))) # it's not safe to inherit from this process as # rostest changes stdout to a StringIO, which is not a # proper file. logfileout, logfileerr = subprocess.PIPE, subprocess.PIPE if self.cwd == 'node': cwd = os.path.dirname(self.args[0]) elif self.cwd == 'cwd': cwd = os.getcwd() elif self.cwd == 'ros-root': cwd = get_ros_root() else: cwd = rospkg.get_ros_home() _logger.info("process[%s]: start w/ args [%s]", self.name, self.args) _logger.info("process[%s]: cwd will be [%s]", self.name, cwd) try: self.popen = subprocess.Popen(self.args, cwd=cwd, stdout=logfileout, stderr=logfileerr, env=full_env, close_fds=True, preexec_fn=os.setsid) except OSError, (errno, msg): self.started = True # must set so is_alive state is correct _logger.error("OSError(%d, %s)", errno, msg) if errno == 8: #Exec format error raise pmon.FatalProcessLaunch("Unable to launch [%s]. \nIf it is a script, you may be missing a '#!' declaration at the top."%self.name) elif errno == 2: #no such file or directory raise pmon.FatalProcessLaunch("""Roslaunch got a '%s' error while attempting to run: %s Please make sure that all the executables in this command exist and have executable permission. This is often caused by a bad launch-prefix."""%(msg, ' '.join(self.args))) else: raise pmon.FatalProcessLaunch("unable to launch [%s]: %s"%(' '.join(self.args), msg))
def start(self): """ Start the process. @raise FatalProcessLaunch: if process cannot be started and it is not likely to ever succeed """ super(LocalProcess, self).start() try: self.lock.acquire() if self.started: _logger.info("process[%s]: restarting os process", self.name) else: _logger.info("process[%s]: starting os process", self.name) self.started = self.stopped = False full_env = self.env # _configure_logging() can mutate self.args try: logfileout, logfileerr = self._configure_logging() except Exception, e: _logger.error(traceback.format_exc()) printerrlog("[%s] ERROR: unable to configure logging [%s]"%(self.name, str(e))) # it's not safe to inherit from this process as # rostest changes stdout to a StringIO, which is not a # proper file. logfileout, logfileerr = subprocess.PIPE, subprocess.PIPE if self.cwd == 'node': cwd = os.path.dirname(self.args[0]) elif self.cwd == 'cwd': cwd = os.getcwd() elif self.cwd == 'ros-root': cwd = get_ros_root() else: cwd = rospkg.get_ros_home() _logger.info("process[%s]: start w/ args [%s]", self.name, self.args) _logger.info("process[%s]: cwd will be [%s]", self.name, cwd) try: self.popen = subprocess.Popen(self.args, cwd=cwd, stdout=logfileout, stderr=logfileerr, env=full_env, close_fds=True, preexec_fn=os.setsid) except OSError, (errno, msg): self.started = True # must set so is_alive state is correct _logger.error("OSError(%d, %s)", errno, msg) if errno == 8: #Exec format error raise FatalProcessLaunch("Unable to launch [%s]. \nIf it is a script, you may be missing a '#!' declaration at the top."%self.name) elif errno == 2: #no such file or directory raise FatalProcessLaunch("""Roslaunch got a '%s' error while attempting to run: %s Please make sure that all the executables in this command exist and have executable permission. This is often caused by a bad launch-prefix."""%(msg, ' '.join(self.args))) else: raise FatalProcessLaunch("unable to launch [%s]: %s"%(' '.join(self.args), msg))
def SaveDotGraph(self, event): timestr = time.strftime("%Y%m%d-%H%M%S") directory = rospkg.get_ros_home() + '/dotfiles/' if not os.path.exists(directory): os.makedirs(directory) filename = directory + timestr + '.dot' print('Writing to file: %s' % filename) with open(filename, 'w') as f: f.write(self.dotstr)
def _load_for_package(self, package, ros_package_proxy): """ Load into local structures the information for this specific package Called in constructor. """ try: rosdep_dependent_packages = ros_package_proxy.depends([package])[package] except KeyError as ex: print("Depends Failed on package", ex) print(" The errors was in ", ros_package_proxy.depends([package])) rosdep_dependent_packages = [] rosdep_dependent_packages.append(package) paths = set() rospack = rospkg.RosPack() rosstack = rospkg.RosStack() for p in rosdep_dependent_packages: stack = None try: stack = rospack.stack_of(p) except rospkg.ResourceNotFound as ex: print("Failed to find stack for package [%s]" % p, file=sys.stderr) if stack: try: paths.add(os.path.join(rosstack.get_path(stack), "rosdep.yaml")) if "ROSDEP_DEBUG" in os.environ: print("loading rosdeps from", os.path.join(rosstack.get_path(stack), "rosdep.yaml")) except AttributeError as ex: print("Stack [%s] could not be found" % (stack)) for s in self.yaml_cache.get_rosstack_depends(stack): try: paths.add(os.path.join(rosstack.get_path(s), "rosdep.yaml")) except AttributeError as ex: print("Stack [%s] dependency of [%s] could not be found" % (s, stack)) else: try: paths.add(os.path.join(rospack.get_path(p), "rosdep.yaml")) if "ROSDEP_DEBUG" in os.environ: print( "Package fallback, no parent stack found for package %s: loading rosdeps from" % p, os.path.join(rospack.get_path(p), "rosdep.yaml"), ) except rospkg.ResourceNotFound as ex: print("Failed to load rosdep.yaml for package [%s]:%s" % (p, ex), file=sys.stderr) for path in paths: yaml_in = self.parse_yaml(path) self._insert_map(yaml_in, path) if "ROSDEP_DEBUG" in os.environ: print("rosdep loading from file: %s got" % path, yaml_in) # Override with ros_home/rosdep.yaml if present ros_home = rospkg.get_ros_home() path = os.path.join(ros_home, "rosdep.yaml") self._insert_map(self.parse_yaml(path), path, override=True)
def __init__(self, parameters): self._parameters = parameters self._process = None self._home_dir = os.path.join(rospkg.get_ros_home(), 'redis', self._parameters['name'].lower().replace(" ", "_")) # clean out old redis information if os.path.isdir(self._home_dir): shutil.rmtree(self._home_dir) self._files = {} self._version_extension = self._introspect_redis_server_version() self._files['redis_conf'] = os.path.join(self._home_dir, 'redis-%s.conf' % self._version_extension) self._files['redis_conf_local'] = os.path.join(self._home_dir, 'redis-%s.conf.local' % self._version_extension) self._files['redis_server_log'] = os.path.join(self._home_dir, 'redis-server.log') self._server = None self._setup()
def __init__(self): # set up database # get the database path from the parameter server; or default to the # user's ~/.ros/ directory self.dbpath = rospy.get_param('~dbpath', rospkg.get_ros_home() + '/program_queue.db') db = sqlite3.connect(self.dbpath) # create tables if they don't exist. db.execute('create table if not exists users(id integer primary key asc autoincrement, name text unique not null, password_hash text not null, admin int not null)') db.execute('create table if not exists tokens(id integer primary key, user_id integer references users(id))') # TODO: add an issue/expiration date to tokens db.execute('create table if not exists programs(id integer primary key asc autoincrement, user_id integer references users(id), name text default "myprogram" not null, type integer, code text default "" not null)') db.execute('create table if not exists output(id integer primary key asc autoincrement, program_id integer references programs(id) not null, time double not null, output text not null)') db.execute('create table if not exists queue(id integer primary key asc autoincrement, program_id integer unique references programs(id))') # create an admin user if one doesn't exist admin_hash = bcrypt.hashpw('admin', bcrypt.gensalt()) db.execute("insert or ignore into users (name, password_hash, admin) values (?, ?, ?)", ('admin', admin_hash, 1,)) db.commit() db.close() # set up services rospy.Service('clear_queue', ClearQueue, self.handle_clear_queue) rospy.Service('create_program', CreateProgram, self.handle_create_program) rospy.Service('create_user', CreateUser, self.handle_create_user) rospy.Service('dequeue_program', DequeueProgram, self.handle_dequeue_program) rospy.Service('get_my_programs', GetMyPrograms, self.handle_get_my_programs) rospy.Service('get_output', GetOutput, self.handle_get_output) rospy.Service('get_program', GetProgram, self.handle_get_program) rospy.Service('get_programs', GetPrograms, self.handle_get_programs) rospy.Service('get_queue', GetQueue, self.handle_get_queue) rospy.Service('login', Login, self.handle_login) rospy.Service('logout', Logout, self.handle_logout) rospy.Service('queue_program', QueueProgram, self.handle_queue_program) rospy.Service('run_program', RunProgram, self.handle_run_program) rospy.Service('update_program', UpdateProgram, self.handle_update_program) rospy.Service('start_queue', Empty, self.handle_start_queue) rospy.Service('stop_queue', Empty, self.handle_stop_queue) rospy.wait_for_service('run_slider_program') rospy.loginfo("Queue ready")
def rosbag_command_callback(rosbag_command): rospy.loginfo("rosbag_command_callback()") # start recording if rosbag_command.command == 'start': global filename0 filename0 = create_file_name(rosbag_command.filename) rospy.loginfo("start recording rosbag") if rosbag_command.topics == '': rosbag_proc = subprocess.Popen(["rosbag","record","-a","-O",filename0]) else: topics_list = rosbag_command.topics.split() rosbag_proc = subprocess.Popen(["rosbag","record"] + topics_list + ["-O",filename0]) # stop recording and save log elif rosbag_command.command == 'stop': rospy.loginfo("stop recording rosbag") subprocess.Popen(["pkill","rosbag","-2"]) subprocess.Popen(["pkill","record","-2"]) rospy.loginfo("killed process") global filename1 if rosbag_command.filename != "": filename1 = create_file_name(rosbag_command.filename) else: filename1 = filename0 rospy.loginfo("create file name") # move bagfile if rosbag_command.path != "": os.system("mkdir -p " + rosbag_command.path) tmpfname = os.path.join(rospkg.get_ros_home(),filename0) + ".bag" while not os.path.exists(tmpfname): rospy.loginfo(tmpfname + " is active") time.sleep(0.1) os.system("mv " + os.path.join(rospkg.get_ros_home(),filename0) + ".bag " + os.path.join(rosbag_command.path,filename1) + ".bag") rospy.loginfo("finish") else : rospy.loginfo("invalid command") return True
def __init__(self, parameters): self._parameters = parameters self._process = None self._home_dir = os.path.join( rospkg.get_ros_home(), 'redis', self._parameters['name'].lower().replace(" ", "_")) self._files = {} self._files['redis_conf'] = os.path.join(self._home_dir, 'redis.conf') self._files['redis_conf_local'] = os.path.join(self._home_dir, 'redis.conf.local') self._files['redis_server_log'] = os.path.join(self._home_dir, 'redis-server.log') self._server = None self._setup()
def decode_url(url, required=False): """ Example URL syntax: file:///full/path/to/local/file.yaml file:///full/path/to/videre/file.ini package://camera_info_manager/tests/test_calibration.yaml package://ros_package_name/calibrations/camera3.yaml /full/path ~/home/path The file: URL specifies a full path name in the local system. The package: URL is handled the same as file:, except the path name is resolved relative to the location of the named ROS package, which must be reachable via $ROS_PACKAGE_PATH. The following variables can be replaced ${NODE_NAME} resolved to the current node name. ${ROS_HOME} resolved to the $ROS_HOME environment variable if defined, ~/.ros if not. XXXX: Use the ros resource_retriever class here one day, when it has python bindings and variable substitution """ if url.startswith('~'): url = os.path.expanduser(url) elif url.startswith('file://'): url = url[7:] elif url.startswith('package://'): package, fragment = url[10:].split('/', 1) url = os.path.join( roslib.packages.get_pkg_dir(package, required=False), fragment) nodename = rospy.names.get_name() if nodename: #rospy returns rully resolved name, so remove first char (~,/) and #return only the first fragment nodename = nodename[1:].split(' ')[-1] else: nodename = '' url = string.Template(url).safe_substitute(NODE_NAME=nodename, ROS_HOME=rospkg.get_ros_home()) url = os.path.abspath(url) if required and not os.path.exists(url): raise Exception("resource not found") return url
def write_pid_file(options_pid_fn, options_core, port): if options_pid_fn or options_core: if options_pid_fn: pid_fn = options_pid_fn else: # NOTE: this assumption is not 100% valid until work on #3097 is complete if port is None: port = DEFAULT_MASTER_PORT # #2987 ros_home = rospkg.get_ros_home() pid_fn = os.path.join(ros_home, 'roscore-%s.pid'%(port)) # #3828 if not os.path.exists(ros_home): os.makedirs(ros_home) with open(pid_fn, "w") as f: f.write(str(os.getpid()))
def write_pid_file(options_pid_fn, options_core, port): if options_pid_fn or options_core: if options_pid_fn: pid_fn = options_pid_fn else: # NOTE: this assumption is not 100% valid until work on #3097 is complete if port is None: port = DEFAULT_MASTER_PORT # #2987 ros_home = rospkg.get_ros_home() pid_fn = os.path.join(ros_home, 'roscore-%s.pid' % (port)) # #3828 if not os.path.exists(ros_home): os.makedirs(ros_home) with open(pid_fn, "w") as f: f.write(str(os.getpid()))
def get_cwd(cwd, binary=''): result = '' if cwd == 'node': result = os.path.dirname(binary) elif cwd == 'cwd': result = os.getcwd() elif cwd == 'ros-root': result = rospkg.get_ros_root() else: result = rospkg.get_ros_home() if not os.path.exists(result): try: os.makedirs(result) except OSError: # exist_ok=True pass return result
def get_ros_home(): ''' Returns the ROS HOME depending on ROS distribution API. @return: ROS HOME path @rtype: C{str} ''' try: import rospkg.distro distro = rospkg.distro.current_distro_codename() if distro in ['electric', 'diamondback', 'cturtle']: import roslib.rosenv return roslib.rosenv.get_ros_home() else: from rospkg import get_ros_home return get_ros_home() except: from roslib import rosenv return rosenv.get_ros_home()
def command_fix_permissions(options): import os import pwd import grp stat_info = os.stat(os.path.expanduser('~')) uid = stat_info.st_uid gid = stat_info.st_gid user_name = pwd.getpwuid(uid).pw_name try: group_name = grp.getgrgid(gid).gr_name except KeyError as e: group_name = gid ros_home = rospkg.get_ros_home() print("Recursively changing ownership of ros home directory '{0}' " "to '{1}:{2}' (current user)...".format(ros_home, user_name, group_name)) failed = [] try: for dirpath, dirnames, filenames in os.walk(ros_home): try: os.lchown(dirpath, uid, gid) except Exception as e: failed.append((dirpath, str(e))) for f in filenames: try: path = os.path.join(dirpath, f) os.lchown(path, uid, gid) except Exception as e: failed.append((path, str(e))) except Exception: import traceback traceback.print_exc() print('Failed to walk directory. Try with sudo?') else: if failed: print('Failed to change ownership for:') for p, e in failed: print('{0} --> {1}'.format(p, e)) print('Try with sudo?') else: print('Done.')
def __init__(self, robot, suggested_name): # Variables self.concert_master_ip = None self.concert_master_port = None self.concert_namespace = None # namespace to expose on the concert master (must not conflict!) self.app_list = None self.app_store = None self.app_manager = None self.invitations = [] self.platform_info = concert_msgs.msg.PlatformInfo() self.platform_info.platform = concert_msgs.msg.PlatformInfo.PLATFORM_LINUX self.platform_info.system = concert_msgs.msg.PlatformInfo.SYSTEM_ROS self.platform_info.robot = robot key = uuid.uuid4() # random 16 byte string, alternatively uuid.getnode() returns a hash based on the mac address, uuid.uid1() based on localhost and time self.platform_info.key = key.hex # convert the uuid key into a hex string self.platform_info.suggested_name = suggested_name self.platform_info.unique_name = "" # Paths self.app_manager_home = os.path.join(rospkg.get_ros_home(),"app_manager") #self.app_list_directory = app_manager.get_default_applist_directory() # /etc/robot/apps self.app_list_directory = rospy.get_param("~app_list_dir", os.path.join(self.app_manager_home,"app_list")) if not os.path.exists(self.app_manager_home): os.makedirs(self.app_manager_home) if not os.path.exists(self.app_list_directory): os.makedirs(self.app_list_directory) self.app_store_url = rospy.get_param("~app_store_url", os.path.join(self.app_manager_home,"app_store","app_store.yaml")) self.app_store_directory = os.path.join(self.app_manager_home,"app_store") self.app_store_app_list_directory = os.path.join(self.app_store_directory, "installed") if not os.path.exists(self.app_store_app_list_directory): os.makedirs(self.app_store_app_list_directory) self.app_list = willow_app_manager.AppList([]) self.app_list.add_directory(self.app_list_directory) self.app_list.add_directory(self.app_store_app_list_directory) try: self.app_store = willow_app_manager.Exchange(self.app_store_url, self.app_store_directory) self.app_store.update() # Let's get an update regardless except willow_app_manager.AppException as e: rospy.logerror("App Manager: failed to load the app store [%s][%s]"%(e,rospy.get_name()))
def command_fix_permissions(options): import os import pwd import grp stat_info = os.stat(os.path.expanduser('~')) uid = stat_info.st_uid gid = stat_info.st_gid user_name = pwd.getpwuid(uid).pw_name try: group_name = grp.getgrgid(gid).gr_name except KeyError as e: group_name = gid ros_home = rospkg.get_ros_home() print("Recursively changing ownership of ros home directory '{0}' " "to '{1}:{2}' (current user)...".format(ros_home, user_name, group_name)) failed = [] try: for dirpath, dirnames, filenames in os.walk(ros_home): try: os.lchown(dirpath, uid, gid) except Exception as e: failed.append((dirpath, str(e))) for f in filenames: try: path = os.path.join(dirpath, f) os.lchown(path, uid, gid) except Exception as e: failed.append((path, str(e))) except Exception: import traceback traceback.print_exc() print("Failed to walk directory. Try with sudo?") else: if failed: print("Failed to change ownership for:") for p, e in failed: print("{0} --> {1}".format(p, e)) print("Try with sudo?") else: print("Done.")
def plan_weld(): rospy.wait_for_service(SERVICE) service = rospy.ServiceProxy(SERVICE, PlanWeld) weld_points = [ Point(x=0.005, y=0, z=0.005), Point(x=0.005, y=-0.2, z=0.005) ] weld_directions = [ Vector3(-0.7071, 0, -0.7071), Vector3(-0.7071, 0, -0.7071) ] work_range = IntervalWithOptimal(min=math.radians(-15), max=math.radians(15), optimal=0) travel_angle = IntervalWithOptimal(min=math.radians(-15), max=math.radians(15), optimal=0) ctwd_range = IntervalWithOptimal(min=0, max=0.015, optimal=0) try: res = service(cdrm_filename=rospkg.get_ros_home() + '/m10ia_on_gantry.welding-cdrm', planning_group_name='robot_with_gantry', robot_group_name='robot', robot_positioner_group_name='gantry', nozzle_link_name='nozzle_link', workpiece_link_name='workpiece_link', planning_timeout=60, weld_points=weld_points, weld_directions=weld_directions, welding_speed=0.01, rx_range=work_range, ry_range=travel_angle, ctwd_range=ctwd_range) except rospy.ServiceException as e: print 'Service exception: ', e return print res
def get_ros_home(): ''' Returns the ROS HOME depending on ROS distribution API. @return: ROS HOME path @rtype: C{str} ''' try: import rospkg.distro distro = rospkg.distro.current_distro_codename() if distro in ['electric', 'diamondback', 'cturtle']: import roslib.rosenv return roslib.rosenv.get_ros_home() else: import rospkg return rospkg.get_ros_home() except: # import traceback # print traceback.format_exc() import roslib.rosenv return roslib.rosenv.get_ros_home()
def _read_rospack_cache(cache, ros_root, ros_package_path): """ Read in rospack_cache data into cache. On-disk cache specifies a ROS_ROOT and ROS_PACKAGE_PATH, which must match the requested environment. @param cache: empty dictionary to store package list in. If no cache argument provided, will use internal _pkg_dir_cache and will return cached answers if available. The format of the cache is {package_name: dir_path, ros_root, ros_package_path}. @type cache: {str: str, str, str} @param ros_package_path: ROS_ROOT value @type ros_root: str @param ros_package_path: ROS_PACKAGE_PATH value or '' if not specified @type ros_package_path: str @return: True if on-disk cache matches and was loaded, false otherwise @rtype: bool """ try: with open(os.path.join(rospkg.get_ros_home(), 'rospack_cache')) as f: for l in f.readlines(): l = l[:-1] if not len(l): continue if l[0] == '#': # check that the cache matches our env if l.startswith('#ROS_ROOT='): if not l[len('#ROS_ROOT='):] == ros_root: return False elif l.startswith('#ROS_PACKAGE_PATH='): if not l[len('#ROS_PACKAGE_PATH=' ):] == ros_package_path: return False else: cache[os.path.basename(l)] = l, ros_root, ros_package_path return True except: pass
def __init__(self): Detector.__init__(self) #----------------------------------------------------------------------- # Create the classifier and download the models #----------------------------------------------------------------------- self.classifier = Classifier(rospkg.get_ros_home()) if self.classifier.need_models(): rospy.logwarn('Need to download models, it may take a while.') self.classifier.download_models() rospy.logwarn('Finished downloading!') self.classifier.initialize() rospy.logwarn('Classifier initialized!') #----------------------------------------------------------------------- # Subscribe to the image feed and initialize other stuff #----------------------------------------------------------------------- rospy.Subscriber('/image_color', Image, self.image_cb, queue_size=1) self.listener = tf.TransformListener() self.field_of_view = math.pi / 4 self.state_count = 0 self.state = Classifier.UNKNOWN self.bridge = CvBridge()
def main(): rospy.init_node('example_quadruped_moveit_config_node') client = actionlib.SimpleActionClient('/cdrm_server/generate_cdrm', GenerateCdrmAction) client.wait_for_server() print 'Generating leg CDRM...' goal = GenerateCdrmGoal(group_name='al', roadmap_k=10, roadmap_size=5000, resolution=0.025, collide_edges=True, collide_tip_link=False) client.send_goal(goal) client.wait_for_result() print 'Saving CDRM...' save_srv = rospy.ServiceProxy('/cdrm_server/save_cdrm', ProcessFile) save_srv(rospkg.get_ros_home() + '/example_quadruped.cdrm') print 'Done'
def _read_rospack_cache(cache, ros_root, ros_package_path): """ Read in rospack_cache data into cache. On-disk cache specifies a ROS_ROOT and ROS_PACKAGE_PATH, which must match the requested environment. @param cache: empty dictionary to store package list in. If no cache argument provided, will use internal _pkg_dir_cache and will return cached answers if available. The format of the cache is {package_name: dir_path, ros_root, ros_package_path}. @type cache: {str: str, str, str} @param ros_package_path: ROS_ROOT value @type ros_root: str @param ros_package_path: ROS_PACKAGE_PATH value or '' if not specified @type ros_package_path: str @return: True if on-disk cache matches and was loaded, false otherwise @rtype: bool """ try: with open(os.path.join(rospkg.get_ros_home(), "rospack_cache")) as f: for l in f.readlines(): l = l[:-1] if not len(l): continue if l[0] == "#": # check that the cache matches our env if l.startswith("#ROS_ROOT="): if not l[len("#ROS_ROOT=") :] == ros_root: return False elif l.startswith("#ROS_PACKAGE_PATH="): if not l[len("#ROS_PACKAGE_PATH=") :] == ros_package_path: return False else: cache[os.path.basename(l)] = l, ros_root, ros_package_path return True except: pass
def where_defined(self, rosdeps): output = "" locations = {} for r in rosdeps: locations[r] = set() rospack = rospkg.RosPack() path = os.path.join(rospkg.get_ros_home(), "rosdep.yaml") rosdep_dict = self.yc.get_specific_rosdeps(path) for r in rosdeps: if r in rosdep_dict: locations[r].add("Override:" + path) for p in rospack.list(): path = os.path.join(rospack.get_path(p), "rosdep.yaml") rosdep_dict = self.yc.get_specific_rosdeps(path) for r in rosdeps: if r in rosdep_dict: addendum = "" if rospack.stack_of(p): addendum = "<<Unused due to package '%s' being in a stack.]]" % p locations[r].add(">>" + path + addendum) rosstack = rospkg.RosStack() for s in rosstack.list(): path = os.path.join(rosstack.get_path(s), "rosdep.yaml") rosdep_dict = self.yc.get_specific_rosdeps(path) for r in rosdeps: if r in rosdep_dict: locations[r].add(path) for rd in locations: output += "%s defined in %s" % (rd, locations[rd]) return output
def SaveDotGraph(self, event): timestr = time.strftime("%Y%m%d-%H%M%S") directory = rospkg.get_ros_home() + '/dotfiles' if not os.path.exists(directory): directory = '.' with wx.FileDialog( self, 'Save dot graph', # May error on Motif due to multiple file types. wildcard='DOT files (.dot)|*.dot|Graphviz files (.gv)|*.gv', defaultDir=directory, defaultFile=timestr + '.dot', style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as file_dialog: if file_dialog.ShowModal() == wx.ID_CANCEL: return filename = file_dialog.GetPath() print('Writing to file: %s' % filename) try: with open(filename, 'w') as f: f.write(self.dotstr) except IOError as e: print('Writing failed:') print(e)
def main(self): """ main command-line entrypoint """ parser = OptionParser( usage="usage: %prog [options] [PACKAGE]...", description= "rosmake recursively builds all dependencies before building a package", prog='rosmake') parser.add_option("--test-only", dest="test_only", default=False, action="store_true", help="only run tests") parser.add_option("-t", dest="test", default=False, action="store_true", help="build and test packages") parser.add_option("-a", "--all", dest="build_all", default=False, action="store_true", help="select all packages") parser.add_option( "-i", "--mark-installed", dest="mark_installed", default=False, action="store_true", help= "On successful build, mark specified packages as installed with ROS_NOBUILD" ) parser.add_option( "-u", "--unmark-installed", dest="unmark_installed", default=False, action="store_true", help= "Remove ROS_NOBUILD from the specified packages. This will not build anything." ) parser.add_option("-v", dest="verbose", default=False, action="store_true", help="display errored builds") parser.add_option("-r", "-k", "--robust", dest="best_effort", default=False, action="store_true", help="do not stop build on error") parser.add_option("--build-everything", dest="robust", default=False, action="store_true", help="build all packages regardless of errors") parser.add_option("-V", dest="full_verbose", default=False, action="store_true", help="display all builds") parser.add_option( "-s", "--specified-only", dest="specified_only", default=False, action="store_true", help="only build packages specified on the command line") parser.add_option("--buildtest", dest="buildtest", action="append", help="package to buildtest") parser.add_option("--buildtest1", dest="buildtest1", action="append", help="package to buildtest1") parser.add_option("--output", dest="output_dir", action="store", help="where to output results") parser.add_option("--pre-clean", dest="pre_clean", action="store_true", help="run make clean first") parser.add_option("--bootstrap", dest="bootstrap", default=False, action="store_true", help="DEPRECATED, UNUSED") parser.add_option("--disable-logging", dest="logging_enabled", default=True, action="store_false", help="turn off all logs") parser.add_option("--target", dest="target", action="store", help="run make with this target") parser.add_option( "--pjobs", dest="ros_parallel_jobs", type="int", action="store", help= "Override ROS_PARALLEL_JOBS environment variable with this number of jobs." ) parser.add_option("--threads", dest="threads", type="int", default=os.environ.get("ROSMAKE_THREADS", parallel_build.num_cpus()), action="store", help="Build up to N packages in parallel") parser.add_option("--profile", dest="print_profile", default=False, action="store_true", help="print time profile after build") parser.add_option( "--skip-blacklist", dest="skip_blacklist", default=False, action="store_true", help= "skip packages containing a file called ROS_BUILD_BLACKLIST (Default behavior will ignore the presence of ROS_BUILD_BLACKLIST)" ) parser.add_option( "--skip-blacklist-osx", dest="skip_blacklist_osx", default=False, action="store_true", help= "deprecated option. it will do nothing, please use platform declarations and --require-platform instead" ) parser.add_option( "--status-rate", dest="status_update_rate", action="store", help="How fast to update the status bar in Hz. Default: 5Hz") options, args = parser.parse_args() self.printer.print_all('rosmake starting...') rospack = self.rospack rosstack = self.rosstack testing = False building = True if options.test_only: testing = True building = False elif options.test: testing = True if options.ros_parallel_jobs: self.ros_parallel_jobs = options.ros_parallel_jobs self.robust_build = options.robust self.best_effort = options.best_effort self.threads = options.threads self.skip_blacklist = options.skip_blacklist if options.skip_blacklist_osx: self.printer.print_all( "Option --skip-blacklist-osx is deprecated. It will do nothing, please use platform declarations and --require-platform instead" ) self.logging_enabled = options.logging_enabled # pass through verbosity options self.printer.full_verbose = options.full_verbose self.printer.verbose = options.verbose if options.status_update_rate: if float(options.status_update_rate) > 0: self.printer.duration = 1.0 / float(options.status_update_rate) else: self.printer.duration = 0 packages = [] #load packages from arguments if options.build_all: packages = [ x for x in rospack.list() if not self.rospack.get_manifest(x).is_catkin ] self.printer.print_all("Building all packages") else: # no need to extend if all already selected if options.buildtest: for p in options.buildtest: packages.extend(self.rospack.get_depends_on(p)) self.printer.print_all( "buildtest requested for package %s adding it and all dependent packages: " % p) if options.buildtest1: for p in options.buildtest1: packages.extend( self.rospack.get_depends_on(p, implicit=False)) self.printer.print_all( "buildtest1 requested for package %s adding it and all depends-on1 packages: " % p) if len(packages) == 0 and len(args) == 0: p = os.path.basename(os.path.abspath('.')) try: if os.path.samefile(rospack.get_path(p), '.'): packages = [p] self.printer.print_all( "No package specified. Building %s" % packages) else: self.printer.print_all( "No package selected and the current directory is not the correct path for package '%s'." % p) except rospkg.ResourceNotFound as ex: try: stack_dir = rosstack.get_path(p) if os.path.samefile(stack_dir, '.'): packages = [p] self.printer.print_all( "No package specified. Building stack %s" % packages) else: self.printer.print_all( "No package or stack arguments and the current directory is not the correct path for stack '%s'. Stack directory is: %s." % (p, rosstack.get_path(p))) except: self.printer.print_all( "No package or stack specified. And current directory '%s' is not a package name or stack name." % p) else: packages.extend(args) self.printer.print_all("Packages requested are: %s" % packages) # Setup logging if self.logging_enabled: date_time_stamp = "rosmake_output-" + time.strftime( "%Y%m%d-%H%M%S") if options.output_dir: #self.log_dir = os.path.join(os.getcwd(), options.output_dir, date_time_stamp); self.log_dir = os.path.abspath(options.output_dir) else: self.log_dir = os.path.join(rospkg.get_ros_home(), "rosmake", date_time_stamp) self.printer.print_all("Logging to directory %s" % self.log_dir) if os.path.exists( self.log_dir) and not os.path.isdir(self.log_dir): self.printer.print_all( "Log destination %s is a file; please remove it or choose a new destination" % self.log_dir) sys.exit(1) if not os.path.exists(self.log_dir): self.printer.print_verbose("%s doesn't exist: creating" % self.log_dir) makedirs_with_parent_perms(self.log_dir) self.printer.print_verbose("Finished setting up logging") stacks_arguments = [s for s in packages if s in rosstack.list()] (self.specified_packages, self.rejected_packages) = rospkg.expand_to_packages( packages, rospack, rosstack) self.printer.print_all("Expanded args %s to:\n%s" % (packages, self.specified_packages)) if self.rejected_packages: self.printer.print_all( "WARNING: The following args could not be parsed as stacks or packages: %s" % self.rejected_packages) if len(self.specified_packages) + len(stacks_arguments) == 0: self.printer.print_all( "ERROR: No arguments could be parsed into valid package or stack names." ) self.printer.running = False return False if options.unmark_installed: for p in self.specified_packages: if self.flag_tracker.remove_nobuild(p): self.printer.print_all("Removed ROS_NOBUILD from %s" % p) self.printer.running = False return True required_packages = self.specified_packages[:] # catch packages of dependent stacks when specified stack is zero-sized #3528 # add them to required list but not the specified list. for s in stacks_arguments: if not rosstack.packages_of(s): for d in rosstack.get_depends(s, implicit=False): try: required_packages.extend(rosstack.packages_of(d)) except ResourceNotFound: self.printer.print_all( 'WARNING: The stack "%s" was not found. We will assume it is using the new buildsystem and try to continue...' % d) # deduplicate required_packages required_packages = list(set(required_packages)) # make sure all dependencies are satisfied and if not warn buildable_packages = [] for p in required_packages: (buildable, error, str) = self.flag_tracker.can_build(p, self.skip_blacklist, [], False) if buildable: buildable_packages.append(p) #generate the list of packages necessary to build(in order of dependencies) counter = 0 for p in required_packages: counter = counter + 1 self.printer.print_verbose( "Processing %s and all dependencies(%d of %d requested)" % (p, counter, len(packages))) self.build_or_recurse(p) # remove extra packages if specified-only flag is set if options.specified_only: new_list = [] for pkg in self.build_list: if pkg in self.specified_packages: new_list.append(pkg) self.dependency_tracker = parallel_build.DependencyTracker( self.specified_packages, rospack=self.rospack ) # this will make the tracker only respond to packages in the list self.printer.print_all( "specified-only option was used, only building packages %s" % new_list) self.build_list = new_list if options.pre_clean: build_queue = parallel_build.BuildQueue( self.build_list, parallel_build.DependencyTracker([], rospack=self.rospack), robust_build=True) self.parallel_build_pkgs(build_queue, "clean", threads=options.threads) build_passed = True if building: self.printer.print_verbose("Building packages %s" % self.build_list) build_queue = parallel_build.BuildQueue(self.build_list, self.dependency_tracker, robust_build=options.robust or options.best_effort) if None not in self.result.keys(): self.result[None] = {} build_passed = self.parallel_build_pkgs(build_queue, options.target, threads=options.threads) tests_passed = True if build_passed and testing: self.printer.print_verbose("Testing packages %s" % packages) build_queue = parallel_build.BuildQueue( self.specified_packages, parallel_build.DependencyTracker(self.specified_packages, rospack=self.rospack), robust_build=True) tests_passed = self.parallel_build_pkgs(build_queue, "test", threads=1) if options.mark_installed: if build_passed and tests_passed: for p in self.specified_packages: if self.flag_tracker.add_nobuild(p): self.printer.print_all( "Marking %s as installed with a ROS_NOBUILD file" % p) else: self.printer.print_all( "All builds and tests did not pass cannot mark packages as installed. " ) self.finish_time = time.time() #note: before profiling self.generate_summary_output(self.log_dir) if options.print_profile: self.printer.print_all(self.get_profile_string()) self.printer.running = False return build_passed and tests_passed
def start(self): """ Start the process. @raise FatalProcessLaunch: if process cannot be started and it is not likely to ever succeed """ super(LocalProcess, self).start() try: self.lock.acquire() if self.started: _logger.info("process[%s]: restarting os process", self.name) else: _logger.info("process[%s]: starting os process", self.name) self.started = self.stopped = False full_env = self.env # _configure_logging() can mutate self.args try: logfileout, logfileerr = self._configure_logging() except Exception as e: _logger.error(traceback.format_exc()) printerrlog("[%s] ERROR: unable to configure logging [%s]"%(self.name, str(e))) # it's not safe to inherit from this process as # rostest changes stdout to a StringIO, which is not a # proper file. logfileout, logfileerr = subprocess.PIPE, subprocess.PIPE if self.cwd == 'node': cwd = os.path.dirname(self.args[0]) elif self.cwd == 'cwd': cwd = os.getcwd() elif self.cwd == 'ros-root': cwd = get_ros_root() else: cwd = rospkg.get_ros_home() if not os.path.exists(cwd): try: os.makedirs(cwd) except OSError: # exist_ok=True pass _logger.info("process[%s]: start w/ args [%s]", self.name, self.args) _logger.info("process[%s]: cwd will be [%s]", self.name, cwd) try: self.popen = subprocess.Popen(self.args, cwd=cwd, stdout=logfileout, stderr=logfileerr, env=full_env, close_fds=True, preexec_fn=os.setsid) except OSError as e: self.started = True # must set so is_alive state is correct _logger.error("OSError(%d, %s)", e.errno, e.strerror) if e.errno == 8: #Exec format error raise FatalProcessLaunch("Unable to launch [%s]. \nIf it is a script, you may be missing a '#!' declaration at the top."%self.name) elif e.errno == 2: #no such file or directory raise FatalProcessLaunch("""Roslaunch got a '%s' error while attempting to run: %s Please make sure that all the executables in this command exist and have executable permission. This is often caused by a bad launch-prefix."""%(e.strerror, ' '.join(self.args))) else: raise FatalProcessLaunch("unable to launch [%s]: %s"%(' '.join(self.args), e.strerror)) self.started = True # Check that the process is either still running (poll returns # None) or that it completed successfully since when we # launched it above (poll returns the return code, 0). poll_result = self.popen.poll() if poll_result is None or poll_result == 0: self.pid = self.popen.pid printlog_bold("process[%s]: started with pid [%s]"%(self.name, self.pid)) return True else: printerrlog("failed to start local process: %s"%(' '.join(self.args))) return False finally: self.lock.release()
def start(self): """ Start the process. @raise FatalProcessLaunch: if process cannot be started and it is not likely to ever succeed """ super(LocalProcess, self).start() try: self.lock.acquire() if self.started: _logger.info("process[%s]: restarting os process", self.name) else: _logger.info("process[%s]: starting os process", self.name) self.started = self.stopped = False full_env = self.env # _configure_logging() can mutate self.args try: logfileout, logfileerr = self._configure_logging() except Exception as e: _logger.error(traceback.format_exc()) printerrlog("[%s] ERROR: unable to configure logging [%s]" % (self.name, str(e))) # it's not safe to inherit from this process as # rostest changes stdout to a StringIO, which is not a # proper file. logfileout, logfileerr = subprocess.PIPE, subprocess.PIPE if self.cwd == 'node': cwd = os.path.dirname(self.args[0]) elif self.cwd == 'cwd': cwd = os.getcwd() elif self.cwd == 'ros-root': cwd = get_ros_root() else: cwd = rospkg.get_ros_home() if not os.path.exists(cwd): try: os.makedirs(cwd) except OSError: # exist_ok=True pass _logger.info("process[%s]: start w/ args [%s]", self.name, self.args) _logger.info("process[%s]: cwd will be [%s]", self.name, cwd) try: self.popen = subprocess.Popen(self.args, cwd=cwd, stdout=logfileout, stderr=logfileerr, env=full_env, close_fds=True, preexec_fn=os.setsid) except OSError as e: self.started = True # must set so is_alive state is correct _logger.error("OSError(%d, %s)", e.errno, e.strerror) if e.errno == 8: #Exec format error raise FatalProcessLaunch( "Unable to launch [%s]. \nIf it is a script, you may be missing a '#!' declaration at the top." % self.name) elif e.errno == 2: #no such file or directory raise FatalProcessLaunch( """Roslaunch got a '%s' error while attempting to run: %s Please make sure that all the executables in this command exist and have executable permission. This is often caused by a bad launch-prefix.""" % (e.strerror, ' '.join(self.args))) else: raise FatalProcessLaunch("unable to launch [%s]: %s" % (' '.join(self.args), e.strerror)) self.started = True # Check that the process is either still running (poll returns # None) or that it completed successfully since when we # launched it above (poll returns the return code, 0). poll_result = self.popen.poll() if poll_result is None or poll_result == 0: self.pid = self.popen.pid printlog_bold("process[%s]: started with pid [%s]" % (self.name, self.pid)) return True else: printerrlog("failed to start local process: %s" % (' '.join(self.args))) return False finally: self.lock.release()
def GetCachePath(self, body): import os cache_dir = rospkg.get_ros_home() cache_name = '{0:s}.chomp'.format(body.GetKinematicsGeometryHash()) return os.path.join(cache_dir, cache_name)
def delete_cache(): from rospkg import get_ros_home p = os.path.join(get_ros_home(), "rospack_cache") if os.path.exists(p): os.remove(p)
def __init__(self): rospack = rospkg.RosPack() jsk_perception_datasets_path = osp.join( rospack.get_path('jsk_perception'), 'learning_datasets') parser = argparse.ArgumentParser() # Dataset directory parser.add_argument('--train_dataset_dir', type=str, default=osp.join(jsk_perception_datasets_path, 'kitchen_dataset', 'train')) parser.add_argument('--val_dataset_dir', type=str, default=osp.join(jsk_perception_datasets_path, 'kitchen_dataset', 'test')) # Model parser.add_argument( '--model_name', type=str, default='resnet50', choices=['vgg16', 'resnet50', 'resnet101']) # Training parameters parser.add_argument('--gpu', type=int, default=0) parser.add_argument('--batch_size', type=int, default=1) parser.add_argument('--max_epoch', type=int, default=100) parser.add_argument('--lr', type=float, default=0.00125) parser.add_argument('--weight_decay', type=float, default=0.0001) parser.add_argument('--out_dir', type=str, default=None) parser.add_argument('--progressbar_update_interval', type=float, default=10) parser.add_argument('--print_interval', type=float, default=100) parser.add_argument('--print_interval_type', type=str, default='iteration', choices=['epoch', 'iteration']) parser.add_argument('--log_interval', type=float, default=10) parser.add_argument('--log_interval_type', type=str, default='iteration', choices=['epoch', 'iteration']) parser.add_argument('--plot_interval', type=float, default=5) parser.add_argument('--plot_interval_type', type=str, default='epoch', choices=['epoch', 'iteration']) parser.add_argument('--eval_interval', type=float, default=10) parser.add_argument('--eval_interval_type', type=str, default='epoch', choices=['epoch', 'iteration']) parser.add_argument('--save_interval', type=float, default=10) parser.add_argument('--save_interval_type', type=str, default='epoch', choices=['epoch', 'iteration']) args = parser.parse_args() self.train_dataset_dir = args.train_dataset_dir self.val_dataset_dir = args.val_dataset_dir self.model_name = args.model_name self.gpu = args.gpu self.batch_size = args.batch_size self.max_epoch = args.max_epoch self.lr = args.lr self.weight_decay = args.weight_decay self.out_dir = args.out_dir self.progressbar_update_interval = args.progressbar_update_interval self.print_interval = args.print_interval self.print_interval_type = args.print_interval_type self.log_interval = args.log_interval self.log_interval_type = args.log_interval_type self.plot_interval = args.plot_interval self.plot_interval_type = args.plot_interval_type self.eval_interval = args.eval_interval self.eval_interval_type = args.eval_interval_type self.save_interval = args.save_interval self.save_interval_type = args.save_interval_type now = datetime.datetime.now() self.timestamp_iso = now.isoformat() timestamp = now.strftime('%Y%m%d-%H%M%S') if self.out_dir is None: self.out_dir = osp.join( rospkg.get_ros_home(), 'learning_logs', timestamp) # Main process self.load_dataset() self.load_model() self.setup_optimizer() self.setup_iterator() self.setup_trainer() self.trainer.run()
def OpenDatabase(file_path): global CoffeeDatabase path = os.path.join(rospkg.get_ros_home(), file_path) CoffeeDatabase = shelve.open(path, flag = 'c', writeback = True)
try: from cStringIO import StringIO except ImportError: from io import BytesIO as StringIO import hashlib import logging import os from rosdistro.loader import load_url import rospkg import rospkg.environment import sys from .indexer import RappIndexer, read_tarball _rapp_repositories_list_file = os.path.join(rospkg.get_ros_home(), 'rocon', 'rapp', 'rapp.list') logger = logging.getLogger('rapp_repositories') logger.addHandler(logging.StreamHandler(sys.stderr)) #logger.setLevel(logging.DEBUG) def load_uris(): ''' Loads the registered repository URIs from a configuration file. :returns: the list of URIs :rtype: [str] ''' try: with open(_rapp_repositories_list_file, 'r') as h:
def get_dir(): """Get the location of the local checkout of the wiki""" return os.path.join(rospkg.get_ros_home(), "driving_wiki")
def run_jobs_ajax(request, email, ros_distro, repo_list): logger.info("---") logger.info(email) logger.info(ros_distro) logger.info(repo_list) logger.info("---") if '_dry' in ros_distro: ros_distro = ros_distro.split("_")[0] conf_file = os.path.join( rospkg.get_ros_home(), 'buildfarm', 'server.yaml' ) f = open(conf_file) info = yaml.load(f.read()) script = find_executable('generate_groovy_prerelease.py') if not script: logger.error('Could not find generate_groovy_prerelease.py script') assert False command = '%s %s %s --repeat 0 --email %s --rosdistro %s' % ( script, info['username'], info['password'], email, ros_distro ) for r in repo_list: command += " --stack %s" % r elif '_wet' in ros_distro: ros_distro = ros_distro.split("_")[0] script = find_executable('generate_jenkins_prerelease') if not script: logger.error('Could not find generate_jenkins_prerelease script') assert False command = "%s %s %s %s" % ( script, email, ros_distro, ' '.join(['%s %s' % (r, v) for r, v in repo_list.iteritems()]) ) else: assert False, 'Neither wet nor dry' logger.info("Executing command") logger.info(command) helper = subprocess.Popen( ['bash', '-c', command], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) res, err = helper.communicate() logger.info(str(res)) logger.info(str(err)) res = res.replace('<', '<a href="') res = res.replace('>', '">the Jenkins server</a>') res = res.replace('\n', '<br>') logger.info(str(res)) success = 'true' if helper.returncode != 0: success = 'false' return simplejson.dumps({ 'success': success, 'command': command, 'std_out': res, 'std_err': err })
def _get_check_dirs(): home_dir = rospkg.get_ros_home() log_dir = rospkg.get_log_dir() dirs = [(log_dir, "ROS node logs"), (os.path.join(home_dir, "rosmake"), "rosmake logs")] return [x for x in dirs if os.path.isdir(x[0])]
def get_sources_cache_dir(): ros_home = rospkg.get_ros_home() return os.path.join(ros_home, 'rosdep', SOURCES_CACHE_DIR)
def connected_file(): return os.path.join(rospkg.get_ros_home(), 'turtlebot-connected')
_cache.packages[distro_id][name] = CacheItem(PackageCacheData(path=None, manifest=manifest), time()) _store_cache() return manifest raise KeyError() def is_known_pkg(self, name): if name in self.known_catkin_pkgs or name in self.known_other_pkgs: return True if self.rosdep is None: return False return self.rosdep.has_key(name) _cache = None try: from rospkg import get_ros_home _cache_dir = os.path.join(get_ros_home(), "catkin_lint") except ImportError: _cache_dir = os.path.join(os.path.expanduser("~"), ".ros", "catkin_lint") def _load_cache(): global _cache global _cache_dir try: with open(os.path.join(_cache_dir, "packages.pickle"), "rb") as f: _cache = pickle.loads(f.read()) if not isinstance(_cache, Cache) or _cache.version != 1: raise RuntimeError() except: _cache = Cache()
def main(self): """ main command-line entrypoint """ parser = OptionParser(usage="usage: %prog [options] [PACKAGE]...", description="rosmake recursively builds all dependencies before building a package", prog='rosmake') parser.add_option("--test-only", dest="test_only", default=False, action="store_true", help="only run tests") parser.add_option("-t", dest="test", default=False, action="store_true", help="build and test packages") parser.add_option("-a", "--all", dest="build_all", default=False, action="store_true", help="select all packages") parser.add_option("-i", "--mark-installed", dest="mark_installed", default=False, action="store_true", help="On successful build, mark specified packages as installed with ROS_NOBUILD") parser.add_option("-u", "--unmark-installed", dest="unmark_installed", default=False, action="store_true", help="Remove ROS_NOBUILD from the specified packages. This will not build anything.") parser.add_option("-v", dest="verbose", default=False, action="store_true", help="display errored builds") parser.add_option("-r","-k", "--robust", dest="best_effort", default=False, action="store_true", help="do not stop build on error") parser.add_option("--build-everything", dest="robust", default=False, action="store_true", help="build all packages regardless of errors") parser.add_option("-V", dest="full_verbose", default=False, action="store_true", help="display all builds") parser.add_option("-s", "--specified-only", dest="specified_only", default=False, action="store_true", help="only build packages specified on the command line") parser.add_option("--buildtest", dest="buildtest", action="append", help="package to buildtest") parser.add_option("--buildtest1", dest="buildtest1", action="append", help="package to buildtest1") parser.add_option("--output", dest="output_dir", action="store", help="where to output results") parser.add_option("--pre-clean", dest="pre_clean", action="store_true", help="run make clean first") parser.add_option("--bootstrap", dest="bootstrap", default=False, action="store_true", help="DEPRECATED, UNUSED") parser.add_option("--disable-logging", dest="logging_enabled", default=True, action="store_false", help="turn off all logs") parser.add_option("--target", dest="target", action="store", help="run make with this target") parser.add_option("--pjobs", dest="ros_parallel_jobs", type="int", action="store", help="Override ROS_PARALLEL_JOBS environment variable with this number of jobs.") parser.add_option("--threads", dest="threads", type="int", default = os.environ.get("ROSMAKE_THREADS", parallel_build.num_cpus()), action="store", help="Build up to N packages in parallel") parser.add_option("--profile", dest="print_profile", default=False, action="store_true", help="print time profile after build") parser.add_option("--skip-blacklist", dest="skip_blacklist", default=False, action="store_true", help="skip packages containing a file called ROS_BUILD_BLACKLIST (Default behavior will ignore the presence of ROS_BUILD_BLACKLIST)") parser.add_option("--skip-blacklist-osx", dest="skip_blacklist_osx", default=False, action="store_true", help="deprecated option. it will do nothing, please use platform declarations and --require-platform instead") parser.add_option("--status-rate", dest="status_update_rate", action="store", help="How fast to update the status bar in Hz. Default: 5Hz") options, args = parser.parse_args() self.printer.print_all('rosmake starting...') rospack = self.rospack rosstack = self.rosstack testing = False building = True if options.test_only: testing = True building = False elif options.test: testing = True if options.ros_parallel_jobs: self.ros_parallel_jobs = options.ros_parallel_jobs self.robust_build = options.robust self.best_effort = options.best_effort self.threads = options.threads self.skip_blacklist = options.skip_blacklist if options.skip_blacklist_osx: self.printer.print_all("Option --skip-blacklist-osx is deprecated. It will do nothing, please use platform declarations and --require-platform instead"); self.logging_enabled = options.logging_enabled # pass through verbosity options self.printer.full_verbose = options.full_verbose self.printer.verbose = options.verbose if options.status_update_rate: if float(options.status_update_rate)> 0: self.printer.duration = 1.0/float(options.status_update_rate) else: self.printer.duration = 0 packages = [] #load packages from arguments if options.build_all: packages = [x for x in rospack.list() if not self.rospack.get_manifest(x).is_catkin] self.printer.print_all( "Building all packages") else: # no need to extend if all already selected if options.buildtest: for p in options.buildtest: packages.extend(self.rospack.get_depends_on(p)) self.printer.print_all( "buildtest requested for package %s adding it and all dependent packages: "%p) if options.buildtest1: for p in options.buildtest1: packages.extend(self.rospack.get_depends_on(p, implicit=False)) self.printer.print_all( "buildtest1 requested for package %s adding it and all depends-on1 packages: "%p) if len(packages) == 0 and len(args) == 0: p = os.path.basename(os.path.abspath('.')) try: if os.path.samefile(rospack.get_path(p), '.'): packages = [p] self.printer.print_all( "No package specified. Building %s"%packages) else: self.printer.print_all("No package selected and the current directory is not the correct path for package '%s'."%p) except rospkg.ResourceNotFound as ex: try: stack_dir = rosstack.get_path(p) if os.path.samefile(stack_dir, '.'): packages = [p] self.printer.print_all( "No package specified. Building stack %s"%packages) else: self.printer.print_all("No package or stack arguments and the current directory is not the correct path for stack '%s'. Stack directory is: %s."%(p, rosstack.get_path(p))) except: self.printer.print_all("No package or stack specified. And current directory '%s' is not a package name or stack name."%p) else: packages.extend(args) self.printer.print_all( "Packages requested are: %s"%packages) # Setup logging if self.logging_enabled: date_time_stamp = "rosmake_output-" + time.strftime("%Y%m%d-%H%M%S") if options.output_dir: #self.log_dir = os.path.join(os.getcwd(), options.output_dir, date_time_stamp); self.log_dir = os.path.abspath(options.output_dir) else: self.log_dir = os.path.join(rospkg.get_ros_home(), "rosmake", date_time_stamp); self.printer.print_all("Logging to directory %s"%self.log_dir) if os.path.exists (self.log_dir) and not os.path.isdir(self.log_dir): self.printer.print_all( "Log destination %s is a file; please remove it or choose a new destination"%self.log_dir) sys.exit(1) if not os.path.exists (self.log_dir): self.printer.print_verbose("%s doesn't exist: creating"%self.log_dir) makedirs_with_parent_perms(self.log_dir) self.printer.print_verbose("Finished setting up logging") stacks_arguments = [s for s in packages if s in rosstack.list()] (self.specified_packages, self.rejected_packages) = rospkg.expand_to_packages(packages, rospack, rosstack) self.printer.print_all("Expanded args %s to:\n%s"%(packages, self.specified_packages)) if self.rejected_packages: self.printer.print_all("WARNING: The following args could not be parsed as stacks or packages: %s"%self.rejected_packages) if len(self.specified_packages) + len(stacks_arguments) == 0: self.printer.print_all("ERROR: No arguments could be parsed into valid package or stack names.") self.printer.running = False return False if options.unmark_installed: for p in self.specified_packages: if self.flag_tracker.remove_nobuild(p): self.printer.print_all("Removed ROS_NOBUILD from %s"%p) self.printer.running = False return True required_packages = self.specified_packages[:] # catch dependent packages which are inside of zero sized stacks #3528 # add them to required list but not the specified list. for s in stacks_arguments: for d in rosstack.get_depends(s, implicit=False): required_packages.extend(rosstack.packages_of(d)) # deduplicate required_packages required_packages = list(set(required_packages)) # make sure all dependencies are satisfied and if not warn buildable_packages = [] for p in required_packages: (buildable, error, str) = self.flag_tracker.can_build(p, self.skip_blacklist, [], False) if buildable: buildable_packages.append(p) #generate the list of packages necessary to build(in order of dependencies) counter = 0 for p in required_packages: counter = counter + 1 self.printer.print_verbose( "Processing %s and all dependencies(%d of %d requested)"%(p, counter, len(packages))) self.build_or_recurse(p) # remove extra packages if specified-only flag is set if options.specified_only: new_list = [] for pkg in self.build_list: if pkg in self.specified_packages: new_list.append(pkg) self.dependency_tracker = parallel_build.DependencyTracker(self.specified_packages, rospack=self.rospack) # this will make the tracker only respond to packages in the list self.printer.print_all("specified-only option was used, only building packages %s"%new_list) self.build_list = new_list if options.pre_clean: build_queue = parallel_build.BuildQueue(self.build_list, parallel_build.DependencyTracker([], rospack=self.rospack), robust_build = True) self.parallel_build_pkgs(build_queue, "clean", threads = options.threads) build_passed = True if building: self.printer.print_verbose ("Building packages %s"% self.build_list) build_queue = parallel_build.BuildQueue(self.build_list, self.dependency_tracker, robust_build = options.robust or options.best_effort) if None not in self.result.keys(): self.result[None] = {} build_passed = self.parallel_build_pkgs(build_queue, options.target, threads = options.threads) tests_passed = True if build_passed and testing: self.printer.print_verbose ("Testing packages %s"% packages) build_queue = parallel_build.BuildQueue(self.specified_packages, parallel_build.DependencyTracker(self.specified_packages, rospack=self.rospack), robust_build = True) tests_passed = self.parallel_build_pkgs(build_queue, "test", threads = 1) if options.mark_installed: if build_passed and tests_passed: for p in self.specified_packages: if self.flag_tracker.add_nobuild(p): self.printer.print_all("Marking %s as installed with a ROS_NOBUILD file"%p) else: self.printer.print_all("All builds and tests did not pass cannot mark packages as installed. ") self.finish_time = time.time() #note: before profiling self.generate_summary_output(self.log_dir) if options.print_profile: self.printer.print_all (self.get_profile_string()) self.printer.running = False return build_passed and tests_passed