kunos Posted September 8, 2009 Posted September 8, 2009 tutto il codice sarebbe complicato perche' sono diverse classi. Cmq la funzione "incriminata" e' questa: public int detectAxis() { int ret = 0; if (device.hasMoved) { if (device.state.px < stateMin.px) stateMin.px = device.state.px; if (device.state.py < stateMin.py) stateMin.py = device.state.py; if (device.state.pz < stateMin.pz) stateMin.pz = device.state.pz; if (device.state.rx < stateMin.rx) stateMin.rx = device.state.rx; if (device.state.ry < stateMin.ry) stateMin.ry = device.state.ry; if (device.state.rz < stateMin.rz) stateMin.rz = device.state.rz; if (device.state.sl0 < stateMin.sl0) stateMin.sl0 = device.state.sl0; if (device.state.sl1 < stateMin.sl1) stateMin.sl1 = device.state.sl1; // MAX if (device.state.px > stateMax.px) stateMax.px = device.state.px; if (device.state.py > stateMax.py) stateMax.py = device.state.py; if (device.state.pz > stateMax.pz) stateMax.pz = device.state.pz; if (device.state.rx > stateMax.rx) stateMax.rx = device.state.rx; if (device.state.ry > stateMax.ry) stateMax.ry = device.state.ry; if (device.state.rz > stateMax.rz) stateMax.rz = device.state.rz; if (device.state.sl0 > stateMax.sl0) stateMax.sl0 = device.state.sl0; if (device.state.sl1 > stateMax.sl1) stateMax.sl1 = device.state.sl1; if (Math.Abs(stateMax.px - stateMin.px) > threshold) ret = 1; if (Math.Abs(stateMax.py - stateMin.py) > threshold) ret = 2; if (Math.Abs(stateMax.pz - stateMin.pz) > threshold) ret = 3; if (Math.Abs(stateMax.rx - stateMin.rx) > threshold) ret = 4; if (Math.Abs(stateMax.ry - stateMin.ry) > threshold) ret = 5; if (Math.Abs(stateMax.rz - stateMin.rz) > threshold) ret = 6; if (Math.Abs(stateMax.sl0 - stateMin.sl0) > threshold) ret = 7; if (Math.Abs(stateMax.sl1 - stateMin.sl1) > threshold) ret = 8; } return ret; } Con i valori di stato minimi e massimi che vengono impostati all'inizio cosi': public void reset() { stateMin.px = 90000; stateMin.py = 90000; stateMin.pz = 90000; stateMin.rx = 90000; stateMin.ry = 90000; stateMin.rz = 90000; stateMin.sl0 = 90000; stateMin.sl1 = 90000; stateMax.px = -90000; stateMax.py = -90000; stateMax.pz = -90000; stateMax.rx = -90000; stateMax.ry = -90000; stateMax.rz = -90000; stateMax.sl0 = -90000; stateMax.sl1 = -90000; } Threshold e' settato a 0.5. In pratica devi andare oltre meta' corsa dell'asse per triggerare il detect EDIT: Purtoppo il forum non vede i tab .. quindi e' un casino postare codice
Guest Vange Posted September 8, 2009 Posted September 8, 2009 public int detectAxis() { int ret = 0; if (device.hasMoved) { if (device.state.px < stateMin.px) stateMin.px = device.state.px; if (device.state.py < stateMin.py) stateMin.py = device.state.py; if (device.state.pz < stateMin.pz) stateMin.pz = device.state.pz; if (device.state.rx < stateMin.rx) stateMin.rx = device.state.rx; if (device.state.ry < stateMin.ry) stateMin.ry = device.state.ry; if (device.state.rz < stateMin.rz) stateMin.rz = device.state.rz; if (device.state.sl0 < stateMin.sl0) stateMin.sl0 = device.state.sl0; if (device.state.sl1 < stateMin.sl1) stateMin.sl1 = device.state.sl1; // MAX if (device.state.px > stateMax.px) stateMax.px = device.state.px; if (device.state.py > stateMax.py) stateMax.py = device.state.py; if (device.state.pz > stateMax.pz) stateMax.pz = device.state.pz; if (device.state.rx > stateMax.rx) stateMax.rx = device.state.rx; if (device.state.ry > stateMax.ry) stateMax.ry = device.state.ry; if (device.state.rz > stateMax.rz) stateMax.rz = device.state.rz; if (device.state.sl0 > stateMax.sl0) stateMax.sl0 = device.state.sl0; if (device.state.sl1 > stateMax.sl1) stateMax.sl1 = device.state.sl1; if (Math.Abs(stateMax.px - stateMin.px) > threshold) ret = 1; if (Math.Abs(stateMax.py - stateMin.py) > threshold) ret = 2; if (Math.Abs(stateMax.pz - stateMin.pz) > threshold) ret = 3; if (Math.Abs(stateMax.rx - stateMin.rx) > threshold) ret = 4; if (Math.Abs(stateMax.ry - stateMin.ry) > threshold) ret = 5; if (Math.Abs(stateMax.rz - stateMin.rz) > threshold) ret = 6; if (Math.Abs(stateMax.sl0 - stateMin.sl0) > threshold) ret = 7; if (Math.Abs(stateMax.sl1 - stateMin.sl1) > threshold) ret = 8; } return ret; } Con i valori di stato minimi e massimi che vengono impostati all'inizio cosi': public void reset() { stateMin.px = 90000; stateMin.py = 90000; stateMin.pz = 90000; stateMin.rx = 90000; stateMin.ry = 90000; stateMin.rz = 90000; stateMin.sl0 = 90000; stateMin.sl1 = 90000; stateMax.px = -90000; stateMax.py = -90000; stateMax.pz = -90000; stateMax.rx = -90000; stateMax.ry = -90000; stateMax.rz = -90000; stateMax.sl0 = -90000; stateMax.sl1 = -90000; } Fixed.
noitide Posted September 8, 2009 Author Posted September 8, 2009 bella prova perfetto.. grazie 1000.. ehm.. io pi
kunos Posted September 8, 2009 Posted September 8, 2009 bella prova perfetto.. grazie 1000.. ehm.. io pi
noitide Posted September 8, 2009 Author Posted September 8, 2009 (edited) ah beh se allora il tuo problema e' il codice di basso livello per interfacciarti alle periferiche allora buona fortuna xk? Edited September 8, 2009 by noitide
kunos Posted September 9, 2009 Posted September 9, 2009 ah beh se allora il tuo problema e' il codice di basso livello per interfacciarti alle periferiche allora buona fortuna xk?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now