Skip to content

Commit 85f5c69

Browse files
committed
joint configurations
add unit option to addconfiguration refactor table of configurations to Rboto
1 parent 70fe11e commit 85f5c69

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

roboticstoolbox/robot/DHRobot.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,26 +204,10 @@ def angle(theta, fmt=None):
204204
s += "\n" + str(table)
205205

206206
# show named configurations
207-
if len(self._configdict) > 0:
208-
table = ANSITable(
209-
Column("name", colalign=">"),
210-
*[Column(f"q{j:d}", colalign="<", headalign="<") for j in range(self.n)],
211-
border="thin")
212-
213-
for name, q in self._configdict.items():
214-
qlist = []
215-
for i, L in enumerate(self):
216-
if L.isprismatic():
217-
qlist.append(f"{q[i]: .3g}")
218-
else:
219-
qlist.append(angle(q[i], "{: .3g}"))
220-
table.row(name, *qlist)
221-
222-
s += "\n" + str(table)
207+
s += self.configurations_str()
223208

224209
return s
225210

226-
227211
def __add__(self, L):
228212
nlinks = []
229213

roboticstoolbox/robot/Robot.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# import roboticstoolbox as rtb
55
from spatialmath import SE3
66
from spatialmath.base.argcheck import isvector, getvector, getmatrix, \
7-
verifymatrix
7+
verifymatrix, getunit
88
from roboticstoolbox.robot.Link import Link
99
from 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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy