Using python script to build a robot

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
jocaps

Using python script to build a robot

Post by jocaps »

Hi,

I'd like to write a parser that reads a robot joint and link configuration (in xml or in other text format used by other softwares) and then imports it in freeCAD. But Im pretty new with freeCAD and I'd like some advise first if this is possible and secondly what are python commands that I should look at. The python API documentation and examples seems to be pretty limited so I am as it here maybe someone can guide me.

The text-format file that constructs my robot get separate .stl files for each link and then assigns position and rotation (rather than DH-parameter) to link the robot arms.
Unlike in freeCAD where the whole arm is already linked through a wrl file (which isn't bad in itself but I'd like to stay away from .wrl formats). Is it hard or possible to make the linking through .obj object grouping with FreeCADs Python API?
jocaps

Re: Using python script to build a robot

Post by jocaps »

jocaps wrote:Hi,

I'd like to write a parser that reads a robot joint and link configuration (in xml or in other text format used by other softwares) and then imports it in freeCAD. But Im pretty new with freeCAD and I'd like some advise first if this is possible and secondly what are python commands that I should look at. The python API documentation and examples seems to be pretty limited so I am as it here maybe someone can guide me.
So I took a look at the freecad repository. It seems there is a FreeCAD.open function but this imports iges and stp files. FreeCAD.open("foobar.stl") returns an error for me if i try to import an existing stl file (file is found but it doesnt like it). Whats the python import function for stl's then?
jocaps

Re: Using python script to build a robot

Post by jocaps »

jocaps wrote: So I took a look at the freecad repository. It seems there is a FreeCAD.open function but this imports iges and stp files. FreeCAD.open("foobar.stl") returns an error for me if i try to import an existing stl file (file is found but it doesnt like it). Whats the python import function for stl's then?
After a bit of code searching in the svn I got what I wanted :) I have to import Mesh and then do a Mesh.open.

By the way, I discovered a "bug" (or is it?). When you switch to Inventor-Style Navigation you won't be able to do Many operation (Like those in Drafting, Part ..etc.), is this intentional?. This is a drawback if I am working mobile on a laptop without a mouse. Some laptops (like my old Dell) has 2 mousekeys on the touchpad and you press both keys to emulate the middle button. I do a lot of CAD drawing while on the bus/train, but this would be very difficult with FreeCAD if I constantly want to rotate my object (since the default rotation involves pressing the middle and the left mouse buttons). But maybe someone has a tip?
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Using python script to build a robot

Post by wmayer »

So I took a look at the freecad repository. It seems there is a FreeCAD.open function but this imports iges and stp files. FreeCAD.open("foobar.stl") returns an error for me if i try to import an existing stl file (file is found but it doesnt like it). Whats the python import function for stl's then?
FreeCAD.open is actually deprecated and FreeCAD.openDocument should be used instead. However, this function only loads .fcstd (project) files.

For the various file formats the corresponding module's open function must be used. For example, for .stl, .obj, .ply it's the Mesh module, for .step, .iges, .brep it's the Part module and so. For some file formats such as .svg there are several modules able to load.
By the way, I discovered a "bug" (or is it?). When you switch to Inventor-Style Navigation you won't be able to do Many operation (Like those in Drafting, Part ..etc.), is this intentional?. This is a drawback if I am working mobile on a laptop without a mouse. Some laptops (like my old Dell) has 2 mousekeys on the touchpad and you press both keys to emulate the middle button. I do a lot of CAD drawing while on the bus/train, but this would be very difficult with FreeCAD if I constantly want to rotate my object (since the default rotation involves pressing the middle and the left mouse buttons). But maybe someone has a tip?
When using the Inventor navigation then for picking, selection and so on you have to press the CTRL button. However, there is an alternative to rotate the view for CAD navigation: press SHIFT and click (press & release) the right mouse button. Now simply move your mouse. When releasing the SHIFT button it stops rotating.
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Using python script to build a robot

Post by jriegel »

To the first question - robot and kinematics.

Thats defined in two files. Described are this files here:
https://sourceforge.net/apps/mediawiki/ ... Axis_Robot

The CSV kinematic file:
http://free-cad.svn.sourceforge.net/vie ... iew=markup


And the visual file:
http://free-cad.svn.sourceforge.net/vie ... iew=markup

Just generate thus files and you are done...
Stop whining - start coding!
jocaps

Re: Using python script to build a robot

Post by jocaps »

jriegel wrote:To the first question - robot and kinematics.

Thats defined in two files. Described are this files here:
https://sourceforge.net/apps/mediawiki/ ... Axis_Robot

The CSV kinematic file:
http://free-cad.svn.sourceforge.net/vie ... iew=markup


And the visual file:
http://free-cad.svn.sourceforge.net/vie ... iew=markup

Just generate thus files and you are done...
Yes. Though what about for other jointed-robots. Can I construct a 5 jointed or 7 jointed robot and will I also get inverse kinematic for these like those of kuka (if I input the "kinematic" file, as DH paremeter). Will the robotic workbench work with robots with prismatic joints? Apparently the ik is using a Pieper solver for 6-jointed bodies with revolutionary joints. Though I can always write a python library that does a numerical solution for any jointed robot (even a mobile one). Though I am not sure how flexible the python API is (i.e. will it allow me to implement some physics motions with real time simulation?)
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Using python script to build a robot

Post by jriegel »

We use as base lib the KDL library, which is able to do IK for any kind or number of joints.
But in FreeCAD we have only the interface for 6-axis robot so far. KDL is part of the
OROCOS project. Take a look there.
Stop whining - start coding!
Post Reply