API Question Reliably detecting spacecraft attachment to a launcher

loyalj

New member
Joined
Jan 9, 2010
Messages
20
Reaction score
0
Points
0
Location
Toronto
Hey all, I'm working on a DLL based spacecraft project in my spare time and can't figure out how to accomplish something fairly important to the project. I looked through the forum history and the SDK docs but haven't had much luck; hoping the forum can help out.

What I am looking to do is detect whether or not my spacecraft is currently the payload of an off the shelf launcher. And more specifically, I want to be able to detect the "your spacecraft has been jettisoned by the launcher and is now no it's own in orbit" so that I can initiate my spacecraft's startup/main functions.

The two launcher's I'm using are the Energia and The Falcon collection.. both are really great launchers and I am particularly fond of the Falcons since I'm looking to get as realistic as I can with the project. Both also produce exactly the same results in the following cases.

I've tried GetFlightStatus() and the freeflight/vs landed bit accurately reflects the status of my craft while attached to either launcher. When the launcher lifts off my craft is shown as in flight. But, in either state the second bit is always 0.. so my craft doesn't know it's attached to something.. Tried getting similar info back from GetStatus() and didn't have any luck.

Say mine is a mothership which launches cubesats or something.. it wouldn't help to detect freeflight at lift off and then start ejecting the cubesats.. it's got to wait till orbit.

I tried counting attachments with AttachmentCount(), both parent and child.. no luck. Tried grabbing dock handles but always get Null back... So I am assuming that the launchers do something in their own code to manage payloads which doesn't really allow for easy detection.

I suppose I could always use freeflight status + altitude to detect if I am in orbit or not... but then the spacecraft is specific to one body as a lunar orbit could be under 100km which earth could not..

Anyone know of a way to solve this sort of thing and actually detect this kind of thing explicitly?
 
I'd say it depends on the method the launcher uses to "attach" your craft.

If it uses attachment points or docking ports, it should be possible to scan those via the API functions you listed. If it just slaves your vessel via DefSetStateEx(), it is not that easy. You could maybe use the oapi::Module::clbkVesselJump() callback in this case, but it will be a lot more complicated.

I could also imagine a method where only meshes are displayed, and the actual vessel is only created at jettison. You'd then know that you are on your own the moment your vessel is created. But I doubt this is used...

Do you know what method the launchers use?
 
Thanks for the quick reply. I don't know exactly how the launchers attach.. but it's not through docks or attachments. So it's probably the method you're suggesting. My craft is definitely being created before launch since I can run code with it attached to the launcher.

I'll probably just have to settle for free-flight/altitude/timer trigger combo of some sort... the first few projects are all earth orbiters so... not ideal but it could probably work.
 
The next version of my Prometheus will include calling each vessel's clbkGeneric when jettisoned. Perhaps you could persuade the authors of the launchers you want to use to include something like this.
 
Hi,
if your payload is already present in the scenario before launch, then I think it would be using an "attachment point" to attach to the launcher.

You could use GetAttachmentStatus() to see if you are still attached to anything. e.g....

Code:
int am_i_attached = 0;                // 0 = not attached, 1 = attached
DWORD natt = AttachmentCount (true);  // get number of child-to-parent att points
for (DWORD k = 0; k < natt; k++)
{
ATTACHMENTHANDLE atth = GetAttachmentHandle (true, k);
if (!GetAttachmentStatus(atth) == NULL) am_i_attached = 1;
}

Any help?
Cheers,
Brian
 
Well, the OP already noted that he used AttachmentCount() with both possible values to no avail.
 
Back
Top