Compile error: An expression was found which produces a result that is not used showing up in URSim

Hello, I am trying to write a palletizing script but getting this error … I have tried to debug it multiple time but still not able to figure out the issue. if any body can help…

input_pallet_left_sensor = 0
input_pallet_right_sensor = 1
input_conveyor_box_sensor = 2
output_vacuum_gripper = 0

Define configurable parameters

num_layers = 5
pattern = “zigzag” # Pattern of the product on skid (e.g., “zigzag”, “straight”)
layer_offset = [0.0, 0.0, 0.05]
rotation_flip = True
num_boxes_per_layer = 5 # Define number of boxes per layer based on your palletizing pattern

Define positions

home_pos = p[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
conveyor_pos = p[0.5, 0.0, 0.0, 0.0, 0.0, 0.0]

Pallet positions (placeholders, these need to be calibrated)

pallet_left_pos = p[1.0, -0.5, 0.0, 0.0, 30.14, 0.0]
pallet_right_pos = p[1.0, 0.5, 0.0, 0.0, 30.14, 0.0]

Function to move to a position

def move_to_position(target_pos):
textmsg("Moving to position: ", target_pos)
movej(target_pos, a=1.2, v=0.25)

Function to pick up a box

def pick_box():
textmsg(“Picking up box”)
move_to_position(conveyor_pos)
set_digital_out(output_vacuum_gripper, True) # Turn on vacuum gripper
sleep(1.0) # Wait for grip
move_to_position(home_pos)

Function to place a box on a pallet

def place_box(pallet_pos, layer_num, box_num):
textmsg("Placing box on pallet. Layer: ", layer_num, " Box: ", box_num)
target_pos = pallet_pos.copy()
if rotation_flip and (layer_num % 2 == 1):
target_pos[3] += 3.14 # Rotate 180 degrees
target_pos[2] += layer_num * layer_offset[2] # Adjust for layer height
target_pos[0] += box_num * layer_offset[0] # Adjust for box position
target_pos[1] += box_num * layer_offset[1] # Adjust for box position
move_to_position(target_pos)
set_digital_out(output_vacuum_gripper, False) # Turn off vacuum gripper
sleep(1.0) # Wait for release
move_to_position(home_pos)

Main program loop

while True:
textmsg(“Starting main loop”)

# Check which pallet to use
if get_digital_in(input_pallet_left_sensor):
    pallet_pos = pallet_left_pos
elif get_digital_in(input_pallet_right_sensor):
    pallet_pos = pallet_right_pos
else:
    textmsg("No pallet detected")
    stop()

# Check if there is a box on the conveyor
if get_digital_in(input_conveyor_box_sensor):
    textmsg("Box detected on conveyor")
    pick_box()
    
    # Place the box on the pallet
    for layer in range(num_layers):
        for box in range(num_boxes_per_layer):
            place_box(pallet_pos, layer, box)
            
            # Update pattern if necessary
            if pattern == "zigzag":
                textmsg("Applying zigzag pattern")
                # Implement zigzag pattern logic
                pass
            elif pattern == "straight":
                textmsg("Applying straight pattern")
                # Implement straight pattern logic
                pass

sleep(0.1)  # Small delay to prevent excessive CPU usage
textmsg("Main loop iteration complete")

this is the program

Can you include a screenshot of where the the compiler thinks the issue is? Not exactly sure what language you’re using there in your main program loop, but you don’t have any “Ends” for your if statements or for loops. Looks more like python code than URScript, considering there aren’t any for loops in urscript

1 Like

def place_box(pallet_pos, layer_num, box_num):
textmsg("Placing box on pallet. Layer: ", layer_num, " Box: ", box_num)
target_pos = pallet_pos.copy() # Copy pallet_pos to avoid modifying the original
if rotation_flip and (layer_num % 2 == 1):
target_pos[3] += 3.14 # Rotate 180 degrees
target_pos[2] += layer_num * layer_offset[2] # Adjust for layer height
target_pos[0] += box_num * layer_offset[0] # Adjust for box position
target_pos[1] += box_num * layer_offset[1] # Adjust for box position
move_to_position(target_pos)
set_digital_out(output_vacuum_gripper, False) # Turn off vacuum gripper
sleep(1.0) # Wait for release
move_to_position(home_pos)
end
I am getting error in this area of the code and yes I found the end issue but still getting error



This are the functions causing the error

That error message seems to be pretty generic - I’ve seen it show up for many reasons - usually just syntax errors or unrecognized variables (capitalization mismatch, etc.)

Looking at your code, I don’t recognize the += operation on several of the lines.

It is just to add the position depending on the layer num and the layer offset. I will simplify that but can you please explain why is it coming for this code?


I have read the code multiple time and still couldn’t find the issue in it

Again, unless I’m mistaken here I don’t think “For” is a recognized command in URScript. And Again again, if you post the screenshot of the pendent, it tends to highlight in red where it thinks the problem is. Often that’s because the lines immediately before it have a syntax error, but that would further help us narrow it down for you.

And unless you’ve got these declared globally somewhere else, I don’t see how the compiler is supposed to know what “layer”, “num_boxes_per_layer”, “box”, etc are. I’d advise you take a look at the URScript manual here: https://s3-eu-west-1.amazonaws.com/ur-support-site/214314/scriptmanualG5_%205.15.1.pdf

Range() also isn’t a command. Can you confirm that you are intending to write URScript and not Python?