General Question Translation mode RCS

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US
Is there a way (or an addon) to define keyboard shortcuts for translation mode RCS? Basically, instead of switching between rotation/translation modes, I'd like to be able to access both at the same time.

It must be possible, as the FlyByWire addon does it somehow. Thank you in advance.
 

kamaz

Unicorn hunter
Addon Developer
Joined
Mar 31, 2012
Messages
2,298
Reaction score
4
Points
0
It's doable via API, but there is no add-on which re-maps the keyboard this way AFAIK.

Get a joystick :)
 
Last edited:

kamaz

Unicorn hunter
Addon Developer
Joined
Mar 31, 2012
Messages
2,298
Reaction score
4
Points
0
No, this behavior is hardcoded into the core.

What has now occured to me is that one could use my remapper, so that if the "yaw left" key is hit, it sends sends the following sequence:

Ctrl+ Numpad / (RCS ON/ROT)
Numpad 1 (yaw left)
Ctrl+ Numpad / (RCS OFF)

And if you press "translate left" it sends:

Ctrl+ Numpad / (RCS ON/ROT)
Numpad / (RCS LIN)
Numpad 1 (move left)
Ctrl+ Numpad / (RCS OFF)

...a bit roundabout way, but could work. Just make sure to switch off RCS (Ctrl+ Numpad /) at the beginning of the flight.

Would be very natural with an additional numpad/keyboard since the remapper supports multiple keyboards, so "1" on keyboard #1 is left yaw, and "1" on keyboard #2 is left move.
 
Last edited:

blixel

Donator
Donator
Joined
Jun 29, 2010
Messages
647
Reaction score
0
Points
16
Is there a way (or an addon) to define keyboard shortcuts for translation mode RCS? Basically, instead of switching between rotation/translation modes, I'd like to be able to access both at the same time.

It must be possible, as the FlyByWire addon does it somehow. Thank you in advance.

Try this
 

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US

I have. The translation mode keys don't work until you switch into translation mode.

I've also remapped translation keys in keymap.cfg to be different from rotation keys, but still unless you are in translation mode, they don't work.
 

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US
It's doable via API, but there is no add-on which re-maps the keyboard this way AFAIK.

Get a joystick :)

I do have a joystick. I didn't mention it to keep things simple.


How does FlyByWire do it then?

What has now occured to me is that one could use my remapper, so that if the "yaw left" key is hit, it sends sends the following sequence:

Ctrl+ Numpad / (RCS ON/ROT)
Numpad 1 (yaw left)
Ctrl+ Numpad / (RCS OFF)

And if you press "translate left" it sends:

Ctrl+ Numpad / (RCS ON/ROT)
Numpad / (RCS LIN)
Numpad 1 (move left)
Ctrl+ Numpad / (RCS OFF)

...a bit roundabout way, but could work. Just make sure to switch off RCS (Ctrl+ Numpad /) at the beginning of the flight.

Would be very natural with an additional numpad/keyboard since the remapper supports multiple keyboards, so "1" on keyboard #1 is left yaw, and "1" on keyboard #2 is left move.

I am on Linux (running Orbiter in wine), so unfortunately this won't work for me. Plus, wouldn't a female voice say "Translation" or "Rotation" every time you pressed the key?
 

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US
Here is more data for y'all, which will hopefully help resolve the problem.

Basically, I am running the Orbiter under wine (CrossOver actually) in Linux. I am using Thrustmaster T. Flight HOTAS joystick.

So far I've been using the FlyByWire addon and remapped the hat switch for translation mode RCS.

Everything worked great, except there seems to be a bug of some sort, where whenever I select a vehicle (Alt-F3), it gets a "jolt".

For example, DGIV shows "Excessive G" message. Or if I select the Arrow Freighter, it literally "jumps up" a bit off the ground.

I think some sort of bogus ME or RCS value gets sent to the vehicle by FBW for a split second, which causes this.

I don't have this problem, when I enable the joystick in Orbiter and don't use FBW.

Trying to overcome this, I wrote a small Linux program with which I can "hide" the HAT switch from the Orbiter (to prevent panning) and remap it to any keys on the keyboard.

The only missing piece of the puzzle is how to make these keys control the translation mode RCS directly. I think it should be possible, as again, FBW does it.

So my 2 questions are:

1. Is the source code for FBW available somewhere? If so, I can just use it as a starting point and write my own addon.

2. If not, can someone please point me to the right part of the API that deals with these things? I looked through the API briefly, but couldn't find anything that made sense.

Thank you again.
 

kamaz

Unicorn hunter
Addon Developer
Joined
Mar 31, 2012
Messages
2,298
Reaction score
4
Points
0
1. Is the source code for FBW available somewhere? If so, I can just use it as a starting point and write my own addon.

You should have it under under Doc\FlyByWire\Sources

2. If not, can someone please point me to the right part of the API that deals with these things? I looked through the API briefly, but couldn't find anything that made sense.

See VESSEL::SetThrusterGroupLevel and friends.

Here's how I'd do it:

Code:
double tStart = 0; 
double tBurn = 0.1; // RCS pulse time
int group;

void yourModule::clbkPreStep  (double simt, double  simdt, double  mjd)
{
  VESSEL *v = oapiGetFocusInterface();
  if ( ! v ) return;  

  if ( keyPressed ) {
    tStart = simt;    

    if ( keyPressed == LEFT_YAW_KEY )  {
      group = THGROUP_ATT_YAWLEFT;
    } else if ( keyPressed == LEFT_MOVE_KEY ) {
      group = THGROUP_ATT_LEFT; 
    }
    // etc.

    v->SetThrusterGroupLevel(group, 1.0);
    tStart = simt;
  } else {
    if ( tStart > 0 ) {
       if ( simt - tStart > tBurn ) {
          v->SetThrusterGroupLevel(group, 0.0);
          tStart = 0;
       }
    }      
}

Also, you probably need to use DirectX for keyboard input, because Orbiter ignores windows messages -- I should have a working code for this somewhere, let me know if you need it.

---------- Post added at 02:07 AM ---------- Previous post was at 02:01 AM ----------

I think some sort of bogus ME or RCS value gets sent to the vehicle by FBW for a split second, which causes this.

This may be related to another bug in FBW, which causes it to apply very small, but non-zero RCS thrust if time acceleration is used, thus ending up with the vehicle tumbling uncontrollably. At least that's what I saw when I was using that joystick :)
 

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US
Heh, right under my nose. :rofl: Thanks kamaz.

By DirectX for keyboard input you the (deprecated) DirectInput API? If you would be so kind, please post a snippet of your code or a link. Thanks again. :cheers:
 

kamaz

Unicorn hunter
Addon Developer
Joined
Mar 31, 2012
Messages
2,298
Reaction score
4
Points
0
...It seems that you don't need to use DirectX to get keyboard input and SetWindowsHookEx works fine. The code below is taken from [ame="http://orbithangar.com/searchid.php?ID=6443"]Master/slave (rev. 38)[/ame]

Code:
HHOOK hook;

DLLCLBK LRESULT CALLBACK hookproc(int ncode, WPARAM wparam, LPARAM lparam)
{
	if ( ncode >= 0 ) {
           // Process keyboard event
        }

	return CallNextHookEx(hook,ncode,wparam,lparam);
}


void HookKeyboard(void)
{
	hook = SetWindowsHookEx( WH_KEYBOARD, hookproc, GetModuleHandle("mydllfile.dll"), NULL);
	if( ! hook )
		Log("Unable to install keyboard hook");
}

See also http://www.codeproject.com/Articles/1264/KeyBoard-Hooks
 
Last edited:

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US
Thanks again kamaz. Here is my first rough version:

https://github.com/dimitry-ishenko/remap/releases/download/0.2.0/remap.zip

:cheers:

If anybody is interested, feel free to give it a whirl. Feedback is appreciated.

By default the key mappings are as follows:

Alt + NUM4 / NUM6 Engage left/right translation thrusters.
Alt + NUM9 / NUM3 Engage up/down translation thrusters.
Alt + NUM8 / NUM2 Engage forward/back translation thrusters.

Shift + NUM4 / NUM6 Engage bank left/right rotation thrusters.
Shift + NUM2 / NUM8 Engage pitch up/down rotation thrusters.
Shift + NUM1 / NUM3 Engage yaw left/right rotation thrusters.

In combination with Ctrl, the thrusters are engaged at 10% maximum thrust
for fine control.

I've only briefly tested it, but it seems to work OK. Few quirks:

1. The NumLock key has to be ON for these to work.
2. The Shift + <key> combination is acting weird. If you press the Shift first and then the <key>, for some reason the GetAsyncKeyState function does not register the <key>. But if you press the <key> first, followed by Shift, then it will work.

I have a feeling it might be related to me running it under WINE. I don't have a working Windows box to try it on though.

If anyone tries it on a Windows machine, please let me know if you experience the same problem.

In the next version I think I am going to switch to SetWindowsHookEx, which should handle both of the problems.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,923
Reaction score
232
Points
138
Location
Cape
Will pressing the Shift + numkeys conflict with the SC3 animations ?
 

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US
Will pressing the Shift + numkeys conflict with the SC3 animations ?

Er…no…er, not, as, such. :)

They will both act when you press Shift + <Num Key>, which is probably not what you want. Can you tell me what these SC3 (Spacecraft3 ?) animations are? Sorry, I am really new to Orbiter. :tiphat:
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,923
Reaction score
232
Points
138
Location
Cape
If you are focussed on a Spacecraft3 (SC3) vessel with animations. Pressing LeftShift + num(n) will activate the animation for that assigned key.
 

kamaz

Unicorn hunter
Addon Developer
Joined
Mar 31, 2012
Messages
2,298
Reaction score
4
Points
0
Cool! Will test when I get home.

Are you planning to make the key bindings configurable?
 

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US
Cool! Will test when I get home.

Are you planning to make the key bindings configurable?

Well... possibly. Currently the bindings can be easily changed by modifing the control array in remap.hpp and recompiling.

By the way, the source code is available here.

Time permitting my basic roadmap is to:
1. Switch to SetWindowsHookEx / LowLevelKeyboardProc.

This should handle the Shift modifier not working (for me at least).

Plus, currently if you press the keys in reverse order (eg, a <Num Key> first and then the <Alt> key) the thrusters will be activated anyway. (As opposed to pressing the <Alt> key first, followed by the <Num Key>.)

I am not sure if I like that behavior and with SetWindowsHookEx / LowLevelKeyboardProc I should be able to avoid it.

2. Add a .cfg file of some sort, or maybe even hook into the main keymap.cfg and add entries like:

RCSLeftDirect = NUMPAD4 ALT
LPRCSLeftDirect = NUMPAD4 ALT CTRL
...

or something like that. This way all the key mappings are kept in the same file.

What do you think?

---------- Post added at 04:35 PM ---------- Previous post was at 04:24 PM ----------

If you are focussed on a Spacecraft3 (SC3) vessel with animations. Pressing LeftShift + num(n) will activate the animation for that assigned key.

Oh. I think I will probably just disable the rotational truster control for now and make them customizable later.
 

kamaz

Unicorn hunter
Addon Developer
Joined
Mar 31, 2012
Messages
2,298
Reaction score
4
Points
0
2. Add a .cfg file of some sort, or maybe even hook into the main keymap.cfg

Precisely what I had in mind.

---------- Post added at 10:56 PM ---------- Previous post was at 05:36 PM ----------

2. The Shift + <key> combination is acting weird. If you press the Shift first and then the <key>, for some reason the GetAsyncKeyState function does not register the <key>. But if you press the <key> first, followed by Shift, then it will work.

Works OK in Windows.
 

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US
I knew it -- must be bug in WINE. OK thank you again. :tiphat:

---------- Post added 01-13-15 at 02:50 PM ---------- Previous post was 01-12-15 at 11:50 PM ----------

Found out last night there is a "feature" in Linux that if your NumLock is on and you press any of the numpad keys while holding the Shift, they will act as if the NumLock is off (arrows, page up/down, etc). And vice versa.

I switched to using scan codes instead of virtual key codes and now everything works fine for me as well.

Here's the latest version.

Next step is to make it configurable via keymap.cfg.
 

D-mo

Member
Orbiter Contributor
Joined
Dec 11, 2014
Messages
43
Reaction score
7
Points
8
Location
US
OK here is first draft of the final version. All the mappings are now configured via the keymap.cfg file.

I haven't tested it very much, but so far everything seems to work as advertised. :thumbup:

If anyone finds bugs, please let me know.

Download is here.

Source code is here.
 
Top