|
| 1 | +:github_url: https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/doc/examples/trajecotry_joint_interface_example.rst |
| 2 | + |
| 3 | +.. _trajecotry_joint_interface_example: |
| 4 | + |
| 5 | +Trajectory Joint Interface example |
| 6 | +================================== |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +At first, we create a ``UrDriver`` object as usual: |
| 11 | + |
| 12 | +.. literalinclude:: ../../examples/trajectory_point_interface.cpp |
| 13 | + :language: c++ |
| 14 | + :caption: examples/trajectory_point_interface.cpp |
| 15 | + :linenos: |
| 16 | + :lineno-match: |
| 17 | + :start-at: std::unique_ptr<urcl::ToolCommSetup> tool_comm_setup; |
| 18 | + :end-before: // --------------- INITIALIZATION END ------------------- |
| 19 | + |
| 20 | +We use a small helper function to make sure that the reverse interface is active and connected |
| 21 | +before proceeding. |
| 22 | + |
| 23 | + |
| 24 | +Initialization |
| 25 | +-------------- |
| 26 | + |
| 27 | +As trajectory execution will be triggered asynchronously, we define a callback function to handle a |
| 28 | +finished trajectory. A trajectory is considered finished when the robot is no longer executing it, |
| 29 | +independent of whether it successfully reached its final point. The trajectory result will reflect |
| 30 | +whether it was executed successfully, was canceled upon request or failed for some reason. |
| 31 | + |
| 32 | +.. literalinclude:: ../../examples/trajectory_point_interface.cpp |
| 33 | + :language: c++ |
| 34 | + :caption: examples/trajectory_point_interface.cpp |
| 35 | + :linenos: |
| 36 | + :lineno-match: |
| 37 | + :start-at: void trajDoneCallback(const urcl::control::TrajectoryResult& result) |
| 38 | + :end-at: } |
| 39 | + |
| 40 | +That callback can be registered at the ``UrDriver`` object: |
| 41 | + |
| 42 | + |
| 43 | +.. literalinclude:: ../../examples/trajectory_point_interface.cpp |
| 44 | + :language: c++ |
| 45 | + :caption: examples/trajectory_point_interface.cpp |
| 46 | + :linenos: |
| 47 | + :lineno-match: |
| 48 | + :start-at: g_my_driver->registerTrajectoryDoneCallback(&trajDoneCallback); |
| 49 | + :end-at: g_my_driver->registerTrajectoryDoneCallback(&trajDoneCallback); |
| 50 | + |
| 51 | + |
| 52 | +MoveJ Trajectory |
| 53 | +---------------- |
| 54 | + |
| 55 | +Then, in order to execute a trajectory, we need to define a trajectory as a sequence of points and |
| 56 | +parameters. The following example shows execution of a 2-point trajectory using URScript's |
| 57 | +``movej`` function: |
| 58 | + |
| 59 | +.. literalinclude:: ../../examples/trajectory_point_interface.cpp |
| 60 | + :language: c++ |
| 61 | + :caption: examples/trajectory_point_interface.cpp |
| 62 | + :linenos: |
| 63 | + :lineno-match: |
| 64 | + :start-after: // --------------- MOVEJ TRAJECTORY ------------------- |
| 65 | + :end-before: // --------------- END MOVEJ TRAJECTORY ------------------- |
| 66 | + |
| 67 | +In fact, the path is followed twice, once parametrized by a segment duration and once using maximum |
| 68 | +velocity / acceleration settings. If a duration > 0 is given for a segment, the velocity and |
| 69 | +acceleration settings will be ignored as in the underlying URScript functions. In the example |
| 70 | +above, each of the ``g_my_driver->writeTrajectoryPoint()`` calls will be translated into a |
| 71 | +``movej`` command in URScript. |
| 72 | + |
| 73 | +While the trajectory is running, we need to tell the robot program that connection is still active |
| 74 | +and we expect the trajectory to be running. This is being done by the |
| 75 | +``g_my_driver->writeTrajectoryControlMessage(urcl::control::TrajectoryControlMessage::TRAJECTORY_NOOP);`` |
| 76 | +call. |
| 77 | + |
| 78 | +MoveL Trajectory |
| 79 | +---------------- |
| 80 | + |
| 81 | +Similar to the ``movej``-based trajectory, execution can be done interpolating in joint space: |
| 82 | + |
| 83 | +.. literalinclude:: ../../examples/trajectory_point_interface.cpp |
| 84 | + :language: c++ |
| 85 | + :caption: examples/trajectory_point_interface.cpp |
| 86 | + :linenos: |
| 87 | + :lineno-match: |
| 88 | + :start-after: // --------------- MOVEL TRAJECTORY ------------------- |
| 89 | + :end-before: // --------------- END MOVEL TRAJECTORY ------------------- |
| 90 | + |
| 91 | +Spline based interpolation |
| 92 | +-------------------------- |
| 93 | + |
| 94 | +Similar to the :ref:`spline_example`, the trajectory point interface can be used to execute motions |
| 95 | +using the spline interpolation: |
| 96 | + |
| 97 | +.. literalinclude:: ../../examples/trajectory_point_interface.cpp |
| 98 | + :language: c++ |
| 99 | + :caption: examples/trajectory_point_interface.cpp |
| 100 | + :linenos: |
| 101 | + :lineno-match: |
| 102 | + :start-after: // --------------- SPLINE TRAJECTORY ------------------- |
| 103 | + :end-before: // --------------- END SPLINE TRAJECTORY ------------------- |
0 commit comments