Robot: Apply clang format

This commit is contained in:
wmayer
2023-09-11 10:10:04 +02:00
committed by wwmayer
parent c2dd436325
commit e1aa8197d3
9 changed files with 155 additions and 133 deletions

View File

@@ -64,4 +64,3 @@ INSTALL(
PATTERN "Makefile*" EXCLUDE
PATTERN "*.pdf" EXCLUDE
)

View File

@@ -1,25 +1,25 @@
# FreeCAD init script of the Robot module
# (c) 2001 Juergen Riegel
#***************************************************************************
#* Copyright (c) 2002 Juergen Riegel <juergen.riegel@web.de> *
#* *
#* 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 <juergen.riegel@web.de> *
# * *
# * 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 *
# * *
# ***************************************************************************/

View File

@@ -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 <juergen.riegel@web.de> *
#* *
#* 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 <juergen.riegel@web.de> *
# * *
# * 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())

View File

@@ -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)

View File

@@ -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")

View File

@@ -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)
)

View File

@@ -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))

View File

@@ -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

View File

@@ -2,4 +2,3 @@
* \ingroup CWORKBENCHES
* \brief Simulates 6-axis robot movements
*/