robotology/speech

Conflicts when loading two grammars

jypuigbo opened this issue · 0 comments

Hi,

We are using two modules that load different grammars at different times, but, asynchronously, one of the modules might need to override the other. This means, we actually want just one grammar loaded at a time, and we need to eventually stop one of them and load the new one.

We are using the rpc command recog grammarXML for both of them. We were expecting this command to be interrupting all other grammars when triggered, and enabling them again afterwards.

Instead, what happens is:

  • The RPC command recog triggers the function handleRecognitionCmd()
  • Option grammarXML
    • Saves the xml grammar in a temporal file grammarTmp.grxml
    • Loads the new grammar file from the known location
    • Refreshes the runtime grammar
    • Disables the from_file grammar and enables runtime grammar
    • Waits until recognition is done in waitNextRecognitionLEGACY
      • within while(Time::now()<endTime && !gotSomething) waits until the recognition is done or some time has passed
    • Disables the from_file grammar and enables runtime grammar

My guess is that two RPC commands to recognize a sentence from a grammar, are running in parallel. As a quick, non-interfering fix, I would suggest to add an RPC command to interrupt the existing runtime grammar by:

  • Setting to false a variable that would be in the while condition named before
  • Setting it back to true after exiting the while
  • Disable the runtime grammar and enable the from_file grammar

With this fix, none of the previous applications would be affected at all, whereas our conflicts would be over.

If needed I can prepare the changes and make a pull request.

Thanks a lot.