# -*- coding: UTF-8 -*-
# Copyright 2015-2025 - RoboDK Inc. - https://robodk.com/
#
# This is a compiled post processor. Please contact us at info@robodk.com if you need access to the source code of this post processor.
#
# This file loads the compiled version of the RoboDK post processor for:
#   Fanuc R30i robot controllers
#
# More information about RoboDK Post Processors and Offline Programming:
#     https://robodk.com/help#PostProcessor
#     https://robodk.com/doc/en/PythonAPI/postprocessor.html
# ----------------------------------------------------

import sys
import os

import math
from robodk import *

# Detect Python version and post processor
print("Using Python version: " + str(sys.version_info))
path_file = os.path.dirname(__file__).replace(os.sep, "/")
print("RoboDK Post Processor: " + path_file)

# Check if the post is compatible with the Python version
version_str = str(sys.version_info[0]) + str(sys.version_info[1])
path_library = path_file + '/v' + version_str
if not os.path.isdir(path_library):
    msg = "Invalid Python version or post processor not found. Make sure you are using a supported Python version: " + path_library
    msg += "\nSelect Tools-Options-Python and select a supported Python version"
    print(msg)
    raise Exception(msg)

# Load the post processor
exec("from v" + version_str + ".Fanuc_R30i import RobotPost as BasePost")

class RobotPost(BasePost):

    # ------------------------ Customize your RoboDK post processor using the following variables ------------------------

    # maximum number of lines per program. It will then generate multiple "pages" (files).
    # This setting can be overriden by RoboDK settings (Tools-Options-Program)
    MAX_LINES_X_PROG = 9999

    # Generate sub programs
    INCLUDE_SUB_PROGRAMS = True

    # set default joint speed (percentage of the total speed)
    JOINT_SPEED = "20%"

    # set default cartesian speed motion
    SPEED = "200mm/sec"

    # set default CNT value (all motion until smooth value is changed)
    # CNT_VALUE = 'CNT5' # 5% smoothing (set CNT1-CNT100)
    CNT_VALUE = "FINE"

    # Set the acceleration value. For example: ACC20 or empty
    ACCEL_VALUE = ""

    # Active UFrame Id (register)
    ACTIVE_UF = 9

    # Active UTool Id (register)
    ACTIVE_UT = 9

    # Spare Position register for calculations (such as setting UFRAME and UTOOL)
    SPARE_PR = 9

    # Set the maximum index to use when linking to existing Frame IDs. This is a safety feature as linking to non valid IDs can make the controller behave unexpectedly
    MAX_FRAME_ID = 9

    # Set the maximum index to use when linking to existing Tool IDs. This is a safety feature as linking to non valid IDs can make the controller behave unexpectedly
    MAX_TOOL_ID = 9

    # Custom string to add at the end of each linear movement. For example: Offset,PR[1], or COORD
    CUSTOM_STRING = ""

    # Custom string to add at the end of each joint movement. For example: Offset,PR[1], or COORD
    CUSTOM_STRING_J = ""

    # Set the turntable group (usually GP2 or GP3, set to None to not use a new group)
    # TURNTABLE_GROUP = None
    # TURNTABLE_GROUP = 'GP3'
    TURNTABLE_GROUP = "GP2"

    # Disables motion group heuristics and uses user defnined mapping
    USE_VAR_AXES_MOTION_GROUP = False

    # Motion group for each axis, default first 9 axes in group 1, then next 9 axes in group 2
    # AXES_MOTION_GROUP = [1,1,1,1,2,2,2,2]
    AXES_MOTION_GROUP = [1, 1, 1, 1, 1, 1, 2, 2, 3, 1, 1, 1, 2, 2, 2, 2, 2, 2]

    # Always use RoboDK user frames (references)
    USE_ROBODK_UFRAME = False

    # Always use RoboDK tool frames (tools)
    USE_ROBODK_UTOOL = False

    # Set to True to generate programs compatible with RJ3 controllers (small difference in the program header, program names should have less than 6-8 characters)
    FANUC_RJ3_COMPATIBLE = False

    # Maximum number of characters for program names
    # R-30iB+ limit is 16 characters, R-30iA and R-30iB are 12 characters and RJ3 is 8 characters
    MAX_PROG_CHARS = 12

    # Maximum number of characters for a line of code
    # R-30iB+ limit is 80 characters, R-30iA, R-30iB and RJ3 are 72 characters
    MAX_LINE_CHARS = 72

    # Set the flags for external axes (keep it to 5 at most)
    EXTAXES_FLAGS = ['1', '*', '*', '*', '*']

    # Set custom application data, such as welding options or external axes options
    # You may need to configure the custom /APPL header if you see this error when you try to run your program: "INTP-281 No application data"
    # APPLICATION_DATA = ['ARC : TRUE;' , 'ARC Welding Equipment : 1,*,*,*,*;']
    APPLICATION_DATA = None

    # Compile LS program to TP programs
    # More help here: https://robodk.com/doc/en/Robots-Fanuc.html#LSvsTP
    # Set the path to Roboguide WinOLPC tools, alternatively, set to None to prevent generating TP files
    # This step is ignored if the path does not exist
    PATH_MAKE_TP = "C:/Program Files (x86)/FANUC/WinOLPC/bin/"    # PATH_MAKE_TP = None # Ignore program compilation

    # Generate a drip feeder program: this will split long programs in subprograms and load them to the controller as they are executed
    # Set a file name to use an automatic dripfeeder: Files will be sent over FTP as they are executed
    # Right click a program and select "Send Program to Robot" to trigger the dripfeeding automatically
    # DRIPFEED_FILE_NAME = "Fanuc_SendProgram_DripFeed.py"
    DRIPFEED_FILE_NAME = None    # Don't do any dripfeeding

    # Force user input to save the folder
    FORCE_POPUP_SAVE = False

    # Set to True for a 5-axis robot arm that is modelled like a 6-axis robot
    # This flag is automatically set to True for 5-axis robots such as the Fanuc LR Mate 100i
    IS_5DOF_ARM = False

    # --------------------------------------------------------------------------------------------------------------------

    pass

if __name__== "__main__":
    exec("from v" + version_str + ".Fanuc_R30i import test_post")
    test_post()

