Float to string conversion

Hello,

I would like to make a feature request for converting from float/int/poses to strings so that they can be sent over sockets. Here at Behco/MRM we have worked with Canon on a vision application that requires we send the position of a grasp over a socket_send_string to the Canon system. This is a tedious task that requires us to go to the grasp position and then write down the positional data and then type that positional data out into a string.

Converting from string to float or from float to string should be an easy function that will help with accessibility.

1 Like

Did you try to feed a float variable to e.g. the command socket_send_string() or socket_send_line()?
It will automatically send the float with dot-notation as a string.

You can use socket_send_string() and socket_send_byte() to build up the preferred string formatting, with e.g. byte 10 for LF etc.

1 Like

Thanks for the feedback. We need to be able to format the string e.g. “[var_1,var_2,var_3].” Can we do this on the UR? I know the operator ‘+’ does not work with strings in polyscope but the vision system requires this format to read.

Try the following;

socket_send_byte(91)   # ascii char [
socket_send_string(var_1)
socket_send_byte(44)   #ascii char ,
socket_send_string(var_2)
socket_send_byte(44)
socket_send_string(var_3)
socket_send_byte(93)   # ascii char ]
socket_send_byte(13)   # CR
socket_send_byte(10)   # LF

This would send all the components you describe above, e.g. resulting in [1.23,2.34,3.45]\r\n

If this is not suitable, may I suggest creating a daemon, that could receive your variables over XML-RPC, build these into the right format, and send to the camera over socket.

2 Likes

Why not put the variables into a list and then simply send the list? You can read in a list as sent from an external server so why not send the list back? Since all of your values are numbers you can put them in a list. We actually send poses back and forth from an external server to the robot and vice versa, they come across as a data object with key/value pairs

Also notice, that the release of PolyScope 3.8 / 5.2 add multiple string manupulation features, including float to string.

1 Like