diff --git a/examples/pybullet/vrhand.py b/examples/pybullet/vrhand.py index 44651c65e..2ab6ab732 100644 --- a/examples/pybullet/vrhand.py +++ b/examples/pybullet/vrhand.py @@ -53,15 +53,28 @@ def convertSensor(x): b = (v-minV)/float(maxV-minV) return (1.0-b) +controllerId = -1 + +serialSteps = 0 +serialStepsUntilCheckVREvents = 3 + + ser = serial.Serial(port='COM9',baudrate=115200,parity=serial.PARITY_ODD,stopbits=serial.STOPBITS_TWO,bytesize=serial.SEVENBITS) if (ser.isOpen()): while True: events = p.getVREvents() for e in (events): if (e[BUTTONS][33]&p.VR_BUTTON_IS_DOWN): + controllerId = e[0] + if (e[0] == controllerId): p.changeConstraint(hand_cid,e[POSITION],e[ORIENTATION], maxForce=50) + serialSteps = 0 while ser.inWaiting() > 0: + serialSteps=serialSteps+1 + if (serialSteps>serialStepsUntilCheckVREvents): + ser.flushInput() + break line = str(ser.readline()) words = line.split(",") if (len(words)==6):