Advanced Question Creating vessels and interacting with them

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Maybe. Are there code samples that use that interface to share values?

Yes; see AAPO, my LM tutorial, and the stock Dragonfly.

The other module is a airbag module. But shouldn't have sometime to get the Dg vessel info?

Why? the mothership is the one in control is it not? the Airbag vessel just needs to jump when the mothership tells it to.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,730
Reaction score
2,698
Points
203
Location
Dallas, TX
Why? the mothership is the one in control is it not? the Airbag vessel just needs to jump when the mothership tells it to.
Yes I just need to figure out how to tell it to jump

Where is your LM tutorial?

---------- Post added at 09:19 PM ---------- Previous post was at 09:07 PM ----------

on your LM code. You are setting the descent stage propellent the same as the lm right.

So for me if looks like I need to set
Code:
bagdoor_operate = dg->bagdoor_status;
and dg vessel needs to be the airbag. If the state of the bagdoor_status changes then do something in the airbag module, right?


Code:
void LM::StageSep (void)
{
	if (DescentStage_attached) // Sanity check, is there a descent stage to jettison?
	{
		// Create descent stage as seperate vessel
		char name[255];
		strcpy (name, GetName()); 
		strcat (name, "_DescentStage");
		OBJHANDLE oh_ds = SpawnObject (this, name, "AAPO/Parts/DescentStage", LM_DES_OFFSET, 0.1);

		// Match descent stage's propellant levels to LM's descent tanks  
		VESSEL *ds = oapiGetVesselInterface (oh_ds);		// get interface for descent stage
		ds->SetPropellantMass (ds->GetPropellantHandleByIndex (0), GetPropellantMass (ph_descent));
		ds->SetPropellantMass (ds->GetPropellantHandleByIndex (1), GetPropellantMass (ph_descent_O2));
		ds->SetPropellantMass (ds->GetPropellantHandleByIndex (2), GetPropellantMass (ph_descent_H2O));

		// Play sound effect
		PlayVesselWave (OrbiterSoundID, SOUND_STAGESEP);	

		// Update vessel state
		DescentStage_attached = false;
	} // End "if (DescentStage_Attached)"

} // End "LM::StageSep"
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Yes I just need to figure out how to tell it to jump

That's the easy part. In the mothership's code you will have something something along the lines of...

Code:
bag->bag_status = whatever;

then in the bag's module you write something along the lines of...

Code:
if (bag_status == whatever)
{
  Do something;
}
else
{
  Do some other thing;
}

simple as that.

Where is your LM tutorial?

See signature.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,730
Reaction score
2,698
Points
203
Location
Dallas, TX
Thanks

I have this in the mother ship
Code:
VESSEL *bag = oapiGetVesselInterface (airbag1);		
bagdoor_operate = bag->bagdoor_status;

but get a weird error:
.\LEONOVOEXT.cpp(3086) : error C2039: 'bagdoor_status' : is not a member of 'VESSEL'
c:\orbiter2010p1a\orbitersdk\include\VesselAPI.h(57) : see declaration of 'VESSEL'

in the h it is
Code:
enum BagDoorStatus { CLOSED, OPEN, CLOSING, OPENING } bagdoor_status;
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,730
Reaction score
2,698
Points
203
Location
Dallas, TX
Ok now I am lost

---------- Post added 06-10-13 at 05:15 AM ---------- Previous post was 06-09-13 at 10:23 PM ----------

Code:
LEONOVOEXT *bag = dynamic_cast<LEONOVOEXT*>((VESSEL2*)airbag1);

VESSEL *bag = oapiGetVesselInterface (airbag1);		
bagdoor_operate = bag->bagdoor_status;
bag->bagdoor_status;
bag->airbag_jettison;

But I get this;
.\LEONOVOEXT.cpp(3088) : error C2371: 'bag' : redefinition; different basic types
.\LEONOVOEXT.cpp(3086) : see declaration of 'bag'
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
I get this;
.\LEONOVOEXT.cpp(3088) : error C2371: 'bag' : redefinition; different basic types
.\LEONOVOEXT.cpp(3086) : see declaration of 'bag'

You declared bag as LEONOVOEXT, and in the next line you redeclared it as VESSEL. You can't do that.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,730
Reaction score
2,698
Points
203
Location
Dallas, TX
Thanks
Not sure what it should be?

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

If I followed the code this should be right. Leoairbag is the module for the airbag1 vessel
Code:
VESSEL *bag = dynamic_cast<LEOAIRBAG*>((VESSEL2*)airbag1);

VESSEL *bag = oapiGetVesselInterface (airbag1);		
bagdoor_operate = bag->bagdoor_status;
bag->bagdoor_status;
bag->airbag_jettison;
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Is airbag1 an OBJHANDLE and that's why you get the vessel interface from it?

If so, that should rather look this way:
Code:
LEONOVOEXT *bag = dynamic_cast<LEONOVOEXT*>((VESSEL2*)oapiGetVesselInterface (airbag1));

bagdoor_operate = bag->bagdoor_status;
bag->bagdoor_status;
bag->airbag_jettison;
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,730
Reaction score
2,698
Points
203
Location
Dallas, TX
Thanks. yes OBJHANDLE airbag;
Code:
OBJHANDLE airbag1;
OBJHANDLE airbag2;
OBJHANDLE airbag3;
OBJHANDLE airbag4;
OBJHANDLE airbag5;

I am trying to get the bag_status and jettison to the airbagmodule vessel so it will scale the meshes,

---------- Post added at 05:16 PM ---------- Previous post was at 08:25 AM ----------

OK. Now I change one of the airbag.cfg so that it includes
Code:
; === Configuration file for vessel class DeltaGlider ===
ClassName = leonovairbag1
MeshName = leonovairbag1A
Module = LEOAIRBAG
BEGIN_ATTACHMENT
P 0 0 0.0  1 0 0  0 1 0  leo
END_ATTACHMENT

in the leoairbag code I have this:
Code:
void Airbag::Timestep (double simt)
{
sprintf(oapiDebugString(),"1a%2f 1a%2f",airbag_jettison,bagdoor_operate );

and it goes to it from here:
Code:
DLLCLBK void ovcTimestep (VESSEL *vessel, double simt)
{
Airbag *dg = (Airbag*)vessel;

dg->Timestep (simt);
}

But when I run it I don't see any screen output even if I select the airbag

---------- Post added 06-11-13 at 05:21 AM ---------- Previous post was 06-10-13 at 05:16 PM ----------

Where should the cfg be? The vessels that get created the cfg are in Orbiter/cfg. BUt I made a vessel using scenario editor where the cfg was in orbiter/cfg/vessels and I was able to scale it. the module is airbag2. If I use this cfg nothing
Code:
; === Configuration file for vessel class DeltaGlider ===
ClassName = leonovairbag2
MeshName = leonovairbag2A
Module = AIRBAG2
BEGIN_ATTACHMENT
P 0 0 0.0  1 0 0  0 1 0  leo
END_ATTACHMENT

So should I be creating the vesssels in cfg/vessels?
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Code:
DLLCLBK void ovcTimestep (VESSEL *vessel, double simt)
Is something calling exported from your module ovcTimestep function?

It isn't called by Orbiter (no such string exists in the orbiter.exe file), so if you don't call it from any of your modules explicitly, it won't be called at all.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,730
Reaction score
2,698
Points
203
Location
Dallas, TX
Thanks. I redid the airbagmodule. And right now it auto inflates.
I changed the scn to reflect the new cfg and when it runs it inflates but also dettach and puts on the sun.



Code:
airbag2:leonovairbag2D
  STATUS Orbiting Jupiter
  RPOS 44705874.95 -3290350.52 -114031282.51
  RVEL -30003.678 -2015.401 -8678.410
  AROT 67.11 -77.41 121.45
  ATTACHED 0:13,LEONOV
  AFCMODE 7
  NAVFREQ 0 0
END

end of scenario
Code:
airbag2:leonovairbag2D
  STATUS Orbiting Sun
  RPOS 0.01 -0.00 764653455.23
  RVEL -0.000 0.000 -20716.105
  AROT 0.00 -0.00 0.00
  AFCMODE 7
END

So it became dettached and to the sun.

here is it cfg
Code:
; === Configuration file for vessel class DeltaGlider ===
ClassName = leonovairbag2
MeshName = leonovairbag2A
Module = AIRBAG2
BEGIN_ATTACHMENT
P 0 0 0.0  1 0 0  0 1 0  leo
END_ATTACHMENT


on the mothership if I create the airbag vessels like this:
Code:
   airbag1 = oapiCreateVesselEx ("airbag1", "leonovairbag1B", &vs);
	airbag2 = oapiCreateVesselEx ("airbag2", "leonovairbag2D", &vs);
   airbag3 = oapiCreateVesselEx ("airbag3", "leonovairbag3C", &vs);
	airbag4 = oapiCreateVesselEx ("airbag4", "leonovairbag4B", &vs);
    airbag5 = oapiCreateVesselEx ("airbag5", "leonovairbag5B", &vs);
    airbag6 = oapiCreateVesselEx ("airbag6", "leonovairbag6B", &vs);

now I get this:
runtime error.
https://dl.dropboxusercontent.com/u/71242599/runtime%20error.jpg


cpp of airbag module
https://dl.dropboxusercontent.com/u/71242599/AIRBAG2.CPP

https://dl.dropboxusercontent.com/u/71242599/AIRBAG2.H

---------- Post added at 05:54 PM ---------- Previous post was at 06:09 AM ----------

scenario start:
airbag2:leonovairbag2C
STATUS Orbiting Jupiter
RPOS 57532056.05 -2387633.50 -109491017.89
RVEL -28482.620 -2099.992 -12006.235
AROT 67.11 -77.41 121.45
ATTACHED 0:13,LEONOV
AFCMODE 7
NAVFREQ 0 0
END

end of scenario:
airbag2:leonovairbag2D
STATUS Orbiting Sun
RPOS 0.00 -0.00 765597222.58
RVEL -0.000 0.000 -1121.478
AROT 0.00 -0.00 0.00
AFCMODE 7
END

No sure why it ends up dettached and on the sun.

; === Configuration file for vessel class DeltaGlider ===
ClassName = leonovairbag2
MeshName = leonovairbag2A
Module = AIRBAG2
BEGIN_ATTACHMENT
P 0 0 0.0 1 0 0 0 1 0 leo
END_ATTACHMENT

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

I am redoing my airbag module and so no dettaching and in the sun.

but where is this called?
Code:
void AIRBAG2::clbkPostStep(double simt, double simdt, double mjd)
{
	sprintf(oapiDebugString(),"%2f %2f",bagdoor_operate,bagdoor_proc);

I never see the string displayed?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,730
Reaction score
2,698
Points
203
Location
Dallas, TX
OK. I redid my code. The vessels are not created but are there at the start of the scenario.

So How do I tell the airbag3 vessel that bagdoor_operate is 2 and airbag_jettison is 0 from the control of the mothership LEONOV?
AIRBAG3 vessel
Code:
if (bagdoor_operate >= 2 && airbag_jettison == 0) {
Code:
void LEONOVOEXT::Airbag_Status()
{
		
		OBJHANDLE airbag1 = (GetName(), "airbag1");

				VESSEL *bag1 = oapiGetVesselInterface (airbag1);		// get interface for descent stage
bagdoor_operate = bag1->bagdoor_status;

}

but I get this error
.\LEONOVOEXT.cpp(3054) : error C2039: 'bagdoor_status' : is not a member of 'VESSEL'
        c:\orbiter2010p1a\orbitersdk\include\VesselAPI.h(57) : see declaration of 'VESSEL'

but it is 
	  enum BagDoorStatus { CLOSED, OPEN, CLOSING, OPENING } bagdoor_status;
 
Last edited:
Top