44# import roboticstoolbox as rtb
55from spatialmath import SE3
66from spatialmath .base .argcheck import isvector , getvector , getmatrix , \
7- verifymatrix
7+ verifymatrix , getunit
88from roboticstoolbox .robot .Link import Link
99from spatialmath .base .transforms3d import tr2delta
1010# from roboticstoolbox.backend import URDF
@@ -179,14 +179,14 @@ def n(self):
179179 """
180180 return self ._n
181181
182- def addconfiguration (self , name , q ):
182+ def addconfiguration (self , name , q , unit = 'rad' ):
183183 """
184184 Add a named joint configuration (Robot superclass)
185185
186186 :param name: Name of the joint configuration
187187 :type name: str
188188 :param q: Joint configuration
189- :type q: ndarray(n,)
189+ :type q: ndarray(n) or list
190190
191191 Example:
192192
@@ -199,8 +199,41 @@ def addconfiguration(self, name, q):
199199 >>> robot.mypos
200200 """
201201 v = getvector (q , self .n )
202+ v = getunit (v , unit )
202203 self ._configdict [name ] = v
203204 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 ""
204237
205238 def dyntable (self ):
206239 """
0 commit comments