Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Addons > Addon Development
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Addon Development Developers post news, updates, & discussions here about your projects in development.

Reply
 
Thread Tools
Old 04-12-2018, 05:22 PM   #16
fred18
Addon Developer

Default

Vrot not Arot
fred18 is offline   Reply With Quote
Old 04-12-2018, 10:21 PM   #17
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Quote:
Originally Posted by fred18 View Post
 Vrot not Arot
Thanks. When i get to my pc I will see where that is set.

---------- Post added at 05:21 PM ---------- Previous post was at 12:29 PM ----------

Ok i fixed that. But trying to turn.
Code:
	if (i3 > 0){
		
			VESSELSTATUS2 vs2;
			memset(&vs2, 0, sizeof(vs2));
			vs2.version = 2;
			GetStatusEx(&vs2);
			
			
			double radius = (targetSpeed*targetSpeed) / (grav_acc*tan(CurrentSterzo * 2 * Max_Steering_Angle));
			theta = CurrentSpeed*oapiGetSimStep() / radius;
			vs2.surf_hdg += theta;

			if (vs2.surf_hdg>2 * PI){ vs2.surf_hdg -= 2 * PI; }
		}

	if (i3 < 0){

		VESSELSTATUS2 vs2;
		memset(&vs2, 0, sizeof(vs2));
		vs2.version = 2;
		GetStatusEx(&vs2);

		double radius = (targetSpeed*targetSpeed) / (grav_acc*tan(CurrentSterzo * 2 * Max_Steering_Angle));
		theta = CurrentSpeed*oapiGetSimStep() / radius;


		vs2.surf_hdg += theta;

		if (vs2.surf_hdg<0){ vs2.surf_hdg += 2 * PI; }
	}
Code:
oid LER2016::clbkPostStep(double simt, double simdt, double mjd) {
	i3 = GetControlSurfaceLevel(AIRCTRL_RUDDER);
}
max steering is 360. As the ler has turn 360 degrees
gattispilot is online now   Reply With Quote
Old 04-14-2018, 10:40 PM   #18
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Tried new code. Same result no turning. As I see it when you turn the heading value gets changed.
Code:
void LER2016::MoveAround(){
	double theta = 0;
	Max_Steering_Angle = 360;

	memset(&vs2, 0, sizeof(vs2));
	vs2.version = 2;
	GetStatusEx(&vs2);
	if (FORWARDgear==1)
	
		


 {
		double d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg) / each_deg);
		double d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) / each_deg);
			vs2.surf_lat += d_lat*RAD;
			vs2.surf_lng += d_lng*RAD;
		}
	if (REVERSEgear == 1)




	{
		double d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg)/each_deg);
		double d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) /each_deg);
		vs2.surf_lat -= d_lat*RAD;
		vs2.surf_lng -= d_lng*RAD;
	}
	sprintf(oapiDebugString(), "targetSpeed %2.2f hd %2.2f ANg %2.2f", targetSpeed, vs2.surf_hdg, AngSpeed);
	if (i3 > 0){//right turn
		
		VESSELSTATUS2 vs2;
		memset(&vs2, 0, sizeof(vs2));
		vs2.version = 2;
		GetStatusEx(&vs2);
		double d_hdg = AngSpeed*oapiGetSimStep();//AngSpeed= 1.5*RAD
		vs2.surf_hdg -= d_hdg;

		if (vs2.surf_hdg<0){ vs2.surf_hdg += 2 * PI; }
		}

	if (i3 < 0){//left turn

		VESSELSTATUS2 vs2;
		memset(&vs2, 0, sizeof(vs2));
		vs2.version = 2;
		GetStatusEx(&vs2);
		double d_hdg = AngSpeed*oapiGetSimStep();
		vs2.surf_hdg += d_hdg;

		if (vs2.surf_hdg>2 * PI){ vs2.surf_hdg -= 2 * PI; }
	}


		double lng, lat, hdg;
		lng = vs2.surf_lng;
		lat = vs2.surf_lat;
		hdg = vs2.surf_hdg;


		{
			MATRIX3 rot1 = RotationMatrix(_V(0 * RAD, (90 * RAD - lng), 0 * RAD), TRUE);
			MATRIX3 rot2 = RotationMatrix(_V(-lat + 0 * RAD, 0, 0 * RAD), TRUE);
			MATRIX3 rot3 = RotationMatrix(_V(0, 0, 180 * RAD + hdg), TRUE);


			MATRIX3 rot4 = RotationMatrix(_V(90 * RAD, 0, 0), TRUE);
			//MATRIX3 rot4 = RotationMatrix(_V(90 * RAD - pitch_angle, 0, roll_angle), TRUE);

			//		MATRIX3 rot_pitch = RotationMatrix(_V(pitch_angle, 0, 0));
			//	MATRIX3 rot_roll = RotationMatrix(_V(0, 0, roll_angle));

			MATRIX3 RotMatrix_Def = mul(rot1, mul(rot2, mul(rot3, rot4)));




			vs2.arot.x = atan2(RotMatrix_Def.m23, RotMatrix_Def.m33);
			vs2.arot.y = -asin(RotMatrix_Def.m13);
			vs2.arot.z = atan2(RotMatrix_Def.m12, RotMatrix_Def.m11);

		}
		vs2.vrot.x = 2.35;

		//sprintf(oapiDebugString(), "targetSpeed %2.2f d_lat %2.2f d_lng %2.2f,rt %2.2f degree %2.2f hdg %2.2f", targetSpeed, vs2.surf_lat, vs2.surf_lng, rt, each_deg, vs2.surf_hdg);
		
		DefSetStateEx(&vs2);
		return;
	}


---------- Post added at 05:40 PM ---------- Previous post was at 07:19 AM ----------

So I got d_hdg to change. but the vessel still goes straight.
gattispilot is online now   Reply With Quote
Old 04-17-2018, 10:22 AM   #19
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

So the d_heading changes but not the vessel heading.
Not sure what I am missing. Once this is fixed it will be the change direction based on the wheels.

Code:
void LER2016::MoveAround(){
	double theta = 0;
	Max_Steering_Angle = 360;

	memset(&vs2, 0, sizeof(vs2));
	vs2.version = 2;
	GetStatusEx(&vs2);
	if (FORWARDgear==1)
	
		


 {
		double d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg) / each_deg);
		double d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) / each_deg);
			vs2.surf_lat += d_lat*RAD;
			vs2.surf_lng += d_lng*RAD;
			
		}
	if (REVERSEgear == 1)




	{
		double d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg)/each_deg);
		double d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) /each_deg);
		vs2.surf_lat -= d_lat*RAD;
		vs2.surf_lng -= d_lng*RAD;
		
	}
//	sprintf(oapiDebugString(), "targetSpeed %2.2f hd %2.2f ANg %2.2f", targetSpeed, vs2.surf_hdg, AngSpeed);
	if (i3 > 0){
		
		VESSELSTATUS2 vs2;
		memset(&vs2, 0, sizeof(vs2));
		vs2.version = 2;
		GetStatusEx(&vs2);
		d_hdg = d_hdg+.1;//rate of steering change of heading
		vs2.surf_hdg -= d_hdg;

		if (vs2.surf_hdg<0){ vs2.surf_hdg += 2 * PI; }
		
		}

	if (i3 < 0){

		VESSELSTATUS2 vs2;
		memset(&vs2, 0, sizeof(vs2));
		vs2.version = 2;
		GetStatusEx(&vs2);
		d_hdg = d_hdg-.1;//rate of steering change of heading
		vs2.surf_hdg += d_hdg;

		if (vs2.surf_hdg>2 * PI){ vs2.surf_hdg -= 2 * PI; }
		
	}


		
		lng = vs2.surf_lng;
		lat = vs2.surf_lat;
		hdg = vs2.surf_hdg;


		{
			MATRIX3 rot1 = RotationMatrix(_V(0 * RAD, (90 * RAD - lng), 0 * RAD), TRUE);
			MATRIX3 rot2 = RotationMatrix(_V(-lat + 0 * RAD, 0, 0 * RAD), TRUE);
			MATRIX3 rot3 = RotationMatrix(_V(0, 0, 180 * RAD + hdg), TRUE);


			MATRIX3 rot4 = RotationMatrix(_V(90 * RAD, 0, 0), TRUE);
			//MATRIX3 rot4 = RotationMatrix(_V(90 * RAD - pitch_angle, 0, roll_angle), TRUE);

			//		MATRIX3 rot_pitch = RotationMatrix(_V(pitch_angle, 0, 0));
			//	MATRIX3 rot_roll = RotationMatrix(_V(0, 0, roll_angle));

			MATRIX3 RotMatrix_Def = mul(rot1, mul(rot2, mul(rot3, rot4)));




			vs2.arot.x = atan2(RotMatrix_Def.m23, RotMatrix_Def.m33);
			vs2.arot.y = -asin(RotMatrix_Def.m13);
			vs2.arot.z = atan2(RotMatrix_Def.m12, RotMatrix_Def.m11);

		}
		vs2.vrot.x = 2.35;

		//sprintf(oapiDebugString(), "targetSpeed %2.2f d_lat %2.2f d_lng %2.2f,rt %2.2f degree %2.2f hdg %2.2f", targetSpeed, vs2.surf_lat, vs2.surf_lng, rt, each_deg, vs2.surf_hdg);
		sprintf(oapiDebugString(), "targetSpeed %2.2f hd %2.2f d_hdg %2.2f,hdg %2.2f", targetSpeed, i, d_hdg, vs2.surf_hdg);
		DefSetStateEx(&vs2);
		return;
	}
gattispilot is online now   Reply With Quote
Old 04-17-2018, 03:41 PM   #20
fred18
Addon Developer

Default

I think it is because you calculate d_lat and d_lng before changing the heading and not afterwards. you should first calculate the final heading and then calculate the differences in latitude and longitude with that heading
fred18 is offline   Reply With Quote
Thanked by:
Old 04-17-2018, 05:14 PM   #21
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Thanks. So the turning stuff should come first?
gattispilot is online now   Reply With Quote
Old 04-17-2018, 06:22 PM   #22
fred18
Addon Developer

Default

Quote:
Originally Posted by gattispilot View Post
 Thanks. So the turning stuff should come first?
Check my code of GeneralVehicle but if I remember correctly yes, since the delta latitude and longitude are using heading, first the correct heading should be calculated.
fred18 is offline   Reply With Quote
Thanked by:
Old 04-18-2018, 12:14 AM   #23
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Ok. So I got it to turn and do some crab walk. But for somereason I don't see the mesh when I am in f1 mode.
Code:
iMeshMain = AddMesh("LER8");
	SetMeshVisibilityMode(iMeshMain, MESHVIS_ALWAYS);
Code:
void LER2016::MoveAround(){
	double theta = 0;
	Max_Steering_Angle = 360;

	memset(&vs2, 0, sizeof(vs2));
	vs2.version = 2;
	GetStatusEx(&vs2);
	double sinTurn = sin(2 * PI * TURN_proc);
	double cosTurn = cos(2 * PI * TURN_proc);


	if (FORWARDgear==1)
	
		


 {
		if (i3 < 0){

			
			d_hdg = d_hdg + .000001;//rate of steering change of heading
			vs2.surf_hdg -= d_hdg;

			if (vs2.surf_hdg<0){ vs2.surf_hdg += 2 * PI; }
			rot += 0.005;//animation axle wheel turn rate
			if (rot > .125) rot = .125;
		}

		if (i3 > 0){
			rot -= 0.005;//animation axle wheel turn rate
			if (rot < -.125) rot = -.125;
			
			d_hdg = d_hdg - .0000001;//rate of steering change of heading
			vs2.surf_hdg += d_hdg;

			if (vs2.surf_hdg>2 * PI){ vs2.surf_hdg -= 2 * PI; }

		}
		if (i3 == 0) {// straight so straighten wheels
			if (abs(rot) <= 0.005) rot = 0;
			else if (rot < 0) rot += 0.005;
			else if (rot > 0) rot -= 0.005;

			double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
			double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);

			vs2.surf_lat += d_lat*RAD;
			vs2.surf_lng += d_lng*RAD;
		}
		double d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg) / each_deg);
		double d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) / each_deg);

		//double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
		//double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);

			vs2.surf_lat += d_lat*RAD;
			vs2.surf_lng += d_lng*RAD;
			
		}
	if (REVERSEgear == 1)




	
		
		
		{
			if (i3 > 0){


				d_hdg = d_hdg + .000001;//rate of steering change of heading
				vs2.surf_hdg -= d_hdg;

				if (vs2.surf_hdg<0){ vs2.surf_hdg += 2 * PI; }

			}

			if (i3 < 0){


				d_hdg = d_hdg - .0000001;//rate of steering change of heading
				vs2.surf_hdg += d_hdg;

				if (vs2.surf_hdg>2 * PI){ vs2.surf_hdg -= 2 * PI; }

			}
		
		
		
		
		
		
		
		
		
		
		
		
		
		double d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg)/each_deg);
		double d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) /each_deg);
		vs2.surf_lat -= d_lat*RAD;
		vs2.surf_lng -= d_lng*RAD;
		
	}
//	sprintf(oapiDebugString(), "targetSpeed %2.2f hd %2.2f ANg %2.2f", targetSpeed, vs2.surf_hdg, AngSpeed);
	

	


		
		lng = vs2.surf_lng;
		lat = vs2.surf_lat;
		hdg = vs2.surf_hdg;


		{
			MATRIX3 rot1 = RotationMatrix(_V(0 * RAD, (90 * RAD - lng), 0 * RAD), TRUE);
			MATRIX3 rot2 = RotationMatrix(_V(-lat + 0 * RAD, 0, 0 * RAD), TRUE);
			MATRIX3 rot3 = RotationMatrix(_V(0, 0, 180 * RAD + hdg), TRUE);


			MATRIX3 rot4 = RotationMatrix(_V(90 * RAD, 0, 0), TRUE);
			//MATRIX3 rot4 = RotationMatrix(_V(90 * RAD - pitch_angle, 0, roll_angle), TRUE);

			//		MATRIX3 rot_pitch = RotationMatrix(_V(pitch_angle, 0, 0));
			//	MATRIX3 rot_roll = RotationMatrix(_V(0, 0, roll_angle));

			MATRIX3 RotMatrix_Def = mul(rot1, mul(rot2, mul(rot3, rot4)));




			vs2.arot.x = atan2(RotMatrix_Def.m23, RotMatrix_Def.m33);
			vs2.arot.y = -asin(RotMatrix_Def.m13);
			vs2.arot.z = atan2(RotMatrix_Def.m12, RotMatrix_Def.m11);

		}
		vs2.vrot.x = 2.35;

		//sprintf(oapiDebugString(), "targetSpeed %2.2f d_lat %2.2f d_lng %2.2f,rt %2.2f degree %2.2f hdg %2.2f", targetSpeed, vs2.surf_lat, vs2.surf_lng, rt, each_deg, vs2.surf_hdg);
		//sprintf(oapiDebugString(), "targetSpeed %2.2f hd %2.2f d_hdg %2.2f,hdg %2.2f", targetSpeed, i, d_hdg, vs2.surf_hdg);
		DefSetStateEx(&vs2);
		return;
	}
gattispilot is online now   Reply With Quote
Old 05-06-2018, 12:30 PM   #24
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Well I got most working. Because I am not using thrust to move no speed is shown on the HUD. So I think I may need to add to the hud.

The 360 turning of wheels is working too well either.
Code:
void LER2016::MoveAround(){
	double theta = 0;
	Max_Steering_Angle = 360;

	memset(&vs2, 0, sizeof(vs2));
	vs2.version = 2;
	GetStatusEx(&vs2);
	double sinTurn = sin(2 * PI * TURN_proc);
	double cosTurn = cos(2 * PI * TURN_proc);


	if (FORWARDgear==1)
	
		


 {
		if (i3 < 0){

			
			d_hdg = d_hdg + .000001;//rate of steering change of heading
			vs2.surf_hdg -= d_hdg;

			if (vs2.surf_hdg<0){ vs2.surf_hdg += 2 * PI; }
			rot += 0.005;//animation axle wheel turn rate
			if (rot > .125) rot = .125;
		}

		if (i3 > 0){
			rot -= 0.005;//animation axle wheel turn rate
			if (rot < -.125) rot = -.125;
			
			d_hdg = d_hdg - .0000001;//rate of steering change of heading
			vs2.surf_hdg += d_hdg;

			if (vs2.surf_hdg>2 * PI){ vs2.surf_hdg -= 2 * PI; }

		}
		if (i3 == 0) {// straight so straighten wheels
			if (abs(rot) <= 0.005) rot = 0;
			else if (rot < 0) rot += 0.005;
			else if (rot > 0) rot -= 0.005;

			double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
			double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);

			vs2.surf_lat += d_lat*RAD;
			vs2.surf_lng += d_lng*RAD;
		}
		double d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg) / each_deg);
		double d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) / each_deg);

		//double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
		//double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);

			vs2.surf_lat += d_lat*RAD;
			vs2.surf_lng += d_lng*RAD;
			
		}
gattispilot is online now   Reply With Quote
Old 05-09-2018, 10:41 AM   #25
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

https://drive.google.com/open?id=1R-...aPGpgooUwcaoZ_

So this is what I have so far.

Keyboard keys:
1 opens door
2 opens door
4 quickly straighten wheels
5/6 rotate wheels
7 lights on/off
J sunscreen
G camera position


keypad
8 forward gear
2 reverse gear
+ more speed
- less speed
1/3 rudder controls

So for normal steering use 1/3 keypad. Hold it hold for the turns. Let up and the LER will go that heading.

Then for position changing use 5/6. The heading doesn't change but the position does.
gattispilot is online now   Reply With Quote
Old 06-05-2018, 10:44 AM   #26
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

This is weird. So I placed in at Brighton Beach and it did like it should. But put somewhere else on the moon. And she drives badly.

LER2016:LER5
STATUS Landed Moon
POS 2.6934640 -86.0896775
HEADING -77158062202641666000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 000000000000000.00
ALT 2.350
AROT 176.843 -40.480 5.138


Not sure why the heading value is crazy:
Code:
void LER2016::MoveAround(){
	double theta = 0;
	Max_Steering_Angle = 360;

	memset(&vs2, 0, sizeof(vs2));
	vs2.version = 2;
	GetStatusEx(&vs2);
	double sinTurn = sin(2*PI * TURN_proc);
	double cosTurn = cos(2*PI * TURN_proc);


	if (FORWARDgear==1)
	
		


 {
		if (i3 < 0){

			
			d_hdg = d_hdg + .000001;//rate of steering change of heading
			vs2.surf_hdg -= d_hdg;

			if (vs2.surf_hdg<0){ vs2.surf_hdg += 2 * PI; }
			rot += 0.005;//animation axle wheel turn rate
			if (rot > .125) rot = .125;
		}

		if (i3 > 0){
			rot -= 0.005;//animation axle wheel turn rate
			if (rot < -.125) rot = -.125;
			
			d_hdg = d_hdg - .0000001;//rate of steering change of heading
			vs2.surf_hdg += d_hdg;

			if (vs2.surf_hdg>2 * PI){ vs2.surf_hdg -= 2 * PI; }

		}




		if (i3 == 0) {// straight so straighten wheels
		
			// sprintf (oapiDebugString (), "turn %2.2f cos %2.2f sin %2.2f", TURN_proc, cosTurn, sinTurn );

			
			
			
			if (abs(rot) <= 0.005) rot = 0;
			else if (rot < 0) rot += 0.005;
			else if (rot > 0) rot -= 0.005;

			double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
			double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);

			vs2.surf_lat += d_lat*RAD;
			vs2.surf_lng += d_lng*RAD;
		}

		if (TURN_proc == 0){
			double d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg) / each_deg);
			double d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) / each_deg);
		
		//double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
		//double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);

			vs2.surf_lat += d_lat*RAD;
			vs2.surf_lng += d_lng*RAD;
			
	}
}
	if (REVERSEgear == 1)




	
		
		
		{
			if (i3 > 0){


				d_hdg = d_hdg + .000001;//rate of steering change of heading
				vs2.surf_hdg -= d_hdg;

				if (vs2.surf_hdg<0){ vs2.surf_hdg += 2 * PI; }

			}

			if (i3 < 0){


				d_hdg = d_hdg - .0000001;//rate of steering change of heading
				vs2.surf_hdg += d_hdg;

				if (vs2.surf_hdg>2 * PI){ vs2.surf_hdg -= 2 * PI; }

			}
		
			if (i3 == 0) {// straight so straighten wheels

		
		
			if (abs(rot) <= 0.005) rot = 0;
			else if (rot < 0) rot += 0.005;
			else if (rot > 0) rot -= 0.005;

			double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
			double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);

			vs2.surf_lat -= d_lat*RAD;
			vs2.surf_lng -= d_lng*RAD;
	}

	if (TURN_proc == 0){
		double d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg) / each_deg);
		double d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) / each_deg);

		//double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
		//double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);

		vs2.surf_lat -= d_lat*RAD;
		vs2.surf_lng -= d_lng*RAD;

	}
}
//	sprintf(oapiDebugString(), "targetSpeed %2.2f hd %2.2f ANg %2.2f", targetSpeed, vs2.surf_hdg, AngSpeed);
	

	


		
		lng = vs2.surf_lng;
		lat = vs2.surf_lat;
		hdg = vs2.surf_hdg;


		{
			MATRIX3 rot1 = RotationMatrix(_V(0 * RAD, (90 * RAD - lng), 0 * RAD), TRUE);
			MATRIX3 rot2 = RotationMatrix(_V(-lat + 0 * RAD, 0, 0 * RAD), TRUE);
			MATRIX3 rot3 = RotationMatrix(_V(0, 0, 180 * RAD + hdg), TRUE);


			MATRIX3 rot4 = RotationMatrix(_V(90 * RAD, 0, 0), TRUE);
			//MATRIX3 rot4 = RotationMatrix(_V(90 * RAD - pitch_angle, 0, roll_angle), TRUE);

			//		MATRIX3 rot_pitch = RotationMatrix(_V(pitch_angle, 0, 0));
			//	MATRIX3 rot_roll = RotationMatrix(_V(0, 0, roll_angle));

			MATRIX3 RotMatrix_Def = mul(rot1, mul(rot2, mul(rot3, rot4)));




			vs2.arot.x = atan2(RotMatrix_Def.m23, RotMatrix_Def.m33);
			vs2.arot.y = -asin(RotMatrix_Def.m13);
			vs2.arot.z = atan2(RotMatrix_Def.m12, RotMatrix_Def.m11);

		}
		vs2.vrot.x = 2.35;

		//sprintf(oapiDebugString(), "targetSpeed %2.2f d_lat %2.2f d_lng %2.2f,rt %2.2f degree %2.2f hdg %2.2f", targetSpeed, vs2.surf_lat, vs2.surf_lng, rt, each_deg, vs2.surf_hdg);
		//sprintf(oapiDebugString(), "targetSpeed %2.2f hd %2.2f d_hdg %2.2f,hdg %2.2f", targetSpeed, i, d_hdg, vs2.surf_hdg);
		DefSetStateEx(&vs2);
		return;
	}
i3 is the rudder


I re ran it and still has issues.

LER2016:LER5
STATUS Landed Moon
POS 2.6845745 -86.0917536
HEADING 247.66
ALT 2.350
AROT -178.424 19.600 4.144
AFCMODE 7
IDS 0:560 100 1:564 100
NAVFREQ 0 0
DOORL 1 0.0000
DOORR 1 0.0000
SUNSCREEN 1 1.0000
END

It doesn't seem to turn correctly
gattispilot is online now   Reply With Quote
Old 06-05-2018, 11:21 AM   #27
Urwumpe
Certain Super User
 
Urwumpe's Avatar

Default

Is d_hdg initialized?

---------- Post added at 13:11 ---------- Previous post was at 13:09 ----------

And better pay attention to a less chaotic source code formatting - its terribly hard to read your code because the } are travelling around wildly.

---------- Post added at 13:21 ---------- Previous post was at 13:11 ----------

For example: This is your code after doing some cheap formatting work on it.

Code:
void LER2016::MoveAround() {
	double theta = 0;
	Max_Steering_Angle = 360;
	memset(&vs2, 0, sizeof(vs2));
	vs2.version = 2;
	GetStatusEx(&vs2);
	double sinTurn = sin(2*PI * TURN_proc);
	double cosTurn = cos(2*PI * TURN_proc);

	if (FORWARDgear == 1) {
		if (i3 < 0) {			
			d_hdg = d_hdg + .000001;//rate of steering change of heading
			vs2.surf_hdg -= d_hdg;
			if (vs2.surf_hdg<0) { 
				vs2.surf_hdg += 2 * PI; 
			}
			rot += 0.005;//animation axle wheel turn rate
			if (rot > .125) rot = .125;
		}
		else if (i3 > 0) {			
			rot -= 0.005;//animation axle wheel turn rate
			if (rot < -.125) rot = -.125;
			
			d_hdg = d_hdg - .0000001;//rate of steering change of heading
			vs2.surf_hdg += d_hdg;

			if (vs2.surf_hdg > 2 * PI) { 
				vs2.surf_hdg -= 2 * PI; 
			}
		}
		else if (i3 == 0) { // straight so straighten wheels		
			// sprintf (oapiDebugString (), "turn %2.2f cos %2.2f sin %2.2f", TURN_proc, cosTurn, sinTurn );					
			if (abs(rot) <= 0.005) 
				rot = 0;
			else if (rot < 0) 
				rot += 0.005;
			else if (rot > 0) 
				rot -= 0.005;

			double d_lat = (targetSpeed * oapiGetSimStep() * cosTurn / each_deg);
			double d_lng = (targetSpeed * oapiGetSimStep() * sinTurn / each_deg);
			vs2.surf_lat += d_lat * RAD;
			vs2.surf_lng += d_lng * RAD;
		}

		if (TURN_proc == 0) {
			double d_lat = (targetSpeed * oapiGetSimStep() * cos(vs2.surf_hdg) / each_deg);
			double d_lng = (targetSpeed * oapiGetSimStep() * sin(vs2.surf_hdg) / each_deg);		
			//double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
			//double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);
			vs2.surf_lat += d_lat * RAD;
			vs2.surf_lng += d_lng * RAD;			
		}
	}
	
	if (REVERSEgear == 1) {		
		if (i3 > 0) {
			d_hdg = d_hdg + .000001;//rate of steering change of heading
			vs2.surf_hdg -= d_hdg;
			if (vs2.surf_hdg < 0) { 
				vs2.surf_hdg += 2 * PI; 
			}
		}
		if (i3 < 0) {
			d_hdg = d_hdg - .0000001;//rate of steering change of heading
			vs2.surf_hdg += d_hdg;
			if (vs2.surf_hdg > 2 * PI) { 
				vs2.surf_hdg -= 2 * PI; 
			}
		}	
		if (i3 == 0) {// straight so straighten wheels		
			if (abs(rot) <= 0.005) 
				rot = 0;
			else if (rot < 0) 
				rot += 0.005;
			else if (rot > 0) 
				rot -= 0.005;

			double d_lat = (targetSpeed * oapiGetSimStep() * cosTurn / each_deg);
			double d_lng = (targetSpeed * oapiGetSimStep() * sinTurn / each_deg);
			vs2.surf_lat -= d_lat * RAD;
			vs2.surf_lng -= d_lng * RAD;
		}

		if (TURN_proc == 0) {
			double d_lat = (targetSpeed * oapiGetSimStep() * cos(vs2.surf_hdg) / each_deg);
			double d_lng = (targetSpeed * oapiGetSimStep() * sin(vs2.surf_hdg) / each_deg);
			//double d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
			//double d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);
			vs2.surf_lat -= d_lat * RAD;
			vs2.surf_lng -= d_lng * RAD;
		}
	}
	//sprintf(oapiDebugString(), "targetSpeed %2.2f hd %2.2f ANg %2.2f", targetSpeed, vs2.surf_hdg, AngSpeed);		
	lng = vs2.surf_lng;
	lat = vs2.surf_lat;
	hdg = vs2.surf_hdg;

	//????????????????????????????????????????????????????
	{
		MATRIX3 rot1 = RotationMatrix(_V(0 * RAD, (90 * RAD - lng), 0 * RAD), TRUE);
		MATRIX3 rot2 = RotationMatrix(_V(-lat + 0 * RAD, 0, 0 * RAD), TRUE);
		MATRIX3 rot3 = RotationMatrix(_V(0, 0, 180 * RAD + hdg), TRUE);
		MATRIX3 rot4 = RotationMatrix(_V(90 * RAD, 0, 0), TRUE);
		//MATRIX3 rot4 = RotationMatrix(_V(90 * RAD - pitch_angle, 0, roll_angle), TRUE);
		//		MATRIX3 rot_pitch = RotationMatrix(_V(pitch_angle, 0, 0));
		//	MATRIX3 rot_roll = RotationMatrix(_V(0, 0, roll_angle));
		MATRIX3 RotMatrix_Def = mul(rot1, mul(rot2, mul(rot3, rot4)));
		vs2.arot.x = atan2(RotMatrix_Def.m23, RotMatrix_Def.m33);
		vs2.arot.y = -asin(RotMatrix_Def.m13);
		vs2.arot.z = atan2(RotMatrix_Def.m12, RotMatrix_Def.m11);

	}
	vs2.vrot.x = 2.35;
	//sprintf(oapiDebugString(), "targetSpeed %2.2f d_lat %2.2f d_lng %2.2f,rt %2.2f degree %2.2f hdg %2.2f", targetSpeed, vs2.surf_lat, vs2.surf_lng, rt, each_deg, vs2.surf_hdg);
	//sprintf(oapiDebugString(), "targetSpeed %2.2f hd %2.2f d_hdg %2.2f,hdg %2.2f", targetSpeed, i, d_hdg, vs2.surf_hdg);
	DefSetStateEx(&vs2);
	return;
}
Notice the difference? Its BTW really easy to see which code is yours and which code you got from somebody else and which was just copy and pasted into the right place: Your unknown contributor used more whitespaces (And can thus expect a higher income as software developer, as scientific studies have shown.)
Urwumpe is offline   Reply With Quote
Thanked by:
Old 06-05-2018, 12:11 PM   #28
fred18
Addon Developer

Default

Quote:
Originally Posted by Urwumpe View Post
 (And can thus expect a higher income as software developer, as scientific studies have shown.)
hope you are right there
fred18 is offline   Reply With Quote
Old 06-05-2018, 12:16 PM   #29
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Thanks. So in Vision Studio is there a way to see which brackets are matched?

I will correct my format.

I drove it some more. No more heading issue. But then it got to a spot where it just spun its wheels.

As I see it using the rudder control changes the heading. But by rotating the wheels in the Z axis then the vehicle will keep the heading but move in that direction. TURN_proc is 0 if going straight.
gattispilot is online now   Reply With Quote
Old 06-17-2018, 12:11 PM   #30
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

I think the turning needs looked at.

So i3 is the rudder postion -1 left turn, 0 straight, 1 right turn

Code:
void LER2016::MoveAround(){
	memset(&vs2, 0, sizeof(vs2));
	vs2.version = 2;
	GetStatusEx(&vs2);
	double sinTurn = sin(2*PI * TURN_proc);
	double cosTurn = cos(2*PI * TURN_proc);
	
	if (FORWARDgear==1)
	 {
		if (i3 < 0){
			d_hdg = d_hdg + .00001;//rate of steering change of heading
			vs2.surf_hdg -= d_hdg;

			if (vs2.surf_hdg<0){ vs2.surf_hdg += 2 * PI; }
			rot += 0.005;//animation axle wheel turn rate
			if (rot > .125) rot = .125;
		}
		if (i3 > 0){
			rot -= 0.005;//animation axle wheel turn rate
			if (rot < -.125) rot = -.125;
			
			d_hdg = d_hdg - .00001;//rate of steering change of heading
			vs2.surf_hdg += d_hdg;

			if (vs2.surf_hdg>2 * PI){ vs2.surf_hdg -= 2 * PI; }
		}
		if (i3 == 0) {// straight so straighten wheels
			// sprintf (oapiDebugString (), "turn %2.2f cos %2.2f sin %2.2f", TURN_proc, cosTurn, sinTurn );
			if (abs(rot) <= 0.005) rot = 0;
			else if (rot < 0) rot += 0.005;
			else if (rot > 0) rot -= 0.005;
		}
		if (TURN_proc == 0){//wheels are straight so move with heading
			 d_lat = (targetSpeed*oapiGetSimStep()*cos(vs2.surf_hdg) / each_deg);
			 d_lng = (targetSpeed*oapiGetSimStep()*sin(vs2.surf_hdg) / each_deg);
		}
		else {//wheels are not straight so move no matter the heading
			 d_lat = (targetSpeed*oapiGetSimStep()*cosTurn / each_deg);
			 d_lng = (targetSpeed*oapiGetSimStep()*sinTurn / each_deg);
		}
		//sprintf(oapiDebugString(), "turn %2.2f cos %2.2f sin %2.2f lat %2.2f lng %2.2f", TURN_proc, cosTurn, sinTurn, d_lat, d_lng);

			vs2.surf_lat += d_lat*RAD;
			vs2.surf_lng += d_lng*RAD;

}
So if left rudder is selected.
d_hdg is increased. this is the rate of heading change.
vs2.surf_hdg -= d_hdg; change heading - heading change

The rest is just to tell the wheels how much to rotate.
gattispilot is online now   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Addons > Addon Development


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 12:11 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.