import vcCore as vc
import vcBehaviors as vc_beh
import vcRobotics2 as rb2

comp = vc.getComponent()
app = vc.getApplication()
world = vc.getWorld()

motion = comp.findBehavior("MotionController")
Y101a = comp.findBehavior("Y101")
Y102a = comp.findBehavior("Y102")
X101a = comp.Properties["X101"]
X102a = comp.Properties["X102"]

driverIndex = 2
isExternal = False
valueType = rb2.vcDriverTargetValueType.POSITION
isSynchronized = False
TimeOut = 60
TargetValue1 = 100
TargetValue2 = 0

async def OnRun():
  X101a.Value = False
  X102a.Value = True
  
  while True:
    await vc.delay(0.1)

    if Y101a.Value == True:
      X102a.Value = False
      motionId = motion.addIndependentTarget(
                0,  driverIndex,isExternal,
        valueType,  TargetValue1,isSynchronized
      )
      motion.moveIndependent()
      await motion.waitUntilTargetsReached([motionId],TimeOut)
      X101a.Value = True
      

    if Y102a.Value == True:
      X101a.Value = False
      motionId = motion.addIndependentTarget(
                0,  driverIndex,isExternal,
        valueType,  TargetValue2,isSynchronized
      )
      motion.moveIndependent()
      await motion.waitUntilTargetsReached([motionId],TimeOut)
      X102a.Value = True
      