### Install ROS Kinetic Control and MoveIt Packages Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/rtb-data/rtbdata/xacro/yumi_description/README.md This command installs essential ROS Kinetic packages related to robot control, motion planning (MoveIt), and various interfaces required for robot simulation and operation. It ensures that the necessary libraries and tools are available for the ABB YuMi setup. ```bash sudo apt-get install ros-kinetic-control-toolbox ros-kinetic-controller-interface ros-kinetic-controller-manager ros-kinetic-joint-limits-interface ros-kinetic-transmission-interface ros-kinetic-moveit-core ros-kinetic-moveit-planners ros-kinetic-moveit-ros-planning ``` -------------------------------- ### Python Docstring Full Structure Example Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Documentation-Style-Gudie Illustrates the comprehensive structure of a NumPy-style Python docstring, detailing the recommended ordering and content for various sections such as parameters, returns, examples, notes, and references. It also demonstrates the use of `.. runblock:: pycon` for executable code examples. ```python """ One line description Longer paragraph description. Each section of the docstring should be seperated by a single line, except for rst directives (lines that start with ".. " which should be seperated by 2 blank lines Note ---- An optional emphasised important single note Attributes ---------- hermitian If True, `a` is a ... Raises ------ LinAlgError If the SVD computation does not converge. Returns ------- b The pseudo-inverse of ... Synopsis -------- Here is an extended description... Examples -------- Example description .. runblock:: pycon >>> import roboticstoolbox as rtb >>> panda = rtb.models.Panda().ets() >>> solver = rtb.IK_QP() >>> Tep = panda.fkine([0, -0.3, 0, -2.2, 0, 2, 0.7854]) >>> solver.solve(panda, Tep) Notes ----- - Lower priority notes - The pseudo-inverse of a matrix A, ... - Another note References ---------- .. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. See Also -------- scipy.linalg.pinv : Similar function in SciPy. .. versionchanged:: X.Y.Z Description of change """ ``` -------------------------------- ### Install Roboticstoolbox-Python for Google Colab Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/notebooks/ik_benchmark.ipynb Detects if the environment is Google Colab and installs the `roboticstoolbox-python` and `qpsolvers` packages. This ensures all necessary dependencies are available for running the robotics examples and benchmarks. ```python try: # We must install required packages if we are in Google Colab import google.colab %pip install roboticstoolbox-python>=1.0.2 %pip install qpsolvers[quadprog] COLAB = True except: pass ``` -------------------------------- ### Python Property and Setter Docstring Example Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Documentation-Style-Guide Shows how to document Python properties using the `@property` decorator and their corresponding setters. The example includes a description of the property's purpose, an embedded runnable code example, notes, and a cross-reference to another method using `:meth:`. ```Python @property def name(self): """ Set/get image name An image has a string-valued name that can be read and written. The name is shown by the Image repr and when images are displayed graphically. Example ------- Example description .. runblock:: pycon >>> from machinevisiontoolbox import Image >>> img = Image.Read('flowers1.png') >>> img.name[-70:] >>> img.name = 'my image' >>> img.name Notes ----- Images loaded from a file have their name initially set to the full file pathname. See Also -------- :meth:`Read` """ return self._name @name.setter def name(self, name): self._name = name ``` -------------------------------- ### Build ROS industrial_core Package from Source Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/rtb-data/rtbdata/xacro/yumi_description/README.md This step involves cloning the `industrial_core` package from a specific GitHub repository into your ROS workspace and then building it using `catkin_make`. This is crucial as the package might not be officially released for ROS Kinetic, requiring a source build. ```bash git clone https://github.com/OrebroUniversity/industrial_core.git catkin_make ``` -------------------------------- ### Embedding Runnable Code Examples in Docstrings Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Documentation-Style-Guide Illustrates the specific syntax for embedding runnable Python console examples within docstrings. It highlights the use of the `.. runblock:: pycon` directive, emphasizing that the example code must immediately follow the directive without a blank line or indentation. ```APIDOC """ Examples -------- Example description .. runblock:: pycon >>> import roboticstoolbox as rtb >>> panda = rtb.models.Panda().ets() >>> solver = rtb.IK_QP() >>> Tep = panda.fkine([0, -0.3, 0, -2.2, 0, 2, 0.7854]) >>> solver.solve(panda, Tep) """ ``` -------------------------------- ### Python Docstring Embedded Code Examples with `runblock` Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Documentation-Style-Gudie Illustrates the precise syntax for embedding executable code examples within a Python docstring using the Sphinx `.. runblock:: pycon` directive. It emphasizes the requirement for no blank lines or indentation between the directive and the example code for proper rendering. ```python """ Examples -------- Example description .. runblock:: pycon >>> import roboticstoolbox as rtb >>> panda = rtb.models.Panda().ets() >>> solver = rtb.IK_QP() >>> Tep = panda.fkine([0, -0.3, 0, -2.2, 0, 2, 0.7854]) >>> solver.solve(panda, Tep) """ ``` -------------------------------- ### Build Main ROS Workspace for ABB YuMi Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/rtb-data/rtbdata/xacro/yumi_description/README.md After ensuring that the `industrial_core` package is built and its environment sourced, this command compiles the primary ROS workspace containing the ABB YuMi robot's URDF and Gazebo files. This final compilation integrates all components for the robot's simulation and control. ```bash catkin_make ``` -------------------------------- ### Install Robotics Toolbox for Python via pip or conda Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst Instructions for installing the Robotics Toolbox for Python and its basic visualization dependencies using either the pip or conda package managers. ```bash pip install roboticstoolbox-python ``` ```bash conda install -c conda-forge roboticstoolbox-python ``` -------------------------------- ### Installing Robotics Toolbox for Python Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/rtb-data/README.md Illustrates the primary installation command for the Robotics Toolbox for Python (RTB-P). This command automatically handles the installation of the `rtb-data` package as a dependency, eliminating the need for a separate installation of the data package. ```bash pip install roboticstoolbox-python ``` -------------------------------- ### Python Docstring Section Ordering (NumPy Style) Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Documentation-Style-Guide Illustrates the recommended order and structure for sections within a NumPy-style Python docstring. It includes sections like 'Note', 'Attributes', 'Raises', 'Returns', 'Synopsis', 'Examples', 'Notes', 'References', and 'See Also', demonstrating how to embed runnable code examples using the `.. runblock:: pycon` directive. ```Python """ One line description Longer paragraph description. Each section of the docstring should be seperated by a single line, except for rst directives (lines that start with ".. " which should be seperated by 2 blank lines Note ---- An optional emphasised important single note Attributes ---------- hermitian If True, `a` is a ... Raises ------ LinAlgError If the SVD computation does not converge. Returns ------- b The pseudo-inverse of ... Synopsis -------- Here is an extended description... Examples -------- Example description .. runblock:: pycon >>> import roboticstoolbox as rtb >>> panda = rtb.models.Panda().ets() >>> solver = rtb.IK_QP() >>> Tep = panda.fkine([0, -0.3, 0, -2.2, 0, 2, 0.7854]) >>> solver.solve(panda, Tep) Notes ----- - Lower priority notes - The pseudo-inverse of a matrix A, ... - Another note References ---------- .. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. See Also -------- scipy.linalg.pinv : Similar function in SciPy. .. versionchanged:: X.Y.Z Description of change """ ``` -------------------------------- ### Install robotics-toolbox-python from GitHub Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/README.md Provides instructions to clone the robotics-toolbox-python repository from GitHub and install the bleeding-edge version of the library in editable mode using pip3. This setup is suitable for development or accessing the latest features. ```shell script git clone https://github.com/petercorke/robotics-toolbox-python.git cd robotics-toolbox-python pip3 install -e . ``` -------------------------------- ### Basic Spatial Transformation Operations in Robotics Toolbox Python Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Working-with-Jupyter This example demonstrates fundamental spatial transformation operations using the imported modules. It includes creating an SE3 object, a translation matrix, and a rotation matrix, showcasing the intuitive syntax for common robotics tasks. ```python a = SE3(1, 2, 3) T = transl(1, 2, 3) R = rotx(0.3) ``` -------------------------------- ### Starting `rtbtool` Interactive Environment Source: https://github.com/petercorke/robotics-toolbox-python/wiki/rtbtool This snippet shows the initial banner and automatic imports when launching the `rtbtool` command-line interface. It highlights how `roboticstoolbox` and `spatialmath` are pre-loaded, allowing direct use of their functions and objects without explicit package prefixes. It also demonstrates built-in interactive help commands. ```Python ____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _ |__/ | | |__] | | | | | [__ | | | | | | |__] | | \/ | \ |__| |__] |__| | | |___ ___] | |__| |__| |___ |__] |__| _/\_ for Python from roboticstoolbox import * from spatialmath import * func/object? - show brief help help(func/object) - show detailed help func/object?? - show source code Python 3.8.5 (default, Sep 4 2020, 02:22:02) Type 'copyright', 'credits' or 'license' for more information IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help. >>> ``` -------------------------------- ### Python Property Docstring for Getters and Setters Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Documentation-Style-Gudie Demonstrates how to document Python properties using the `@property` and `@name.setter` decorators. The docstring is placed on the getter method and includes details on purpose, examples, and related notes, ensuring clear documentation for property access. ```python @property def name(self): """ Set/get image name An image has a string-valued name that can be read and written. The name is shown by the Image repr and when images are displayed graphically. Example ------- Example description .. runblock:: pycon >>> from machinevisiontoolbox import Image >>> img = Image.Read('flowers1.png') >>> img.name[-70:] >>> img.name = 'my image' >>> img.name Notes ----- Images loaded from a file have their name initially set to the full file pathname. See Also -------- :meth:`Read` """ return self._name @name.setter def name(self, name): self._name = name ``` -------------------------------- ### Install Robotics Toolbox for Python using pip Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/README.md This snippet provides commands to install the Robotics Toolbox for Python via pip. It covers the basic installation and how to include optional features like collision checking by specifying them in a comma-separated list. ```Shell Script pip3 install roboticstoolbox-python ``` ```Shell Script pip3 install roboticstoolbox-python[optionlist] ``` -------------------------------- ### Perform Editable Install of Python Package Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Common-Issues Performs an editable (interactive) installation of the Python package from the current directory. This links the package to the source code, allowing changes to be reflected without reinstallation, though C extensions may still require a full reinstall if modified. ```Shell pip install -e . ``` -------------------------------- ### Recording VPython Backend Animation to Video Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Backends Illustrates how to record a robot animation from the VPython backend to a video file. It demonstrates starting and stopping recording, and stepping through the animation frame by frame, recommending slower rates for better results. ```python env.record_start(5) # Record at 5 fps for q in qt.q: time.sleep(1/5) env.step(puma, q=q) env.record_stop('vpython_video.mp4', save_fps=25) # Save the resulting file at 25 fps ``` -------------------------------- ### Using Pre-loaded Robot Models in `rtbtool` Source: https://github.com/petercorke/robotics-toolbox-python/wiki/rtbtool This example illustrates how pre-loaded robot models, such as `puma` and `panda`, can be directly accessed and used within the `rtbtool` environment. It demonstrates forward kinematics (`fkine`) to calculate the pose and plotting (`plot`) of the `puma` robot in its home configuration (`qn`). ```Python >>> puma.fkine(puma.qn) Out[1]: SE3:┏ ┓ ┃ 0 0 1 0.596 ┃ ┃ 0 1 0 -0.15 ┃ ┃-1 0 0 0.657 ┃ ┃ 0 0 0 1 ┃ ┗ ┛ >>> puma.plot(puma.qn) ``` -------------------------------- ### Robotics Toolbox Backend Connector API Reference Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Backends Comprehensive API documentation for the `Connector.py` interface, detailing methods for launching, stepping, adding/removing objects, resetting, restarting, closing, holding, and getting frames from external robot simulation backends. ```APIDOC launch() - launch the external program with an empty or specific scene as defined by args step(dt) - requests the external program to make a time step of defined time updating the state of the environment, including all robots, as defined by the robot's actions. id = add(object) - adds an object to the external environment. If object is a robot, it must be of an appropriate class. This adds the object to a list of which will act upon the step() method being called. This method returns the id of the object. remove(id) - removes the specified object from the external environment. reset() - triggers the external program to reset to the original state defined by launch restart() - request the external program to close and relaunch to the state defined by launch close() - requests that the external program to gracefully close hold() - requests that the external program stays open, will prevent Python from exiting the script. Is blocking getframe() - return a PIL image for current frame if possible ``` -------------------------------- ### Initialize and Plot Puma560 Robot Model in Python Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/notebooks/graphics-test.ipynb This snippet demonstrates how to import the `roboticstoolbox` library, instantiate a `Puma560` robot model using Denavit-Hartenberg (DH) parameters, and then plot its initial configuration. The `%matplotlib inline` magic command is included for use in interactive environments like Jupyter notebooks to display plots directly. ```python from roboticstoolbox import * %matplotlib inline puma = models.DH.Puma560() env = puma.plot(puma.qn) ``` -------------------------------- ### Demonstrating Python NamedTuple Access Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Variable-number-of-return-arguments Provides an interactive example of instantiating a `namedtuple` and accessing its elements using both traditional index-based and more readable attribute-based methods. ```Python >>> x=jt(1,2,3) >>> print(x) jtraj(q=1, qd=2, qdd=3) >>> x[1] 2 >>> x.qdd 3 ``` -------------------------------- ### Importing Modules for MATLAB-like Robotics Environment Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Working-with-Jupyter This snippet shows the essential Python imports required to set up an environment that provides functionality similar to the Robotics Toolbox for MATLAB. It imports all symbols from `spatialmath`, `spatialmath.base`, and `roboticstoolbox`. ```python from spatialmath import * from spatialmath.base import * from roboticstoolbox import * ``` -------------------------------- ### Instantiating and Testing a Custom Robot Model in Python Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/roboticstoolbox/models/DH/README.md This code example shows how to instantiate a custom robot model defined within the `robotics-toolbox-python` framework. It then demonstrates how to print its kinematic parameters and verify predefined joint configurations, ensuring the model behaves as expected. ```python myrobot = MYROBOT() # instantiate an instance of your model print(myrobot) # display its kinematic parameters print(myrobot.MYCONFIG) # check that the joint configuration works ``` -------------------------------- ### Python Named Arguments Example Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Argument-handling Illustrates the Pythonic way of passing arguments using named parameters, which significantly enhances readability and allows for clear default values. ```Python Link(d=0, theta=1, alpha=2, a=3) ``` -------------------------------- ### Evaluate Inverse Kinematics Performance for 6DOF Robot Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Kinematics Python example demonstrating how to instantiate a 6DOF Puma560 robot, calculate its forward kinematics, and then use an inverse kinematics solver (`ikine_XX`) to find joint angles. The residual error is printed. Performance benchmarks for various IK methods and SciPy optimization solvers (e.g., Nelder-Mead, Powell, SLSQP) without joint limits are also discussed in the context of this example. ```python puma = rtb.models.DH.Puma560() T = puma.fkine(puma.qn) sol = puma.ikine_XX(T) print("residual = ", np.linalg.norm(T - puma.fkine(sol.q))) ``` -------------------------------- ### Initialize Robot Model for Inverse Kinematics Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/notebooks/ik_benchmark.ipynb Initializes a `Panda` robot model from the `roboticstoolbox` library and extracts its Elementary Transform Sequence (ETS). This setup is crucial for defining the robot's kinematics and subsequently performing inverse kinematics calculations. ```python # Our robot and ETS robot = rtb.models.Panda() ets = robot.ets() ``` -------------------------------- ### Visualizing 3D Poses with SE3.plot() in Python Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst This example shows how to visualize an `SE3` pose object as a 3D coordinate frame using the `plot()` method. It allows specifying visual properties like color and label for the plotted frame, aiding in debugging and understanding spatial relationships. ```python T.plot(color='red', label='2') ``` -------------------------------- ### Python Package Import Order and Examples Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Coding-conventions This snippet illustrates the recommended order and specific import statements for common packages used in the project, including standard libraries, NumPy, SciPy, Matplotlib, Spatial Math Toolbox, and Robotics Toolbox, to ensure consistency and avoid circular dependencies. ```Python # Standard Python packages # NumPy import numpy as np # SciPy import script as sp # Matplotlib import matplotlib as mpl import matplotlib.pyplot as ppt import mpl_toolkits.mplot3d as mpl3d # Spatial Math Toolbox import spatialmath as sm from spatialmath import base # Robotics Toolbox (for toolbox code) from roboticstoolbox.module import class # example for internal imports # Robotics Toolbox (for application code) import roboticstoolbox as rtb # All other imports ``` -------------------------------- ### Python/MATLAB Keyword-Value Arguments Example Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Argument-handling Demonstrates a function call using explicit keyword-value pairs, a common pattern in MATLAB and a possible (though less Pythonic) approach in Python for argument passing. ```Python Link('d', 0, 'theta', 1, 'alpha', 2, 'a', 3) ``` -------------------------------- ### Resolved-Rate Motion Control with bdsim and Robotics Toolbox Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/roboticstoolbox/blocks/README.md This Python example demonstrates resolved-rate motion control for a Puma560 robot using the `bdsim` block diagram simulation package. It constructs a block diagram by defining and connecting blocks for Jacobian calculation, constant task-space velocity, joint velocity product, joint position integration, and robot arm plotting. The simulation runs for a specified duration, illustrating a common robotics control strategy. This specific example is derived from Figure 8.5 of 'Robotics, Vision & Control, 2nd edition'. ```python from math import pi import numpy as np from roboticstoolbox.models.DH import Puma560 import bdsim bd = bdsim.BlockDiagram() puma = Puma560() q0 = [0, pi/4, pi, 0, pi/4, 0] # define the blocks jacobian = bd.JACOBIAN(robot=puma, frame='0', inverse=True, name='Jacobian') velocity = bd.CONSTANT([0, 0.5, 0, 0, 0, 0]) # task-space velocity qdot = bd.PROD('**', matrix=True) integrator = bd.INTEGRATOR(x0=q0) robot = bd.ARMPLOT(robot=puma, q0=q0, name='plot') # connect the blocks bd.connect(jacobian, qdot[0]) bd.connect(velocity, qdot[1]) bd.connect(qdot, integrator) bd.connect(integrator, jacobian, robot) bd.compile() # check the diagram bd.report() # list all blocks and wires bd.run(1.5) # simulate for 1.5s bd.done() ``` -------------------------------- ### Load and Use URDF Robot Models with Specific End-Effector Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst This example demonstrates loading a robot model from a URDF file using `rtb.models.URDF`. It also shows how to specify a particular end-effector when performing kinematic operations, which is useful for branched robots or models with multiple end-effectors. ```Python import roboticstoolbox as rtb panda = rtb.models.URDF.Panda() print(panda) T = panda.fkine(panda.qz, end='panda_hand') print(T) ``` -------------------------------- ### Generate Cartesian Path and Compute Inverse Kinematics Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst This example demonstrates generating a straight-line Cartesian path between two poses using `rtb.tools.trajectory.ctraj`. It then computes the inverse kinematics for each pose along this path using the Levenberg-Marquardt method (`ikine_LM`). ```Python import numpy as np from spatialmath import SE3 import roboticstoolbox as rtb puma = rtb.models.DH.Puma560() t = np.arange(0, 2, 0.010) T0 = SE3(0.6, -0.5, 0.0) T1 = SE3(0.4, 0.5, 0.2) Ts = rtb.tools.trajectory.ctraj(T0, T1, len(t)) len(Ts) sol = puma.ikine_LM(Ts) sol.q.shape ``` -------------------------------- ### MATLAB Keyword-Value Pair Argument Example Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Argument-handling Illustrates the standard MATLAB approach for passing optional arguments using keyword-value pairs, where keywords are strings. ```MATLAB plot(x, y, 'Color', 'red', 'LineWidth', 2) ``` -------------------------------- ### Creating Multi-Valued Pose Objects with SE3 in Python Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst This example demonstrates how to create an `SE3` object that contains a sequence of multiple pose values, leveraging the class's inheritance from `collections.UserList`. It uses NumPy's `linspace` to generate a range of rotation angles, resulting in an `SE3` instance holding 100 rotation matrices, which can then be indexed or iterated over. ```python from spatialmath import SE3 import numpy as np R = SE3.Rx(np.linspace(0, np.pi/2, num=100)) len(R) ``` -------------------------------- ### CMake Configuration for Ridgeback Description ROS Package Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/rtb-data/rtbdata/xacro/ridgeback_description/CMakeLists.txt This CMakeLists.txt file defines the build process for the `ridgeback_description` ROS package. It specifies minimum CMake version, declares package dependencies using `find_package` (e.g., `catkin`, `roslaunch`), and defines installation rules for various assets like meshes, launch files, URDF models, and executable scripts. It also includes conditional logic for enabling testing and checking launch files. ```CMake cmake_minimum_required(VERSION 2.8.3) project(ridgeback_description) find_package(catkin REQUIRED COMPONENTS roslaunch) catkin_package() install(DIRECTORY meshes launch urdf DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) install(PROGRAMS scripts/env_run DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) if(CATKIN_ENABLE_TESTING) find_package(roslaunch REQUIRED) roslaunch_add_file_check(launch/description.launch) endif() ``` -------------------------------- ### Define Robot Kinematics using Elementary Transform Sequence (ETS) Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst This example illustrates how to construct a robot model using Elementary Transform (ET) notation. It defines the kinematic chain as a sequence of simple rigid-body transformations and then creates a `Robot` object from this sequence. ```Python from roboticstoolbox import ET import roboticstoolbox as rtb # Puma dimensions (m), see RVC2 Fig. 7.4 for details l1 = 0.672; l2 = -0.2337; l3 = 0.4318; l4 = 0.0203; l5 = 0.0837; l6 = 0.4318 e = ET.tz(l1) * ET.Rz() * ET.ty(l2) * ET.Ry() * ET.tz(l3) * ET.tx(l4) * ET.ty(l5) * ET.Ry() * ET.tz(l6) * ET.Rz() * ET.Ry() * ET.Rz() print(e) robot = rtb.Robot(e) print(robot) ``` -------------------------------- ### Python Class Docstring and __init__ Method Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Documentation-Style-Guide Demonstrates the correct placement and structure of a class docstring in Python, emphasizing that the `__init__` method should not have its own docstring. Parameters for `__init__` are documented directly within the class docstring's 'Parameters' section. ```Python class ExampleClass(): """ The summary line for a class docstring should fit on one line. Parameters ---------- param1 Description of `param1`. param2 Description of `param2`. Multiple lines are supported. param3 Description of `param3`. """ def __init__(self, param1, param2, param3): """ Not here, there should be NO docstring here """ pass ``` -------------------------------- ### Compute Jacobians, Hessians, and Manipulability for Robot Models Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst Illustrates how to calculate various differential kinematic properties for robot models in `robotics-toolbox-python`, including spatial and body Jacobians, Hessians, and different measures of manipulability (Yoshikawa, Asada), and the manipulability Jacobian. Examples cover both numerical and symbolic computations. ```python import roboticstoolbox as rtb puma = rtb.models.DH.Puma560() # Assuming 'q' is a joint configuration (e.g., puma.qn or a symbolic variable) J = puma.jacob0(q) J = puma.jacobe(q) ``` ```python import roboticstoolbox as rtb import numpy as np puma = rtb.models.DH.Puma560() J = puma.jacob0(puma.qr) np.linalg.matrix_rank(J) rtb.jsingu(J) ``` ```python import roboticstoolbox as rtb puma = rtb.models.DH.Puma560() # Assuming 'q' is a joint configuration (e.g., puma.qn or a symbolic variable) H = puma.hessian0(q) H = puma.hessiane(q) ``` ```python import roboticstoolbox as rtb puma = rtb.models.DH.Puma560() m = puma.manipulability(puma.qn) print("Yoshikawa manipulability is", m) m = puma.manipulability(puma.qn, method="asada") print("Asada manipulability is", m) ``` ```python import roboticstoolbox as rtb puma = rtb.models.DH.Puma560() m = puma.manipulability(puma.qn, axes="trans") print("Yoshikawa manipulability is", m) ``` ```python import roboticstoolbox as rtb puma = rtb.models.DH.Puma560() # Assuming q, J, H are defined from previous calculations Jm = puma.manipm(q, J, H) ``` -------------------------------- ### Evaluate Inverse Kinematics Performance for 7DOF Robot Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Kinematics Python example demonstrating how to instantiate a 7DOF Panda robot, define a target `SE3` pose, and then use an inverse kinematics solver (`ikine_XX`) to find the corresponding joint angles. The residual error is printed, showcasing the solver's accuracy. Performance benchmarks for various IK methods are also provided. ```python puma = Panda() T = SE3(0.7, 0.2, 0.1) * SE3.OA([0, 1, 0], [0, 0, -1]) sol = puma.ikine_XX(T) print("residual = ", np.linalg.norm(T - puma.fkine(sol.q))) ``` -------------------------------- ### Compute Inverse Kinematics for Robot Pose Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/notebooks/iros2020-workshop.ipynb Solves the inverse kinematics numerically to find the joint angles `q` corresponding to a target end-effector pose `T` using the `ikine` method. Additional status information is returned but ignored in this example. ```python q, *_ = puma.ikine(T) q ``` -------------------------------- ### Solve Inverse Kinematics for a Desired End-Effector Pose Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/README.md This example demonstrates solving inverse kinematics (IK) to find joint configurations that achieve a specified end-effector pose. It constructs a target SE(3) pose using `spatialmath.SE3` and then uses the `robot.ik_LM` method (Levenberg-Marquardt) to find a joint solution. The resulting joint angles are then used to verify the pose with forward kinematics. ```python from spatialmath import SE3 Tep = SE3.Trans(0.6, -0.3, 0.1) * SE3.OA([0, 1, 0], [0, 0, -1]) sol = robot.ik_LM(Tep) # solve IK print(sol) q_pickup = sol[0] print(robot.fkine(q_pickup)) # FK shows that desired end-effector pose was achieved ``` -------------------------------- ### Implement Resolved-Rate Motion Control in Swift Simulator Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/README.md This comprehensive example demonstrates real-time resolved-rate motion control for the Panda robot within the Swift simulator. It initializes the environment and robot, defines a target end-effector pose, and then iteratively calculates joint velocities using `rtb.p_servo` and the robot's Jacobian to move the end-effector towards the target. The simulation steps forward in time until the target is reached. ```python import swift import roboticstoolbox as rtb import spatialmath as sm import numpy as np env = swift.Swift() env.launch(realtime=True) panda = rtb.models.Panda() panda.q = panda.qr Tep = panda.fkine(panda.q) * sm.SE3.Trans(0.2, 0.2, 0.45) arrived = False env.add(panda) dt = 0.05 while not arrived: v, arrived = rtb.p_servo(panda.fkine(panda.q), Tep, 1) panda.qd = np.linalg.pinv(panda.jacobe(panda.q)) @ v env.step(dt) # Uncomment to stop the browser tab from closing # env.hold() ``` -------------------------------- ### Solve IK using Robot class's integrated ikine_LM method Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/IK/ik.rst This example demonstrates a more convenient way to solve Inverse Kinematics by directly calling an `ikine_` method on a `Robot` object. The `ikine_LM` method is invoked on the `panda` robot instance with the target end-effector pose, simplifying the IK solving process. ```python import roboticstoolbox as rtb # Make a Panda robot panda = rtb.models.Panda() # Make a goal pose Tep = panda.fkine([0, -0.3, 0, -2.2, 0, 2, 0.7854]) # Solve the IK problem panda.ikine_LM(Tep) ``` -------------------------------- ### Solve IK using explicit IK_LM solver class with ETS Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/IK/ik.rst This example demonstrates how to use the `IK_LM` solver class directly. An instance of `IK_LM` is created, and the Inverse Kinematics problem is solved by passing an `ETS` (Elementary Transform Sequence) object and a target pose to its `solve` method. This approach is suitable for comparing different solvers on the same robot. ```python import roboticstoolbox as rtb # Make a Panda robot panda = rtb.models.Panda() # Get the ETS of the Panda ets = panda.ets() # Make an IK solver solver = rtb.IK_LM() # Make a goal pose Tep = panda.fkine([0, -0.3, 0, -2.2, 0, 2, 0.7854]) # Solve the IK problem solver.solve(ets, Tep) ``` -------------------------------- ### Python Docstring References Section Formatting Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Documentation-Style-Gudie Provides examples for formatting the 'References' section within a Python docstring. It shows both numbered references using reStructuredText directives (`.. [N]`) and unnumbered bullet-point lists, allowing for flexible citation styles. ```python """ Use numbered references with the directive if you refer to the reference. Otherwise use a bullet point. References ---------- .. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. .. [2] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. OR References ---------- - G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. - G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. """ ``` -------------------------------- ### Generic Robotics Toolbox Backend Environment Usage Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Backends Provides a general template for interacting with any of the roboticstoolbox backends by creating an environment instance, launching it, adding a robot, and stepping through the simulation loop. ```python from roboticstoolbox.backends.BACKEND import BACKEND env = BACKEND() # where BACKEND is PyPlot, VPython or Swift env.launch() # start the backend env.add(robot) # add a robot to the backend for ...: robot.q = some value env.step() ``` -------------------------------- ### Docstring Reference Formatting Guidelines Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Documentation-Style-Guide Provides guidelines and examples for formatting the 'References' section within Python docstrings. It illustrates both numbered references using the `.. [N]` directive and unnumbered bullet-point references, advising to use the directive only when the reference is explicitly referred to in the text. ```APIDOC """ Use numbered references with the directive if you refer to the reference. Otherwise use a bullet point. References ---------- .. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. .. [2] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. OR References ---------- - G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. - G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142. """ ``` -------------------------------- ### Compute Forward Kinematics for Robot's Home Configuration Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/notebooks/iros2020-workshop.ipynb Calculates the end-effector pose using forward kinematics for the robot's predefined 'home' or 'ready' configuration (`puma.qr`). This demonstrates the `fkine` method with a standard, known robot pose. ```python puma.fkine(puma.qr) ``` -------------------------------- ### IKSolution Class API Reference Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/IK/stubs/roboticstoolbox.robot.IK.IKSolution.rst Comprehensive API documentation for the `roboticstoolbox.robot.IK.IKSolution` class, including its constructor and attributes. This class is designed to hold the results and diagnostic information from an inverse kinematics computation. ```APIDOC Class: roboticstoolbox.robot.IK.IKSolution Module: roboticstoolbox.robot.IK Description: Represents the solution of an inverse kinematics (IK) problem, encapsulating the found joint configuration and various diagnostic metrics. Methods: __init__(self, ...) Description: Initializes an IKSolution object. Parameters: (Details not provided in source text, typically includes the solution 'q' and other metrics) Returns: None Attributes: iterations: (Type and description not specified in source, typically int) The number of iterations performed during the IK solution process. reason: (Type and description not specified in source, typically str) The reason for the termination of the IK solution process (e.g., convergence, max iterations, no solution). residual: (Type and description not specified in source, typically float) The final residual error of the IK solution. searches: (Type and description not specified in source, typically int) The number of searches or restarts performed during the IK solution (if applicable). q: (Type and description not specified in source, typically numpy.ndarray) The joint configuration (solution) found by the IK solver. success: (Type and description not specified in source, typically bool) A boolean flag indicating whether the IK solution was successful. ``` -------------------------------- ### Loading MATLAB .mat Files with Robotics Toolbox Python Source: https://github.com/petercorke/robotics-toolbox-python/wiki/The-data-package This example illustrates how to load and parse a MATLAB-style `.mat` file from the `rtb-data` package using the `loadmat` function. The function automatically locates the specified file within the installed data package and returns its parsed contents, facilitating the use of datasets from sources like the RVC book. ```python from roboticstoolbox.tools.data import loadmat m = loadmat("data/house.mat") ``` -------------------------------- ### Plot Robot Configuration or Animation in Python Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst Illustrates the basic `plot` method for displaying a robot at a given joint configuration or animating a sequence of configurations. This uses the default PyPlot backend. ```python puma.plot(q) ``` -------------------------------- ### Reinstall Python Package from Local Directory Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Common-Issues Uninstalls any existing installation and then reinstalls the Python package from the current directory. This is particularly useful for rebuilding C extensions after source code modifications, even with interactive installs. ```Shell pip install . ``` -------------------------------- ### Visualize Robot Model with Swift Simulator Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst This snippet illustrates how to visualize a robot model in a 3D environment using the `plot` method with the 'swift' backend. Swift is a web-based visualizer that provides high-quality 3D animations. ```Python panda.plot(qz, backend="swift") ``` -------------------------------- ### Perform Forward and Analytic Inverse Kinematics with Puma Robot Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst This snippet demonstrates how to compute the forward kinematics for a Puma robot using `fkine` and then perform analytic inverse kinematics using `ikine_a`, specifying a desired robot configuration. ```Python T = puma.fkine([0.1, 0.2, 0.3, 0.4, 0.5, 0.6]) puma.ikine_a(T, config="lun") ``` -------------------------------- ### Perform forward and inverse kinematics with Robotics Toolbox Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/intro.rst Shows a complete workflow for kinematic analysis using `roboticstoolbox`. It covers instantiating a robot model (Puma560), printing its properties, performing forward kinematics (`fkine`) to calculate the end-effector pose from joint angles, and then solving inverse kinematics (`ikine_LM`) to find joint angles for a given pose using a Levenberg-Marquardt minimization approach. ```python import roboticstoolbox as rtb puma = rtb.models.DH.Puma560() # instantiate robot model print(puma) print(puma.qr) T = puma.fkine([0.1, 0.2, 0.3, 0.4, 0.5, 0.6]) # forward kinematics print(T) sol = puma.ikine_LM(T) # inverse kinematics print(sol) ``` -------------------------------- ### IKSolver Class API Reference Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/docs/source/IK/iksolver.rst Documents the `IKSolver` abstract base class from the `roboticstoolbox.robot.IK` module, outlining its public and private methods for inverse kinematics operations. This class serves as a foundation for various IK solver implementations. ```APIDOC IKSolver (Abstract Base Class) ------------------------------ Module: roboticstoolbox.robot.IK Purpose: Abstract base class for Inverse Kinematics (IK) solvers, providing a common interface for different IK algorithms. Inheritance: Inherits from an unspecified base class (indicated by ':show-inheritance:'). Public Methods: - step: Description: Performs a single iterative step towards solving the inverse kinematics problem. Signature: IKSolver.step(...) - solve: Description: Solves the inverse kinematics problem, typically by iteratively calling 'step' until a solution is found or a limit is reached. Signature: IKSolver.solve(...) - error: Description: Calculates the current error of the inverse kinematics solution, indicating how far the current configuration is from the target. Signature: IKSolver.error(...) Private Methods: - _random_q: Description: Generates a random joint configuration (q) for internal use, often for initialization or exploration. Signature: IKSolver._random_q(...) - _check_jl: Description: Checks joint limits for a given joint configuration, ensuring the solution remains within physical constraints. Signature: IKSolver._check_jl(...) ``` -------------------------------- ### Python Positional Arguments Example Source: https://github.com/petercorke/robotics-toolbox-python/wiki/Argument-handling Shows a function call using only positional arguments in Python, highlighting potential readability and maintainability issues when argument meaning is not immediately clear. ```Python Link(0, 1, 2, 3) ``` -------------------------------- ### Execute and Display Benchmark Results for Fast IK Solvers Source: https://github.com/petercorke/robotics-toolbox-python/blob/master/notebooks/ik_benchmark.ipynb Executes the defined fast inverse kinematics solvers against a set of pre-generated problems, measuring the execution time for each. After all solvers have run, it prints a formatted table using `ANSITable` comparing their total execution times and average time per solution, providing a clear performance overview. ```python for name, solver in zip(speed_names, speed_solvers): print(f"Solving with {name}") start = time.time() for i in range(speed_problems): solver(Tep[i]) total_time = time.time() - start times.append(total_time) print(f"\nNumerical Inverse Kinematics Methods Times Compared over {speed_problems} problems\n") table = ANSITable( "Method", "Total Time (s)", "Average Time per Solution (μs)", border="thin", ) for name, t in zip(speed_names, times): table.row( name, np.round(t, 4), np.round((t / speed_problems) * 1e6, 4), ) table.print() ```