電腦對電腦
程式碼:
function
sysCall_init()
KickBallV = 10
R_KickBallVel = (
math.pi
/180)*KickBallV
B_KickBallVel = -(
math.pi
/180)*KickBallV
Sphere_handle=sim.getObjectHandle(
'Sphere'
)
BRod_handle=sim.getObjectHandle(
'BRod'
)
BRev_handle=sim.getObjectHandle(
'BRev'
)
BMo_handle=sim.getObjectHandle(
'BMo'
)
--
RRod_handle=sim.getObjectHandle(
'RRod'
)
RRev_handle=sim.getObjectHandle(
'RRev'
)
RMo_handle=sim.getObjectHandle(
'RMo'
)
end
function
sysCall_actuation()
position_BR=sim.getObjectPosition(BRod_handle,-1)
position_S=sim.getObjectPosition(Sphere_handle,-1)
X =position_S[1] - position_BR[1]
Y =position_S[2] - position_BR[2]
if
1
then
if
X <= 0.02
and
Y <= 0
then
sim.setJointTargetVelocity(BRev_handle,B_KickBallVel)
sim.setJointTargetVelocity(BRev_handle,-1)
elseif
X > 0.02
and
Y <= 0
then
sim.setJointTargetVelocity(BRev_handle,B_KickBallVel)
sim.setJointTargetVelocity(BRev_handle,1)
elseif
X <= 0.02
and
Y > 0
then
sim.setJointTargetVelocity(BRev_handle,R_KickBallVel)
sim.setJointTargetVelocity(BRev_handle,-1)
elseif
X > 0.02
and
Y > 0
then
sim.setJointTargetVelocity(BRev_handle,R_KickBallVel)
sim.setJointTargetVelocity(BRev_handle,1)
end
YYYYY = Y*5
sim.setJointTargetVelocity(BMo_handle,YYYYY)
end
---
position_RR=sim.getObjectPosition(RRod_handle,-1)
X =position_S[1] - position_RR[1]
Y =position_S[2] - position_RR[2]
if
1
then
if
X <= 0.02
and
Y <= 0
then
sim.setJointTargetVelocity(RRev_handle,B_KickBallVel)
sim.setJointTargetVelocity(RRev_handle,-1)
elseif
X > 0.02
and
Y <= 0
then
sim.setJointTargetVelocity(RRev_handle,B_KickBallVel)
sim.setJointTargetVelocity(RRev_handle,1)
elseif
X <= 0.02
and
Y > 0
then
sim.setJointTargetVelocity(RRev_handle,R_KickBallVel)
sim.setJointTargetVelocity(RRev_handle,-1)
elseif
X > 0.02
and
Y > 0
then
sim.setJointTargetVelocity(RRev_handle,R_KickBallVel)
sim.setJointTargetVelocity(RRev_handle,1)
end
YYYYY = Y*5
sim.setJointTargetVelocity(RMo_handle,YYYYY)
end
end
--by 40623130--