Universal Robots Forum

How to move UR by publishing pose into /ur_hardware_interface/script_command in Python

Hi all,

We are working on a ur10e, and the fisrt task is to make the robot move to a target position. We are using python as a programmin language and we are not intersted to use moveit packgae to do this task, since we have already done it and it made this task complicated without benefeít. I have found out there is possibility to publish the desired pose message into /ur_hardware_interface/script_command topic, but what I dont know exactly how I can use the message structure and associated command in python. I think there are multiple commands like movel,movej,servoj that are suppose to do the task, but we could not make ´them work. I put the simplified code that we developed to serve the task below, but robot did not move. I should mentioned we launched the ros driver already and robot is controlled by moveit package.

import rospy
from tf2_msgs.msg import TFMessage
import geometry_msgs
from geometry_msgs.msg import Point, Pose, PoseStamped
from math import pi, sqrt
from std_msgs.msg import String, Bool
from tf import TransformListener
import tf
import math

def talker():
rospy.init_node(‘ur10e_script_publisher’, anonymous=True)
pub = rospy.Publisher(’/ur_hardware_interface/script_command’, String, queue_size=10)
rate = rospy.Rate(10) # 10hz

#while not rospy.is_shutdown():
print "robit is moving to target ----"
msg = ("movel(get_inverse_kin(p[1.1,0,0,0,0,0]), a=1.4, v=1.05, t=0, r=0)" + "\n")
pub.publish(msg)
print msg
rospy.spin()

if name == ‘main’:
talker()

A more appropriate solution would be to use the actual controller interface offered by the controller directly. Simply publish your trajectory to /scaled_pos_joint_traj_controller/follow_joint_trajectory/goal (or better use an action client to do so, as otherwise you won’t get any feedback or result from your motion.)

Your goal should look similar like this:

goal:
  trajectory:
    header:
      seq: 0
      stamp:
        secs: 0
        nsecs: 0
      frame_id: ''
    joint_names:
      - shoulder_pan_joint
      - shoulder_lift_joint
      - elbow_joint
      - wrist_1_joint
      - wrist_2_joint
      - wrist_3_joint
    points:
    - positions: [0, 0, 0, 0, 0, 0] # fill your desired joint positions here
      velocities: [0, 0, 0, 0, 0, 0] # you want to stop at your final position
      accelerations: [] # no need to fill those
      effort: [] # no need to fill those
      time_from_start: {secs: 2, nsecs: 0} # reducing this time will make your trajectory execution faster obviously
  path_tolerance:
  - {name: '', position: 0.0, velocity: 0.0, acceleration: 0.0}
  goal_tolerance:
  - {name: '', position: 0.0, velocity: 0.0, acceleration: 0.0}
  goal_time_tolerance: {secs: 0, nsecs: 0}

If you want to use Cartesian poses, use some inverse kinematics like trac_ik to get a corresponding joint pose first.

Alternatively, become part of our beta test program and use the new advanced controllers:

  • Cartesian trajectory controller (similar to the joint trajectory controller shown above, but using the IK on the robot controller)
  • Passthrough controllers (Cartesian and joint domain available, will perform trajectory interpolation on the robot controller instead of ROS.

You can find everything on the beta-testing branch of the driver.

If you really want to use the scripting interface, however, make sure that the robot is put into “remote control” mode before executing the script code, as otherwise it will not accept motion commands coming from the scripting interface.

Hello mauch, I have a question to your answer. If I understood it right, I
have following opportunities to move the robot to Cartesian poses:

  • Use beta Driver with Cartesian trajectory controller ( I can easy
    publish Cartesian pose / my desired target point in space?)

  • use inverse kinematic to get joint pose and then publishing it to
    the `"/scaled_pos_joint_traj_controller/follow_joint_trajectory/goal"
    topic.

I search for inverse kinematic in the ROS-Driver and the file
“kinematics.yalm” have some solver inside. (kinematics_solver:
kdl_kinematics_plugin/KDLKinematicsPlugin or kinematics_solver:
ur_kinematics/UR5KinematicsPlugin). does it work? or how i have to use
it?
ROS-Driver has debug function and there are some MoveGroup
capabilities to load, can it help me to move the robot to Cartesian
poses?

What about Planning Cartesian pose and then execute it in MoveIt? I
scroll MoveIt-tutorial (Move Group C++ Interface) and there is example
with panda-config. But there are finished scripts and I don’t know how
to do it with my UR5.

my purpose:
the aim of my “work” is to move the UR5 (I am using ros noetic) to the
object. Certain coordinates of the object are given.

Sorry if my question is not qualified, I am new in ROS and this theme
is complicate. I hope for a detailed answer please.

I search for inverse kinematic in the ROS-Driver and the file
“kinematics.yalm” have some solver inside. (kinematics_solver:
kdl_kinematics_plugin/KDLKinematicsPlugin or kinematics_solver:
ur_kinematics/UR5KinematicsPlugin). does it work? or how i have to use
it?
ROS-Driver has debug function and there are some MoveGroup
capabilities to load, can it help me to move the robot to Cartesian
poses?

The ur_robot_driver does not provide those things you mention.

Of course, you can use the`ur_robot_driver? with MoveIt and given your project description this seems like the best approach. Make sure to follow the MoveIt! instructions on setting up a custom MoveIt configuration for your application and then you should be ready to go.

how can i setting up a custom MoveIt configuration? i go through MoveIt tutorial ( http://moveit2_tutorials.picknik.ai/doc/move_group_interface/move_group_interface_tutorial.html#move-group-c-interface). I need features like this. To plan a Cartesian Point and execute this. But in the Tutorial all scripts and libraries are already configured and there is no Tutorial how can i config my ur5.

By the way, i install demo-testing branch to try out, how can i use Cartesian trajectory controller. But how i start and configure it? There is no Tutorial how can i configure my Controller.yaml and how to launch Cartesian features =(

you’ll need to use MoveIt!'s setup assistant to create your own workcell configuration.

is it necessary to create own configuration? or can i use existing ur5_moveit_config? ( catkin_ws/src/fmauch_universal_robot/ur5_moveit_config) or is there something missing?

In order to use the MoveIt! configuration from universal_robot/ur5_moveit_config, you’ll have to change the default cotroller.yaml file (see this comment).

Apart from that, this won’t respect any objects inside your actual workcell setup. The robot is probably mounted on a table, there might be other objects in the way, etc. Due to this it does make a lot of sense to create your own configuration.

where can i find URDF or COLLADA Robot Model to create New Moveit configuration package?

I want to start moveit! Setup Assistant, and i need to load URDF. I tried to use URDF from this:

/catkin_ws/src/fmauch_universal_robot/ur_description/urdf - there is 3 urdf files.

but i have always Error: URDF/COLLADA file is not a valid robot model.

Where can i find valid file to create own configuration?

ur5_robot.urdf.xacro seems to work for me: