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
  #1  
Old
gattispilot's Avatar
gattispilot gattispilot is offline
Addon Developer
Default LER for 2016
by gattispilot 04-06-2018, 11:28 AM

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

	
}
Reply With Quote
Views 2482 Comments 30
Thanked by:
Total Comments 30

Comments

Old 04-06-2018, 12:37 PM   #2
PhantomCruiser
Wanderer
 
PhantomCruiser's Avatar

Default

Hope you get it worked out. I really like the LER.
PhantomCruiser is offline   Reply With Quote
Thanked by:
Old 04-06-2018, 12:50 PM   #3
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

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.
gattispilot is offline   Reply With Quote
Thanked by:
Old 04-07-2018, 12:20 PM   #4
LeePalmer
Orbinaut
Default

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?
LeePalmer is offline   Reply With Quote
Old 04-08-2018, 11:43 AM   #5
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Thanks.
[IMG][/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 ----------



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


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 }
};
gattispilot is offline   Reply With Quote
Old 04-09-2018, 12:15 PM   #6
fred18
Addon Developer

Default

Rotation Matrix?
fred18 is offline   Reply With Quote
Thanked by:
Old 04-09-2018, 12:30 PM   #7
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Quote:
Originally Posted by fred18 View Post
 Rotation Matrix?
Thanks. Not sure what you mean though
gattispilot is offline   Reply With Quote
Old 04-09-2018, 12:35 PM   #8
Woo482
Moderator
 
Woo482's Avatar


Default

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
Woo482 is offline   Reply With Quote
Old 04-09-2018, 12:39 PM   #9
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

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 by gattispilot; 04-09-2018 at 12:48 PM.
gattispilot is offline   Reply With Quote
Old 04-09-2018, 02:54 PM   #10
fred18
Addon Developer

Default

Quote:
Originally Posted by gattispilot View Post
 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.
fred18 is offline   Reply With Quote
Old 04-11-2018, 09:57 PM   #11
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

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 by gattispilot; 04-11-2018 at 10:00 PM.
gattispilot is offline   Reply With Quote
Old 04-11-2018, 10:32 PM   #12
LeePalmer
Orbinaut
Default

Try removing / each_deg
LeePalmer is offline   Reply With Quote
Old 04-12-2018, 10:34 AM   #13
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

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:
gattispilot is offline   Reply With Quote
Old 04-12-2018, 04:00 PM   #14
fred18
Addon Developer

Default

Quote:
Originally Posted by gattispilot View Post
 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.
fred18 is offline   Reply With Quote
Old 04-12-2018, 04:17 PM   #15
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Quote:
Originally Posted by fred18 View Post
 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.
gattispilot is offline   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 03:33 AM.

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.