PyChrono ChFunction / ChFunction_Mocap

55 views
Skip to first unread message

Helge Grossert

unread,
Sep 11, 2019, 3:53:24 AM9/11/19
to ProjectChrono

Hi everybody,


I'm trying to design a rheonomic constraint using measured data. So basically a body is linked to a ground body by a ChLinkLockLock and the motion is added by the SetMotion_Z method. This works with the "standard"-chrono functions like ChFunction_Sine. Unfortunately, I wasn't able to use the measured data as the time-dependent function for the constraint. In a first attempt, I stuck to the method shown in the first PyChrono-Tutorial:


class InputSignal(chrono.ChFunction):
    def __init__(self, signal):
        self.signal = signal
        super().__init__()

    def Get_y(self, x):
        return self.signal(x)


The signal is an object of a class that owns an interpolant version of the measured data, which is used to make the signal callable. Using this class leads to


    RuntimeError: SWIG director type mismatch in output value of type 'double'


Because of that, I tried to use the ChFunction_Mocap. I initialize it with the number of datapoints of signal and its samplerate:


fcn = chrono.ChFunction_Mocap(len(signal), signal.samplerate)


From my understanding, the next step would be to add the values of the signal to the ChFunction_Mocap object. To accomplish that, I tried:


fcn.Set_array_y(signal.y)


signal.y is a numpy array. This leads to


    TypeError: in method 'ChFunction_Mocap_Set_array_y', argument 2 of type 'chrono::ChArray< > const &'


I tried to use a list and bites datatypes as inputs to Set_array_y but none of them worked. So the question is, which is the correct datatype of measured data to use ChFunction_Mocap in PyChrono?

Thank you very much in advance, help will be very much appreciated.


Kind regards

Helge Grossert

Alessandro Tasora

unread,
Sep 11, 2019, 6:04:42 AM9/11/19
to Helge Grossert, ProjectChrono

Dear Helge

Few hints here (I am out of office so I try to guess)

1- the InputClass first idea is good, it looks correct, I do not know why it fails (maybe self.signal (x) returns a type that is not exactly a primitive float? Does it fails also if you write the python casting as   return float(self.signal (x)) ?

2- do not use ChFunction_Mocap because it is very old, maybe removed in future (and as you see, it is not 100% wrapped in PyChrono)

3- alternative to 2 is using ChFunction_Recorder,  that can be populated via AddPoint(x, y)
Use AddPoint multiple times for all your array values.

Alessandro Tasora

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchrono+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/4c4e4091-b69c-409d-b050-3b97e7d47561%40googlegroups.com.

Helge Grossert

unread,
Sep 11, 2019, 6:35:04 AM9/11/19
to ProjectChrono
Hey Alessandro,

Thank you very much for your quick response. Your first guess was right, calling self.signal returns an array of floats, which was thought to be used for multidimensional signals. However, adding the float() in that line as you suggested solved the problem and the code runs without any errors.

So once again, thank you very much, and kind regards,
Helge Grossert
To unsubscribe from this group and stop receiving emails from it, send an email to projec...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages