Orbiter-Forum  

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

Addon Requests If you have a request for a new addon or want to know where to find a specific addon, ask it here!

Reply
 
Thread Tools
Old 12-10-2018, 02:27 AM   #226
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Code:
ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
		OBJHANDLE hChild = GetAttachmentStatus(ah);
		if (oapiIsVessel(hChild)) { // something is attached!
			VESSEL *v = oapiGetVesselInterface(hChild);
			sprintf(oapiDebugString(), "%s is attached",
				v->GetName());
			DetachChild(ah, 5);
		}
		else sprintf(oapiDebugString(), "nothing is attached");
				//else sprintf(oapiDebugString(), "nothing is attached");
			}
I got a CTD and the sat was not seen

I have a separate key for detaching though

---------- Post added at 08:27 PM ---------- Previous post was at 08:24 PM ----------

I reran I get nothing is attached and then ctd
gattispilot is offline   Reply With Quote
Old 12-10-2018, 02:32 AM   #227
Majid
Orbinaut
Default

Where are your running the code now?

Run this in clbkPreStep or clbkPostStep, make sure nothing else is in those methods to prevent CTD from other sources. What happens? When you press your key to release, what code is run?

THIS piece of code should not cause a CTD unless I'm mistaken:

Code:
ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
if (ah == NULL) {
   sprintf(oapiDebugString(), "Attachment Handle is NULL");
}
else {
OBJHANDLE hChild = GetAttachmentStatus(ah);
if (oapiIsVessel(hChild)) { // something is attached!
         VESSEL *v = oapiGetVesselInterface(hChild);
	sprintf(oapiDebugString(), "%s is attached", 
        v->GetName());
        DetachChild(ah, 5);
}
else sprintf(oapiDebugString(), "nothing is attached");
}


---------- Post added at 02:32 AM ---------- Previous post was at 02:30 AM ----------

But basically you'll want to run something like the above piece of code whenever releasing. I don't know the entirety of your source file so it's hard to tell where the CTD is coming from.
Majid is online now   Reply With Quote
Old 12-10-2018, 02:39 AM   #228
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

So I took the detach child line out and it worked:
Code:
ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
		OBJHANDLE hChild = GetAttachmentStatus(ah);
		if (oapiIsVessel(hChild)) { // something is attached!
			VESSEL *v = oapiGetVesselInterface(hChild);
			sprintf(oapiDebugString(), "%s is attached",
				v->GetName());
			//DetachChild(ah, 1);
		}
		else sprintf(oapiDebugString(), "nothing is attached");
				//else sprintf(oapiDebugString(), "nothing is attached");
			}

I have this for detach:
Code:
if (key == OAPI_KEY_F6){
			if (spintable == 0)	spintable = 1;
			else if (spintable == 3) DetachChild(sat_attach1, 1.0);

			return 1;
		}
CTRL f6 once starts the spin when at the correct rate? spintable =3 then press CTRLf6 again and it detaches

---------- Post added at 08:39 PM ---------- Previous post was at 08:33 PM ----------

This is in poststep
Code:
if (SPIN1 == 1){



		if ((spintable == 1) && (rotchange <= .50))rotchange = rotchange + .001;//OPERATE SPINTABLE and if rate change is less than .3 do not increase
		ANGULAR_VEL = 2 * PI * (rotchange);//apply rot to ang vel



		//sprintf(oapiDebugString(), " phi %d tilt %f spintable %f", spintable, ANGULAR_VEL, rotchange);
		if (phi < 0)phi = 0;
		//if (phi >1.2)phi = 1.2;
		xp1 = arm1_tip[1] - arm1_tip[0]; normalise(xp1);
		xr1 = arm1_tip[2] - arm1_tip[0]; normalise(xr1);
		if ((spintable == 1) || (spintable == 3)) phi = ANGULAR_VEL *simt;  //move ase attachment and ius
		ROT = _V(sin(phi), 0, cos(phi));
		if ((spintable == 1) && (rotchange >= .50)) spintable = 3;  // up to speed
		//SetAttachmentParams(sat_attach4, pl4_ofs, DIR, pl4_rot);//ase
		SetAttachmentParams(sat_attach1, pl1_ofs, pl1_dir, ROT);//satellite
		//sets new attachment rotation values for saving
		pl1_rot.x = ROT.x;
		//pl4_dir.x = DIR.x;
		pl1_rot.y = ROT.y;
		//pl4_dir.y = DIR.y;
		pl1_rot.z = ROT.z;
		
		ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
		OBJHANDLE hChild = GetAttachmentStatus(ah);
		if (oapiIsVessel(hChild)) { // something is attached!
			VESSEL *v = oapiGetVesselInterface(hChild);
			sprintf(oapiDebugString(), "%s is attached",
				v->GetName());
			//DetachChild(ah, 1);
		}
		else sprintf(oapiDebugString(), "nothing is attached");
				//else sprintf(oapiDebugString(), "nothing is attached");
			}
when I press CTRL f6 the 2nd time it dettached
now to get it to spin
gattispilot is offline   Reply With Quote
Old 12-10-2018, 02:39 AM   #229
Majid
Orbinaut
Default

This doesn't make much sense.

Code:
ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
		OBJHANDLE hChild = GetAttachmentStatus(ah);
		if (oapiIsVessel(hChild)) { // something is attached!
			VESSEL *v = oapiGetVesselInterface(hChild);
			sprintf(oapiDebugString(), "%s is attached",
				v->GetName());
			//DetachChild(ah, 1);
The detach child call cannot cause any problems if the oapiIsVessel check passes. You were likely getting CTD due to other code interactions.

I advise against caching attachment handles like you seem to be doing here.
Code:
if (key == OAPI_KEY_F6){
			if (spintable == 0)	spintable = 1;
			else if (spintable == 3) DetachChild(sat_attach1, 1.0);

			return 1;
		}
Your code to detach really should be this, with all the checks (minus the debug calls ofc):
Code:
ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
if (ah == NULL) {
   sprintf(oapiDebugString(), "Attachment Handle is NULL");
}
else {
OBJHANDLE hChild = GetAttachmentStatus(ah);
if (oapiIsVessel(hChild)) { // something is attached!
         VESSEL *v = oapiGetVesselInterface(hChild);
	sprintf(oapiDebugString(), "%s is attached", 
        v->GetName());
        DetachChild(ah, 5);
}
else sprintf(oapiDebugString(), "nothing is attached");
}
You have to detach the vessel *first* and then you can give it angular velocity.
Majid is online now   Reply With Quote
Old 12-10-2018, 02:45 AM   #230
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Thanks. But on your code wouldn't it automatically detach? I want the attachment point to spin and then press a key and release.

So then on the angular velocity where should it go?
gattispilot is offline   Reply With Quote
Old 12-10-2018, 02:48 AM   #231
Majid
Orbinaut
Default

Adding the spin is easy. Right BEFORE DetachChild, you get the attachment status and get the child's OBJHANDLE then call SetAngularVel like so.

Code:
        OBJHANDLE hChild = GetAttachmentStatus(sat_attach1);
        DetachChild(sat_attach1, 1.0);
        if (oapiIsVessel(hChild)) {
             VESSEL *vChild = oapiGetVesselInterface(hChild);
              vChild->SetAngularVel(...)
        }


---------- Post added at 02:48 AM ---------- Previous post was at 02:46 AM ----------

Quote:
Originally Posted by gattispilot View Post
 Thanks. But on your code wouldn't it automatically detach? I want the attachment point to spin and then press a key and release.

So then on the angular velocity where should it go?
The code I posted is for when you do the final detach. The point I'm trying to drive home is the if statements and sanity checks to prevent CTD's. Just because you expect something to be attached doesn't mean it always will be. So detaching against some cached attachment handle is very dangerous and error prone.

So on first keypress you set off some flag to start rotating the attachment point and then on the second keypress you use my code to detach, and you won't have to cache any handles. My code shouldn't be in clbkPreStep or clbkPostStep, that was just to try and diagnose the CTD's.

Last edited by Majid; 12-10-2018 at 02:51 AM.
Majid is online now   Reply With Quote
Old 12-10-2018, 03:15 AM   #232
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

THanks

So I added if spintable =4 which means the attachment spinning is at the rate and the 2nd CTRL F6 is pressed

Code:
if (SPIN1 == 1){//spintable#1



        if ((spintable == 1) && (rotchange <= .50))rotchange = rotchange + .001;//OPERATE SPINTABLE and if rate change is less than .3 do not increase
        ANGULAR_VEL = 2 * PI * (rotchange);//apply rot to ang vel



        //sprintf(oapiDebugString(), " phi %d tilt %f spintable %f", spintable, ANGULAR_VEL, rotchange);
        if (phi < 0)phi = 0;
        //if (phi >1.2)phi = 1.2;
        xp1 = arm1_tip[1] - arm1_tip[0]; normalise(xp1);
        xr1 = arm1_tip[2] - arm1_tip[0]; normalise(xr1);
        if ((spintable == 1) || (spintable == 3)) phi = ANGULAR_VEL *simt;  //move ase attachment and ius
        ROT = _V(sin(phi), 0, cos(phi));
        if ((spintable == 1) && (rotchange >= .50)) spintable = 3;  // up to speed
        //SetAttachmentParams(sat_attach4, pl4_ofs, DIR, pl4_rot);//ase
        SetAttachmentParams(sat_attach1, pl1_ofs, pl1_dir, ROT);//satellite
        //sets new attachment rotation values for saving
        pl1_rot.x = ROT.x;
        //pl4_dir.x = DIR.x;
        pl1_rot.y = ROT.y;
        //pl4_dir.y = DIR.y;
        pl1_rot.z = ROT.z;
        
        ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
        OBJHANDLE hChild = GetAttachmentStatus(ah);
        if (oapiIsVessel(hChild)) { // something is attached!
            VESSEL *v = oapiGetVesselInterface(hChild);
            sprintf(oapiDebugString(), "%s is attached",
                v->GetName());
            if (spintable == 4){//spin is complete
                OBJHANDLE hChild = GetAttachmentStatus(sat_attach1);
                DetachChild(sat_attach1, 1.0);
                if (oapiIsVessel(hChild)) {
                    VESSEL *vChild = oapiGetVesselInterface(hChild);
                    vChild->SetAngularVel(_V(0, 0, 2));
                }
            }
        }
        else sprintf(oapiDebugString(), "nothing is attached");
                //else sprintf(oapiDebugString(), "nothing is attached");
            }
No CTD but the sat jumps away and no spinning.

---------- Post added at 09:03 PM ---------- Previous post was at 08:56 PM ----------

OK confused

1sk Key CTRL f6 sets spintable to 1 that starts the attachment to spin. when it gets to the desired rate then spintable is set to 3. Then press CTRL F6 again now spintable =4 and dettach the sat.

---------- Post added at 09:10 PM ---------- Previous post was at 09:03 PM ----------

For some reason when I had it detach from the key it would detach fine. Now it jumps high

---------- Post added at 09:15 PM ---------- Previous post was at 09:10 PM ----------

Code:
if (KEYMOD_CONTROL(kstate)) {
		if (key == OAPI_KEY_F6){
			if (spintable == 0)	spintable = 1;
			else if (spintable == 3) {
				spintable = 4;//DetachChild(sat_attach1, 1.0);
				DetachChild(sat_attach1, 1.0);
			}
			return 1;
		}
and
Code:
		ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
		OBJHANDLE hChild = GetAttachmentStatus(ah);
		if (oapiIsVessel(hChild)) { // something is attached!
			VESSEL *v = oapiGetVesselInterface(hChild);
			sprintf(oapiDebugString(), "%s is attached",
				v->GetName());
			if (spintable == 4){//spin is complete
				OBJHANDLE hChild = GetAttachmentStatus(sat_attach1);
				//DetachChild(sat_attach1, 0.001);
				if (oapiIsVessel(hChild)) {
					VESSEL *vChild = oapiGetVesselInterface(hChild);
					vChild->SetAngularVel(_V(2, 0, 0));
				}
			}
		}
		else sprintf(oapiDebugString(), "nothing is attached");
				//else sprintf(oapiDebugString(), "nothing is attached");
			}
no ctd or jumps But no spinning sat
gattispilot is offline   Reply With Quote
Old 12-10-2018, 03:20 AM   #233
Majid
Orbinaut
Default

Remove the code from clbkPreStep or clbkPostStep and move it to here:

Code:
if (KEYMOD_CONTROL(kstate)) {
		if (key == OAPI_KEY_F6){
			if (spintable == 0)	spintable = 1;
			else if (spintable == 3) {
				spintable = 4;
                                OBJHANDLE hChild = GetAttachmentStatus(sat_attach1);
				DetachChild(sat_attach1, 1.0);
                                if (oapiIsVessel(hChild)) {
					VESSEL *vChild = oapiGetVesselInterface(hChild);
					vChild->SetAngularVel(_V(2, 0, 0));
				}
			}
			return 1;
		}
Majid is online now   Reply With Quote
Old 12-10-2018, 03:30 AM   #234
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Works thanks. Is there a way to set the angular Velocity to 50 rpm on the z axis?
gattispilot is offline   Reply With Quote
Old 12-10-2018, 03:55 AM   #235
Majid
Orbinaut
Default

Quote:
Originally Posted by gattispilot View Post
 Works thanks. Is there a way to set the angular Velocity to 50 rpm on the z axis?
1 rotation is 360 degrees, 50 rotations is equal to 18000 degrees/minute, which is 300 degrees/second. Go to the scenario editor, open a scn with a dg in orbit and use the scenario editor to give 300 degrees/s angular velocity in z axis and confirm if that looks right. If it does, then just copy the code from the scn editor.

---------- Post added at 03:55 AM ---------- Previous post was at 03:50 AM ----------

Code:
VECTOR3 avel;
avel.data[0] = 0;
avel.data[1] = 0;
avel.data[2] = 300*RAD;
vChild->SetAngularVel(avel);

Last edited by Majid; 12-10-2018 at 03:59 AM.
Majid is online now   Reply With Quote
Old 12-11-2018, 02:11 AM   #236
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Thanks.
Code:
if ((spintable == 1) && (rotchange <= .50))rotchange = rotchange + .001;//OPERATE SPINTABLE and if rate change is less than .3 do not increase
		ANGULAR_VEL = 2 * PI * (rotchange);//apply rot to ang vel



		//sprintf(oapiDebugString(), " phi %d tilt %f spintable %f", spintable, ANGULAR_VEL, rotchange);
		if (phi < 0)phi = 0;
		//if (phi >1.2)phi = 1.2;
		xp1 = arm1_tip[1] - arm1_tip[0]; normalise(xp1);
		xr1 = arm1_tip[2] - arm1_tip[0]; normalise(xr1);
		if ((spintable == 1) || (spintable == 3)) phi = ANGULAR_VEL *simt;  //move ase attachment and ius
		ROT = _V(sin(phi), 0, cos(phi));
		if ((spintable == 1) && (rotchange >= .50)) spintable = 3;  // up to speed
		//SetAttachmentParams(sat_attach4, pl4_ofs, DIR, pl4_rot);//ase
		SetAttachmentParams(sat_attach1, pl1_ofs, pl1_dir, ROT);//satellite
		//sets new attachment rotation values for saving
		pl1_rot.x = ROT.x;
		//pl4_dir.x = DIR.x;
		pl1_rot.y = ROT.y;
		//pl4_dir.y = DIR.y;
		pl1_rot.z = ROT.z;

		ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
		OBJHANDLE hChild = GetAttachmentStatus(ah);
		if (oapiIsVessel(hChild)) { // something is attached!
			VESSEL *v = oapiGetVesselInterface(hChild);
			//	sprintf(oapiDebugString(), "%s is attached",
			//	v->GetName());
		}


Code:
if (KEYMOD_CONTROL(kstate)) {
			if (key == OAPI_KEY_F6){
				if (spintable == 0)	spintable = 1;
				else if (spintable == 3) {
					spintable = 4;
					OBJHANDLE hChild = GetAttachmentStatus(sat_attach1);
					DetachChild(sat_attach1, 1.0);
					if (oapiIsVessel(hChild)) {
						VESSEL *vChild = oapiGetVesselInterface(hChild);
						VECTOR3 avel;
						avel.data[0] = 0;
						avel.data[1] = 0;
						avel.data[2] = 300 * RAD;
						vChild->SetAngularVel(avel);
					}
				}
				
				return 1;
			}
Works great. the only thing I noticed it seem the rotation of attachment was clockwise and release was counter clock wise?

Not sure which direction it should be.

Am I not sure the spinning rate I have is 50 rpm either.

---------- Post added at 05:44 AM ---------- Previous post was at 05:38 AM ----------

seem very good at attachments. Could you look at the Bepi issue.

I had it attached and then when unattached rotate. It did but when detach it went up rather than out. So I tried docking but when dock and then that vessel is attached it goes bad:
https://drive.google.com/open?id=1oq...YJ04BOWfuTXpZG

---------- Post added at 08:11 PM ---------- Previous post was at 05:44 AM ----------

Another question:

I want just control surfaces in atmosphere and rcs in space.
Code:
ATMPRESSURE = GetAtmPressure();
if (ATMPRESSURE >.1)//in atmosphere so use control surfaces
{
	//EnableRCS(true);
	SetADCtrlMode(7);// enable all control surfaces
	(GetAttitudeMode() == RCS_NONE);
}
else {
	//EnableRCS(false);
	SetADCtrlMode(0);//disable control surface
	(GetAttitudeMode() == RCS_ROT);
	(GetAttitudeMode() == RCS_LIN);
}
but I get rcs on the pad on the Earth
gattispilot is offline   Reply With Quote
Old 12-13-2018, 02:19 AM   #237
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Thanks. The launch works. What needs some work is the before launch.
As I read the SF doc. By pressing CTRL f6 the spintable rotates and maybe increases in rotation. When it hits 50 rpm then it stops increasing and maintains that 50 rpm. Then when released it will spin to a stop. So the spin table is an attachment point.
So in the scn SPIN1 is listed that lets it to use 1 attachment.
If my code when Spintable ==1 then start the spin. When it reaches 50? then spintable =3.
Code:
if (SPIN1 == 1){//spintable#1



		if ((spintable == 1) && (rotchange <= .50))rotchange = rotchange + .001;//OPERATE SPINTABLE and if rate change is less than .3 do not increase
		ANGULAR_VEL = 2 * PI * (rotchange);//apply rot to ang vel



		//sprintf(oapiDebugString(), " phi %d tilt %f spintable %f", spintable, ANGULAR_VEL, rotchange);
		if (phi < 0)phi = 0;
		//if (phi >1.2)phi = 1.2;
		xp1 = arm1_tip[1] - arm1_tip[0]; normalise(xp1);
		xr1 = arm1_tip[2] - arm1_tip[0]; normalise(xr1);
		if ((spintable == 1) || (spintable == 3)) phi = ANGULAR_VEL *simt;  //move ase attachment and ius
		ROT = _V(sin(phi), 0, cos(phi));
		if ((spintable == 1) && (rotchange >= .50)) spintable = 3;  // up to speed
		//SetAttachmentParams(sat_attach4, pl4_ofs, DIR, pl4_rot);//ase
		SetAttachmentParams(sat_attach1, pl1_ofs, pl1_dir, ROT);//satellite
		//sets new attachment rotation values for saving
		pl1_rot.x = ROT.x;
		//pl4_dir.x = DIR.x;
		pl1_rot.y = ROT.y;
		//pl4_dir.y = DIR.y;
		pl1_rot.z = ROT.z;

		ATTACHMENTHANDLE ah = GetAttachmentHandle(false, 0);
		OBJHANDLE hChild = GetAttachmentStatus(ah);
		if (oapiIsVessel(hChild)) { // something is attached!
			VESSEL *v = oapiGetVesselInterface(hChild);
			//	sprintf(oapiDebugString(), "%s is attached",
			//	v->GetName());
		}

		
		//else sprintf(oapiDebugString(), "nothing is attached");
		//else sprintf(oapiDebugString(), "nothing is attached");
	
}
Not sure about the rate increase and the end point of 50 rpm
gattispilot is offline   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Addons > Addon Requests


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 11:57 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.