forked from vision-agh/apse_uav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendIkMovementSequence-mov.py
executable file
·127 lines (99 loc) · 3.68 KB
/
sendIkMovementSequence-mov.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Make sure to have CoppeliaSim running, with followig scene loaded:
#
# scenes/messaging/ikMovementViaRemoteApi.ttt
#
# Do not launch simulation, then run this script
from zmqRemoteApi import RemoteAPIClient
import time
import numpy as np
import ctypes
print('Program started')
client = RemoteAPIClient()
sim = client.getObject('sim')
sim.stopSimulation()
while sim.getSimulationState() != sim.simulation_stopped:
time.sleep(0.1)
executedMovId = 'notReady'
targetArm = '/z1_robot'
stringSignalName = targetArm + '_executedMovId'
robotBaseHandle = sim.getObject(targetArm)
scriptHandle = sim.getScript(sim.scripttype_childscript, robotBaseHandle)
tipHandle = sim.getObject('/tip')
targetHandle = sim.getObject('/target')
yokeBoardHandle = sim.getObject('/yoke_board')
tipArucoHandle = sim.getObject('/gripper_board')
def waitForMovementExecuted(id_):
global executedMovId, stringSignalName
while executedMovId != id_:
s = sim.getStringSignal(stringSignalName)
executedMovId = s
def waitForMovementExecutedAsync(id_):
global executedMovId
while executedMovId != id_:
s = sim.waitForSignal(id_)
if s is True:
executedMovId = id_
# Set-up some movement variables:
maxVel = 0.1
maxAccel = 0.01
# Start simulation:
sim.startSimulation()
# Wait until ready:
waitForMovementExecutedAsync('z1_ready')
#this part is illustrated in labeled_image_sample_3.png
tip_aruco_rb_orig = sim.getObjectPose(tipArucoHandle, robotBaseHandle)
tip_aruco_rb = [+4.7920e-01, 0, +5.5858e-01, -0.5, 0.5, -0.5, 0.5]
tip_aruco_w = sim.getObjectPose(tipArucoHandle, -1)
robot_base_w_orig = sim.getObjectPose(robotBaseHandle, -1)
tip_aruco_rb_orig_invert = sim.callScriptFunction('remoteApi_invertPose', scriptHandle, tip_aruco_rb_orig)
robot_base_w = sim.multiplyPoses(tip_aruco_w, tip_aruco_rb_orig_invert)
yoke_aruco_rb_orig = sim.getObjectPose(yokeBoardHandle, robotBaseHandle)
yoke_aruco_w = sim.getObjectPose(yokeBoardHandle, -1)
robot_base_w_invert = sim.callScriptFunction('remoteApi_invertPose', scriptHandle, robot_base_w)
yoke_aruco_rb = sim.multiplyPoses(robot_base_w_invert, yoke_aruco_w)
# Get initial pose:
initialPose, initialConfig = sim.callScriptFunction('remoteApi_getPoseAndConfig_base', scriptHandle)
zeroPose = [0.5, 0, 0.5, 0, 0, 0, 1]
# Send first movement sequence:
targetPose = yoke_aruco_rb
movementData = {
'id': 'movSeq1',
'type': 'mov',
'targetPose': targetPose,
'maxVel': maxVel,
'maxAccel': maxAccel
}
sim.callScriptFunction('remoteApi_movementDataFunction',scriptHandle,movementData)
# Execute first movement sequence:
sim.callScriptFunction('remoteApi_executeMovement', scriptHandle, 'movSeq1')
# Wait until above movement sequence finished executing:
waitForMovementExecutedAsync('movSeq1')
# Send second and third movement sequence, where third one should execute
# immediately after the second one:
# targetPose = yoke_rb
#
# movementData = {
# 'id': 'movSeq2',
# 'type': 'mov',
# 'targetPose': targetPose,
# 'maxVel': maxVel,
# 'maxAccel': maxAccel
# }
# sim.callScriptFunction('remoteApi_movementDataFunction',scriptHandle,movementData)
# movementData = {
# 'id': 'movSeq3',
# 'type': 'mov',
# 'targetPose': initialPose,
# 'maxVel': maxVel,
# 'maxAccel': maxAccel
# }
# sim.callScriptFunction('remoteApi_movementDataFunction',scriptHandle,movementData)
#
# # Execute second and third movement sequence:
# sim.callScriptFunction('remoteApi_executeMovement',scriptHandle,'movSeq2')
# # sim.callScriptFunction('remoteApi_executeMovement',scriptHandle,'movSeq3')
#
# # Wait until above 2 movement sequences finished executing:
# waitForMovementExecutedAsync('movSeq3')
# sim.stopSimulation()
print('Program ended')