23
23
import sys
24
24
from importlib .metadata import version
25
25
26
+
27
+
26
28
try :
27
29
from colored import fg , bg , attr
28
30
51
53
puma = models .DH .Puma560 ()
52
54
panda = models .DH .Panda ()
53
55
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 ():
62
57
parser = argparse .ArgumentParser ("Robotics Toolbox shell" )
63
58
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
+ )
65
62
parser .add_argument (
66
63
"--color" ,
67
64
"-c" ,
@@ -78,6 +75,14 @@ def main():
78
75
default = None ,
79
76
help = "execution result prefix, include {} for execution count number" ,
80
77
)
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
+ )
81
86
parser .add_argument (
82
87
"--showassign" ,
83
88
"-a" ,
@@ -89,10 +94,6 @@ def main():
89
94
"--book" , default = False , action = "store_true" ,
90
95
help = "use defaults as per RVC book"
91
96
)
92
- parser .add_argument (
93
- "--vision" , default = False , action = "store_true" ,
94
- help = "import vision toolbox (MVTB)"
95
- )
96
97
parser .add_argument (
97
98
"--ansi" ,
98
99
default = False ,
@@ -113,38 +114,25 @@ def main():
113
114
action = "store_true" ,
114
115
help = "use Swift as default backend" ,
115
116
)
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
117
122
118
123
# TODO more options
119
124
# color scheme, light/dark
120
125
# silent startup
121
126
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
143
129
144
- # build the banner, import * packages and their versions
130
+ return args
145
131
132
+ def make_banner ():
146
133
# banner template
147
134
# https://patorjk.com/software/taag/#p=display&f=Cybermedium&t=Robotics%20Toolbox%0A
135
+
148
136
banner = f"""\
149
137
____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
150
138
|__/ | | |__] | | | | | [__ | | | | | | |__] | | \/
@@ -186,13 +174,53 @@ def main():
186
174
187
175
print (fg ("yellow" ) + banner + attr (0 ))
188
176
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 :
190
219
print (
191
220
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 "
196
224
)
197
225
198
226
# drop into IPython
@@ -222,7 +250,7 @@ def out_prompt_tokens(self, cli=None):
222
250
c .InteractiveShell .prompts_class = MyPrompt
223
251
if args .showassign :
224
252
c .InteractiveShell .ast_node_interactivity = "last_expr_or_assign"
225
-
253
+ c . TerminalIPythonApp . force_interact = False
226
254
# set precision, same as %precision
227
255
c .PlainTextFormatter .float_precision = "%.3f"
228
256
@@ -235,18 +263,16 @@ def out_prompt_tokens(self, cli=None):
235
263
code = path .open ("r" ).readlines ()
236
264
if code is None :
237
265
code = [
266
+ "startup()" ,
238
267
"%precision %.3g" ,
239
- "plt.ion()" ,
240
268
]
241
-
242
269
else :
243
270
code .append ("plt.ion()" )
244
- if args . vision :
245
- code . append ( "from machinevisiontoolbox import *" )
271
+
272
+
246
273
c .InteractiveShellApp .exec_lines = code
247
274
IPython .start_ipython (config = c , user_ns = globals ())
248
275
249
276
250
-
251
277
if __name__ == "__main__" :
252
278
main ()
0 commit comments