I am attempting to drive two servo motor in response to a serial command from a c++ application on my PC. I have been able to drive the two servo motor in response to a sensor using SPI but can not get a stable solution for serial over usb. Ideally I am looking for something that could support at least 60 Hz or even 120 Hc which I figure should be no problem.
Within the attached sketch.cpp file everything appears to work and is stable if I comment out either of the servos. servo.write(...) call and the associated servo articulates as expected. However if I have both the servo.write() active in the code (line ~48 and 49) the SerialFromPC.cpp file tends to fail on the WriteFile(hSerial...) line.
Another interesting thing is that the failure only seemed to happen after a negative command was sent to the arduino uno. I attempted to only pass positive values then offset it. I offset by 50 so the resulting valRoll was midRool + rollAng - 50; but that failed as well...
Also I am sure the byte handling for sending floats over serial is garbage. if you have any suggestions that would be great. I was hoping to do something along the lines of r2.324p-12.04 to set the roll and pitch to 2.324 and -12.04 degrees respectively.
sketch.cpp (1.31 KB)
SerialFromPC.cpp (2.67 KB)