From e1aa8197d36ba32b2c1d4905edf16fb08a400e77 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 11 Sep 2023 10:10:04 +0200 Subject: [PATCH] Robot: Apply clang format --- src/Mod/Robot/CMakeLists.txt | 1 - src/Mod/Robot/Init.py | 44 +++++----- src/Mod/Robot/InitGui.py | 55 ++++++------ src/Mod/Robot/KukaExporter.py | 85 ++++++++++--------- src/Mod/Robot/MovieTool.py | 9 +- src/Mod/Robot/RobotExample.py | 56 +++++++----- .../RobotExampleTrajectoryOutOfShapes.py | 27 +++--- src/Mod/Robot/RobotGlobal.h | 10 +-- src/Mod/Robot/robot.dox | 1 - 9 files changed, 155 insertions(+), 133 deletions(-) diff --git a/src/Mod/Robot/CMakeLists.txt b/src/Mod/Robot/CMakeLists.txt index 03376fce7a..b6605ac7d6 100644 --- a/src/Mod/Robot/CMakeLists.txt +++ b/src/Mod/Robot/CMakeLists.txt @@ -64,4 +64,3 @@ INSTALL( PATTERN "Makefile*" EXCLUDE PATTERN "*.pdf" EXCLUDE ) - diff --git a/src/Mod/Robot/Init.py b/src/Mod/Robot/Init.py index 8db77748e5..c1ed296277 100644 --- a/src/Mod/Robot/Init.py +++ b/src/Mod/Robot/Init.py @@ -1,25 +1,25 @@ # FreeCAD init script of the Robot module # (c) 2001 Juergen Riegel -#*************************************************************************** -#* Copyright (c) 2002 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2002 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ diff --git a/src/Mod/Robot/InitGui.py b/src/Mod/Robot/InitGui.py index c9a0117eca..813788984c 100644 --- a/src/Mod/Robot/InitGui.py +++ b/src/Mod/Robot/InitGui.py @@ -1,38 +1,41 @@ -# Robot gui init module +# Robot gui init module # (c) 2009 Juergen Riegel # # Gathering all the information to start FreeCAD # This is the second one of three init scripts, the third one # runs when the gui is up -#*************************************************************************** -#* Copyright (c) 2009 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2009 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ -class RobotWorkbench ( Workbench ): +class RobotWorkbench(Workbench): "Robot workbench object" + def __init__(self): - self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Robot/Resources/icons/RobotWorkbench.svg" + self.__class__.Icon = ( + FreeCAD.getResourceDir() + "Mod/Robot/Resources/icons/RobotWorkbench.svg" + ) self.__class__.MenuText = "Robot" self.__class__.ToolTip = "Robot workbench" @@ -40,7 +43,9 @@ class RobotWorkbench ( Workbench ): # load the module import RobotGui import Robot + def GetClassName(self): return "RobotGui::Workbench" + Gui.addWorkbench(RobotWorkbench()) diff --git a/src/Mod/Robot/KukaExporter.py b/src/Mod/Robot/KukaExporter.py index 62fd5f1f83..7a854872e7 100644 --- a/src/Mod/Robot/KukaExporter.py +++ b/src/Mod/Robot/KukaExporter.py @@ -11,7 +11,7 @@ $BWDSTART = FALSE LDAT_ACT=LCPDAT1 FDAT_ACT=FP4 BAS(#CP_PARAMS,0.2) -LIN XP4 +LIN XP4 ;ENDFOLD """ @@ -24,49 +24,52 @@ DECL LDAT LCPDAT1={VEL 2.0,ACC 100.0,APO_DIST 100.0,APO_FAC 50.0,ORI_TYP #VAR} HeaderSrc = """&ACCESS RVP &REL 1 &PARAM TEMPLATE = C:\KRC\Roboter\Template\ExpertVorgabe -&PARAM EDITMASK = * +&PARAM EDITMASK = * """ -def ExportCompactSub(Rob,Trak,FileName): - print(Rob,Trak,FileName) - Traj = Trak.Trajectory - # open the output file - SrcFile = open(FileName,'w') - # header - SrcFile.write(HeaderSrc) - # subroutine definition - SrcFile.write("DEF "+Trak.Name+"( )\n\n") - SrcFile.write(";- Kuka src file, generated by FreeCAD (https://www.freecad.org)\n") - SrcFile.write(";- "+ time.asctime()+"\n\n") - # defining world and base - SrcFile.write(";------------- definitions ------------\n") - SrcFile.write("EXT BAS (BAS_COMMAND :IN,REAL :IN ) ;set base to World\n") - SrcFile.write("BAS (#INITMOV,0 ) ;Initialicing the defaults for Vel and so on \n\n") - - SrcFile.write("\n;------------- main part ------------\n") +def ExportCompactSub(Rob, Trak, FileName): + print(Rob, Trak, FileName) + Traj = Trak.Trajectory + # open the output file + SrcFile = open(FileName, "w") + # header + SrcFile.write(HeaderSrc) + # subroutine definition + SrcFile.write("DEF " + Trak.Name + "( )\n\n") + SrcFile.write(";- Kuka src file, generated by FreeCAD (https://www.freecad.org)\n") + SrcFile.write(";- " + time.asctime() + "\n\n") + # defining world and base + SrcFile.write(";------------- definitions ------------\n") + SrcFile.write("EXT BAS (BAS_COMMAND :IN,REAL :IN ) ;set base to World\n") + SrcFile.write("BAS (#INITMOV,0 ) ;Initialicing the defaults for Vel and so on \n\n") - for w in Traj.Waypoints: - (X,Y,Z) = (w.Pos.Base.x,w.Pos.Base.x,w.Pos.Base.x) - (A,B,C) = (w.Pos.Rotation.toEuler()) - V = w.Velocity / 1000.0 # from mm/s to m/s - SrcFile.write("$VEL.CP = %f ; m/s ; m/s \n"%V) - SrcFile.write("LIN {X %.3f,Y %.3f,Z %.3f,A %.3f,B %.3f,C %.3f} ; %s\n"%(w.Pos.Base.x,w.Pos.Base.y,w.Pos.Base.z,A,B,C,w.Name)) - - # end of subroutine - SrcFile.write("\n;------------- end ------------\n") - SrcFile.write("END \n\n") + SrcFile.write("\n;------------- main part ------------\n") - SrcFile.close() - # open the output file - #DatFile = open(FileName[:-4]+'.dat','w') - # header - #DatFile.write(HeaderSrc) - # subroutine definition - #DatFile.write("DEFDAT "+Trak.Name+" PUBLIC\n\n") - #DatFile.write("ENDDAT\n") - #DatFile.close() - -def ExportFullSub(Rob,Trak,FileName): - print(Trak,FileName) + for w in Traj.Waypoints: + (X, Y, Z) = (w.Pos.Base.x, w.Pos.Base.x, w.Pos.Base.x) + (A, B, C) = w.Pos.Rotation.toEuler() + V = w.Velocity / 1000.0 # from mm/s to m/s + SrcFile.write("$VEL.CP = %f ; m/s ; m/s \n" % V) + SrcFile.write( + "LIN {X %.3f,Y %.3f,Z %.3f,A %.3f,B %.3f,C %.3f} ; %s\n" + % (w.Pos.Base.x, w.Pos.Base.y, w.Pos.Base.z, A, B, C, w.Name) + ) + # end of subroutine + SrcFile.write("\n;------------- end ------------\n") + SrcFile.write("END \n\n") + + SrcFile.close() + # open the output file + # DatFile = open(FileName[:-4]+'.dat','w') + # header + # DatFile.write(HeaderSrc) + # subroutine definition + # DatFile.write("DEFDAT "+Trak.Name+" PUBLIC\n\n") + # DatFile.write("ENDDAT\n") + # DatFile.close() + + +def ExportFullSub(Rob, Trak, FileName): + print(Trak, FileName) diff --git a/src/Mod/Robot/MovieTool.py b/src/Mod/Robot/MovieTool.py index a9a101b612..0c6f4b51b9 100644 --- a/src/Mod/Robot/MovieTool.py +++ b/src/Mod/Robot/MovieTool.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -import os,sys,string -import FreeCAD,FreeCADGui,Robot,RobotGui +import os, sys, string +import FreeCAD, FreeCADGui, Robot, RobotGui x = 1920 y = 1080 @@ -11,12 +11,13 @@ OutDir = "c:/temp/Movie/" Trajectory = None Robot = None + def run(): Tool = Robot.Tool Tool = Tool.inverse() # duration in seconds time the pictures per second gives the size size = int(Trajectory.Duration * 24.0) for l in range(size): - Robot.Tcp = Trajectory.position(l/24.0).multiply(Tool) + Robot.Tcp = Trajectory.position(l / 24.0).multiply(Tool) FreeCADGui.updateGui() - FreeCADGui.ActiveDocument.ActiveView.saveImage(OutDir + "Rob_" + l + ".jpg",x,y,"White") + FreeCADGui.ActiveDocument.ActiveView.saveImage(OutDir + "Rob_" + l + ".jpg", x, y, "White") diff --git a/src/Mod/Robot/RobotExample.py b/src/Mod/Robot/RobotExample.py index 48198d7ad3..e53333e36b 100644 --- a/src/Mod/Robot/RobotExample.py +++ b/src/Mod/Robot/RobotExample.py @@ -1,6 +1,6 @@ -# Example how to use the basic robot class Robot6Axis which represent a 6-Axis +# Example how to use the basic robot class Robot6Axis which represent a 6-Axis # industrial robot. The Robot Module is dependent on Part but not on other Modules. -# It works mostly with the basic types Placement, Vector and Matrix. So we need +# It works mostly with the basic types Placement, Vector and Matrix. So we need # only: from Robot import * from Part import * @@ -34,47 +34,52 @@ rob.Tcp = Start print(rob.Axis2) # Waypoints: -w = Waypoint(Placement(),name="Pt",type="LIN") -print(w.Name,w.Type,w.Pos,w.Cont,w.Velocity,w.Base,w.Tool) +w = Waypoint(Placement(), name="Pt", type="LIN") +print(w.Name, w.Type, w.Pos, w.Cont, w.Velocity, w.Base, w.Tool) # generate more. The Trajectory find always outomatically a unique name for the waypoints l = [w] for i in range(5): - l.append(Waypoint(Placement(Vector(0,0,i*100),Vector(1,0,0),0),"LIN","Pt")) + l.append(Waypoint(Placement(Vector(0, 0, i * 100), Vector(1, 0, 0), 0), "LIN", "Pt")) -# create a trajectory +# create a trajectory t = Trajectory(l) print(t) for i in range(7): - t.insertWaypoints(Waypoint(Placement(Vector(0,0,i*100+500),Vector(1,0,0),0),"LIN","Pt")) + t.insertWaypoints( + Waypoint(Placement(Vector(0, 0, i * 100 + 500), Vector(1, 0, 0), 0), "LIN", "Pt") + ) # see a list of all waypoints: print(t.Waypoints) -del rob,Start,t,l,w +del rob, Start, t, l, w # === working with the document === -# +# # Working with the robot document objects: # first create a robot in the active document -if(App.activeDocument() is None):App.newDocument() +if App.activeDocument() is None: + App.newDocument() -App.activeDocument().addObject("Robot::RobotObject","Robot") +App.activeDocument().addObject("Robot::RobotObject", "Robot") # Define the visual representation and the kinematic definition (see [[6-Axis Robot]] for details about that) -App.activeDocument().Robot.RobotVrmlFile = App.getResourceDir()+"Mod/Robot/Lib/Kuka/kr500_1.wrl" -App.activeDocument().Robot.RobotKinematicFile = App.getResourceDir()+"Mod/Robot/Lib/Kuka/kr500_1.csv" +App.activeDocument().Robot.RobotVrmlFile = App.getResourceDir() + "Mod/Robot/Lib/Kuka/kr500_1.wrl" +App.activeDocument().Robot.RobotKinematicFile = ( + App.getResourceDir() + "Mod/Robot/Lib/Kuka/kr500_1.csv" +) # start position of the Axis (only that which differ from 0) App.activeDocument().Robot.Axis2 = -90 App.activeDocument().Robot.Axis3 = 90 -# retrieve the Tcp position +# retrieve the Tcp position pos = App.getDocument("Unnamed").getObject("Robot").Tcp # move the robot -pos.move(App.Vector(-10,0,0)) +pos.move(App.Vector(-10, 0, 0)) App.getDocument("Unnamed").getObject("Robot").Tcp = pos # create an empty Trajectory object in the active document -App.activeDocument().addObject("Robot::TrajectoryObject","Trajectory") +App.activeDocument().addObject("Robot::TrajectoryObject", "Trajectory") # get the Trajectory t = App.activeDocument().Trajectory.Trajectory # add the actual TCP position of the robot to the trajectory @@ -85,9 +90,11 @@ print(App.activeDocument().Trajectory.Trajectory) # insert some more Waypoints and the start point at the end again: for i in range(7): - t.insertWaypoints(Waypoint(Placement(Vector(0,1000,i*100+500),Vector(1,0,0),i),"LIN","Pt")) + t.insertWaypoints( + Waypoint(Placement(Vector(0, 1000, i * 100 + 500), Vector(1, 0, 0), i), "LIN", "Pt") + ) -t.insertWaypoints(StartTcp) # end point of the trajectory +t.insertWaypoints(StartTcp) # end point of the trajectory App.activeDocument().Trajectory.Trajectory = t print(App.activeDocument().Trajectory.Trajectory) @@ -99,9 +106,16 @@ print(App.activeDocument().Trajectory.Trajectory) # python module. Here is in detail the Kuka Postprocessor described from KukaExporter import ExportCompactSub -ExportCompactSub(App.activeDocument().Robot,App.activeDocument().Trajectory,tempfile.gettempdir()+'/TestOut.src') +ExportCompactSub( + App.activeDocument().Robot, + App.activeDocument().Trajectory, + tempfile.gettempdir() + "/TestOut.src", +) # and that's kind of how its done: for w in App.activeDocument().Trajectory.Trajectory.Waypoints: - (A,B,C) = (w.Pos.Rotation.toEuler()) - 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)) + (A, B, C) = w.Pos.Rotation.toEuler() + 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) + ) diff --git a/src/Mod/Robot/RobotExampleTrajectoryOutOfShapes.py b/src/Mod/Robot/RobotExampleTrajectoryOutOfShapes.py index 385db1d388..0af77333b0 100644 --- a/src/Mod/Robot/RobotExampleTrajectoryOutOfShapes.py +++ b/src/Mod/Robot/RobotExampleTrajectoryOutOfShapes.py @@ -5,18 +5,19 @@ import FreeCADGui as Gui count = 0 FirstPos1 = None FirstPos2 = None -LastPos2 = None +LastPos2 = None SortedEdgeList = [] for so in Gui.Selection.getSelectionEx(): - for edge in obj.SubObjects: - if edge.Type != 'Part::TopoShape':continue - pos1 = edge.valueAt(0) - pos2 = edge.valueAt(edge.Length) - print(pos1,pos2) - if count==0: # first edge - FirstPos1 = pos1 - FirstPos2 = pos2 - elif count==1 : # second edge - continue - else: # the rest - SortedEdgeList.append( (pos1,pos2,edge) ) + for edge in obj.SubObjects: + if edge.Type != "Part::TopoShape": + continue + pos1 = edge.valueAt(0) + pos2 = edge.valueAt(edge.Length) + print(pos1, pos2) + if count == 0: # first edge + FirstPos1 = pos1 + FirstPos2 = pos2 + elif count == 1: # second edge + continue + else: # the rest + SortedEdgeList.append((pos1, pos2, edge)) diff --git a/src/Mod/Robot/RobotGlobal.h b/src/Mod/Robot/RobotGlobal.h index f32c8c83b4..78fcbafcde 100644 --- a/src/Mod/Robot/RobotGlobal.h +++ b/src/Mod/Robot/RobotGlobal.h @@ -29,19 +29,19 @@ // Robot #ifndef RobotExport #ifdef Robot_EXPORTS -# define RobotExport FREECAD_DECL_EXPORT +#define RobotExport FREECAD_DECL_EXPORT #else -# define RobotExport FREECAD_DECL_IMPORT +#define RobotExport FREECAD_DECL_IMPORT #endif #endif // RobotGui #ifndef RobotGuiExport #ifdef RobotGui_EXPORTS -# define RobotGuiExport FREECAD_DECL_EXPORT +#define RobotGuiExport FREECAD_DECL_EXPORT #else -# define RobotGuiExport FREECAD_DECL_IMPORT +#define RobotGuiExport FREECAD_DECL_IMPORT #endif #endif -#endif //ROBOT_GLOBAL_H +#endif// ROBOT_GLOBAL_H diff --git a/src/Mod/Robot/robot.dox b/src/Mod/Robot/robot.dox index 16f68f1cca..5e80c1dbd1 100644 --- a/src/Mod/Robot/robot.dox +++ b/src/Mod/Robot/robot.dox @@ -2,4 +2,3 @@ * \ingroup CWORKBENCHES * \brief Simulates 6-axis robot movements */ -