question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ValueError: math domain error` triggered in drive_xy

See original GitHub issue

Using the following testing script

from brachiograph import BrachioGraph
from time import sleep

# The servo_x_degree_ms signs need flipping as my motors
# go in the opposite direction to those in the article
plotter = BrachioGraph(
  inner_arm=8.2,
  outer_arm=8.85,
  servo_1_degree_ms=10,
  servo_2_degree_ms=-10,
)
print("Resetting arm position")
plotter.set_angles(angle_1=-90, angle_2=90)
print("Set up complete")

plotter.drive_xy()

and moving around with a,d,l,k I can consistently trigger a math domain error. I think this happens when the hypotenuse becomes very small or perhaps negative?

Here’s the stack trace

Traceback (most recent call last):
File "test.py", line 23, in <module>
plotter.drive_xy()
File "/home/pi/branchiograph/brachiograph.py", line 698, in drive_xy
self.xy(self.current_x, self.current_y)
File "/home/pi/branchiograph/brachiograph.py", line 434, in xy
(angle_1, angle_2) = self.xy_to_angles(x, y)
File "/home/pi/branchiograph/brachiograph.py", line 590, in xy_to_angles
(hypotenuse**2+self.INNER_ARM**2-self.OUTER_ARM**2)/(2*hypotenuse*self.INNER_ARM)
ValueError: math domain error

and here are the values printed during driving the plotter

Resetting arm position
Set up complete
-9.2 8.85
-10.2 8.85
-11.2 8.85
-12.2 8.85
-13.2 8.85
-14.2 8.85
-13.2 8.85
-12.2 8.85
-11.2 8.85
-12.2 8.85
-13.2 8.85
-14.2 8.85
-13.2 8.85
-12.2 8.85
-11.2 8.85
-11.2 9.85
-11.2 10.85
-11.2 11.85
-11.2 12.85
-11.2 13.85

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
willpricecommented, Dec 8, 2019

I’ve added a bit of code to catch this issue and inform the user. https://github.com/willprice/BrachioGraph/commit/c8d764d3d50916e7ea4408d3d27ce832a613a0e8 In that branch I’ve turned all the return str messages into exceptions too.

0reactions
willpricecommented, Dec 8, 2019

That looks super useful. Thanks @evildmp, I’ll check it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: math domain error - python
Your code is doing a log of a number that is less than or equal to zero. That's mathematically undefined, so Python's log...
Read more >
Python ValueError: math domain error Solution
The ValueError is a type of error that indicates you are performing a mathematical operation on a value that does not work with...
Read more >
Python Math Domain Error (How to Fix This Stupid Bug)
ValueError: math domain error. Python raises this error when you try to do something that is not mathematically possible or mathematically defined.
Read more >
Math domain error - GrovePi
I'm helping high school students set up a network of sensors to run irrigation in an experimental citrus grove.
Read more >
How to fix ValueError, math domain error - Ignition
Hi I try to use math.log in my function, but it does not return any values, I get ValueError, math domain error, how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found