Skip to content

mlx.getFrame(frame) returns "math domain error" #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AutomatedAI opened this issue Jun 10, 2020 · 8 comments
Closed

mlx.getFrame(frame) returns "math domain error" #20

AutomatedAI opened this issue Jun 10, 2020 · 8 comments
Labels
bug Something isn't working

Comments

@AutomatedAI
Copy link

Hello,

I am trying to run the basic example to stream data over i2c through the MCP2221. The Serial number is pulled from the MLC90640 easily but each time mlx.getFrame(frame) is called I get a "math domain error" if I print the exception. Any ideas as to why this may be happening? I am using Ubuntu 16.04 and python 3. Thanks!

@caternuson
Copy link
Contributor

By basic example, do you mean the mlx90640_simpletest.py one in this library? Can you post the full text of the error code you get when you try running it.

$ export BLINKA_MCP2221=1
$ python3 mlx90640_simpletest.py

@AutomatedAI
Copy link
Author

Apologies and and happy to clarify!

I have my export BLINKA_MCP2221=1 set correctly and the error is in regard to the python3 mlx90640_simpletest.py

Everything seemed to be working correctly when running the program. I get the "MLX addr detected on I2C" and the serial number of the device.

When the following lines of code are run (I added the "as e" and "print e" to figure out what is happening in the library )
try:
mlx.getFrame(frame)
except ValueError as e:
# these happen, no biggie - retry
print(e)
continue

I print the ValueError each iteration as "math domain error" so I would guess a cos value or something is incorrectly being calculated.

Thanks for your help!

@AutomatedAI
Copy link
Author

After debugging a bit, the error occurs in the second iteration of "self._CalculateTo(mlx90640Frame, emissivity, tr, framebuf)". I was able to replicate on a raspberry pi so it is probably related to some math feature of python in Linux. I'll see if I can figure out a solution. Fingers crossed!

@BLIII
Copy link
Contributor

BLIII commented Jun 16, 2020

I also am encountering this exact same error and started debugging the same way that @AutomatedAI did (with printing the exception). When I did this, I received the following:

MLX addr detected on I2C ['0x102a', '0xbfb7', '0x6187']
math domain error
math domain error
...

When I set BLINKA_MCP2221=1 I receive the following:

Traceback (most recent call last):
  File "mlx90640_simpletest.py", line 2, in <module>
    import board
  File "/home/pi/thermal_imager/.env/lib/python3.7/site-packages/board.py", line 33, in <module>
    from adafruit_blinka.agnostic import board_id, detector
  File "/home/pi/thermal_imager/.env/lib/python3.7/site-packages/adafruit_blinka/agnostic/__init__.py", line 18, in <module>
    chip_id = detector.chip.id
  File "/home/pi/thermal_imager/.env/lib/python3.7/site-packages/adafruit_platformdetect/chip.py", line 87, in id
    "BLINKA_MCP2221 environment variable "
RuntimeError: BLINKA_MCP2221 environment variable set, but no MCP2221 device found

I am not sure if it matters but I am attaching the MLX90640 to the RPi using Qwiic connectors and a Sparkfun pHat. I will continue to debug tomorrow to see if I get anywhere.

@BLIII
Copy link
Contributor

BLIII commented Jun 16, 2020

After some more digging, I believe this is related to this PR: #18

If I make the following dirty hack to the _CalculateTo function in adafruit_mlx90640.py, the code will at least run:

                Sx = (
                    alphaCompensated
                    * alphaCompensated
                    * alphaCompensated
                    * (irData + alphaCompensated * taTr)
                )

                if Sx < 0:
                  continue

                Sx = math.sqrt(math.sqrt(Sx)) * self.ksTo[1]

My board has two broken pixels that causes Sx to be negative so the code chokes when calculating the sqrt.

Is there a way to get the PR mentioned above merged and released?

@evaherrada evaherrada added the bug Something isn't working label Jul 1, 2020
@jepler
Copy link
Contributor

jepler commented Sep 9, 2020

A third user on discord help-with-circuitpython has reported the same problem.

@ladyada
Copy link
Member

ladyada commented Sep 9, 2020

@jepler if they apply #18 does that help?

@ladyada
Copy link
Member

ladyada commented Sep 9, 2020

going to close with the assumption #18 fixed it. if not, we can re-open!

@ladyada ladyada closed this as completed Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants