import
sim as vrep
import
math
import
random
import
time
import
keyboard
print
(
'Start'
)
vrep.simxFinish(
-
1
)
clientID
=
vrep.simxStart(
'192.168.0.4'
,
19997
,
True
,
True
,
5000
,
5
)
if
clientID !
=
-
1
:
print
(
'Connected to remote API server'
)
res
=
vrep.simxAddStatusbarMessage(
clientID,
"40823218"
,
vrep.simx_opmode_oneshot)
if
res
not
in
(vrep.simx_return_ok, vrep.simx_return_novalue_flag):
print
(
"Could not add a message to the status bar."
)
opmode
=
vrep.simx_opmode_oneshot_wait
STREAMING
=
vrep.simx_opmode_streaming
vrep.simxStartSimulation(clientID, opmode)
ret,base_handle
=
vrep.simxGetObjectHandle(clientID,
"joint1"
,opmode)
ret,bottom_handle
=
vrep.simxGetObjectHandle(clientID,
"joint2"
,opmode)
ret,top_handle
=
vrep.simxGetObjectHandle(clientID,
"joint3"
,opmode)
ret,rotate_handle
=
vrep.simxGetObjectHandle(clientID,
"joint4"
,opmode)
ret,wrist_handle
=
vrep.simxGetObjectHandle(clientID,
"joint5"
,opmode)
while
True
:
if
keyboard.is_pressed(
"a"
):
vrep.simxSetJointTargetVelocity(clientID,base_handle,
0.2
,opmode)
if
keyboard.is_pressed(
"f"
):
vrep.simxSetJointTargetVelocity(clientID,base_handle,
-
0.2
,opmode)
if
keyboard.is_pressed (
"w"
):
vrep.simxSetJointTargetVelocity(clientID,bottom_handle,
0.2
,opmode)
if
keyboard.is_pressed (
"s"
):
vrep.simxSetJointTargetVelocity(clientID,bottom_handle,
-
0.2
,opmode)
if
keyboard.is_pressed (
"e"
):
vrep.simxSetJointTargetVelocity(clientID,top_handle,
0.2
,opmode)
if
keyboard.is_pressed (
"d"
):
vrep.simxSetJointTargetVelocity(clientID,top_handle,
-
0.2
,opmode)
if
keyboard.is_pressed (
"r"
):
vrep.simxSetJointTargetVelocity(clientID,rotate_handle,
0.2
,opmode)
if
keyboard.is_pressed (
"j"
):
vrep.simxSetJointTargetVelocity(clientID,wrist_handle,
0.2
,opmode)
if
keyboard.is_pressed (
"k"
):
vrep.simxSetJointTargetVelocity(clientID,wrist_handle,
-
0.2
,opmode)
if
keyboard.is_pressed (
"space"
):
vrep.simxSetJointTargetVelocity(clientID,base_handle,
0
,opmode)
vrep.simxSetJointTargetVelocity(clientID,bottom_handle,
0
,opmode)
vrep.simxSetJointTargetVelocity(clientID,top_handle,
0
,opmode)
vrep.simxSetJointTargetVelocity(clientID,rotate_handle,
0
,opmode)
vrep.simxSetJointTargetVelocity(clientID,wrist_handle,
0
,opmode)
else
:
print
(
'Failed connecting to remote API server'
)
print
(
'End'
)