urcontrol/tests/servoj_circle.py

62 lines
1.4 KiB
Python
Raw Normal View History

2022-05-19 15:11:25 +00:00
import rtde_control
import time
import math
rtde_c = rtde_control.RTDEControlInterface("192.168.1.101")
# Parameters
velocity = 0.1 #0.5
acceleration = 0.1 #0.5
frequency= 100
dt = 1.0/frequency # 2ms
lookahead_time = 0.1
gain = 300
joint_q = [-1.54, -1.83, -2.28, -0.59, 1.60, 0.023]
# Move to initial joint position with a regular moveJ
2022-05-19 15:29:54 +00:00
duration=20
xcenter=-0.5
ycenter=0.1
2022-05-19 15:11:25 +00:00
zcenter=0.5
c=0
2022-05-19 15:29:54 +00:00
cx=0
scale=0.1
rtde_c.moveJ([3.091137462206234, -1.2753459082058711, -1.7658837933568385, -1.6701929639036406, 1.5738425257277626, 4.658345567448585],0.1,0.1)
joint_q=rtde_c.getInverseKinematics([xcenter+math.sin(cx)*0.2,ycenter+math.cos(c)*scale,zcenter+math.sin(c)*scale,0.0,3.14159,0.0])
print("Start q")
print(joint_q)
2022-05-19 15:11:25 +00:00
print("Starting Servo")
# Execute 500Hz control loop for 2 seconds, each cycle is 2ms
for i in range(frequency*duration):
start = time.time()
2022-05-19 15:29:54 +00:00
c=i/(frequency*duration) * 2 *3.1415 * 8
2022-05-19 15:11:25 +00:00
c%= (2*3.1415)
2022-05-19 15:29:54 +00:00
cx=i/(frequency*duration) * 2 *3.1415 * 1
cx%= (2*3.1415)
2022-05-19 15:11:25 +00:00
2022-05-19 15:29:54 +00:00
joint_q=rtde_c.getInverseKinematics([xcenter+math.sin(cx)*0.2,ycenter+math.cos(c)*scale,zcenter+math.sin(c)*scale,0.0,3.14159,0.0])
2022-05-19 15:11:25 +00:00
#print(joint_q)
rtde_c.servoJ(joint_q, velocity, acceleration, dt, lookahead_time, gain)
end = time.time()
stepduration = end - start
if stepduration < dt:
time.sleep(dt - stepduration)
print("Finished")
rtde_c.servoStop()
2022-05-19 15:29:54 +00:00
rtde_c.stopScript()