diff --git a/abb_egm_pyclient/run/__init__ b/abb_egm_pyclient/run/__init__ new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/abb_egm_pyclient/run/__main__.py b/abb_egm_pyclient/run/__main__.py new file mode 100644 index 0000000000000000000000000000000000000000..dc2a6afd3f0e6b65c4c940e173f481f83e024455 --- /dev/null +++ b/abb_egm_pyclient/run/__main__.py @@ -0,0 +1,55 @@ +import argparse +from abb_egm_pyclient.run import print_egm_feedback +from abb_egm_pyclient.run import send_configuration +from abb_egm_pyclient.run import send_pose + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Run one of the example EGM scripts.") + parser.add_argument("port", type=int, help="UDP port") + + subparsers = parser.add_subparsers(help="sub-command help") + + func_sel_mapping = { + "print": print_egm_feedback, + "joint": send_configuration, + "pose": send_pose, + } + + parser_print = subparsers.add_parsers( + "print", + help="print messages recieved from the EGM interface on the controller", + dest="func_selection", + ) + + parser_joint = subparsers.add_parsers( + "joint", + help="print messages recieved from the EGM interface on the controller", + dest="func_selection", + ) + parser_joint.add_argument("joint_values", nargs="*", type=float, metavar=("j1", "j2", "j3", "j4", "j5", "j6", "j7")) + + parser_world = subparsers.add_parsers( + "pose", + help="print messages recieved from the EGM interface on the controller", + dest="func_selection", + ) + parser_joint.add_argument("pose_values", nargs="6", type=float, metavar=("x", "y", "z", "rx", "ry", "rz")) + + args = parser.parse_args() + + if args.func_selection == "print": + print_egm_feedback(args.port) + + if args.func_selection == "joint": + if len(args.joint_values) not in (6, 7): + raise argparse.ArgumentError() + send_configuration(args.port, args.joint_values) + + if args.func_selection == "pose": + send_configuration(args.port, *args.pose_values) + + func = func_sel_mapping[args.func_selection] + + + + diff --git a/examples/print_egm_feedback.py b/abb_egm_pyclient/run/print_egm_feedback.py similarity index 81% rename from examples/print_egm_feedback.py rename to abb_egm_pyclient/run/print_egm_feedback.py index 1e3177815b8505491e653f144289f4a9026e6b62..5f88e96deb357c05f08f3c486cbf9436c001cb09 100644 --- a/examples/print_egm_feedback.py +++ b/abb_egm_pyclient/run/print_egm_feedback.py @@ -6,12 +6,12 @@ try: except ImportError: raise ImportWarning("abb_egm not found, have you installed the package?") -UDP_PORT = 6510 +DEFAULT_UDP_PORT = 6510 log = logging.getLogger("egm_client") -def print_egm_feedback() -> None: +def print_egm_feedback(port: int) -> None: """Print EGM feedback. Parameters @@ -20,7 +20,7 @@ def print_egm_feedback() -> None: Frequency of prints in hertz. """ - egm_client = EGMClient(port=UDP_PORT) + egm_client = EGMClient(port=port) while True: try: @@ -34,4 +34,4 @@ def print_egm_feedback() -> None: if __name__ == "__main__": - print_egm_feedback() + print_egm_feedback(port=DEFAULT_UDP_PORT) diff --git a/examples/send_configuration.py b/abb_egm_pyclient/run/send_configuration.py similarity index 88% rename from examples/send_configuration.py rename to abb_egm_pyclient/run/send_configuration.py index 5c698cbef15935a376601dc03069b9c2f10396fc..2677666e324bcc02d60cd8a2ef6dc2963d17f1cd 100644 --- a/examples/send_configuration.py +++ b/abb_egm_pyclient/run/send_configuration.py @@ -6,15 +6,12 @@ import time import numpy as np import numpy.typing as npt -try: - from abb_egm_pyclient import EGMClient -except ImportError: - raise ImportWarning("abb_egm not found, have you installed the package?") +from abb_egm_pyclient import EGMClient -UDP_PORT = 6510 +DEFAULT_UDP_PORT = 6510 -def send_configuration(target_conf: Sequence[float], joint_vel=1.0) -> None: +def send_configuration(port: int, target_conf: Sequence[float], joint_vel=1.0) -> None: """Move robot to target configuration Parameters @@ -27,7 +24,7 @@ def send_configuration(target_conf: Sequence[float], joint_vel=1.0) -> None: # send rate in hz rate = 10 - egm_client = EGMClient(port=UDP_PORT) + egm_client = EGMClient(port=port) pb_robot_msg = egm_client.receive_msg() start_conf: Sequence[float] = pb_robot_msg.feedBack.joints.joints diff --git a/abb_egm_pyclient/run/send_pose.py b/abb_egm_pyclient/run/send_pose.py new file mode 100644 index 0000000000000000000000000000000000000000..e709586f0ab3807e1d303637698617b1225b1f50 --- /dev/null +++ b/abb_egm_pyclient/run/send_pose.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python +"""Send pose example.""" + + +def send_pose(port, x, y, z, rx, ry, rz): + raise NotImplementedError("Planned example") diff --git a/examples/send_frame.py b/examples/send_frame.py deleted file mode 100644 index 82d32bc7aa2c5914f179f78fe7b6e565092f5f10..0000000000000000000000000000000000000000 --- a/examples/send_frame.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env python -"""Send frame example.""" - -raise NotImplementedError("Planned example")