I am trying to create a node that will take a series of input numbers, add them all up and subtract the result from a fixed number.
The intention is to generate a PPM (pulse position modulation) signal for use in radio control of a vehicle. To do that the transmitter sends a “frame”, which is a stream of varying length pulses (with each pulse representing a servo position) with a sync pulse at the end. The frame length is fixed length, usually 22ms. The sync pulse must be 22000 minus the sum of the widths of all the channel pulses, which are between 1000ms and 2000ms. The sync pulse will always be much longer than the longest channel pulse, so the receiver can detect it and then know that the next pulse is channel 1.
The node I’m trying to create is just to calculate the length of the sync pulse. But I am getting strange results, and I can only guess it is related to nodes being evaluated in a sequence other than what I am expecting. For testing, and to make the arithmetic a bit easier, I’ve set the fixed value at 200, and I have eight pulses with lengths varying from 10 to 17. With these values I would expect the result to be 92 (100 - 10 - 11 - … -17) but that is not what I get. I actually get 85. The intermediate results are different too, as they seem to one less than the number I’ve actually subtracted.
I don’t know how to correct this. Or would it be easier to just do it in C++?