gladevcp crashes with a segfault after working properly

More
9 years 8 months ago #87290 by robottom
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!

Please Log in or Create an account to join the conversation.

More
9 years 8 months ago #87388 by andypugh
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

Please Log in or Create an account to join the conversation.

More
9 years 8 months ago #87389 by andypugh
You can see a number of sample models, including robots, in the sample configs:
sim/axis/vismach...

Please Log in or Create an account to join the conversation.

More
9 years 8 months ago #87441 by robottom
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.

Please Log in or Create an account to join the conversation.

More
9 years 8 months ago #87446 by andypugh

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

Please Log in or Create an account to join the conversation.

More
9 years 8 months ago #87484 by robottom
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, ...

Please Log in or Create an account to join the conversation.

Moderators: HansU
Time to create page: 0.387 seconds
Powered by Kunena Forum