fossasia/pslab-python

Update triangle waveform function to match pslab-android

bessman opened this issue · 4 comments

fossasia/pslab-hardware#111
fossasia/pslab-android#2364

The triangle waveform generated by pslab-android was messed up due to a difference in how the modulo operator is handled in Python and Java. pslab-python uses this function:

y = abs(x % 4 - 2) - 1, -1 <= x < 3

In Python, -1 % 4 == 3, so this results in:

Figure_1

But in Java, the modulo operator return the negative remainder if the dividend is negative; -1 % 4 == -1, so this function instead results in:

Figure_2

pslab-android now uses this function instead:

y = abs(x % 4 - 2), 0 <= x < 4

Which results in:

Figure_3

This function should also be used in pslab-python, for two reasons:

  1. We want to minimize differences between pslab-python and pslab-android
  2. As the bug in pslab-android demonstrates, it is unwise to rely on the behavior of the modulo operator with negative numbers

Since this change will change pslab-python's observerble behavior (i.e. the bytes it sends over serial), it will be necessary to re-record the serial traffic for the associated test case.

i want to work on this issue.

Go ahead! You will need to change:

  1. This function
  2. And the associated test data

To update the test data, your changes must be run against the PSLab hardware. I can help you with that when you are done with point 1 above.

@bessman Is this issue still open ?

Yes.