Skip to content

Commit

Permalink
Added model parameter to the install script, inspired by TURTLEBOT3_M…
Browse files Browse the repository at this point in the history
…ODEL env variable
  • Loading branch information
Ivan Shalnov committed Jan 13, 2021
1 parent c97bd5a commit a4e7f3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/robot_upstart/install_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def get_argument_parser():
help="Create symbolic link to job launch files instead of copying them.")
p.add_argument("--wait", action='store_true',
help="Pass a wait flag to roslaunch.")
p.add_argument("--model", type=str, metavar="MODEL",
help="Specify the model of your robot if not specified under ROBOT_MODEL")

return p

Expand All @@ -85,7 +87,7 @@ def main():
j = robot_upstart.Job(
name=job_name, interface=args.interface, user=args.user,
workspace_setup=args.setup, rosdistro=args.rosdistro,
master_uri=args.master, log_path=args.logdir)
master_uri=args.master, log_path=args.logdir, model=args.model)

for this_pkgpath in args.pkgpath:
pkg, pkgpath = this_pkgpath.split('/', 1)
Expand Down
14 changes: 13 additions & 1 deletion src/robot_upstart/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Job(object):
""" Represents a ROS configuration to launch on machine startup. """

def __init__(self, name="ros", interface=None, user=None, workspace_setup=None,
rosdistro=None, master_uri=None, log_path=None):
rosdistro=None, master_uri=None, log_path=None, model=None):
"""Construct a new Job definition.
:param name: Name of job to create. Defaults to "ros", but you might
Expand All @@ -67,6 +67,8 @@ def __init__(self, name="ros", interface=None, user=None, workspace_setup=None,
default of using /tmp, it is the user's responsibility to manage log
rotation.
:type log_path: str
:param model: Your robot model if not specified under ROBOT_MODEL.
:type model: str
"""

self.name = name
Expand Down Expand Up @@ -105,6 +107,16 @@ def __init__(self, name="ros", interface=None, user=None, workspace_setup=None,
# startup job itself. List of strs.
self.files = []

# Sets the model environment variable if provided, else results in
# ROBOT_MODEL=ROBOT
if model:
self.model = name.upper() + '_MODEL=' + model
else:
try:
self.model = name.upper() + '_MODEL=' + os.environ[name.upper() + '_MODEL']
except KeyError:
self.model = name.upper() + '_MODEL=ROBOT'

def add(self, package=None, filename=None, glob=None):
""" Add launch or other configuration files to Job.
Expand Down
3 changes: 3 additions & 0 deletions templates/job-start.em
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export ROS_MASTER_URI=@(master_uri)
@[else]@
export ROS_MASTER_URI=http://127.0.0.1:11311
@[end if]@
@[if model]@
export @(model)
@[end if]@
export ROS_HOME=${ROS_HOME:=$(echo ~@(user))/.ros}
export ROS_LOG_DIR=$log_path

Expand Down

0 comments on commit a4e7f3b

Please sign in to comment.