# ChatGPT follies with URScript

**URL:** <https://forum.universal-robots.com/t/chatgpt-follies-with-urscript/38841>\
**Category:** URScript\
**Created:** [March 3, 2025, 8:26pm UTC](https://forum.universal-robots.com/t/chatgpt-follies-with-urscript/38841 "2025-03-03T20:26:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpeva](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@dpeva](https://forum.universal-robots.com/u/dpeva)\
**Post date:** [March 3, 2025, 8:26pm UTC](https://forum.universal-robots.com/t/chatgpt-follies-with-urscript/38841/1 "2025-03-03T20:26:36Z")

</div>

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.**

---

<div class="post-metadata">

**Author:** ![zoe.levin](https://avatars.discourse-cdn.com/v4/letter/z/b5a626/32.png) [@zoe.levin](https://forum.universal-robots.com/u/zoe.levin)\
**Post date:** [March 3, 2025, 9:52pm UTC](https://forum.universal-robots.com/t/chatgpt-follies-with-urscript/38841/2 "2025-03-03T21:52:54Z")

</div>

Something I’ve noticed is that since there is not a lot of information/data on URScript, ChatGPT defaults to using python. As far as I know, UR does not support slicing. As for the code, I would just do something like  
index=0  
old\_index = 24  
` While (index<max_index):`  
` bin_list_new[index]=bin_list_orig[old_index]`  
` old_index=old_index+1`  
` index = index+1`  
` if (index%8==0):`  
` old_index = old_index-16`  
` end`  
`end `  
Here’s a script manual that you can reference for URScript functions. Happy coding 🙂  
[URScript Manual](https://s3-eu-west-1.amazonaws.com/ur-support-site/115824/scriptManual_SW5.11.pdf)

---

<div class="post-metadata">

**Author:** ![dpeva](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@dpeva](https://forum.universal-robots.com/u/dpeva)\
**Post date:** [March 4, 2025, 2:32pm UTC](https://forum.universal-robots.com/t/chatgpt-follies-with-urscript/38841/3 "2025-03-04T14:32:46Z")

</div>

Thanks - I wasn’t really aware of the %8 (modulus) syntax in the if statement - ran that by ChatGPT and it explained it.  
I did walk through the numbers just to understand it better, and discovered that in your line:

> ```
> old_index = old_index-16
> 
> ```

the 16 value should be 15

ultimately the mapping should be:

0 to 7 map from 24 to 31  
8 to 15 map from 16 to 23  
16 to 23 map from 8 to 15  
24 to 31 map from 0 to 7

Our existing code has worked for several years on several machines, so I probably won’t change it, but it’s nice to see some cleaner options.
