Skip to content

Commit 7f68cb2

Browse files
committed
graft in code/structure from rvctool, remove vision stuff
1 parent c54c194 commit 7f68cb2

File tree

1 file changed

+73
-47
lines changed

1 file changed

+73
-47
lines changed

roboticstoolbox/bin/rtbtool.py

+73-47
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import sys
2424
from importlib.metadata import version
2525

26+
27+
2628
try:
2729
from colored import fg, bg, attr
2830

@@ -51,17 +53,12 @@
5153
puma = models.DH.Puma560()
5254
panda = models.DH.Panda()
5355

54-
55-
def main():
56-
# setup defaults
57-
np.set_printoptions(
58-
linewidth=120,
59-
formatter={"float": lambda x: f"{0:8.4g}" if abs(x) < 1e-10 else f"{x:8.4g}"},
60-
)
61-
56+
def parse_arguments():
6257
parser = argparse.ArgumentParser("Robotics Toolbox shell")
6358
parser.add_argument("script", default=None, nargs="?", help="specify script to run")
64-
parser.add_argument("--backend", "-b", default=None, help="specify Matplotlib backend")
59+
parser.add_argument(
60+
"--backend", "-B", default=None, help="specify graphics backend"
61+
)
6562
parser.add_argument(
6663
"--color",
6764
"-c",
@@ -78,6 +75,14 @@ def main():
7875
default=None,
7976
help="execution result prefix, include {} for execution count number",
8077
)
78+
parser.add_argument(
79+
"-b",
80+
"--no-banner",
81+
dest="banner",
82+
default=True,
83+
action="store_false",
84+
help="suppress startup banner",
85+
)
8186
parser.add_argument(
8287
"--showassign",
8388
"-a",
@@ -89,10 +94,6 @@ def main():
8994
"--book", default=False, action="store_true",
9095
help="use defaults as per RVC book"
9196
)
92-
parser.add_argument(
93-
"--vision", default=False, action="store_true",
94-
help="import vision toolbox (MVTB)"
95-
)
9697
parser.add_argument(
9798
"--ansi",
9899
default=False,
@@ -113,38 +114,25 @@ def main():
113114
action="store_true",
114115
help="use Swift as default backend",
115116
)
116-
args = parser.parse_args()
117+
args, rest = parser.parse_known_args()
118+
119+
# remove the arguments we've just parsed from sys.argv so that IPython can have a
120+
# go at them later
121+
sys.argv = [sys.argv[0]] + rest
117122

118123
# TODO more options
119124
# color scheme, light/dark
120125
# silent startup
121126

122-
sys.argv = [sys.argv[0]]
123-
124-
if args.book:
125-
# set book options
126-
args.resultprefix = ""
127-
args.prompt = ">>> "
128-
args.showassign = True
129-
args.ansi = False
130-
args.examples = True
131-
132-
# set default backend for Robot.plot
133-
if args.swift:
134-
Robot.default_backend = "swift"
135-
136-
# set matrix printing mode for spatialmath
137-
SE3._ansimatrix = args.ansi
138-
139-
# set default matplotlib backend
140-
if args.backend is not None:
141-
print(f"Using matplotlb backend {args.backend}")
142-
mpl.use(args.backend)
127+
if args.script is not None:
128+
args.banner = False
143129

144-
# build the banner, import * packages and their versions
130+
return args
145131

132+
def make_banner():
146133
# banner template
147134
# https://patorjk.com/software/taag/#p=display&f=Cybermedium&t=Robotics%20Toolbox%0A
135+
148136
banner = f"""\
149137
____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
150138
|__/ | | |__] | | | | | [__ | | | | | | |__] | | \/
@@ -186,13 +174,53 @@ def main():
186174

187175
print(fg("yellow") + banner + attr(0))
188176

189-
if args.showassign:
177+
def startup():
178+
plt.ion()
179+
180+
def main():
181+
182+
args = parse_arguments()
183+
184+
185+
# setup defaults
186+
np.set_printoptions(
187+
linewidth=120,
188+
formatter={"float": lambda x: f"{0:8.4g}" if abs(x) < 1e-10 else f"{x:8.4g}"},
189+
)
190+
191+
if args.book:
192+
# set book options
193+
args.resultprefix = ""
194+
args.prompt = ">>> "
195+
args.showassign = True
196+
args.ansi = False
197+
args.examples = True
198+
199+
# set default backend for Robot.plot
200+
if args.swift:
201+
Robot.default_backend = "swift"
202+
203+
# set matrix printing mode for spatialmath
204+
SE3._ansimatrix = args.ansi
205+
206+
# set default matplotlib backend
207+
if args.backend is not None:
208+
print(f"Using matplotlb backend {args.backend}")
209+
mpl.use(args.backend)
210+
211+
# build the banner, import * packages and their versions
212+
213+
214+
if args.banner:
215+
banner = make_banner()
216+
print(banner)
217+
218+
if args.showassign and args.banner:
190219
print(
191220
fg("red")
192-
+ """Results of assignments will be displayed, use trailing ; to suppress
193-
194-
""",
195-
attr(0),
221+
+ "Results of assignments will be displayed, use trailing ; to suppress"
222+
+ attr(0)
223+
+ "\n"
196224
)
197225

198226
# drop into IPython
@@ -222,7 +250,7 @@ def out_prompt_tokens(self, cli=None):
222250
c.InteractiveShell.prompts_class = MyPrompt
223251
if args.showassign:
224252
c.InteractiveShell.ast_node_interactivity = "last_expr_or_assign"
225-
253+
c.TerminalIPythonApp.force_interact = False
226254
# set precision, same as %precision
227255
c.PlainTextFormatter.float_precision = "%.3f"
228256

@@ -235,18 +263,16 @@ def out_prompt_tokens(self, cli=None):
235263
code = path.open("r").readlines()
236264
if code is None:
237265
code = [
266+
"startup()",
238267
"%precision %.3g",
239-
"plt.ion()",
240268
]
241-
242269
else:
243270
code.append("plt.ion()")
244-
if args.vision:
245-
code.append("from machinevisiontoolbox import *")
271+
272+
246273
c.InteractiveShellApp.exec_lines = code
247274
IPython.start_ipython(config=c, user_ns=globals())
248275

249276

250-
251277
if __name__ == "__main__":
252278
main()

0 commit comments

Comments
 (0)