4
4
# import roboticstoolbox as rtb
5
5
from spatialmath import SE3
6
6
from spatialmath .base .argcheck import isvector , getvector , getmatrix , \
7
- verifymatrix
7
+ verifymatrix , getunit
8
8
from roboticstoolbox .robot .Link import Link
9
9
from spatialmath .base .transforms3d import tr2delta
10
10
# from roboticstoolbox.backend import URDF
@@ -179,14 +179,14 @@ def n(self):
179
179
"""
180
180
return self ._n
181
181
182
- def addconfiguration (self , name , q ):
182
+ def addconfiguration (self , name , q , unit = 'rad' ):
183
183
"""
184
184
Add a named joint configuration (Robot superclass)
185
185
186
186
:param name: Name of the joint configuration
187
187
:type name: str
188
188
:param q: Joint configuration
189
- :type q: ndarray(n,)
189
+ :type q: ndarray(n) or list
190
190
191
191
Example:
192
192
@@ -199,8 +199,41 @@ def addconfiguration(self, name, q):
199
199
>>> robot.mypos
200
200
"""
201
201
v = getvector (q , self .n )
202
+ v = getunit (v , unit )
202
203
self ._configdict [name ] = v
203
204
setattr (self , name , v )
205
+
206
+ def configurations_str (self ):
207
+ deg = 180 / np .pi
208
+
209
+ # TODO: factor this out of DHRobot
210
+ def angle (theta , fmt = None ):
211
+
212
+ if fmt is not None :
213
+ return fmt .format (theta * deg ) + "\u00b0 "
214
+ else :
215
+ return str (theta * deg ) + "\u00b0 "
216
+
217
+ config = self .config ()
218
+ # show named configurations
219
+ if len (self ._configdict ) > 0 :
220
+ table = ANSITable (
221
+ Column ("name" , colalign = ">" ),
222
+ * [Column (f"q{ j :d} " , colalign = "<" , headalign = "<" ) for j in range (self .n )],
223
+ border = "thin" )
224
+
225
+ for name , q in self ._configdict .items ():
226
+ qlist = []
227
+ for i , c in enumerate (config ):
228
+ if c == 'P' :
229
+ qlist .append (f"{ q [i ]: .3g} " )
230
+ else :
231
+ qlist .append (angle (q [i ], "{: .3g}" ))
232
+ table .row (name , * qlist )
233
+
234
+ return "\n " + str (table )
235
+ else :
236
+ return ""
204
237
205
238
def dyntable (self ):
206
239
"""
0 commit comments