Writing to file using simPackFloatTable

Typically: "How do I... ", "How can I... " questions
Post Reply
atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

Writing to file using simPackFloatTable

Post by atoz » 16 Oct 2017, 22:00

Hi,

I'm trying to record joint values of my robot to a file. I've been following the joint recorder method and attempting to convert the recorded data table to a string using simPackFloatTable but it doesn't seem to work. The method returns webdingy symbols as output in the test output file. My test code is as follows:

Code: Select all

	file = io.open("folder\\test.txt", "w")
        data={123.234,123.123}
        data_s= simPackFloatTable(data)
        print(data_s)  -- prints ¤w÷B·>÷B
        
        file:write(data_s)
        file:flush()
        file:close()
Any idea what I am doing wrong?

Thanks

coppelia
Site Admin
Posts: 7226
Joined: 14 Dec 2012, 00:25

Re: Writing to file using simPackFloatTable

Post by coppelia » 17 Oct 2017, 08:15

Hello,

simPackFloatTable and similar will generate a data buffer, that is not printable (or at least, it will just give you garbage). For each value in the table it will create exactly 4 bytes.

What exactly is you intent by packing your data? Packing data is usually used to abstract the data for the time of sending/storing it, but also to minimize the amount of data. After packing the data, you will always have to unpack it again.

Cheers

atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

Re: Writing to file using simPackFloatTable

Post by atoz » 17 Oct 2017, 11:56

Thanks. It seems I didn't understand the abstraction of packing data. My intention was to convert all joint values to a single string using simPackFloatTable to make it easier to write the values to a file. I didn't realise the data representation is changed completely.

coppelia
Site Admin
Posts: 7226
Joined: 14 Dec 2012, 00:25

Re: Writing to file using simPackFloatTable

Post by coppelia » 19 Oct 2017, 14:22

Yes, when you pack tables, then the data takes minimal storage/transmission space, but the data is not human-readable anymore.
You probably simply want to concatenate strings, and write that to file (e.g. use local resultString=string1..string2)

Cheers

Post Reply