Author Topic: How to manage an analog in-game control  (Read 2434 times)

CJH

  • Newbie
  • *
  • Posts: 21
How to manage an analog in-game control
« on: November 25, 2018, 05:45:33 PM »
Is there an effective and accepted way to use a voice command to control a progress-bar-style counter in a game?

For example, let's say you can gradually open a valve from 0% (closed) to 100% (open) by holding down the d key, and the game shows you a gauge with a needle that gradually moves from 0 to 100 until you release the d key.

I've tried pressing a key until a "stop" is issued, but the counter keeps moving significantly after the "stop" command. If I say "stop" when the gauge is at 50%, it can keep going until it reaches 65% or higher before stopping. It acts as though keystrokes are buffered and need to be processed until they are all gone before it actually stops. I also tried repeatedly pressing and releasing the key in a loop until a stop variable was set and this made no difference.

Perhaps this is an instance where voice control cannot give the fine-grained control I desire?


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: How to manage an analog in-game control
« Reply #1 on: November 25, 2018, 06:10:33 PM »
A voice command is not instant, as the speech recognition engine waits for you to finish speaking, after which it must process the data to attempt to match what you've said to a possible phrase, which also takes time.

If this control requires a fast response, which it likely does if the overshoot is that significant, you'll either have to use a non-voice trigger for the stop command, or use preset hold times(E.G. you'd say "increase by 10 percent", and the key would be held down for the appropriate amount of time, meaning you estimate the percentage increase required from the current value to the desired value before issuing the command).

The latter assumes that the response to the control is linear(I.E. the increase from 0% to 10% takes as long as that from 10% to 20%, and so on).


One other option to consider, which is not usable with all controls, is to always reduce the control to 0 as a known starting point, so you can set an absolute value(I.E. always reduce by 100%, so no matter the initial position it will return to 0%, then increase to the desired setting).

CJH

  • Newbie
  • *
  • Posts: 21
Re: How to manage an analog in-game control
« Reply #2 on: November 25, 2018, 07:52:08 PM »
Setting a key to "stop" seems to work fine. I should have thought of that. Thank you.

How about this? I want a hat switch to serve different functions based on a command I say. For example, if I say "mix," I'd like hat up to go richer and hat down to go leaner. If I say "pitch," I want hat up/down to do pitch up/down. I need to think this through some more, but it would be a great thing for VR.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: How to manage an analog in-game control
« Reply #3 on: November 25, 2018, 08:03:32 PM »
A hat is mapped as buttons within VoiceAttack, so you can trigger commands with it as well.

You can't easily send joystick buttons to games though, so you'll want to have those functions mapped to the keyboard and have VoiceAttack send the relevant keypresses.


Something like this:
pitch;mix
Code: [Select]
Set Text [hatMode] to '{CMD}'

hat up
Code: [Select]
Begin Text Compare : [hatMode] Equals 'mix'
    Press NumPad Add key and hold for 0,06 seconds and release
Else
    Press Up key and hold for 0,06 seconds and release
End Condition

CJH

  • Newbie
  • *
  • Posts: 21
Re: How to manage an analog in-game control
« Reply #4 on: November 25, 2018, 08:27:22 PM »
I'm going to have to spend some time with the more complex parts of the manual. I've only had VA for a few days, so all I've done is rudimentary things. I don't know what the braces and brackets mean, for example. But from what I understand you're saying it's possible for a hat switch to have completely different functions based on a command you speak.

So if I say "mix," the hat will do mix functions. If I say "flaps," that same hat switch will do flaps functions. If I say "brake bias," it will do bias functions. Do I have that correct?

More specifically, if I say "mix," hat up will send "^M" for rich. If I say "flaps," the same hat up button will send "F" for flaps up. If it can actually do this, it will make my VR life so much better.

The problem is that I'm an old geezer and if this can work, I'll end up spending more time implementing it than flying or driving in VR.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: How to manage an analog in-game control
« Reply #5 on: November 25, 2018, 08:59:19 PM »
So if I say "mix," the hat will do mix functions. If I say "flaps," that same hat switch will do flaps functions. If I say "brake bias," it will do bias functions. Do I have that correct?

More specifically, if I say "mix," hat up will send "^M" for rich. If I say "flaps," the same hat up button will send "F" for flaps up. If it can actually do this, it will make my VR life so much better.

As you'd be using the hat switch to trigger commands, it can do whatever you set it up to do.

In that example you're setting a value using one command("{CMD}" will be replaced by the phrase you spoke to trigger the command), then checking that value in the commands mapped to your hat switch(you'll have to map one command to each direction you want to use) and choosing keypress(es) relevant to that value.

You can set the key(s) pressed to what you require, and expand the list using "Add Else If to Conditional Block" actions to check more values.


One thing to note is that the mapped keys will not be held down while the hat switch remains in position; To do that you can use a loop, which will mean the command waits in the background, holding the key down until the hat changes position, at which point it will release the key:

Code: [Select]
Begin Text Compare : [hatMode] Equals 'mix'
    Press down Left Shift+M keys
    Start Loop While : [{STATE_JOYSTICK1POV1}] Equals 'UP'
    End Loop
    Release Left Shift+M keys
Else
    Press down F key
    Start Loop While : [{STATE_JOYSTICK1POV1}] Equals 'UP'
    End Loop
    Release F key
End Condition
This assumes you have your joystick mapped to slot 1, and the hat you're using is enabled as hat 1 on that stick.

For other directions you'll have to use the appropriate values(found on pages 151 and 152 of VoiceAttackHelp.pdf), E.G. "DOWN" instead of "UP".



EDIT: I have attached a profile containing these examples, to extrapolate from.

CJH

  • Newbie
  • *
  • Posts: 21
Re: How to manage an analog in-game control
« Reply #6 on: November 26, 2018, 09:50:14 AM »
That was very helpful.  Thank you. I will start spending some time with this after work and see where I can get.

CJH

  • Newbie
  • *
  • Posts: 21
Re: How to manage an analog in-game control
« Reply #7 on: November 27, 2018, 09:17:50 AM »
I got confused while working on this. First, I enabled Joystick1 POV1 for up/down. When creating a new command and pressing the joystick button, it reported POV1 UP as joystick1 pov1. When I pressed POV1 DOWN, it told me I was pressing joystick1 pov2. I believe it should have reported POV1 DOWN as joystick1 pov1 as well. This took me quite a while to figure out since I was doing compares on joystick1pov2 being up or down and the compares weren't working at all because pov2 isn't enabled. I finally figured out that the compares had to be for joystick1pov1 = UP or DOWN.

In general, it worked in the test window. Actual in-game performance was poor enough that it will take more time poking at it. I think that holding down the key and looping is not going to be as reliable as just doing repeated keypresses (holding pov1 UP and building a loop that continuously repeats the command is not as good as doing pov1 UP pov1 UP pov1 UP, ad nauseuam). I had trouble with voice recognition in-game that I did not have in the test window. The logs didn't show anything as though it didn't hear anything at all. 

I ran out of time but I lay in bed with other ideas running through my head...maybe it would be better to skip voice recognition for this particular use button presses to change the mode. For example, pressing joystick1 button1 cycles through different modes...pitch, mix, flaps, etc. And each mode then sets the mode of the hat switch on the top of the joystick.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: How to manage an analog in-game control
« Reply #8 on: November 27, 2018, 06:35:11 PM »
I got confused while working on this. First, I enabled Joystick1 POV1 for up/down. When creating a new command and pressing the joystick button, it reported POV1 UP as joystick1 pov1. When I pressed POV1 DOWN, it told me I was pressing joystick1 pov2. I believe it should have reported POV1 DOWN as joystick1 pov1 as well. This took me quite a while to figure out since I was doing compares on joystick1pov2 being up or down and the compares weren't working at all because pov2 isn't enabled. I finally figured out that the compares had to be for joystick1pov1 = UP or DOWN.
The mixing of terminology is confusing, I agree, however the documentation for the "{STATE_JOYSTICKxPOVy}" token I referenced(page 151 and 152 of VoiceAttackHelp.pdf) does clarify this.


In general, it worked in the test window. Actual in-game performance was poor enough that it will take more time poking at it. I think that holding down the key and looping is not going to be as reliable as just doing repeated keypresses (holding pov1 UP and building a loop that continuously repeats the command is not as good as doing pov1 UP pov1 UP pov1 UP, ad nauseuam). I had trouble with voice recognition in-game that I did not have in the test window. The logs didn't show anything as though it didn't hear anything at all.
In the example I posted, the keypress doesn't actually repeat, instead the key is held down as long as the hat is held up.
The game will see the key down event, followed by a key up event when the hat is moved from the up position(there will be some milliseconds of processing delay).

What performance issues are you experiencing, specifically?


As you're using this with a VR system, are you using a different microphone(E.G. the one built into your VR headset)? Are you switching VoiceAttack to listen on that microphone instead?

CJH

  • Newbie
  • *
  • Posts: 21
Re: How to manage an analog in-game control
« Reply #9 on: November 27, 2018, 07:16:31 PM »
I understood what your code was doing, but it was moving too fast in-game. In the end, it was better to do individual keypresses and have finer control than holding down the key. I had some things happen in the game (IL-2) that I now think are more game-related than VA-related. I have to investigate more. I use the same headset in VR that I do when I'm not in VR. And it's hooked to my computer and not to the headset (Lenovo). While recognition worked fine in the VA console, in game it was kind of flaky. It wouldn't recognize random words and would list nothing in the log. I used a hold-down-to-talk button to avoid any external noise that might confuse it between actual commands.

So tonight I abandoned that effort. I scrapped the speech recognition (saying "mix," "temp", "pitch", etc.) and selected one button that would cycle through those options. The selected mode would put the hat in the selected mode and I didn't have to worry about voice recognition. Initial in-game testing shows it working very well. For VR, this is a godsend because I can set the mode with one button and use the hat for several different features. As I cycle through the modes, VA speaks the selected mode. T It would be nice if VA would send a text message to the VR screen instead, but I can live with the Microsoft voice.

I appreciate the code you provided. It was more than enough to get me on track and accomplish what I wanted to do. Now if only I could learn to fly.


CJH

  • Newbie
  • *
  • Posts: 21
Re: How to manage an analog in-game control
« Reply #10 on: November 27, 2018, 07:56:42 PM »
I figured out how to copy and paste something outside of VA. This combination of hold-down and pause seems to work okay. Holding the key down and looping until the key is released is just too fast.

Code: [Select]
Else If Text Compare : [HatMode] Equals 'temp'
Start Loop While : [{STATE_JOYSTICK1POV1}] Equals 'DOWN'
Press Left Alt+=  keys and hold for 0.025 seconds and release
Pause 0.25 seconds
End Loop