forked from tsinghua-rll/UR5_Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UR5_pid.py
37 lines (32 loc) · 1.05 KB
/
UR5_pid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import logging
import time
from RTIF.API import API
# this script demonstrate how to control the robot arm to a specified location
# by writing the angle of each joint.
#
# Notice: the default initial position is a singular position which we can only
# control the joint angle but cannot set tool location (the Invert Kines solver
# will report error)
def main(ROBOT_HOST = "192.168.1.104"):
logging.getLogger().setLevel(logging.INFO)
api = API(ROBOT_HOST)
target=[]#the target position of end effector x,y,z,rx,ry,rz
qnear=[]
target_j=api.get_inv_kin(target,qnear)
current_j=api.GetCurrentJointRad
kp=3
kv=0.5
lamb=kp/kv
error=current_j-target_j
sat=vmax/(lamb*np.abs(error))
scale=np.ones(6)
if np.any(sat<1):
index=np.argmin(sat)
unclipped=kp*error[index]
clipped=kv*vmax*np.sign(error[index])
scale=np.ones(6*clipped/unclipped)
scale[index]=1
qv=-kv*(dx+np.clip(sat/scale,0,1)*scale[index]*lamb*error)
api.SpeedJointRad(qv,a,t)
if __name__ == "__main__":
main()