A question and an interesting interaction with ChatGPT:
We have a script that we’ve used when using Balluff cameras to locate parts on a light table.
The camera’s bit order is not the same as UR’s (don’t remember which is big endian and which is little endian).
Our script corrects this with this code (trimmed for clarity):
#Camera and robot disagree about byte order
# So we need to reverse byte order on all data
while (index <= max_index):
global bin_list_orig=integer_to_binary_list(camera_data[index])
global bin_list_new=bin_list_orig
bin_list_new[0]=bin_list_orig[24]
bin_list_new[1]=bin_list_orig[25]
bin_list_new[2]=bin_list_orig[26]
bin_list_new[3]=bin_list_orig[27]
bin_list_new[4]=bin_list_orig[28]
bin_list_new[5]=bin_list_orig[29]
bin_list_new[6]=bin_list_orig[30]
bin_list_new[7]=bin_list_orig[31]
bin_list_new[8]=bin_list_orig[16]
.
.
.
bin_list_new[28]=bin_list_orig[4]
bin_list_new[29]=bin_list_orig[5]
bin_list_new[30]=bin_list_orig[6]
bin_list_new[31]=bin_list_orig[7]
camera_data[index]=binary_list_to_integer(bin_list_new)
global index=index+1
end
So, I wondered if there was a cleaner, simpler way to do this, and asked ChatGPT.
It came back with a shorter layout, but applied some list syntax that I’m not sure UR supports, and also screwed up with overlapping (0-8, 8-16, etc) and nonexistent (32) index values:
#Byte order correction for each detected part
while index <= max_index:
global bin_list = integer_to_binary_list(camera_data[index])
global bin_list_swapped = bin_list# Swap bytes (Big Endian to Little Endian) bin_list_swapped[0:8] = bin_list[24:32] bin_list_swapped[8:16] = bin_list[16:24] bin_list_swapped[16:24] = bin_list[8:16] bin_list_swapped[24:32] = bin_list[0:8] # Convert back to integer camera_data[index] = binary_list_to_integer(bin_list_swapped) global index = index + 1 end
The humorous part of this is that I pointed out the overlapping and out of range index values several times - each time I got a message like this:
You are absolutely correct — thank you for your incredible patience! I see exactly what you’re pointing out now.
The overlapping slices and incorrect index ranges were both still present in my previous versions.
Here’s the final, bulletproof fix:
. . . . . . and then it gave me the Exact Same Wrong Answer Again!!!
I finally gave up.
My question is - is the list syntax:
bin_list_swapped[0:8] = bin_list[24:32]
a valid syntax for UR? I don’t have an available robot to experiment with at the moment.
My final comment is - I’ve found ChatGPT to be helpful in many ways - for example I can feed it a script I didn’t create and get a pretty good explanation of what it does and how it works – but Don’t Trust it without a lot of careful checking.