1616import argparse
1717from math import pi # lgtm [py/unused-import]
1818import numpy as np
19+ import scipy as sp
1920import matplotlib .pyplot as plt # lgtm [py/unused-import]
2021from roboticstoolbox import * # lgtm [py/unused-import]
2122from spatialmath import * # lgtm [py/polluting-import]
2223from spatialmath .base import * # lgtm [py/polluting-import]
23-
24+ import matplotlib as mpl
25+ from pathlib import Path
26+ import sys
27+
28+ try :
29+ from colored import fg , bg , attr
30+ _colored = True
31+ # print('using colored output')
32+ except ImportError :
33+ # print('colored not found')
34+ _colored = False
2435
2536# setup defaults
2637np .set_printoptions (linewidth = 120 , formatter = {'float' : lambda x : f"{ x :8.4g} " if abs (x ) > 1e-10 else f"{ 0 :8.4g} " })
@@ -30,7 +41,7 @@ parser = argparse.ArgumentParser('Robotics Toolbox shell')
3041parser .add_argument ('script' , default = None , nargs = '?' ,
3142 help = 'specify script to run' )
3243parser .add_argument ('--backend' , '-b' , default = None ,
33- help = 'specify graphics frontend ' )
44+ help = 'specify graphics backend ' )
3445parser .add_argument ('--color' , '-c' , default = 'neutral' ,
3546 help = 'specify terminal color scheme (neutral, lightbg, nocolor, linux), linux is for dark mode' )
3647parser .add_argument ('--confirmexit' , '-x' , default = False ,
@@ -39,40 +50,50 @@ parser.add_argument('--prompt', '-p', default='>>> ',
3950 help = 'input prompt' )
4051parser .add_argument ('--resultprefix' , '-r' , default = None ,
4152 help = 'execution result prefix, include {} for execution count number' )
42- parser .add_argument ('--showassign ' , '-a' , default = False , action = 'store_true ' ,
43- help = 'display the result of assignments' )
53+ parser .add_argument ('--noshowassign ' , '-a' , default = False , action = 'store_false ' ,
54+ help = 'do not display the result of assignments' )
4455args = parser .parse_args ()
4556
57+ sys .argv = [sys .argv [0 ]]
58+
4659if args .backend is not None :
47- print (f"Using matplotlub backend { args .backend } " )
48- plt .use (args .backend )
60+ print (f"Using matplotlb backend { args .backend } " )
61+ mpl .use (args .backend )
62+
4963
5064# load some robot models
5165puma = models .DH .Puma560 ()
5266panda = models .DH .Panda ()
5367
5468# print the banner
5569# https://patorjk.com/software/taag/#p=display&f=Cybermedium&t=Robotics%20Toolbox%0A
56- print (r"""____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
70+ print (fg ( 'yellow' ) + r"""____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
5771|__/ | | |__] | | | | | [__ | | | | | | |__] | | \/
5872| \ |__| |__] |__| | | |___ ___] | |__| |__| |___ |__] |__| _/\_
5973
6074for Python
6175
6276from roboticstoolbox import *
6377from spatialmath import *
78+ import numpy as np
79+ import scipy as sp
6480
6581func/object? - show brief help
6682help(func/object) - show detailed help
6783func/object?? - show source code
6884
69- """ )
85+ """ , attr ( 0 ) )
7086
71- if args .script is not None :
72- path = Path (args .script )
73- if not path .exists ():
74- raise ValueError (f"script does not exist: { args .script } " )
75- exec (path .read_text ())
87+ if args .noshowassign == False :
88+ print (fg ('red' ) + """Results of assignments will be displayed, use trailing ; to suppress
89+
90+ """ , attr (0 ))
91+
92+ # if args.script is not None:
93+ # path = Path(args.script)
94+ # if not path.exists():
95+ # raise ValueError(f"script does not exist: {args.script}")
96+ # exec(path.read_text())
7697
7798
7899## drop into IPython
@@ -103,7 +124,19 @@ c.InteractiveShellEmbed.colors = args.color
103124c .InteractiveShell .confirm_exit = args .confirmexit
104125# c.InteractiveShell.prompts_class = ClassicPrompts
105126c .InteractiveShell .prompts_class = MyPrompt
106- if args .showassign :
127+ if args .noshowassign == False :
107128 c .InteractiveShell .ast_node_interactivity = 'last_expr_or_assign'
108129
109- IPython .embed (config = c )
130+ code = None
131+ if args .script is not None :
132+ path = Path (args .script )
133+ if not path .exists ():
134+ raise ValueError (f"script does not exist: { args .script } " )
135+ code = path .open ('r' ).readlines ()
136+ if code is None :
137+ code = ["plt.ion()" ]
138+ else :
139+ code .append ("plt.ion()" )
140+
141+ c .InteractiveShellApp .exec_lines = code
142+ IPython .start_ipython (config = c , user_ns = globals ())
0 commit comments