Skip to content
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

Cannot convert SampleInfo timestamps to nanoseconds [19737] #57

Closed
ryanheidema opened this issue Sep 5, 2023 · 1 comment · Fixed by #68
Closed

Cannot convert SampleInfo timestamps to nanoseconds [19737] #57

ryanheidema opened this issue Sep 5, 2023 · 1 comment · Fixed by #68

Comments

@ryanheidema
Copy link

I am having an issue using the source_timestamp and reception_timestamp on a SampleInfo instance retrieved via fastdds.DataReader.take(). Specifically, I want to call to_ns() on the source_timestamp and reception_timestamp and am getting the following error. I have outlined my findings below and would appreciate any help!

terminate called after throwing an instance of 'Swig::DirectorMethodException'
  what():  SWIG director method error. In method 'on_data_available': AttributeError: 'SwigPyObject' object has no attribute 'to_ns'

I have created the following function, get_data(), which is being used in the callback function to a SubscriberListener class I've created, which overrides the on_data_available( ) method of the fastdds.DataReader.

def get_data(data: fastdds.LoanableCollection, reader: fastdds.DataReader):
    infos: fastdds.SampleInfoSeq = fastdds.SampleInfoSeq()
    ret: fastdds.ReturnCode_t = reader.take(data, infos)
    if ret == fastdds.ReturnCode_t.RETCODE_OK:
        return (data, infos)
    else:
        return None

def callback(reader: fastdds.DataReader):
    data_seq = GeneratedClassSeq()
    data = get_data(data_seq, reader)
    reception_ns = data[1][0].reception_timestamp.to_ns() # line that throws error

Now, I've checked the generated python bindings in fastdds.py, and do not understand what the issue is. The SampleInfoSeq class defines that I'm using defines __getItem__(), which I am using to get a SampleInfo instance. The SampleInfo class has properties reception_timestamp and source_timestamp, as defined below, which I am accessing via .reception_timestamp. I'm expecting the resultant object from that call to be of type Time_t, which according to fastdds.py has the to_ns() function, but I cannot properly call it.

From fastdds.py:

class SampleInfo(object):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr
    ...
    source_timestamp = property(_fastdds_python.SampleInfo_source_timestamp_get, _fastdds_python.SampleInfo_source_timestamp_set)
    reception_timestamp = property(_fastdds_python.SampleInfo_reception_timestamp_get, _fastdds_python.SampleInfo_reception_timestamp_set)
    ...

class Time_t(object):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr
    INFINITE_SECONDS = _fastdds_python.Time_t_INFINITE_SECONDS
    INFINITE_NANOSECONDS = _fastdds_python.Time_t_INFINITE_NANOSECONDS
    seconds = property(_fastdds_python.Time_t_seconds_get, _fastdds_python.Time_t_seconds_set)
    nanosec = property(_fastdds_python.Time_t_nanosec_get, _fastdds_python.Time_t_nanosec_set)

    def __init__(self, *args):
        _fastdds_python.Time_t_swiginit(self, _fastdds_python.new_Time_t(*args))

    def fraction(self, *args):
        return _fastdds_python.Time_t_fraction(self, *args)

    def to_ns(self):
        return _fastdds_python.Time_t_to_ns(self)
    ...

Documentation Referenced:

@richiware richiware changed the title Cannot convert SampleInfo timestamps to nanoseconds Cannot convert SampleInfo timestamps to nanoseconds [19737] Oct 16, 2023
@richiware
Copy link
Member

#68 should fix your problem.

@MiguelCompany MiguelCompany linked a pull request Oct 20, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants