dronecrew / px4tools

PX4 flight analysis tools.
BSD 3-Clause "New" or "Revised" License
83 stars 48 forks source link

Error while executing Log based System Identification and Control Design.ipynb example #11

Closed mzahana closed 7 years ago

mzahana commented 7 years ago

I am trying to use the logsysid module in the px4tools on one of the logs that I fetched from Pixhawk, running PX4 stack.

When I run the provided example in , https://github.com/dronecrew/px4tools/blob/master/examples/Log%20based%20System%20Identification%20and%20Control%20Design.ipynb

I get the following error

fit quality 88.29 %

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-cf0438594eeb> in <module>()
      1 gains, design_data = px4tools.logsysid.control_design(data[20:80],
----> 2     do_plot=True)
      3 print(json.dumps(gains, indent=4))

/home/abdkadma/anaconda2/lib/python2.7/site-packages/px4tools/logsysid.pyc in control_design(raw_data, do_plot, rolling_mean_window)
    359     K_roll = attitude_control_design(
    360         'roll rate', roll_acc, data.ATTC_Roll,
--> 361         rolling_mean_window=rolling_mean_window, do_plot=do_plot)
    362 
    363     pitch_acc = data.ATT_PitchRate.diff()/dt

/home/abdkadma/anaconda2/lib/python2.7/site-packages/px4tools/logsysid.pyc in attitude_control_design(name, y, u, rolling_mean_window, do_plot, verbose)
    319 
    320     K, G_ol_rate, G_cl_rate = attitude_rate_design(
--> 321         G_ol, K_guess, d_tc, verbose)
    322 
    323     if do_plot:

/home/abdkadma/anaconda2/lib/python2.7/site-packages/px4tools/logsysid.pyc in attitude_rate_design(G, K_guess, d_tc, verbose)
    260     H = control.tf(H_num, H_den)
    261 
--> 262     ss_open = control.tf2ss(G*H)
    263 
    264     if verbose:

/home/abdkadma/anaconda2/lib/python2.7/site-packages/control/matlab.pyc in tf2ss(*args)
    762             raise TypeError("tf2ss(sys): sys must be a TransferFunction \
    763 object.")
--> 764         return _convertToStateSpace(sys)
    765     else:
    766         raise ValueError("Needs 1 or 2 arguments; received %i." % len(args))

/home/abdkadma/anaconda2/lib/python2.7/site-packages/control/statesp.pyc in _convertToStateSpace(sys, **kw)
    665             # I think this will fail if num and den aren't 1-D after
    666             # the squeeze
--> 667             lti_sys = lti(squeeze(sys.num), squeeze(sys.den))
    668             return StateSpace(lti_sys.A, lti_sys.B, lti_sys.C, lti_sys.D,
    669                               sys.dt)

/home/abdkadma/anaconda2/lib/python2.7/site-packages/scipy/signal/ltisys.pyc in __init__(self, *system, **kwargs)
    759         self._den = None
    760 
--> 761         self.num, self.den = normalize(*system)
    762 
    763     def __repr__(self):

/home/abdkadma/anaconda2/lib/python2.7/site-packages/scipy/signal/filter_design.pyc in normalize(b, a)
   1084     if len(b.shape) == 1:
   1085         b = asarray([b], b.dtype.char)
-> 1086     while a[0] == 0.0 and len(a) > 1:
   1087         a = a[1:]
   1088     outb = b * (1.0) / a[0]

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

What could be the problem?

jgoppert commented 7 years ago

I can reproduce this if I don't have a slycot installed, it must be a bug in python control. Please install slycot using the command below:

pip install slycot

I've filed a bug with python control here: https://github.com/python-control/python-control/issues/120

Here is my output without slycot.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/home/jgoppert/anaconda3/lib/python3.5/site-packages/control-dev-py3.5.egg/control/statesp.py in _convertToStateSpace(sys, **kw)
    646         try:
--> 647             from slycot import td04ad
    648             if len(kw):

ImportError: No module named 'slycot'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-3-cf0438594eeb> in <module>()
      1 gains, design_data = px4tools.logsysid.control_design(data[20:80],
----> 2     do_plot=True)
      3 print(json.dumps(gains, indent=4))
mzahana commented 7 years ago

Does it make a difference if I am using Python 2.7?

jgoppert commented 7 years ago

No, it shouldn't.