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
As I said before, look at my code in AAPO for SLA sep and review my LM tutorial's bit on stage separation.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
ok. I got them to create and to attach. I had to add the child info to the cfg.

Yeah Thanks.

Now to get the airbag module to scale the bags.

What I am not sure is how the info is transfer to the airbag module.

on the airbag module there is this:

#define DLLEXPORT __declspec(dllexport)
#define DLLIMPORT __declspec(dllimport)

// shared data
DLLIMPORT double bagdoor_proc;
DLLIMPORT int bagdoor_operate;
DLLIMPORT int airbag_jettison;



AIRBAG.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int bagdoor_operate" (__imp_?bagdoor_operate@@3HA)
AIRBAG.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int airbag_jettison" (__imp_?airbag_jettison@@3HA)
AIRBAG.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) double bagdoor_proc" (__imp_?bagdoor_proc@@3NA)
 
Last edited:

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
ok. I got them to create and to attach. I had to add the child info to the cfg.

Yeah Thanks.

Now to get the airbag module to scale the bags.

See my parachute code in AAPO
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
OK thanks..Looking at the CM_Drogue. I can scale the bags. But it is the ability from the main ship to tell it to open the doors scale the bags and press the key again and detach the vessels all from the main ship
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
That's the easy part, you control it as you would any other multi-stage animation sequence.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
Ok. I have been able to create the airbag vessels and attach, Thanks. The final piece is the airbag module.
Here is the original code for 2006 orbiter:

https://dl.dropboxusercontent.com/u/71242599/airbagmodule.txt

I can compile a new version as I get these errors

Creating library ./../../../Modules/LEOAIRBAG.lib and object ./../../../Modules/LEOAIRBAG.exp
AIRBAG.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int bagdoor_operate" (__imp_?bagdoor_operate@@3HA)
AIRBAG.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int airbag_jettison" (__imp_?airbag_jettison@@3HA)
AIRBAG.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) double bagdoor_proc" (__imp_?bagdoor_proc@@3NA)
./../../../Modules/LEOAIRBAG.dll : fatal error LNK1120: 3 unresolved externals

Somehow it needs to get from the mother ship the values of bagdoor_proc, airbag_jettison, and bagdoor_operate.


From the mothership code
DLLEXPORT double bagdoor_proc;
DLLEXPORT int bagdoor_operate;
DLLEXPORT int airbag_jettison;
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
That is what the VESSEL interface is for.

Seriously, go back and review my code tutorial on stage separation or Jedia's IMS-related posts on the same subject.

This question has been answered multiple times.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
I looked at your blog on staging. But I am not sure how the data is shared between the 2 vessels

Code:
void LEONOVOEXT::clbkPostCreation (void)

{
LEONOVOEXT *dg = (LEONOVOEXT*)vessel;


bagdoor_operate = dg->bagdoor_status;

dg->Airbag_Check();

from the mother ship.
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
In object oriented programming languages like C++ what happens in a given class instance or program stays in that instance. Each active planet vessel and mfd in Orbiter is an instance of it's corresponding class. (in this case VESSEL). If you want one to send values from one to another you must define an external class interface. Think of the "ds->" pointer as a file path to a vessel, mfd, or planet other than the one who's code you are currently running.

...this last option is entirely optional but I'm going to do it because I'm a completionist and knowing how to do it may come in handy later. Lets set the propellant levels in our spawned descent stage to those in our parent vessel's descent tanks.

For this to work we need to do it after we've spawned the descent stage vessel but before we delete the descent tanks from our parent vessel.

Code:
		oapiCreateVessel (name, "UMMU_Apollo/LM_descentstage", vs);	// create descent stage vessel

		[COLOR="red"]// Match descent stage's propellant levels to LM's descent tanks  
		OBJHANDLE oh_descent = oapiGetObjectByName (name);		// get handle of descent stage vessel 
		VESSEL *ds = oapiGetVesselInterface (oh_descent);		// get interface for descent stage
		ds->SetPropellantMass (ds->GetPropellantHandleByIndex (0), GetPropellantMass (ph_descentFuel));
		ds->SetPropellantMass (ds->GetPropellantHandleByIndex (1), GetPropellantMass (ph_descentO2));
		ds->SetPropellantMass (ds->GetPropellantHandleByIndex (2), GetPropellantMass (ph_descentH2O));[/COLOR]
		
		// Remove descent stage from vessel instance
		DelThruster (th_descent);						// Delete descent stage engine

This is actually our first interaction with external class interfaces/instances.

"OBJHANDLE oh_descent = oapiGetObjectByName (name);" gets a handle for the descent stage vessel that we just created.

"VESSEL *ds = oapiGetVesselInterface (oh_descent);" This function creates a new class interface (it does not create a new vessel) called "ds" that points to an existing vessel (our descent stage). Using this interface we can call functions in that vessel's code as well as our own.

NOTE: much care should be taken in which functions you call. All sort of errors/bugs can arise from calling a function that is not declared or has a different definition from the vessel you're calling it from. To play it safe, restrict these calls to default Orbiter API functions such as the above.

"ds->" indicates that we are calling the function that follows in "ds"'s code rather than our own vessel's. In this case we are getting handles for 3 of ds's propellant tanks and setting their propellant masses to the masses in our parent vessel's descent tanks.

NOTE: this assumes that the descent stage vessel has 3 tanks. this can cause issues if does not. To head-off any such problems I will simply post the source code of my descent stage here. At this point, if you've been following along, you should know what to do with it.
...
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
I added these lines:
Code:
void LEONOVOEXT::clbkPostCreation (void)

{
LEONOVOEXT *dg = (LEONOVOEXT*)vessel;


bagdoor_operate = dg->bagdoor_status;

dg->Airbag_Check();

now I get a CTD . It is back in the airbag_check code.

Code:
void LEONOVOEXT::Airbag_Check()
{
 VESSELSTATUS2 vs;
  vs.version = 2;
  vs.flag=0;
  GetStatusEx (&vs);
}

if I comment the GetStatusEx (&vs); then no ctd

---------- Post added at 02:49 PM ---------- Previous post was at 02:23 PM ----------

got the CTD fixed
Code:
void LEONOVOEXT::clbkPostCreation (void)

{
LEONOVOEXT *dg = (LEONOVOEXT*)vessel;


bagdoor_operate = dg->bagdoor_status;

Airbag_Check();
So as I understand for me this is calling bagdoor_operate to the dg vessel bagdoor_status, right
 
Last edited:

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 but "dg" has to actually connect to another vessel and the bagdoor function must be declared within it otherwise you will get a unresolved external symbol error and/or CTD
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
So how it is connect?

That would explain then CTD with

dg->Airbag_Check();

this doesn't give a CTD

Airbag_Check();


this is the only places bagdoor_statuis is mentioned

Code:
if (bagdoor_status >= CLOSING) {
        double da = simdt * LIFT_SPEED;
        if (bagdoor_status == CLOSING) {
            if (bagdoor_proc > 0.0) bagdoor_proc = max (0.0, bagdoor_proc-da);
            else                bagdoor_status = CLOSED;
        } else {
            if (bagdoor_proc < 1.0) bagdoor_proc = min (1.0, bagdoor_proc+da);
            else                bagdoor_status = OPEN;
        }

void LEONOVOEXT::RevertAIRBAG (void)
{
bagdoor_status = ((bagdoor_status == CLOSED || bagdoor_status == CLOSING )? OPENING : CLOSING);
}


Yes but "dg" has to actually connect to another vessel and the bagdoor function must be declared within it otherwise you will get a unresolved external symbol error and/or CTD
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
Ok thanks. this is the only mention of that
Code:
airbag1 = oapiCreateVesselEx ("airbag1", "leonovairbag1B", &vs);
    airbag2 = oapiCreateVesselEx ("airbag2", "leonovairbag2C", &vs);
   airbag3 = oapiCreateVesselEx ("airbag3", "leonovairbag3C", &vs);
    airbag4 = oapiCreateVesselEx ("airbag4", "leonovairbag4B", &vs);
    airbag5 = oapiCreateVesselEx ("airbag5", "leonovairbag5B", &vs);
    airbag6 = oapiCreateVesselEx ("airbag6", "leonovairbag6B", &vs);



airbag1_vessel = oapiGetVesselInterface (airbag1);
airbag2_vessel = oapiGetVesselInterface (airbag2);
airbag3_vessel = oapiGetVesselInterface (airbag3);
airbag4_vessel = oapiGetVesselInterface (airbag4);
airbag5_vessel = oapiGetVesselInterface (airbag5);
airbag6_vessel = oapiGetVesselInterface (airbag6);
originally the airbag vessels used the airbag module

---------- Post added at 05:41 PM ---------- Previous post was at 04:08 PM ----------

So it looks like airbag1_vessel connects to airbag1 vessel, right? So the mother ship can control airbag 1 vessel

So how do they share airbag_status
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Same way you would pass any other variable between two functions.

"Variable A in Function B" = "Variable A in Function A"
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
cpp from airbag module
Code:
void Airbag::Timestep (double simt)
{
//bagdoor animation
if (bagdoor_operate >= 2 && airbag_jettison == 0) {
double da = oapiGetSimStep() * BAGDOOR_OPERATING_SPEED;
if (bagdoor_operate == 2) {
if (bagdoor_proc > 0.0)
bagdoor_proc = max (0.0, bagdoor_proc - da);
else
bagdoor_operate = 0;
} else
{
if (bagdoor_proc < 1.0)
bagdoor_proc = min (1.0, bagdoor_proc + da);
else
{
bagdoor_operate = 1;
}
}
if (_stricmp (GetName(), "airbag1") == 0)
SetAnimation (anim_bagdoor1, bagdoor_proc);
else if (_stricmp (GetName(), "airbag2") == 0)
SetAnimation (anim_bagdoor2, bagdoor_proc);
else if (_stricmp (GetName(), "airbag3") == 0)
SetAnimation (anim_bagdoor3, bagdoor_proc);
else if (_stricmp (GetName(), "airbag4") == 0)
SetAnimation (anim_bagdoor4, bagdoor_proc);
else if (_stricmp (GetName(), "airbag5") == 0)
SetAnimation (anim_bagdoor5, bagdoor_proc);
else if (_stricmp (GetName(), "airbag6") == 0)
SetAnimation (anim_bagdoor6, bagdoor_proc);
}
}

I don't see how these bagdoor_operate and airbag_jettison get taken from the mothership
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
I don't see how these bagdoor_operate and airbag_jettison get taken from the mothership

Is this your code or someone else's?

I would assume that you would remember where you passed the value from one to the other had you done so.

If you haven't, that's your problem.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
this also gives a CTD.

Code:
dg->Airbag_Check();
if I remove the "dg->" then no CTD

---------- Post added at 08:35 PM ---------- Previous post was at 08:34 PM ----------

It is NOt my code. It was from a vessel made for 2006 Orbiter. I am trying to update the vessel.

---------- Post added at 08:37 PM ---------- Previous post was at 08:35 PM ----------

This is the original cpp and h
https://dl.dropboxusercontent.com/u/71242599/leonovold.txt
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Well that explains a lot.

You'd probably be better off starting from scratch rather than trying to parse large chunks of uncommented code.

You'll learn more and better too.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,731
Reaction score
2,701
Points
203
Location
Dallas, TX
Maybe. Are there code samples that use that interface to share values? This is the last major piece.

---------- Post added at 08:53 PM ---------- Previous post was at 08:47 PM ----------

I did see this:
Code:
DLLCLBK void ovcTimestep (VESSEL *vessel, double simt)
{
Leonov *dg = (Leonov*)vessel;

dg->Timestep (simt);

bagdoor_operate = dg->bagdoor_status;

if (dg->rotating == 0)
{
dg->rotating = 1;
dg->rotsect_status = dg->ROT;
}
dg->TransRings_Check();
dg->Airbag_Check();
}

So it looks like the bagdoor_operate = dg->bagdoor_status; So the bagdoor_status is sent to the dg vessel right?

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