0
$\begingroup$

Rosanswers logo

Hello list,

I really am struggling with using ROS (Indigo on Ubuntu 14.04) and some code that uses Cython (version 0.20.1post0) to bind a C-library to python. In an earlier attempt I used swig, but I also failed in getting that to work reliably.

If I use the code generated with Cython in python without using anything from ROS, everything is fine, no errors or crashes.

But as soon as I use ROS, even only something like 'rospy.init_node('nodename')', there are occasional crashes or hangs. Say something like every 10-th start of that program.

I also fiddled with signal catching of e.g. signal.SIGSEGV, which work when I send it when the program is running, but is not working when a sigsegv really happens (I think).

Does anyone know is there are some clever tricks done in ROS (of Cython) that could explain this? Or a pointer how to attack this? I really am at a loss here.

UPDATE:

I found that the crashes almost always occur in the sleep function of rospy.Rate. I find it strange that initially calling some (Cython) function make this sleep function crash.

Here a stripped version of the program that still has the crashes.

rospy.init_node('peratestinit')

RTM2v_Init()
for DevNr in range(4):
    rtm_usb_ReadStdMsg(DevNr)
    rtm_usb_Read_ready(DevNr)
    rtm_usb_SendStdMsg(DevNr,0, 0, 0, 0);

rate = 50
r = rospy.Rate(rate)

k = 0 ;running = True
while running == True:
    # do some (control) stuff, including some (Cython) rtm_usb function calls
    j = 0
    for i in range(1000):
        j += math.sin(i)
    print 'insleep', j
    r.sleep()
    print 'uitsleep'
    k = k+1
    if k == 10:
        running = False

The rtm functions are communication with a robot arm using Cython generated code. The last printout almost always is the print from direcly before the r.sleep().

If I remove the rospy.init_node and use the regular python time.sleep() instead of r.sleep(), so no ROS at all, everything works!

???

Thanks in advance, Sietse


Originally posted by Sietse on ROS Answers with karma: 168 on 2016-06-02

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

To answer my own question, I found the error. There was a programming error on the Cython site, and for some reason it only manifested itself when running under ROS.

Thanks for your attention. Sietse


Originally posted by Sietse with karma: 168 on 2016-06-06

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by gvdhoorn on 2016-06-06:
Thanks for reporting back. Can you say anything about whether that programming error has been fixed, is there a work-around, any more detail?

Comment by Sietse on 2016-06-06:
It was an error on my part, not in Cython itself. I used a C-function with a (void *) parameter with which data should be returned in a wrong way.

By the way, I do this to get our PERA (Philips Experimental Robot Arm) under ROS control. There should be such an arm in Delft if I am correct.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.