servo_cartesian_test.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import sys
4 import time
5 import rospy
6 from xarm_msgs.srv import *
7 
8 def servo_cartesian_tool(step, freq, time_secs):
9  servo_cart = rospy.ServiceProxy('/xarm/move_servo_cart', Move)
10  req = MoveRequest()
11  req.pose = step
12  req.mvvelo = 0
13  req.mvacc = 0
14  req.mvtime = 1 # tool coordinate motion
15  loop_num = time_secs*float(freq)
16  sleep_sec = 1.0/float(freq)
17  ret = 0
18 
19  try:
20  for i in range(int(loop_num)):
21  res = servo_cart(req)
22  if res.ret:
23  print("Something Wrong happened calling servo_cart service, index is %d, ret = %d"%(i, res.ret))
24  ret = -1
25  break
26  time.sleep(sleep_sec)
27  return ret
28 
29  except rospy.ServiceException as e:
30  print("servo_cartesian (tool) Service call failed: %s"%e)
31  return -1
32 
33 
34 if __name__ == "__main__":
35 
36  rospy.wait_for_service('/xarm/move_servo_cart')
37  rospy.set_param('/xarm/wait_for_finish', True) # return after motion service finish
38 
39  motion_en = rospy.ServiceProxy('/xarm/motion_ctrl', SetAxis)
40  set_mode = rospy.ServiceProxy('/xarm/set_mode', SetInt16)
41  set_state = rospy.ServiceProxy('/xarm/set_state', SetInt16)
42  home = rospy.ServiceProxy('/xarm/go_home', Move)
43 
44  try:
45  motion_en(8,1)
46  set_mode(0)
47  set_state(0)
48  req = MoveRequest() # MoveRequest for go_home
49  req.mvvelo = 0.7
50  req.mvacc = 3.5
51  req.mvtime = 0
52  home(req)
53 
54  except rospy.ServiceException as e:
55  print("Before servo_cartesian, service call failed: %s"%e)
56  exit(-1)
57 
58  # configurations for servo_cartesian
59  set_mode(1)
60  set_state(0)
61 
62  # relative step for servo_cartesian in TOOL Coordinate (req.mvtime = 1)
63  step = [0.3, 0, 0, 0, 0, 0]
64  # publish frequency in Hz:
65  freq = 100
66  # publish time in seconds:
67  time_secs = 5.0
68 
69  time.sleep(2.0)
70  if servo_cartesian_tool(step, freq, time_secs) == 0:
71  print("execution finished successfully!")
def servo_cartesian_tool(step, freq, time_secs)


xarm_api
Author(s):
autogenerated on Sat May 8 2021 02:51:23