|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright 2024, Universal Robots |
| 3 | +# |
| 4 | +# Redistribution and use in source and binary forms, with or without |
| 5 | +# modification, are permitted provided that the following conditions are met: |
| 6 | +# |
| 7 | +# * Redistributions of source code must retain the above copyright |
| 8 | +# notice, this list of conditions and the following disclaimer. |
| 9 | +# |
| 10 | +# * Redistributions in binary form must reproduce the above copyright |
| 11 | +# notice, this list of conditions and the following disclaimer in the |
| 12 | +# documentation and/or other materials provided with the distribution. |
| 13 | +# |
| 14 | +# * Neither the name of the {copyright_holder} nor the names of its |
| 15 | +# contributors may be used to endorse or promote products derived from |
| 16 | +# this software without specific prior written permission. |
| 17 | +# |
| 18 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | +# POSSIBILITY OF SUCH DAMAGE. |
| 29 | + |
| 30 | +import rclpy |
| 31 | +from builtin_interfaces.msg import Duration |
| 32 | +from rclpy.node import Node |
| 33 | +from robot_class import Robot |
| 34 | + |
| 35 | + |
| 36 | +if __name__ == "__main__": |
| 37 | + rclpy.init() |
| 38 | + node = Node("robot_driver_test") |
| 39 | + robot = Robot(node) |
| 40 | + |
| 41 | + # The following list are arbitrary joint positions, change according to your own needs |
| 42 | + waypts = [ |
| 43 | + [-1, -2.5998, -1.004, -2.676, -0.992, -1.5406], |
| 44 | + [-0.5, -2.0, -0.5, -2.0, -0.4, -1.0], |
| 45 | + [0, -1.5, 0, 0, 0, -0.5], |
| 46 | + [-0.5, -2.0, -0.5, -2.0, -0.4, -1.0], |
| 47 | + [-1, -2.5998, -1.004, -2.676, -0.992, -1.5406], |
| 48 | + ] |
| 49 | + # Velocities and accelerations can be omitted |
| 50 | + vels = [ |
| 51 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 52 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 53 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 54 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 55 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 56 | + ] |
| 57 | + accels = [ |
| 58 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 59 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 60 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 61 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 62 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 63 | + ] |
| 64 | + bad_vels = [ |
| 65 | + [0.1, 0.1, 0.1, 0.1, 0.1], |
| 66 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 67 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 68 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 69 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 70 | + ] |
| 71 | + bad_accels = [ |
| 72 | + [0.1, 0.1, 0.1, 0.1, 0.1], |
| 73 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 74 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 75 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 76 | + [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], |
| 77 | + ] |
| 78 | + time_vec = [ |
| 79 | + Duration(sec=2, nanosec=0), |
| 80 | + Duration(sec=6, nanosec=0), |
| 81 | + Duration(sec=10, nanosec=0), |
| 82 | + Duration(sec=14, nanosec=0), |
| 83 | + Duration(sec=18, nanosec=0), |
| 84 | + ] |
| 85 | + |
| 86 | + # Execute trajectory on robot, make sure that the robot is booted and the control script is running |
| 87 | + robot.play() |
| 88 | + # Trajectory using positions, velocities and accelerations |
| 89 | + robot.passthrough_trajectory(waypts, time_vec, vels, accels) |
| 90 | + # Trajectory using only positions |
| 91 | + robot.passthrough_trajectory(waypts, time_vec) |
| 92 | + |
| 93 | + robot.passthrough_trajectory(waypts, time_vec, bad_vels, accels) |
| 94 | + |
| 95 | + robot.passthrough_trajectory(waypts, time_vec, vels, bad_accels) |
0 commit comments