Forum Replies Created
-
AuthorPosts
-
Damien MarchalBlocked
I never used CommunicationController so I looked a bit in its c++ source code.
It seems is possible to communication more data by specify the *template* attribute.`
node.addObject(‘CommunicationController’, name=”sub”, listening=’1′, job=”receiver”, port=”5558″, nbDataField=”4″, pattern=”0″, template=’Vec3d’)
`
That’s said, I see the convention for this template is just inconsistant with what are using in sofa.
Currently it is mapping the following templates to theses data types:
`
double -> double
float -> float
int -> int
Vec3d -> vector<Vec3d>
Vec3f -> vector<Vec3f>
`
While it should be:
`
double -> double
float -> float
int -> int
vector<double> -> vector<double>
vector<float> -> vector<float>
vector<int> -> vector<int>
Vec3d -> Vec3d
Vec3f -> Vec3f
vector<Vec3d> -> vector<Vec3d>
vector<Vec3f> -> vector<Vec3f>
`
Damien MarchalBlockedDone for me, see you in Novembre.
Damien MarchalBlockedHello,
This is an interesting topic. Despite being a working solution I think hijacking the class name is definitely not the way to go. In Sofa the Event class was not design to have an “emitter” information. But a subclass of Event called ScriptEvent is specifically doing that. I don’t know if the ScriptEvent is usable in your case and if it is already exposed in python but if this is not the case I would be a nice addendum and pull-request to Sofapython3.
Damien MarchalBlockedSmall news about that topic…
Yinoussa (from Defrost) made this week a preliminary pull request to Sofa. The aim of this PR is to able to manipulate Eigen matrices in sofa Data field.
It is there: https://github.com/sofa-framework/sofa/pull/1499A second work should coom soon to expose Eigen matrices in Python. One difficulty we have with Eigen matrices is that we havnt found out yet how to write in the Eigen matrices from python without copying everything, but readonly matrices is working now.
Regards,
Damien MarchalBlockedHi all,
We decided to work directly in the master branch of STLIB. There is now a python3 directory there with preliminary work. Far from finished, but if some want to help they are welcome.
Regards,
DM.Damien MarchalBlockedHi all,
There is no support for sparse matrices in the binding yet (lack of time more than technical difficulty). As you pointed out, pybind11 has the proper machinery for that.
The problem is that, to detect the BaseData you want to store in is really holding a Data<Eigen::Sparse> we rely on the AbstractTypeInfo mechanism… which requires to declare an AbstractTypeInfo describing a Data<Eigen::Sparse>. With this done, in
void PythonFactory::fromPython(BaseData* d, const py::object& o) in PythonFactory.cpp it will be possible to detect when a data is Eigen::Sparse and call the proper pybind11 conversion from scipy.The dual function toPython should also be implemented to expose in a copyless way matrices to python.
8 September 2020 at 10:23 in reply to: Error In Running SofaPython3 in Conda Environemtn with Python3.83 #17095Damien MarchalBlockedHi Cai,
About SofaPython3 and Conda the problem seems to be at the initialization of the plugin (where we initialize the python3 interpreter). Maybe, but it is only a guess, there is a mismatch between the version you use for compilation and the one shipped with Conda. On my computer I tend to only use apt and pip3 to install python packages. Each time I tried to use conda it generate a lot of mess so I just gave up. But If you success please tell us.
SofaPython3 is now an official plugin from the sofa-consortium…the new official (and updated) repository is now https://github.com/sofa-framework/SofaPython3
About the question related to old SofaPython. It is not possible to use it in a python environment because the python Sofa modules and the python interpreter are compiled together. So the only way is to use it is to load a Sofa scene with runSofa and do the code there using the python interpreter included in the plugin SofaPython.
Damien MarchalBlockedHello Bruno,
In case compiling the SofaROSConnector plugin there is in SoftRobots a very simple example/library on how to connect ros with Sofa using pyros.
Damien.
Damien MarchalBlockedHi all,
We really need to upgrade SoftRobot so it use SofaPython3…any volunteer ?
DM 🙂
Damien MarchalBlockedHi @Aditay
Thanks for your interest and questions.
I’m not expert in the plugin to use in Sofa to have non linear models. But you are wrong saying SOFA is inherently linear. SOFA (https://www.sofa-framework.org/) is a general purpose modeling framework for deformable mechanics and it is SOFA is not restricted to linear mechanics. Several plugins & components implements non-linear mechanics. But what is true is that most of the one we use are linear. I think you can find an example of use of non linear model in the recent’s Felix Vanneste’s paper available at https://hal.inria.fr/hal-02475589
Here are also few plugins that pops in my head:
– HighOrder plugin: https://github.com/sofa-framework/plugin.HighOrder
– Flexible plugin:https://www.sofa-framework.org/api/master/plugins/Flexible/html/index.html
– https://www.sofa-framework.org/applications/marketplace/tools-for-multi-material-simulations/> Are you looking at working on something at a Voxel level (see
> https://github.com/jonhiller/Voxelyze) and extending (or maybe writing
> another library) on top of it, to simulate/control soft robots?You can do voxels base simulation in SOFA by using the HexahedronFemForceField as well as its multi-resolution extensions (I think it is from this paper: https://hal.inria.fr/inria-00443064). The nice thing with this voxel implementation is that you can any geometrical shape in the voxel grid to have the correct geometry and a simplified mechanics.
In term of roadmap I think that two possible directions starting from that would be to:
– have an in-sofa voxel/implicit shape modeling editor mode to easily’paint’ the shape of the robot
– extends the voxel/octree’s version we have to cope with non-linear materials.Maybe people like @hugotalbot or @jeannicolas could provide more information.
Regards,
DamienDamien MarchalBlockedHi all,
Few month ago I was doing screenshot using python3. For that I was using pygame to open a window with an opengl context then the SofaPython3 functions to build control the simulation and trigger the sofa rendering into this opengl context.
This was more or less looking like this:
def doRendering(display, t): glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45, (display[0]/display[1]), 0.1, 50.0) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); cameraMVM = camera.getOpenGLModelViewMatrix() glMultMatrixd(cameraMVM) Sofa.Simulation.draw(scene) pygame.display.init() display = (800,600) pygame.display.set_mode(display, pygame.DOUBLEBUF|pygame.OPENGL) time = 0.0 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() Sofa.Simulation.glewInit() glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) glEnable(GL_LIGHTING) glEnable(GL_DEPTH_TEST) doRendering(display, time) # here you can use pygame https://stackoverflow.com/questions/17267395/how-to-take-screenshot-of-certain-part-of-screen-in-pygame makeAScreenShot() time+=0.01 pygame.display.flip()
I have no time right now to test the code so please don’t consider it as a working example,more as a source of inspiration.
Damien MarchalBlockedHi Lanandsky,
Last week there was new change in Sofa to stop fetching eigen3 but rely on the use of the one installed on your system. Maybe you could try this option.
This was merged in https://github.com/sofa-framework/sofa/pull/1281
Maybe you should try this version.Regards,
DamienDamien MarchalBlockedHi Abdelrahman and eaparra,
Thanks for posting,
The problem probably happens since activated the support for the C++17 version of the c++language. The change was done just two weeks ago (precisely in PR https://github.com/sofa-framework/sofa/pull/1249). You are right that this problem may be related to the compiler/cmake version.
I will open an issue for that on github
EDIT: The issue is https://github.com/sofa-framework/sofa/issues/1324
Damien MarchalBlockedHi gdrive61,
Using the python binding is what we also did in SoftRobots.
We made some easing functions in the
https://github.com/SofaDefrost/SoftRobots/tree/master/docs/examples/sofarosIt was quickly made bit as I like the API I share an example of it:
# coding: utf8 import sofaros import numpy def send(data): "This function is packing the data from the data field to stream that to ROS" return numpy.asarray(data.value[0], dtype=numpy.float32) recv(data, datafield): """Unpack the data from ros to Sofa""" t = data.tolist() datafield.value = [t[0]+1.0, t[1], t[2]] def createScene(rootNode): sofaros.init("SofaNode") rootNode.createObject("EulerImplicitSolver") rootNode.createObject("CGLinearSolver") s=rootNode.createChild("simulated") s.createObject("MechanicalObject", name="sender", position=[0.0,0.0,0.0]) s.sender.showObject=True s.sender.showObjectScale=1.0 a=rootNode.createChild("animated") a.createObject("MechanicalObject", name="receiver", position=[0.0,0.0,0.0]) a.receiver.showObject=True a.receiver.showObjectScale=1.0 # This create a Sofa component that will publish the # "s.sender.position" data field to ros sofaros.RosSender(rootNode, "/simulation/sender/position", s.sender.findData("position"), sofaros.numpy_msg(sofaros.Floats), send) # The data is received by an external ros point # and republished to the animation/receiver/position topic # the following component will receive data published to this topic # and store the result in the a.receiver.position data field. sofaros.RosReceiver(rootNode, "/animation/receiver/position", a.receiver.findData("position"), sofaros.numpy_msg(sofaros.Floats), recv) return rootNode
Damien
3 April 2020 at 23:02 in reply to: SofaPython3 – Compatibility with SofaPython and other plugins #15642Damien MarchalBlockedHi @stokens,
SofaPython3 can be used without problem with SoftRobots but the examples as well as the STLIB have not been updated so they will not work anymore.
The big difference are in how to implement the ScriptController (because we have extended it a lot) and how to access the data fields. There is no initGraph anymore, in general the work done in this function is not either in the python constructor or in createScene function (or an utility function).
Here is a quick and dirty example (I d’ont have python3 right now so I didn’t test, I hope it will work, otherwise tell me so that I made fresh install to fix it ;))
import Sofa.Core class EmptyController(Sofa.Core.Controller): """ custom %EmptyController% component for SOFA """ def __init__(self, *args, **kwargs): Sofa.Core.Controller.__init__(self, *args, **kwargs) #needed self.finger=kwargs.get("target", None) def init(): pass # DEFAULT EVENTS: def onAnimateBeginEvent(self, event): """ called at the beginning of each time step """ print("AnimatedBegin", event) def onAnimateEndEvent(self, event): """ called at the end of each time step """ print("AnimatedEnd", event) def onKeypressedEvent(self, event): print("Key pressed") a = self.finger.tetra.position.value ### a is a numpy array with a read only access print(a) b = a * 2 print(b) self.finger.tetra.position.value = b ### the value is now squared print(self.finger.tetra.position.value) print(a) with self.finger.tetra.position.writeableArray() as wa: wa += a wa *= 3 print(wa) def onEvent(self, name): print("Event received with name:", name ) def createScene(root): root.addObject("MechanicalObject", name="dofs", positions=[0,0,0,1,1,1,2,2,2]) root.addObject(EmptyController(target=root.dofs))
I’m sorry the documentation does not auto-regenerate on readthedocs (for reason I don’t understand..I need to find time to investigate that).
Hope this helped.
Damien MarchalBlockedHi all,
At DEFROST for grabbing of the screen we are using SofaPython3 and pygame. The rendering of Sofa is done in an openGL canvas using pygame. As we have full control of the simulation and rendering loop we can grab individual frames that are plug that into a machine learning algorithm.
I have not a lot of time to provide code for that but I think Pierre Sheggs may have some. So I poke him.
Damien.
5 March 2020 at 10:48 in reply to: [SOLVED] RigidMapping from Rigid3d to only some particles of FEMbody #15286Damien MarchalBlockedHi Simon,
At Defrost we are using Rigidification to do so. This will associate a rigid frame to a group of deformable dofs. As this is rather complex to implment we are using some helper function to do so. The functions are implemented in STLIB.
Here: https://github.com/SofaDefrost/STLIB/blob/master/python/stlib/physics/mixedmaterial/rigidification.pyThe example scene look like:
def createScene(rootNode): """ """ from stlib.scene import MainHeader from stlib.physics.deformable import ElasticMaterialObject from stlib.physics.mixedmaterial import Rigidify from splib.objectmodel import setData MainHeader(rootNode, plugins=["SofaSparseSolver"]) rootNode.VisualStyle.displayFlags = "showBehavior" modelNode = rootNode.createChild("Modeling") elasticobject = ElasticMaterialObject(modelNode, "mesh/liver.msh", "ElasticMaterialObject") # Rigidification of the elasticobject for given indices with given frameOrientations. o = Rigidify(modelNode, elasticobject, name="RigidifiedStructure", frames=[[0., 0., 0], [0., 0., 0]], groupIndices=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [48, 49, 50, 51]]) # Activate some rendering on the rigidified object. setData(o.RigidParts.dofs, showObject=True, showObjectScale=1, drawMode=2) setData(o.RigidParts.RigidifiedParticules.dofs, showObject=True, showObjectScale=0.1, drawMode=1, showColor=[1., 1., 0., 1.]) setData(o.DeformableParts.dofs, showObject=True, showObjectScale=0.1, drawMode=2) o.RigidParts.createObject("FixedConstraint", indices=0) simulationNode = rootNode.createChild("Simulation") simulationNode.createObject("EulerImplicitSolver") simulationNode.createObject("CGLinearSolver") simulationNode.addChild(o) return rootNode
Damien MarchalBlockedHello Hugo,
I highly support the idea of the SofaAward. So anyone using Sofa don’t hesitate to submit your work to the award. It can be big plugins, tools, framework or something more “simple” like the best sofa simulation you made with all the data/mesh/texture to run it.
See you in Paris.
Damien MarchalBlockedHi all,
thanks for your questionsat @sushil-s:
Given the error message you are reporting says that there is no runSofa application visible. This means either the compilation didn’t went well or the runApplication is not in your “PATH” (if you don’t know what the PATH is: http://www.linfo.org/path_env_var.html). To check if the compilation did well you can go in your build directory, then go to the “bin” subdirectory and there you should find a ‘runSofa’ file.at @tonydelabril:
Unless you really need to compile your own version of sofa I would recommend not to do so and use the binary we provide. To add sofa-launcher there is no need to compile sofa from the source code, because the sofa-launcher is just a set of python scripts so it should work with any runSofa applications available in your path when you run it.Damien MarchalBlockedHello @hugo hello @tonydelabril
I’m not very aware of the MOR plugin I think Felix or Olivier are better suited to answer.
But to give a bet I would say that the binary version is be shipped with the extra tools (including sofa-launcher) and the documentation for MOR was written for the source based version of Sofa (so taking as granted that sofa-launcher is there).
The shortest path for that consist in taking the sofa source code from git as this is where sofa-launcher. It should be possible to use the provided binary with the sofa-launcher from the source.
Damien MarchalBlockedHi @sayan, sorry to reply late, thank @hugo for the poke.
So to answer your first question, yes we are connecting physical robots to Sofa.
The simplest technical solution is to use USB->Arduino->motors. You can find pieces of explanation for this part in our tutoring web site: http://handsonsoftrobotics.lille.inria.fr/Once you have an Arduino board there is a Sofa component you add in your simulation that will handle the communication.
About your second question about having soft robot fabricated with different material layer how exactly do we specify it. There is multiple approach, one consist in using a single mesh (tetrahedral/hexahedral) with different material properties in the different tetrahedral ‘cells’. The other approach is to mix different modelling like: FEM for one material, then Beam for a stiff spring, and connect all that thanks to sofa mapping and/or constraints.
Damien.
Damien MarchalBlockedyes 😉
Damien MarchalBlockedHi @shiva,
There is no “make an exe” button in the runSofa gui. This would be a nice addendum, not to hard to do, but right now there is none.
To achieve what you want to do you can:
– put the content of the .xml or a .scn or a .py as a big string in a .cpp file and use this string as the source of a scene loader. This would allows to load the scene without extra file in the filesystem.
– to visualize the scene, implement a minimalistic application with glut/freeglut/whatever. A good starting, yet not up-to-date, is the example in application/projects/glutOnePickRegards,
DamienDamien MarchalBlockedHi @nicklj, hi hugo,
I will add that to my todo list.
3 August 2019 at 20:31 in reply to: [SOLVED] How to import numpy in python scripting of SOFA? #14057Damien MarchalBlockedHi @Zahra
On my side I don’t use Anaconda and prefer to rely on pip as much as I can.
About SofaPython3. The answer is yes, it make it possible to import Sofa modules and run a simulation directly in any python interpreter (Jupyter, Spyder, python3) in addition to the embedded one in runSofa.Regards,
Damien. -
AuthorPosts