Skip to content

Commit a4e7f3b

Browse files
author
Ivan Shalnov
committed
Added model parameter to the install script, inspired by TURTLEBOT3_MODEL env variable
1 parent c97bd5a commit a4e7f3b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/robot_upstart/install_script.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def get_argument_parser():
6868
help="Create symbolic link to job launch files instead of copying them.")
6969
p.add_argument("--wait", action='store_true',
7070
help="Pass a wait flag to roslaunch.")
71+
p.add_argument("--model", type=str, metavar="MODEL",
72+
help="Specify the model of your robot if not specified under ROBOT_MODEL")
7173

7274
return p
7375

@@ -85,7 +87,7 @@ def main():
8587
j = robot_upstart.Job(
8688
name=job_name, interface=args.interface, user=args.user,
8789
workspace_setup=args.setup, rosdistro=args.rosdistro,
88-
master_uri=args.master, log_path=args.logdir)
90+
master_uri=args.master, log_path=args.logdir, model=args.model)
8991

9092
for this_pkgpath in args.pkgpath:
9193
pkg, pkgpath = this_pkgpath.split('/', 1)

src/robot_upstart/job.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Job(object):
4040
""" Represents a ROS configuration to launch on machine startup. """
4141

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

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

110+
# Sets the model environment variable if provided, else results in
111+
# ROBOT_MODEL=ROBOT
112+
if model:
113+
self.model = name.upper() + '_MODEL=' + model
114+
else:
115+
try:
116+
self.model = name.upper() + '_MODEL=' + os.environ[name.upper() + '_MODEL']
117+
except KeyError:
118+
self.model = name.upper() + '_MODEL=ROBOT'
119+
108120
def add(self, package=None, filename=None, glob=None):
109121
""" Add launch or other configuration files to Job.
110122

templates/job-start.em

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export ROS_MASTER_URI=@(master_uri)
6767
@[else]@
6868
export ROS_MASTER_URI=http://127.0.0.1:11311
6969
@[end if]@
70+
@[if model]@
71+
export @(model)
72+
@[end if]@
7073
export ROS_HOME=${ROS_HOME:=$(echo ~@(user))/.ros}
7174
export ROS_LOG_DIR=$log_path
7275

0 commit comments

Comments
 (0)