gladevcp crashes with a segfault after working properly

More
04 Feb 2017 10:50 #87290 by robottom
robottom created the topic: gladevcp crashes with a segfault after working properly
I've added a gladevcp based tab to the axis gui where I used the manual-example.ui from the sample config sim.axis.gladevcp as an example. In the def __init__ function I've added code to open up a window with a 3D plot from matplotlib showing a 3D model:

from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot

def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
self.nhits = 3

pyplot.ion()

figure = pyplot.figure()
axes = figure.gca(projection='3d')


your_mesh = mesh.Mesh.from_file('HalfDonut.stl')
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors, facecolors='b', edgecolor='k', linewidth=0.2))
# Auto scale to the mesh size
scale = your_mesh.points.flatten(-1)
axes.auto_scale_xyz(scale, scale, scale)

self.axes = axes

this basically works fine. Means: When axis comes up there is my new tab inside axis with my gladevcp UI and a separate window displaying a 3D Plot from matplotlib.
In my tab there is a button with an event handler that just changes the parameter dist (zoom factor of the separate window's 3D Plot) and send a signal to redraw:

def on_replot_pressed(self,widget,data=None):
print "on_button_press called"
self.nhits += 1

# Show the plot to the screen
pyplot.show()

self.axes.dist = self.nhits
pyplot.pause(0.01)
pyplot.draw()

this often works fine. The zoom factor is changed and the 3D Plot redrawed in the separate window but sometimes it crashes - means I can press the button several times and it works but when pressing again the separate window disappears and the gladevcp tab inside axis is blanked out - there is nothing in the tab any more. Looking at DMESG it brings up an error:
gladevcp[4709]: segfault at c ip 080b65ab sp bfcb2f10 error 4 in python2.7[8048000+245000]

Probably there is not somebody using the same combination of gladevcp + matplotlib + numpy but maybe this looks familiar to you and somebody can give me a hint what is going wrong.
Does the gladevcp loosing somehow a handle to the other window and the garbage collector is deleting my 3D plot instance - maybe a stupid comment.
Would be nice if somebody with more experience in gladevcp can help me here since I need the matplotlib to visualize where I am with my robot on linuxcnc in a 3D model.

Many thanks!
More
06 Feb 2017 13:44 #87388 by andypugh
andypugh replied the topic: gladevcp crashes with a segfault after working properly
Rather than matplotlib, have you considered using Vismach?
That makes it fairly easy to connect joint positions to the model, and the zoom / pan etc functions are built in to the display.
linuxcnc.org/docs/2.7/html/gui/vismach.html
More
06 Feb 2017 13:45 #87389 by andypugh
andypugh replied the topic: gladevcp crashes with a segfault after working properly
You can see a number of sample models, including robots, in the sample configs:
sim/axis/vismach...
More
07 Feb 2017 07:29 #87441 by robottom
robottom replied the topic: gladevcp crashes with a segfault after working properly
Hi Andy,

sounds like a good alternative. I was using matplotlib because it is easy to use from a numpy-stl model and I anyhow do the calculation with numpy and loading data with numpy-stl.
The Robot models I saw are created often by a few basic shapes (cylinder, ...) but my model consiting of STL files (many triangles). Do you know if there is experience with vismach and 10K to 100K triangles? Does it perform well? This is also were I got issues with matplotlib. Meanwhile I found a setup with less crashes but performance is good for models of a few thousand of triangles but poor for more.
More
07 Feb 2017 10:32 #87446 by andypugh
andypugh replied the topic: gladevcp crashes with a segfault after working properly

robottom wrote: Do you know if there is experience with vismach and 10K to 100K triangles?


I don't know, I haven't tried it.

I would argue that for visualisation you don't _need_ 100k triangles, though.

The sim/axis/vismach/vmc_toolchange config uses STL files, just make a copy and replace the files with your files. It will look wrong and will animate wrongly, but you will get an idea of the quality of the rendering
More
07 Feb 2017 20:20 #87484 by robottom
robottom replied the topic: gladevcp crashes with a segfault after working properly
Hi Andy,

thanks a lot for the perfect hint with exchanging the stl file. This is an easy test. I did it with an stl file of 35k faces and the model is extremly fast (opening, rotating, ...).
I checked the vismach page you linked above and the examples. It looks like vismach is just created for the purpose of machine simulations. Is there an underlying visualization tool and data model that I can access. There are several features I use in the combination of numpy, numpy-stl and matplotlib like:
- accessing/looping through the faces and calculating on the vertices
- accessing the normals of faces (calculated by numpy-stl)
- plotting additional marker in the 3D object (normals visualization, boxes surrounding the TCP position in the model)
- manipulating the view from a glacevcp UI inputs (buttons, values, ...)
At the first glance it looks like this is not easily possible since the vismach is more closed than my current approach.
I would love to work with vismach since it looks good, much faster rendering, ...
More
07 Feb 2017 20:51 #87486 by andypugh
andypugh replied the topic: gladevcp crashes with a segfault after working properly

robottom wrote: I checked the vismach page you linked above and the examples. It looks like vismach is just created for the purpose of machine simulations. Is there an underlying visualization tool and data model that I can access.


Not that I know of, as far as I know it is only intended for machine visualisation, not for any advanced analysis.
I think it is probably just a thin layer over OpenGL.

The source code, is, of course, available for inspection:
github.com/LinuxCNC/linuxcnc/blob/master/lib/python/vismach.py
More
09 Feb 2017 22:17 #87715 by newbynobi
newbynobi replied the topic: gladevcp crashes with a segfault after working properly
Are you using glade 3.8.5 ?
Allearlier releases caused crahes on my pc using cv3.

Norbert
More
11 Feb 2017 12:09 #87808 by robottom
robottom replied the topic: gladevcp crashes with a segfault after working properly
when I check this in glade I get the version 3.12.1. But as stated in the manual I call glade-gtk2 to change the UI. There the version is 3.8.0. But I'm doubting that this has something to do with glade itself but more with matplotlib.
How should I update the glade to test it?
@Andy: I'm trying to figure out if vismach is an alternative. I did the test in the toolchanger example as stated above. This was working fine. But when I try this in the puma560 simulation my stl-file is not comming up. I copied the puma560gui.py into the folder, changed the call in the .hal file. When I simply add the .stl file nothing is dispalyed. When I change the link1 (original file link1.obj with torso.stl) by:
link1 = AsciiSTL(filename="torso.stl");
#link1 = AsciiOBJ(filename="puma_link1.obj");
link1 = Color([0.18,0.19,0.2,1],[link1])
link1 = Rotate([link1], 180,0,0,1)
There is simply the link1 missing in vismach but not exchanged with torso.stl.
I checked link1.obj and torso.stl in meshlab (dimensions, position, ...) so it is simply not hidden somewhere. All that looks good (torso is 2 times bigger).
In the toolchanger example the .stl-File is correctly displayed in the model. What is different with the puma560gui.py? The code is used (otherwise the link1.obj would not be missing in the vismach display)??
My goal at the end is to have the additional .stl displayed in the view together with the robot simulation. This would be great.
Many thanks again.
More
11 Feb 2017 12:23 #87810 by robottom
robottom replied the topic: gladevcp crashes with a segfault after working properly
sorry guys - forget my second question. My fault. I saved the file that I used with puma560gui.py in meshlab with binary encoding and not in ascii encoding. vismach can only work with ascii encoding.
But still the first question would be of interest.
Moderators: mhaberler
Time to create page: 0.083 seconds
Powered by Kunena Forum