You are on page 1of 4

#DECL path2csv.

tcl
#DECL
#DECL Writes name, location relative to working frame and a configurable
#DECL (edit this file) list of attributes of all locations of a picked
#DECL path into a csv file.
#DECL
#DECL 050607 KUKA Haering, Mueller Markus
#DECL
#DECL RCS: @(#) $Id: path2csv.tcl,v 1.3 2007/11/20 09:57:29 haering Exp $

#------------------------------------------------------------------------------#
# this might change
#------------------------------------------------------------------------------#
set aG(lGlobalAttrNm) [list \
RRS_MOTION_TYPE \
RRS_TOOL_FRAME \
RRS_OBJECT_FRAME \
RRS_JOINT_SPEED \
RRS_CARTESIAN_POSITION_SPEED \
RRS_ZONE_NAME \
RRS_FLYBY_PARAMETER1 \
RRS_FLYBY_PARAMETER2 \
RRS_FLYBY_PARAMETER3 \
SW_LOC_TYPE \
SW_GUN_STATE \
SW_TIME_ON_PT \
MOUNTED_WORKPIECE_FRAME_NAME \
]

set aG(lLocalAttrNm) [list \


RRS_CONFIG_STRING \
]

#------------------------------------------------------------------------------#
# prerequisites
#------------------------------------------------------------------------------#

#------------------------------------------------------------------------------#
# These are the functions
#------------------------------------------------------------------------------#

proc ReadPath {{message_text "Pick a path"}} {

# Read a path from user (pick or key in)


# 000704hae
# 001219hae: optional $message_text added
#
# call:
# ReadPath $message_text
#
# ($message_text is optional)
#
# object_id RETURN object id of path

while {1 > 0} {
uiWriteMsg $message_text

# "set get_pick [uiGetPick]" + key in text manually provided:


# {<manual text>
# }
set get_pick [string trim [string trim [uiGetPick] "{}"]]

if {[catch {apNameToID $get_pick} object_id] == 0} {

# $object_id is a valid ID
uiWriteError ""

if {[catch {apPickByDerivedType $object_id [robdef T_PATH]} \


object_id] == 0} {

# An ancestor of type path can be found

uiWriteMsg ""

return $object_id

} else {

# No ancestor of type path can be found


uiWriteError "Error: \"$get_pick\" is not a path"
}

} else {

# $object_id is not a valid ID


uiWriteError "Error: \"$get_pick\" is unknown."
}
}
}

# getAttrVal
#
# Returns attribute value of object.
#
# Arguments:
# objID ID of object
# attrNm name of attribute
# Results:
# AttrVal value of attribute (" " if attribute is not set at
all)
#
proc getAttrVal {objID attrNm} {

if {![catch {apGetAttr $objID $attrNm} AttrVal]} {


return $AttrVal
}

return " "


}
proc main {} {
global aG

uiWriteError "path2csv: Write all locations of picked path to csv file."

set PathId [ReadPath]


set PathNm [apGetProperty $PathId P_NAME]
set LLocId [apGetProperty $PathId P_WP_LIST]

# working frame

set FrRef [apGetProperty [apWorldID] P_WORKING_FRAME]


set FrRefInv [mathInverseMat3 $FrRef]

#
# open csv file
#

set CsvFile [file join [apWorldID].ce ${PathNm}.csv]

if {[catch {open $CsvFile w} CsvFh]} {


uiWriteError "Error: Cannot open file \"$CsvFile\": $CsvFh"

return
}

#
# write header
#

puts -nonewline $CsvFh "name;x y z rz ry rz"

foreach LocalAttrNm $aG(lLocalAttrNm) {


puts -nonewline $CsvFh ";$LocalAttrNm"
}

foreach GlobalAttrNm $aG(lGlobalAttrNm) {


puts -nonewline $CsvFh ";$GlobalAttrNm"
}

# values of external axes


puts -nonewline $CsvFh ";e1;e2;e3;e4;e5;e6"

puts $CsvFh ""

#
# get location values and write to csv file
#

foreach LocId $LLocId {

set LocNm [apGetProperty $LocId P_NAME]

set LocAbsLoc [apGetProperty $LocId P_ABS_LOC]


set LocRelLoc [mathMultMatMat3 $FrRefInv $LocAbsLoc]

puts -nonewline $CsvFh "${LocNm};$LocRelLoc"

# local location

if {[catch {apNameToID #$LocNm} LocalLocId]} {


set LocalLocId ""
}

foreach LocalAttrNm $aG(lLocalAttrNm) {


puts -nonewline $CsvFh ";[getAttrVal $LocalLocId $LocalAttrNm]"
}

# global location

foreach GlobalAttrNm $aG(lGlobalAttrNm) {


puts -nonewline $CsvFh ";[getAttrVal $LocId $GlobalAttrNm]"
}

# values of external axes

set ExtAxN [apGetProperty $LocId P_EXT_NUM]


set LExtAxVal [apGetProperty $LocId P_EXT_POSE]

for {set IExtAx 0} {$IExtAx < $ExtAxN} {incr IExtAx} {


puts -nonewline $CsvFh ";[lindex $LExtAxVal $IExtAx]"
}

for {set IExtAx $ExtAxN} {$IExtAx < 6} {incr IExtAx} {


puts -nonewline $CsvFh "; "
}

# end of line

puts $CsvFh ""


}

close $CsvFh

uiWriteError "Info: Path $PathNm written to \"$CsvFile\"."


}

#------------------------------------------------------------------------------#
# This is the body
#------------------------------------------------------------------------------#

main