Parsing Bad Target Data

in RobotStudio
Hello,
I am receiving arbitrary robtarget data from a PC via sockets. I am testing for if the user sent a "bad character" in the target data.
Example: (X, Y, Z) or (100, 200, string) or (100, 200, 300BadCharacter)
I am also receiving Quaternions, Axis Configurations, and Velocity data the same method. So far, whenever the robot encounters a bad character in the data, it just makes the bad character a 0 and any other data numbers after that a 0 as well, even if they are numeric (except in the translation data, where RAPID crashes if a bad character is input into the (X,Y,Z)).
My question is, is there a way to parse the bad character out and/or not make the numbers after that a 0? Or is there a way to notify the user that a bad character has been entered? Here is a snippet of how I am receiving said data:
FUNC robtarget ParseTargetData(VAR rawbytes targetData)
! Parse a string of bytes into a robot target
! Inputs:
! -targetData: byte string
! Returns:
! -position: robtarget
VAR robtarget target;
!Read a position (x,y,z).
UnpackRawBytes targetData\Network,2,target.trans.x\Float4;
UnpackRawBytes targetData\Network,6,target.trans.y\Float4;
UnpackRawBytes targetData\Network,10,target.trans.z\Float4;
!Read tool orientation (quaternion angles).
UnpackRawBytes targetData\Network,14,target.rot.q1\Float4;
UnpackRawBytes targetData\Network,18,target.rot.q2\Float4;
UnpackRawBytes targetData\Network,22,target.rot.q3\Float4;
UnpackRawBytes targetData\Network,26,target.rot.q4\Float4;
!Read axes configuration (axis1,axis4,axis6,axisX)
UnpackRawBytes targetData\Network,30,target.robconf.cf1\Float4;
UnpackRawBytes targetData\Network,34,target.robconf.cf4\Float4;
UnpackRawBytes targetData\Network,38,target.robconf.cf6\Float4;
UnpackRawBytes targetData\Network,42,target.robconf.cfX\Float4;
RETURN target;
ENDFUNC
Thanks in advance for any help!
SM
I am receiving arbitrary robtarget data from a PC via sockets. I am testing for if the user sent a "bad character" in the target data.
Example: (X, Y, Z) or (100, 200, string) or (100, 200, 300BadCharacter)
I am also receiving Quaternions, Axis Configurations, and Velocity data the same method. So far, whenever the robot encounters a bad character in the data, it just makes the bad character a 0 and any other data numbers after that a 0 as well, even if they are numeric (except in the translation data, where RAPID crashes if a bad character is input into the (X,Y,Z)).
My question is, is there a way to parse the bad character out and/or not make the numbers after that a 0? Or is there a way to notify the user that a bad character has been entered? Here is a snippet of how I am receiving said data:
FUNC robtarget ParseTargetData(VAR rawbytes targetData)
! Parse a string of bytes into a robot target
! Inputs:
! -targetData: byte string
! Returns:
! -position: robtarget
VAR robtarget target;
!Read a position (x,y,z).
UnpackRawBytes targetData\Network,2,target.trans.x\Float4;
UnpackRawBytes targetData\Network,6,target.trans.y\Float4;
UnpackRawBytes targetData\Network,10,target.trans.z\Float4;
!Read tool orientation (quaternion angles).
UnpackRawBytes targetData\Network,14,target.rot.q1\Float4;
UnpackRawBytes targetData\Network,18,target.rot.q2\Float4;
UnpackRawBytes targetData\Network,22,target.rot.q3\Float4;
UnpackRawBytes targetData\Network,26,target.rot.q4\Float4;
!Read axes configuration (axis1,axis4,axis6,axisX)
UnpackRawBytes targetData\Network,30,target.robconf.cf1\Float4;
UnpackRawBytes targetData\Network,34,target.robconf.cf4\Float4;
UnpackRawBytes targetData\Network,38,target.robconf.cf6\Float4;
UnpackRawBytes targetData\Network,42,target.robconf.cfX\Float4;
RETURN target;
ENDFUNC
Thanks in advance for any help!
SM
Tagged:
Comments
You can do something like this:
If you want to filter out any 'bad character', then you have to create a loop (FOR/WHILE) and test if every character of the string is a digit.
Thanks for the reply. By doing the method you showed above for checking if the character is correct, I guess I would need to check that for each item I am unpacking? In my case, 11 times?
How can I test if the character of the string is a digit/number or not?
Thanks for the help,
SM
Robotics and Vision Specialist
Consat Engineering
Another way is to first unpack the whole RobTarget to string and then iterate over the string.
Thanks for the reply, I will use it the way you suggested. But I first I have to get the whole byte string into a single string.
I am trying to unpack the whole thing and put it into a string. The problem is, I am sending the data via sockets and TCP/IP from LabVIEW, so when it converts it to string, it is just a bunch of weird numbers and characters?
Thanks for all the help!
SM
Would it be better to just unpack all the elements separately, and combine them for the 3 data types (position, quaternions, and config data)? And then parse out the bad characters via John's method?
Thanks,
SM
I do not have much experience with sending data through sockets in LabView, but normally the transmitted and received string should be the same. You could check if LabView also uses ASCII based encoding (and not Base64 for example).
Maybe you can show the (transmitted) robtarget and which characters you get after parsing?
Right now I am creating 3 different strings (pos data, quat data, config data) using the method in this post:
https://forums.robotstudio.com/discussion/9700/receive-robtarget-from-string
Once I get that done I will try to parse out the bad data using your method. Will it work this way?
Thanks
SM
I don't know what the length of the incoming strings will be, so using the: target.trans.x\ASCII:=some number, won't really work, because it only unpacks the characters within that number. Is there a way to check and see what the length of the incoming string is before I unpack it? Or another method to unpack all the data within that translation portion?
Summing all that up, is there a way to unpack rawbytes (that are sent in robtarget format) straight into a string, without knowing what the string length will be?
Thanks for any help!
SM
Since the subject has changed from what the initial question was, I posted it to a new thread:
https://forums.robotstudio.com/discussion/9952/unpacking-rawbytes-to-string#latest
Thanks for all the help!
SM
Also, this is what the incoming string looks like:"[0~100~0]~[0.96593~-0.25882~0~0]~[1~0~0~0]~[150~50]". I am having to use "~" (tilde) because I am bringing in the target data in LV from a comma delimited file. So what I need to do, is to check the data in between the "~" and brackets (well first, ensure that there are even brackets or tilde's), and make sure they are numeric values and/or negative signs and decimal places.
Thanks,
SM
Thanks for the reply. I didn't know you could specify certain characters to keep like that.
If it is a STR_DIGIT or one of the specified characters, what do I do under IF statements? Like how can I parse out the non specified characters, then concatenate them to be a whole robtarget string?
Thanks,
SM