I'm working on a way of getting data into into the Orbiter spaceflight simulator from external controls. I finally figured out how to read my data in C++ computer-side. I had success with a single analog input, it was fast and responsive enough to fly a spacecraft into orbit with just the one input. However a single input isn't very useful so I decided to push things to the max and simulate 100 inputs plus the real input. This introduced control-input lag of course even upping the Serial port speed from 9600 to 115200. So I decided to try and find just where the lag is by timing my inputs. The first time I tried measuring the time however, the serial stream on the serial monitor froze, and I had to manually kill the javaw process and restart the IDE (version 0018). Via commenting, I've reverted my program to the last known working state, but I still get the same lag problem. Here's the complete sketch:
/*
Interface to Orbiter Flightdeck
*/
int analog = 0;
//unsigned long time1 = 0;
//unsigned long time2 = 0;
//unsigned long runtime = 0;
char pitch[11];
//char timeout[30];
void setup()
{
Serial.begin(115200);
}
void loop()
{
analog = analogRead(0);
//time1 = millis();
sprintf(pitch, "<129 %4d>",analog); //the real input
Serial.print(pitch);
for(int i = 0; i<100; i++) //simulated 100 inputs
{
sprintf(pitch,"<%3d %4d>",i,i*10);
Serial.print(pitch);
}
//time2 = millis();
//runtime = time2-time1;
//sprintf(timeout,"Time: %lu",runtime);
//Serial.print(runtime);
}
Does anyone know what could be causing the Serial port lag and program freeze, particularly since this code used to work? I've checked the Arduino using PuTTY, and the data doesn't stream like it used to either. It comes in blocks, then delays before sending the next set of 101 Serial prints.
Thanks for any help.
Matt