# API QuestionI don't understand THRUSTER_HANDLE

#### MJR

##### C++ developer in the mix
Tutorial Publisher
Donator
Okay. My plane has over 8 separate thrusters. However, when I go to THRUSTER_HANDLE, I set the th_main to [8]. Then I go to create the thrusters further down my .cpp. It looks like this.
Code:
    th_main = CreateThruster (_V(0,0,-4.35), _V(0,0,1), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
CreateThrusterGroup (&th_main, 8, THGROUP_MAIN);
just with 7 more versions of that with th_main [1], th_main[2], etc.

When I compile it does not work and says
Code:
>..\..\TransportVehicle\TransportVehicle\Spacecraft.cpp(148) : error C2664: 'VESSEL::CreateThrusterGroup' : cannot convert parameter 1 from 'THRUSTER_HANDLE (*)[1]' to 'THRUSTER_HANDLE *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

What is associated with this problem and how do I properly define 8 grouped thrusters?

#### orb

News Reporter
Is th_main of THRUSTER_HANDLE or THRUSTER_HANDLE [8] type?

If it's an array of thrusters, then why are you doing this?:
Code:
th_main = CreateThruster (_V(0,0,-4.35), _V(0,0,1), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
Code:
th_main [0] = CreateThruster (_V(0,0,-4.35), _V(0,0,1), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
//...
th_main [7] = CreateThruster (...);

If th_main isn't an array of thrusters, then you can't use it with "CreateThrusterGroup"

#### MJR

##### C++ developer in the mix
Tutorial Publisher
Donator
Is th_main of THRUSTER_HANDLE or THRUSTER_HANDLE [8] type?

If it's an array of thrusters, then why are you doing this?:
Code:
th_main = CreateThruster (_V(0,0,-4.35), _V(0,0,1), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
Code:
th_main [0] = CreateThruster (_V(0,0,-4.35), _V(0,0,1), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
//...
th_main [7] = CreateThruster (...);
If th_main isn't an array of thrusters, then you can't use it with "CreateThrusterGroup"
So I just have to delete the CreateThrusterGroup?

News Reporter

#### MJR

##### C++ developer in the mix
Tutorial Publisher
Donator
How can I not ask questions when I already read the API documents and did not understand it? Obviously I need help with this so I don't see how else I am to get the answer.

#### Urwumpe

##### Not funny anymore
Donator
So I just have to delete the CreateThrusterGroup?

No, you have to think about what you are about to do, and not about what you have done.

You do cargo cult programming - you know that the code worked somewhere, but don't know why it worked. And that is a problem you can work on. Like for example learning what arrays are and how you use arrays.

CreateThrusterGroup for example is important if you want orbiter to use this set of thrusters as Main thruster group and react to manual throttle commands.

And if you would know what arrays are, you would know that arrays are just a pointer to the first element in the array, and the position to the next element is just adding the size of the element to the pointer address...

#### tblaxland

Webmaster
Reading the OP, I think he has:
Code:
th_main = CreateThruster (_V(0,0,-4.35), _V(0,0,1), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
th_main [1] = CreateThruster (...);
//...
th_main [7] = CreateThruster (...);
MJR, correct?

The first line should be:
Code:
th_main [0] = CreateThruster (...);
Also, can you show how you have declared th_main? EDIT: This is an alternative way of asking orb's question, that you didn't answer:
orb said:
Is th_main of THRUSTER_HANDLE or THRUSTER_HANDLE [8] type?

#### tblaxland

Webmaster
And if you would know what arrays are, you would know that arrays are just a pointer to the first element in the array, and the position to the next element is just adding the size of the element to the pointer address...
Not quite true, an array lvalue just behaves like a pointer in most instances, but not always:
(The exceptions are when the array is the operand of a sizeof or & operator, or is a string literal initializer for a character array.)
http://www.mrbrklyn.com/resources/C_lang-FAQ.html, item 6.3.​

#### MJR

##### C++ developer in the mix
Tutorial Publisher
Donator
Reading the OP, I think he has:
Code:
th_main = CreateThruster (_V(0,0,-4.35), _V(0,0,1), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
th_main [1] = CreateThruster (...);
//...
th_main [7] = CreateThruster (...);
MJR, correct?

The first line should be:
Code:
th_main [0] = CreateThruster (...);
Also, can you show how you have declared th_main? EDIT: This is an alternative way of asking orb's question, that you didn't answer:
Sorry. I actually didn't see Orb's question that is why I did not respond to it. Anyway, yes that is how I did it at first. Now I am trying to figure it out. Here is the th_main definition and how Ithink that it should look like so don't shoot me in the face because I got something wrong.

Code:
th_main[0] = CreateThruster (_V(x,x,x), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
th_main[1] = CreateThruster (_V(x,x,x), _V(x,x,x), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
th_main[2] = CreateThruster (_V(x,x,x), _V(x,x,x), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
th_main[3] = CreateThruster (_V(x,x,x), _V(x,x,x), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
th_main[4] = CreateThruster (_V(x,x,x), _V(x,x,x), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
th_main[5] = CreateThruster (_V(x,x,x), _V(x,x,x), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
th_main[6] = CreateThruster (_V(x,x,x), _V(x,x,x), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);
th_main[7] = CreateThruster (_V(x,x,x), _V(x,x,x), Spacecraft_MAXMAINTH, hpr, Spacecraft_ISP);

th_main is defined in the thruster_handle that looks like this. I think that also answers your question.

Code:
THRUSTER_HANDLE th_main[7];

P.S. I just put X's on them for the post. In the code they are real numbers.

---------- Post added at 07:52 PM ---------- Previous post was at 07:39 PM ----------

I think I see what I did wrong, but I don't want to make assumptions.

#### orb

News Reporter
th_main is defined in the thruster_handle that looks like this. I think that also answers your question.

Code:
THRUSTER_HANDLE th_main[7];

You have 8 thrusters, so you need:
Code:
THRUSTER_HANDLE th_main [8];

Also, now you're missing direction vector when you create th_main[0].

And I don't think you need to reference th_main by address for CreateThrusterGroup if it's an array.

#### MJR

##### C++ developer in the mix
Tutorial Publisher
Donator
You have 8 thrusters, so you need:
Code:
THRUSTER_HANDLE th_main [8];
Also, now you're missing direction vector when you create th_main[0].

And I don't think you need to reference th_main by address for CreateThrusterGroup if it's an array.
That did the trick. I got rid of CreateThrusterGroup and changed that part to th_main[8]. Thanks.

#### orb

News Reporter
That did the trick. I got rid of CreateThrusterGroup and changed that part to th_main[8]. Thanks.
No, no. You shouldn't have deleted CreateThrusterGroup, but change it to:
Code:
CreateThrusterGroup (th_main, 8, THGROUP_MAIN);

#### MJR

##### C++ developer in the mix
Tutorial Publisher
Donator
No, no. You shouldn't have deleted CreateThrusterGroup, but change it to:
Code:
CreateThrusterGroup (th_main, 8, THGROUP_MAIN);
Ah crap. Probably should have confirmed it after a test run. :lol: Ok, let mwe try that real quick.

#### MJR

##### C++ developer in the mix
Tutorial Publisher
Donator
Okay. Now it officially works. Tested and everything.

#### Attachments

• Untitled.jpg
126 KB · Views: 26

#### Urwumpe

##### Not funny anymore
Donator
Not quite true, an array lvalue just behaves like a pointer in most instances, but not always:

That is compiler time behavior though and limited to the operators, not run-time behavior. also, I think using sizeof on a pointer would still just produce the size of the pointer, even if you use the allocated memory as array.

It is only working like that for objects you declare as array by "E a[n];"

#### computerex

Not quite true, an array lvalue just behaves like a pointer in most instances, but not always:

That's irrelevant for this. Take a look at the assembly code generated by your compiler.

#### MJR

##### C++ developer in the mix
Tutorial Publisher
Donator
Is it natural for Orbiter to act wierd when I have 10 thrusters and contrail all at once? I get flicking of the Earth, the smoke, and surface tiles.

---------- Post added at 07:05 PM ---------- Previous post was at 06:59 PM ----------

Note: It is only in window mode.

#### jedidia

##### shoemaker without legs
Kind of jacking the thread here, but it seems the OP has solved his problems, and since my question is thruster group and thruster handle related I might as well post it here.

The thing I'm trying to do is easy enough. Get the ISP of the main thruster(s). vessel->getISP() returns the default ISP, which isn't neccesserily matching the ISP of the main thruster(s), as I noticed.

I found getthrusterIsp and getthrusterIsp0, but they want a thruster handle of the exact thruster I want the ISP of. There doesn't seem to be a call to get the Isp of the whole main thruster group (probably because they might not have a unified Isp, although I'd consider that a design flaw in the vessel), so what it comes down to is that I have to Identify an arbitrary thruster belonging to the main thruster group and take its Isp. However, the only way I seem to be able to get a thruster handle seems to be by index, and then identify which thruster group it belongs to. Which is where I hit a wall, because I seem unable to find a way to check what group a thruster handle belongs to.

So, if someone could tell me how to do that, he'd already solved my problem. But maybe someone knows an altogether better method to do what I want to do which I haven't thought of?

#### Wishbone

##### Clueless developer
This is taken from Topper's BTC2.0 source code:

Code:
void getGroupThrustParm(VESSEL* vessel, THGROUP_TYPE group, double *F, double *isp) {
*F = 0;
*isp = 0;
int nthr=vessel->GetGroupThrusterCount(group);

for(int i=0; i<nthr; i++) {
THRUSTER_HANDLE th=vessel->GetGroupThruster(group,i);
*F += vessel->GetThrusterMax0(th);
PROPELLANT_HANDLE ph=vessel->GetThrusterResource(th);
double eff=1.0; //Some vessels play games with the propellant handles...
if(ph!=NULL) {
//So only measure efficiency if it's attached to a prop tank, else assume 1.0
eff=vessel->GetPropellantEfficiency(ph);
}
*isp += vessel->GetThrusterIsp(th) * vessel->GetThrusterMax0(th)*eff;
}
if (*F != 0)	*isp /= *F;
else *isp=0;

}