﻿<?xml version="1.0" encoding="utf-8"?>
<Program>
    <Header RobotName="igus Gantry" RobotType="DLE-RG-0001" GripperType="" Software="iRC V902-15-000-Beta-RC6" VelocitySetting="2" />
    <Store Nr="1" Type="position" Value="0 0 0 0 0 0" ValueJoints="0 0 0 0 0 0 0 0 0" Name="homepos" Persistent="false" Descr="Safe home position — gantry Z=0 is fully retracted (highest point)" />
    <Store Nr="2" Type="position" Value="200 50 -20 0 0 0" ValueJoints="200 50 20 0 0 0 0 0 0" Name="pickapproach" Persistent="false" Descr="20mm above pick (Z=-20)" />
    <Store Nr="3" Type="position" Value="200 50 -40 0 0 0" ValueJoints="200 50 40 0 0 0 0 0 0" Name="pickpos" Persistent="false" Descr="Pick position (Z=-40)" />
    <Store Nr="4" Type="position" Value="300 200 -60 0 0 0" ValueJoints="300 200 60 0 0 0 0 0 0" Name="palleta" Persistent="false" Descr="Pallet origin corner A" />
    <Store Nr="5" Type="position" Value="100 200 -60 0 0 0" ValueJoints="100 200 60 0 0 0 0 0 0" Name="palletb" Persistent="false" Descr="Pallet corner B — end of CntX axis" />
    <Store Nr="6" Type="position" Value="300 300 -60 0 0 0" ValueJoints="300 300 60 0 0 0 0 0 0" Name="palletc" Persistent="false" Descr="Pallet corner C — end of CntY axis" />
    <Store Nr="7" Type="position" Value="0 0 0 0 0 0" ValueJoints="0 0 0 0 0 0 0 0 0" Name="slotpos" Persistent="false" Descr="Current pallet slot position (filled by MatrixQuery)" />
    <Store Nr="8" Type="position" Value="0 0 0 0 0 0" ValueJoints="0 0 0 0 0 0 0 0 0" Name="slotapproach" Persistent="false" Descr="20mm above current pallet slot" />
    <Store Nr="9" Type="number" Value="0" Name="slotindex" Persistent="false" Descr="Current slot index (0-based)" />
    <Store Nr="10" Type="number" Value="0" Name="cntx" Persistent="false" Descr="Grid CntX (output from MatrixQuery)" />
    <Store Nr="11" Type="number" Value="0" Name="cnty" Persistent="false" Descr="Grid CntY (output from MatrixQuery)" />
    <MatrixDefinition Nr="12" Name="palletGrid" CntX="4" CntY="2" VarPointA="palletA" VarPointB="palletB" VarPointC="palletC" Descr="4x2 pallet grid" />
    <Output Nr="13" Channel="DOut24" State="True" Descr="Ensure gripper is open on startup" />
    <Wait Nr="14" Type="Time" Seconds="0.5" Descr="Wait for gripper to open" />
    <Linear AbortCondition="False" Nr="15" Source="Variable" vel="100" acc="50" smooth="0" UserFrame="#base" VariableName="homepos" Descr="Move to home position" />
    <Loop Nr="16" Mode="DIn" Condition="false" storageVariable="" Descr="Outer loop: repeat pallet cycle indefinitely" />
    <Loop Nr="17" Mode="Count" Times="8" storageVariable="slotIndex" Descr="Inner loop: fill all 8 pallet slots" />
    <MathOperator Nr="18" Function="subtract" FirstOperand="slotIndex" SecondOperand="1" Descr="" />
    <MatrixQuery Nr="19" Name="palletGrid" VarIndex="slotIndex" VarTargetPos="slotPos" VarCntX="cntX" VarCntY="cntY" Descr="Get XYZ for current slot index" />
    <MathOperator Nr="20" Function="set" FirstOperand="slotapproach" SecondOperand="slotpos" Descr="Copy slot position to approach variable" />
    <MathOperator Nr="21" Function="add" FirstOperand="slotapproach.z" SecondOperand="20" Descr="Raise approach 20mm above slot in Z" />
    <Wait Nr="22" Type="Conditional" Condition="DIn22" Descr="Wait until part is present at pick position" />
    <Linear AbortCondition="False" Nr="23" Source="Variable" vel="100" acc="50" smooth="20" UserFrame="#base" VariableName="pickapproach" Descr="Move to approach above pick" />
    <Linear AbortCondition="False" Nr="24" Source="Variable" vel="50" acc="50" smooth="0" UserFrame="#base" VariableName="pickpos" Descr="Descend to pick position" />
    <Output Nr="25" Channel="DOut23" State="True" Descr="Activate gripper (grip part)" />
    <Output Nr="26" Channel="DOut24" State="False" Descr="Deactivate gripper-open output" />
    <Wait Nr="27" Type="Time" Seconds="0.5" Descr="Wait for gripper to close" />
    <Linear AbortCondition="False" Nr="28" Source="Variable" vel="50" acc="50" smooth="0" UserFrame="#base" VariableName="pickapproach" Descr="Retract from pick position" />
    <Linear AbortCondition="False" Nr="29" Source="Variable" vel="100" acc="50" smooth="20" UserFrame="#base" VariableName="slotapproach" Descr="Move to approach above pallet slot" />
    <Linear AbortCondition="False" Nr="30" Source="Variable" vel="50" acc="50" smooth="0" UserFrame="#base" VariableName="slotpos" Descr="Descend to pallet slot" />
    <Output Nr="31" Channel="DOut24" State="True" Descr="Activate gripper-open (release part)" />
    <Output Nr="32" Channel="DOut23" State="False" Descr="Deactivate gripper-close output" />
    <Wait Nr="33" Type="Time" Seconds="0.5" Descr="Wait for part to be released" />
    <Linear AbortCondition="False" Nr="34" Source="Variable" vel="50" acc="50" smooth="0" UserFrame="#base" VariableName="slotapproach" Descr="Retract from pallet slot" />
    <MathOperator Nr="35" Function="add" FirstOperand="#parts-good" SecondOperand="1" Descr="Increment good parts counter" />
    <EndLoop Nr="36" Descr="End of slot-fill loop" />
    <Linear AbortCondition="False" Nr="37" Source="Variable" vel="100" acc="50" smooth="0" UserFrame="#base" VariableName="homepos" Descr="Return to home — pallet full" />
    <Wait Nr="38" Type="Conditional" Condition="DIn25" Descr="Wait for operator signal to start next batch (DIn25)" />
    <EndLoop Nr="39" Descr="End of outer pallet cycle loop" />
</Program>