Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ import roboticstoolbox as rtb
robot = rtb.models.Panda()
print(robot)

ERobot: panda (by Franka Emika), 7 joints (RRRRRRR), 1 gripper, geometry, collision
URDFRobot.Panda: panda (by Franka Emika), 7 joints (RRRRRRR), 1 gripper, geometry, collision
┌─────┬──────────────┬───────┬─────────────┬────────────────────────────────────────────────┐
│link │ link │ joint │ parent │ ETS: parent to link │
├─────┼──────────────┼───────┼─────────────┼────────────────────────────────────────────────┤
Expand Down
22 changes: 19 additions & 3 deletions src/roboticstoolbox/robot/BaseRobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def _is_symbolic(value: Any) -> bool:
return np.asarray(value).dtype == object


# the modules of the robot classes themselves, as distinct from models built from them
_FRAMEWORK_MODULES = ("roboticstoolbox.robot.", "roboticstoolbox.models.URDF.URDFRobot")


class BaseRobot(SceneNode, DynamicsMixin, RobotPlottingMPLMixin, ABC, Generic[LinkType]):
# set when the links are processed in the constructor
_base_link: LinkType
Expand Down Expand Up @@ -531,9 +535,7 @@ def __str__(self) -> str:
f"{s}",
)

classname = "ERobot"

s = f"{classname}: {self.name}"
s = f"{self._class_label()}: {self.name}"
if self.manufacturer is not None and len(self.manufacturer) > 0:
s += f" (by {self.manufacturer})"
s += f", {self.n} joints ({self.structure})"
Expand All @@ -559,6 +561,20 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return str(self)

def _class_label(self) -> str:
"""
The class of this robot, for the first line of its display

``Robot``, ``Robot2``, ``DHRobot`` or ``URDFRobot`` for an instance of the class
itself, and ``X.Y`` for an instance of a subclass ``Y`` of one of them, for
example ``DHRobot.Puma560`` or ``URDFRobot.Panda``: the kind of robot, then the
model.
"""
cls = type(self)
if cls.__module__.startswith(_FRAMEWORK_MODULES):
return cls.__name__
return f"{cls.__mro__[1].__name__}.{cls.__name__}"

# --------------------------------------------------------------------- #
# --------- Properties ------------------------------------------------ #
# --------------------------------------------------------------------- #
Expand Down
2 changes: 1 addition & 1 deletion src/roboticstoolbox/robot/DHRobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def __str__(self) -> str:

unicode = rtb_get_param("unicode")
border = "thin" if unicode else "ascii"
s = f"DHRobot: {self.name}"
s = f"{self._class_label()}: {self.name}"

if self.manufacturer is not None and len(self.manufacturer) > 0:
s += f" (by {self.manufacturer})"
Expand Down
38 changes: 38 additions & 0 deletions tests/test_robot_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""The first line of a robot's display names its class: the kind of robot, then the
model, as ``DHRobot.Puma560``."""

import roboticstoolbox as rtb


def _first_line(robot):
return str(robot).splitlines()[0]


def test_ets_model():
assert _first_line(rtb.models.ETS.Planar_Y()).startswith("Robot.Planar_Y: ")

Check warning on line 12 in tests/test_robot_label.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_robot_label.py#L12

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


def test_urdf_model():
assert _first_line(rtb.models.URDF.Panda()).startswith("URDFRobot.Panda: ")

Check warning on line 16 in tests/test_robot_label.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_robot_label.py#L16

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


def test_dh_model():
assert _first_line(rtb.models.DH.Puma560()).startswith("DHRobot.Puma560: ")

Check warning on line 20 in tests/test_robot_label.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_robot_label.py#L20

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


def test_the_classes_themselves_have_no_model():
robot = rtb.Robot(rtb.ET.Rz() * rtb.ET.tx(1), name="arm")
dh = rtb.DHRobot([rtb.RevoluteDH(a=1.0)], name="dh")
robot2 = rtb.Robot2(rtb.ET2.R() * rtb.ET2.tx(1), name="flat")

assert _first_line(robot).startswith("Robot: arm")

Check warning on line 28 in tests/test_robot_label.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_robot_label.py#L28

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert _first_line(dh).startswith("DHRobot: dh")

Check warning on line 29 in tests/test_robot_label.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_robot_label.py#L29

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert _first_line(robot2).startswith("Robot2: flat")

Check warning on line 30 in tests/test_robot_label.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_robot_label.py#L30

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


def test_a_users_own_subclass():
class Mine(rtb.Robot):
def __init__(self):
super().__init__(rtb.ET.Rz() * rtb.ET.tx(1), name="mine")

assert _first_line(Mine()).startswith("Robot.Mine: mine")

Check warning on line 38 in tests/test_robot_label.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_robot_label.py#L38

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Loading