16
16
import argparse
17
17
from math import pi # lgtm [py/unused-import]
18
18
import numpy as np
19
+ import scipy as sp
19
20
import matplotlib .pyplot as plt # lgtm [py/unused-import]
20
21
from roboticstoolbox import * # lgtm [py/unused-import]
21
22
from spatialmath import * # lgtm [py/polluting-import]
22
23
from 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
24
35
25
36
# setup defaults
26
37
np .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')
30
41
parser .add_argument ('script' , default = None , nargs = '?' ,
31
42
help = 'specify script to run' )
32
43
parser .add_argument ('--backend' , '-b' , default = None ,
33
- help = 'specify graphics frontend ' )
44
+ help = 'specify graphics backend ' )
34
45
parser .add_argument ('--color' , '-c' , default = 'neutral' ,
35
46
help = 'specify terminal color scheme (neutral, lightbg, nocolor, linux), linux is for dark mode' )
36
47
parser .add_argument ('--confirmexit' , '-x' , default = False ,
@@ -39,40 +50,50 @@ parser.add_argument('--prompt', '-p', default='>>> ',
39
50
help = 'input prompt' )
40
51
parser .add_argument ('--resultprefix' , '-r' , default = None ,
41
52
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' )
44
55
args = parser .parse_args ()
45
56
57
+ sys .argv = [sys .argv [0 ]]
58
+
46
59
if 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
+
49
63
50
64
# load some robot models
51
65
puma = models .DH .Puma560 ()
52
66
panda = models .DH .Panda ()
53
67
54
68
# print the banner
55
69
# https://patorjk.com/software/taag/#p=display&f=Cybermedium&t=Robotics%20Toolbox%0A
56
- print (r"""____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
70
+ print (fg ( 'yellow' ) + r"""____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
57
71
|__/ | | |__] | | | | | [__ | | | | | | |__] | | \/
58
72
| \ |__| |__] |__| | | |___ ___] | |__| |__| |___ |__] |__| _/\_
59
73
60
74
for Python
61
75
62
76
from roboticstoolbox import *
63
77
from spatialmath import *
78
+ import numpy as np
79
+ import scipy as sp
64
80
65
81
func/object? - show brief help
66
82
help(func/object) - show detailed help
67
83
func/object?? - show source code
68
84
69
- """ )
85
+ """ , attr ( 0 ) )
70
86
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())
76
97
77
98
78
99
## drop into IPython
@@ -103,7 +124,19 @@ c.InteractiveShellEmbed.colors = args.color
103
124
c .InteractiveShell .confirm_exit = args .confirmexit
104
125
# c.InteractiveShell.prompts_class = ClassicPrompts
105
126
c .InteractiveShell .prompts_class = MyPrompt
106
- if args .showassign :
127
+ if args .noshowassign == False :
107
128
c .InteractiveShell .ast_node_interactivity = 'last_expr_or_assign'
108
129
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