codice netkar pro - netKar PRO Forums - DrivingItalia.NET simulatori di guida Jump to content

Recommended Posts

Posted

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 :crying: .. quindi e' un casino postare codice

Posted

	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. :sticazzi::asd:

Posted

bella prova :P

perfetto.. grazie 1000.. ehm.. :imbarazzato: io pi

Posted

bella prova :P

perfetto.. grazie 1000.. ehm.. :imbarazzato: io pi

Posted (edited)

ah beh se allora il tuo problema e' il codice di basso livello per interfacciarti alle periferiche allora buona fortuna :sticazzi:

xk?

Edited by noitide
Posted

ah beh se allora il tuo problema e' il codice di basso livello per interfacciarti alle periferiche allora buona fortuna :sticazzi:

xk?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.