Project LER for 2016

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
So I Am trying to get the LER (Lunar Electric Rover) to work in 2016.

I am following fred18's crawler and general vehicle

But when Try to move the vessel rotates wildly.
scn.
Code:
LER:LER5
  STATUS Landed Moon
  POS -33.4375000 41.1184669
  HEADING 0.01
  ALT 0.000
  AROT 135.534 34.803 150.855
  RCSMODE 0
  AFCMODE 7
  IDS 0:560 100 1:564 100
  NAVFREQ 0 0
END

So this is what I have to move it:
Code:
void LER2016::clbkPreStep(double simt, double simdt, double mjd) {
	rt = oapiGetSize(GetSurfaceRef());
	earth_circ = rt * 2 * PI;
	each_deg = earth_circ / 360;
	grav_acc = GGRAV*oapiGetMass(GetSurfaceRef()) / (rt*rt);
	memset(&vs2, 0, sizeof(vs2));
	vs2.version = 2;
	GetStatusEx(&vs2);

	MoveAround();
	
	
}

Code:
int LER2016::clbkConsumeBufferedKey(DWORD key, bool down, char *kstate) {
	// only process keydown events
	if (!down) return 0;

	
		if (KEYDOWN(kstate, OAPI_KEY_NUMPAD8)) {
			FORWARDgear = 1;
			REVERSEgear = 0;
			neutralgear = 0;
			LASTGEAR = 0;
		
			return 1;
		}

		if (KEYDOWN(kstate, OAPI_KEY_NUMPAD4)) {
			if (FORWARDgear == 1)LASTGEAR = 1;
			if (REVERSEgear == 1)LASTGEAR = 2;

			FORWARDgear = 0;
			REVERSEgear = 0;
			neutralgear = 1;
			
			return 1;
		}
		if (KEYDOWN(kstate, OAPI_KEY_NUMPAD2)) {
			FORWARDgear = 0;
			REVERSEgear = 1;
			neutralgear = 0;
			LASTGEAR = 0;
			
			return 1;
		}

		


	return 0;
}
int LER2016::clbkConsumeDirectKey(char *kstate) {

	if (!firstTimestepDone) return 0;

	if (KEYDOWN(kstate, OAPI_KEY_ADD)) {

		if ((FORWARDgear == 1) || (REVERSEgear == 1)){
		//pEngine->IncreaseTgtSpeed(down);
		double dv = 0.01;
		targetSpeed = (targetSpeed + dv);
		if (targetSpeed > MAXSPEED) targetSpeed = MAXSPEED;
		//SetAnimation(anim_SPEEDCONTROL, targetSpeed);
		//increaseTgtSpeed = down;
		//decreaseTgtSpeed = false;
		}
		return 1;
	}
	else if (KEYDOWN(kstate, OAPI_KEY_SUBTRACT)) {
		//pEngine->DecreaseTgtSpeed(down);
		if ((FORWARDgear == 1) || (REVERSEgear == 1)){
			double dv = 0.01;
			targetSpeed = (targetSpeed - dv);
			if (targetSpeed <0) targetSpeed = 0;
			//SetAnimation(anim_SPEEDCONTROL, targetSpeed);
			//decreaseTgtSpeed = down;
			//increaseTgtSpeed = false;
		}
		return 1;
	}
	
	return 0;
}





Code:
void LER2016::MoveAround(){

	
	if (FORWARDgear==1)
	{

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

		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;

		
		DefSetStateEx(&vs2);
		return;
	}

	
}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
There is a General Vehicle version. But I want to make a new version for 2016. And when OMMU come it out I will add that.

But got to get it moving forward first.
 

LeePalmer

Member
Joined
Apr 7, 2013
Messages
40
Reaction score
0
Points
6
A complete guess. If the LER is just turning on the spot and not moving then

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

is setting it to be vs2.surf_hdg inside
DefSetStateEx(&vs2);
The definition of vs2 is different in someway?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks.
wnpgmKw.jpg
[/IMG]
So i ran with a debug statement.
d_lng and L_lat and vs2.heading are all 0.000

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

		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 d_lat %2.2f d_lng %2.2f,rt %2.2f degree %2.2f hdg %2.2f", targetSpeed, d_lat, d_lng, rt, each_deg, vs2.surf_hdg);

		
		DefSetStateEx(&vs2);
		return;
	}

It isn't moving forward. not spinning it place

---------- Post added 04-08-18 at 06:43 AM ---------- Previous post was 04-07-18 at 08:10 AM ----------

hRkgPLT.jpg


So this are the value at the start
then I try to move:
Q3tMUVg.jpg


The lat and lng are the same. So why the spinning?

maybe touchdown points?
Code:
static const int ntdvtx = 3;
static TOUCHDOWNVTX tdvtx[ntdvtx] = {
	{ _V(0, -2.35, 1.5), 26150.8, 18409.6, 3.2, 0.8 },
	{ _V(-2, -2.35, -2.6), 26150.8, 18409.6, 3.2, 0.4 },
	{ _V(2, -2.35, -2.6), 26150.8, 18409.6, 3.2, 0.4 }//,
	//	{ _V(-2, -2.164, 1.5), 1e6, 1e5, 3.2, 0 },
	//	{ _V(2, -2.164, 1.5), 1e6, 1e5, 3.2, 0 },
	//	{ _V(-2, 1.6, -2.6), 1e6, 1e5, 3.2, 0 },
	//	{ _V(2, 1.6, -2.6), 1e6, 1e5, 3.2, 0 },
	//	{ _V(-2, 1.6, 1.5), 1e6, 1e5, 3.2, 0 },
	//	{ _V(2, 1.6, 1.5), 1e6, 1e5, 3.2, 0 }
};
 

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
Rotation Matrix?
 

Woo482

Moderator
Moderator
Addon Developer
GFX Staff
Joined
Feb 13, 2008
Messages
3,048
Reaction score
20
Points
78
Location
Earth?
You need to set the VESSELSTATUS2.arot value using a rotation matrix to derive the proper values, I can't be any more helpful than that because that's where I'm stuck with oMMU's ground movement :lol:
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. I will look at the code samples. But not sure if I saw anything like that?

saw this:
Code:
	if (FWD || BWD || RGT || LFT)
	{
		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);
		
		if (!isMotorcycle) { vs2.vrot.x = Height_From_Ground; }
		else { 
			double gamma= CurrentSterzo * 2 * Max_Steering_Angle;
			vs2.vrot.x = Height_From_Ground * cos(gamma);
		}
		DefSetStateEx(&vs2);
	}
 
Last edited:

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
Thanks. I will look at the code samples. But not sure if I saw anything like that?

saw this:
...
Yes, that's how I sorted it out in the GeneralVehicle module. It works really really nice there as you saw.

Let me note out first, that independently from the rotation matrix definition, your vessel should move on the surface when you're trying to drive around, even if rotating crazily or whatever. If it doesn't move, first sort out that part, then get to the rotation matrix so it doesn't just move, it also moves standing upright.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
ok. So I have this but no movement:
Code:
void LER2016::MoveAround(){

	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);


	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;
		}

		double lng, lat, hdg;
		lng = vs2.surf_lng;
		lat = vs2.surf_lat;
		hdg = vs2.surf_hdg;
		//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;
	}
it goes to it as the targetspeed changes. no change in the lat or lng
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
Code:
void LER2016::MoveAround(){

	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);


	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;
	}
		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);

		}


		//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;
	}
Code:
MATRIX3 LER2016::RotationMatrix(VECTOR3 angles, bool xyz = FALSE)
{
	MATRIX3 m;
	MATRIX3 RM_X, RM_Y, RM_Z;
	RM_X = _M(1, 0, 0, 0, cos(angles.x), -sin(angles.x), 0, sin(angles.x), cos(angles.x));
	RM_Y = _M(cos(angles.y), 0, sin(angles.y), 0, 1, 0, -sin(angles.y), 0, cos(angles.y));
	RM_Z = _M(cos(angles.z), -sin(angles.z), 0, sin(angles.z), cos(angles.z), 0, 0, 0, 1);
	if (!xyz) {
		m = mul(RM_Z, mul(RM_Y, RM_X));
	}
	else {
		m = mul(RM_X, mul(RM_Y, RM_Z));
	}
	return m;
}
So this moves me forward and back. But now I am in the ground. Changing the tD point does nothing:
3BksiNS.jpg
 

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
So this moves me forward and back. But now I am in the ground. Changing the tD point does nothing:

You're basically redoing the GeneralVehicle for this specific vessel and if you check it (and its thread) you'll find out that in the vesselstatus2 strcture the vrot.x defines the height from the ground for landed vessels, martin directly explained that HERE. So if you want to rise up from the ground, change the vs2.vrot.x parameter.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
You're basically redoing the GeneralVehicle for this specific vessel and if you check it (and its thread) you'll find out that in the vesselstatus2 strcture the vrot.x defines the height from the ground for landed vessels, martin directly explained that HERE. So if you want to rise up from the ground, change the vs2.vrot.x parameter.
Thanks so change this:
Code:
vs2.arot.x = atan2(RotMatrix_Def.m23, RotMatrix_Def.m33);

Not at my code writing pc.
 

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
Vrot not Arot
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
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

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
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

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,711
Reaction score
2,683
Points
203
Location
Dallas, TX
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.
TwuPrai.jpg

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;
	}
 

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
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
 
Top