RobotExample.py

Go to the documentation of this file.
00001 # Example how to use the basic robot class Robot6Axis which represent a 6-Axis 
00002 # industrial robot. The Robot Module is  dependend on Part but nor on other Modules.
00003 # It works mostly with the basic types Placement, Vector and Matrix. So we need 
00004 # only:
00005 from Robot import *
00006 from Part import *
00007 from FreeCAD import *
00008 
00009 # === Basic robot stuff ===
00010 # create the robot. If you not specify a other kinematic it becomes a Puma 560
00011 rob = Robot6Axis()
00012 print rob
00013 
00014 # accessing the axis and the Tcp. Axis go from 1-6 and are in degrees:
00015 Start = rob.Tcp
00016 print Start
00017 print rob.Axis1
00018 
00019 # move the first Axis of the robot:
00020 rob.Axis1 = 5.0
00021 # the Tcp has changed (forward kinematic)
00022 print rob.Tcp
00023 
00024 # move the robot back to start position (reverse kinematic):
00025 rob.Tcp = Start
00026 print rob.Axis1
00027 
00028 # the same with axis 2:
00029 rob.Axis2 = 5.0
00030 print rob.Tcp
00031 rob.Tcp = Start
00032 print rob.Axis2
00033 
00034 # Waypoints:
00035 w = Waypoint(Placement(),name="Pt",type="LIN")
00036 print w.Name,w.Type,w.Pos,w.Cont,w.Velocity,w.Base,w.Tool
00037 
00038 # generate more. The Trajectory find allways outomatically a unique name for the waypoints
00039 l = [w]
00040 for i in range(5):
00041   l.append(Waypoint(Placement(Vector(0,0,i*100),Vector(1,0,0),0),"LIN","Pt"))
00042 
00043 # create a trajectory  
00044 t = Trajectory(l)
00045 print t
00046 for i in range(7):
00047   t.insertWaypoints(Waypoint(Placement(Vector(0,0,i*100+500),Vector(1,0,0),0),"LIN","Pt"))
00048 
00049 # see a list of all waypoints:
00050 print t.Waypoints
00051 
00052 del rob,Start,t,l,w
00053 
00054 # === working with the document ===
00055 # 
00056 # Working with the robot document objects:
00057 # first creat a robot in the active document
00058 if(App.activeDocument() == None):App.newDocument()
00059 
00060 App.activeDocument().addObject("Robot::RobotObject","Robot")
00061 # Define the visual representation and the kinematic definition (see [[6-Axis Robot]] for details about that)
00062 App.activeDocument().Robot.RobotVrmlFile = App.getResourceDir()+"Mod/Robot/Lib/Kuka/kr500_1.wrl"
00063 App.activeDocument().Robot.RobotKinematicFile = App.getResourceDir()+"Mod/Robot/Lib/Kuka/kr500_1.csv"
00064 # start positon of the Axis (only that which differ from 0)
00065 App.activeDocument().Robot.Axis2 = -90
00066 App.activeDocument().Robot.Axis3 = 90
00067 
00068 # retrive the Tcp position 
00069 pos = FreeCAD.getDocument("Unnamed").getObject("Robot").Tcp
00070 # move the robot
00071 pos.move(App.Vector(-10,0,0))
00072 FreeCAD.getDocument("Unnamed").getObject("Robot").Tcp = pos
00073 
00074 # create an empty Trajectory object in the active document
00075 App.activeDocument().addObject("Robot::TrajectoryObject","Trajectory")
00076 # get the Trajectory
00077 t = App.activeDocument().Trajectory.Trajectory
00078 # add the actual TCP position of the robot to the trajectory
00079 StartTcp = App.activeDocument().Robot.Tcp
00080 t.insertWaypoints(StartTcp)
00081 App.activeDocument().Trajectory.Trajectory = t
00082 print App.activeDocument().Trajectory.Trajectory
00083 
00084 # insert some more Waypoints and the start point at the end again:
00085 for i in range(7):
00086   t.insertWaypoints(Waypoint(Placement(Vector(0,1000,i*100+500),Vector(1,0,0),i),"LIN","Pt"))
00087 
00088 t.insertWaypoints(StartTcp) # end point of the trajectory
00089 App.activeDocument().Trajectory.Trajectory = t
00090 print App.activeDocument().Trajectory.Trajectory
00091 
00092 # === Simulation ===
00093 # To be done..... ;-)
00094 
00095 # === Exporting the trajectory ===
00096 # the Trajectory is exported by python. That means for every Control Cabinet type is a Post processor
00097 # python module. Here is in detail the Kuka Postprocessor descriped
00098 from KukaExporter import ExportCompactSub
00099 
00100 ExportCompactSub(App.activeDocument().Robot,App.activeDocument().Trajectory,'D:/Temp/TestOut.src')
00101 
00102 # and thats kind of how its done:
00103 for w in App.activeDocument().Trajectory.Trajectory.Waypoints:
00104         (A,B,C) = (w.Pos.Rotation.toEuler())
00105         print ("LIN {X %.3f,Y %.3f,Z %.3f,A %.3f,B %.3f,C %.3f} ; %s"%(w.Pos.Base.x,w.Pos.Base.y,w.Pos.Base.z,A,B,C,w.Name))
00106 

Generated on Wed Nov 23 19:00:36 2011 for FreeCAD by  doxygen 1.6.1