|
| 1 | +:github_url: https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/doc/examples/instruction_executor.rst |
| 2 | + |
| 3 | +.. _instruction_executor_example: |
| 4 | + |
| 5 | +Instruction Executor example |
| 6 | +============================ |
| 7 | + |
| 8 | +This example shows how to use the :ref:`instruction_executor` class. It can be used for easily |
| 9 | +executing a sequence of instructions such as motions on the robot using the built-in URScript functions. |
| 10 | + |
| 11 | +The `instruction_executor.cpp <https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/examples/instruction_executor.cpp>`_ shows how to use this class: |
| 12 | + |
| 13 | +.. note:: For the instruciton executor to work there has to be an established connection to the |
| 14 | + :ref:`reverse_interface`. That means, the respective program has to be running on the robot. The |
| 15 | + example below will do that automatically, if the connected robot is in *remote_control* mode. |
| 16 | + |
| 17 | + |
| 18 | +.. literalinclude:: ../../examples/instruction_executor.cpp |
| 19 | + :language: c++ |
| 20 | + :caption: examples/instruction_executor.cpp |
| 21 | + :linenos: |
| 22 | + :lineno-match: |
| 23 | + :start-at: std::unique_ptr<urcl::ToolCommSetup> tool_comm_setup; |
| 24 | + :end-at: auto instruction_executor = std::make_shared<urcl::InstructionExecutor>(g_my_driver); |
| 25 | + |
| 26 | +At first, a ``InstructionExecutor`` object is created with the URDriver object as it needs that |
| 27 | +for communication with the robot. |
| 28 | + |
| 29 | +Currently, the ``InstructionExecutor`` can either be used to run sequences of motions or single motions. |
| 30 | + |
| 31 | +Execute a sequence of motions |
| 32 | +----------------------------- |
| 33 | + |
| 34 | +To run a sequence of motions, create an |
| 35 | +``std::vector<std::shared_ptr<urcl::cointrol::MotionPrimitive>>`` and pass it to the |
| 36 | +``executeMotion`` function: |
| 37 | + |
| 38 | +.. literalinclude:: ../../examples/instruction_executor.cpp |
| 39 | + :language: c++ |
| 40 | + :caption: examples/instruction_executor.cpp |
| 41 | + :linenos: |
| 42 | + :lineno-match: |
| 43 | + :start-at: // Trajectory definition |
| 44 | + :end-at: instruction_executor->executeMotion(motion_sequence); |
| 45 | + |
| 46 | +Each element in the motion sequence can be a different motion type. In the example, there are two |
| 47 | +``MoveJ`` motions and two ``MoveL`` motion. The primitives' parameters are directly forwarded to |
| 48 | +the underlying script functions, so the parameter descriptions for them apply, as well. |
| 49 | +Particularly, you may want to choose between either a time-based execution speed or an acceleration |
| 50 | +/ velocity parametrization. The latter will be ignored if a time > 0 is given. |
| 51 | + |
| 52 | +Execute a single motion |
| 53 | +----------------------- |
| 54 | + |
| 55 | +To run a single motion, the ``InstructionExecutor`` provides the methods ``moveJ(...)`` and |
| 56 | +``moveL(...)``: |
| 57 | + |
| 58 | +.. literalinclude:: ../../examples/instruction_executor.cpp |
| 59 | + :language: c++ |
| 60 | + :caption: examples/instruction_executor.cpp |
| 61 | + :linenos: |
| 62 | + :lineno-match: |
| 63 | + :start-at: double goal_time_sec = 2.0; |
| 64 | + :end-before: g_my_driver->stopControl(); |
| 65 | + |
| 66 | +Again, time parametrization has priority over acceleration / velocity parameters. |
0 commit comments