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