USB HID communication Very laggy

Here’s what I want to do:
I want to make a voice controlled HID game controller (for an FRC robot) using the MOVI shield and the UnoJoy library.

Here’s the issue:
The sketch works fine until I flash the ATmega 16U2 firmware with the UnoJoy hex file (to make it look like an input device to the computer) and plug it into the computer, at which point it becomes very “laggy” in that it takes a long time to beep after it hears the callsign and a similarly long time to continue with the program once it has heard the command.

It does eventually do the code each command is assigned, it just takes an abnormally long time getting to it. I’ve tested the both UnoJoy programs and MOVI programs by themselves and they work fine. Does anyone know why this is happening?

Here is a video that explains how I set up UnoJoy pretty well, though it is long.

Here is my code:

PS: The “Kill” function actually just makes it move forward slowly and menacingly. It won’t actually kill anyone.

/*Arduino UnoJoy with Movi

  • talking to FRC robot
    */

#include "MOVIShield.h"
MOVI recog(false);
#include “UnoJoy.h”

dataForController_t controllerData = getBlankDataForController(); //unojoy: set variable and get start with clear data

void setup()
{
recog.init();

recog.callSign(“Robot”);
recog.addSentence(“1”);
recog.addSentence(“2”);
recog.addSentence(“3”);
recog.addSentence(“4”);
recog.addSentence(“forward”);//5
recog.addSentence(“right”);//6
recog.addSentence(“left”);//7
recog.addSentence(“backward”);//8
recog.addSentence(“kill”);//9
recog.train();
delay(200);

setupUnoJoy();
}

void loop()
{

signed int result = recog.poll();

if(result==5){
recog.say(“Moving forward”);
controllerData.squareOn = HIGH; //unojoy “pushes” the square button (if it were a ps3 controller)
recall(500);

} else if(result==6) {
recog.say(“Turning right”);
controllerData.crossOn = HIGH; //unojoy “pushes” the cross button
recall(500);

} else if(result==7) {
recog.say(“Turning Left”);
controllerData.circleOn = HIGH; // etc.
recall(500);

} else if(result==8) {
recog.say(“Moving Backward”);
controllerData.triangleOn = HIGH;
recall(500);

} else if(result==9) {
recog.say(“yes master.”);
controllerData.l1On = HIGH;
recall(1000);

}

}

void recall(int count) {
setControllerData(controllerData); //unojoy sends data to computer
delay(count);
controllerData.l1On = LOW;
controllerData.triangleOn = LOW;
controllerData.circleOn = LOW;
controllerData.crossOn = LOW;
controllerData.squareOn = LOW;
}

Sorry for the late response. It took me a while to get my head around this and also: Such a cool project!!!

After all the thinking, here is the simple suggestion: How much noise is produced by your game? Have you tried playing with the threshold?

Let me know,
Gerald

No problem! Thanks for a response at all!

That makes a lot of sense. It seems almost too easy to be true! I’ll give that a try this week.