Skip to content

Update triangle waveform function to match pslab-android #218

Closed
@bessman

Description

@bessman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions