From d41a2fdfd481088392f20996ccf1594344b909e3 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 24 Apr 2017 09:56:27 -0700 Subject: [PATCH] change hand.ino/py to match hardware changes (use pullup resistor, connect to gnd, instead of 5V + pull down resistor) --- examples/pybullet/examples/hand.ino | 4 ++++ examples/pybullet/examples/hand.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/pybullet/examples/hand.ino b/examples/pybullet/examples/hand.ino index faf5b70bc..1e5f5df17 100644 --- a/examples/pybullet/examples/hand.ino +++ b/examples/pybullet/examples/hand.ino @@ -10,6 +10,10 @@ int sensorPin3 = A3; void setup() { // put your setup code here, to run once: Serial.begin(115200); + digitalWrite(A0, INPUT_PULLUP); + digitalWrite(A1, INPUT_PULLUP); + digitalWrite(A2, INPUT_PULLUP); + digitalWrite(A3, INPUT_PULLUP); } void loop() { diff --git a/examples/pybullet/examples/hand.py b/examples/pybullet/examples/hand.py index 10c9fbd89..2c16cfe88 100644 --- a/examples/pybullet/examples/hand.py +++ b/examples/pybullet/examples/hand.py @@ -23,7 +23,7 @@ hand=objects[0] #minV = 400 #maxV = 600 minV = 250 -maxV = 450 +maxV = 400 p.setRealTimeSimulation(1) @@ -44,7 +44,7 @@ def convertSensor(x): if (v>maxV): v=maxV b = (v-minV)/float(maxV-minV) - return (1.0-b) + return (b) ser = None portindex = 0 @@ -62,6 +62,7 @@ while (ser is None and portindex < 30): if (ser is None): ser = serial.Serial(port = "/dev/cu.usbmodem1421",baudrate=115200,parity=serial.PARITY_ODD,stopbits=serial.STOPBITS_TWO,bytesize=serial.SEVENBITS) +pi=3.141592 if (ser is not None and ser.isOpen()): while True: @@ -69,13 +70,13 @@ if (ser is not None and ser.isOpen()): line = str(ser.readline()) words = line.split(",") if (len(words)==6): - middle = convertSensor(words[1]) - pink = convertSensor(words[2]) + pink = convertSensor(words[1]) + middle = convertSensor(words[2]) index = convertSensor(words[3]) thumb = convertSensor(words[4]) - - p.setJointMotorControl2(hand,7,p.POSITION_CONTROL,thumb) - p.setJointMotorControl2(hand,9,p.POSITION_CONTROL,thumb) + + p.setJointMotorControl2(hand,7,p.POSITION_CONTROL,pi/4.) + p.setJointMotorControl2(hand,9,p.POSITION_CONTROL,thumb+pi/10) p.setJointMotorControl2(hand,11,p.POSITION_CONTROL,thumb) p.setJointMotorControl2(hand,13,p.POSITION_CONTROL,thumb)