mavexpression.py 866 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python
  2. '''
  3. mavlink expression evaluation functions
  4. Copyright Andrew Tridgell 2011
  5. Released under GNU GPL version 3 or later
  6. '''
  7. import os
  8. # these imports allow for mavgraph and mavlogdump to use maths expressions more easily
  9. from math import *
  10. from .mavextra import *
  11. '''
  12. Support having a $HOME/.pymavlink/mavextra.py for extra graphing functions
  13. '''
  14. home = os.getenv('HOME')
  15. if home is not None:
  16. extra = os.path.join(home, '.pymavlink', 'mavextra.py')
  17. if os.path.exists(extra):
  18. import imp
  19. mavuser = imp.load_source('pymavlink.mavuser', extra)
  20. from pymavlink.mavuser import *
  21. def evaluate_expression(expression, vars):
  22. '''evaluation an expression'''
  23. try:
  24. v = eval(expression, globals(), vars)
  25. except NameError:
  26. return None
  27. except ZeroDivisionError:
  28. return None
  29. return v