difficulties with simSetGraphUserData

Typically: "How do I... ", "How can I... " questions
richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

difficulties with simSetGraphUserData

Post by richardh » 20 Jan 2017, 16:04

(Running Ubuntu)
I do not understand the Invalid data stream error. I seem to be generating correct data.

In a child script, in the initialisation section, I have
gHandle=simGetObjectHandle("Graph") -- refers to a graph object that is a child to the object associated with the script

In the actuation section, I have at line 56-57
simAddStatusbarMessage(string.format("F Left: %f, Right: %f\n",leftV, rightV))
simSetGraphUserData(gHandle, "LeftAV", leftV)

This appears to be compliant with the function spec:
Lua synopsis number result=simSetGraphUserData(number graphHandle,string dataStreamName,number data)

During an animation, the following is produced in the status bar (on each iteration, it seems).

F Left: -0.820305, Right: -0.731991
Lua runtime error: [string "SCRIPT Mob_Base"]:57: Invalid data stream. (simSetGraphUserData)
stack traceback:
[C]: in function 'simSetGraphUserData'
[string "SCRIPT Mob_Base"]:57: in main chunk

Since leftV has a valid number, which is printed into the Status Bar, why is it invalid as part of a data stream?

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

Re: difficulties with simSetGraphUserData

Post by coppelia » 23 Jan 2017, 11:40

Hello,

Are you sure your data stream type is "Various: user-defined"?
If yes, then please post your scene, it will be easier to track the problem.

Cheers

richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

Re: difficulties with simSetGraphUserData

Post by richardh » 25 Jan 2017, 10:08

a) What is the best way to 'post a scene'? Do you prefer pastebin, or attach a .ttt file?
Here is pastebin url http://pastebin.com/Dkn1M1gT

b) When you say <Are you sure your data stream type is "Various: user-defined"?>, which context do you mean?
In the Graph Object, I have set the datastream resource to "Various: user-defined", but the problem seems to be associated with my child script. It is complaining about the number I am giving it as an invalid data stream.

Is there some way that I have to create a data stream inside the child script?

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

Re: difficulties with simSetGraphUserData

Post by coppelia » 26 Jan 2017, 10:42

Please provide a dropbox, google drive or similar one-click download link to your scene file.

You cannot create new data streams via API calls.

Have a look at this scene, that uses user-defined data streams.

Cheers

richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

Re: difficulties with simSetGraphUserData

Post by richardh » 26 Jan 2017, 12:32

I sent you a pastebin link. This is the same. No?

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

Re: difficulties with simSetGraphUserData

Post by coppelia » 27 Jan 2017, 14:12

I can't seem to be able to download the file in a simple manner via pastebin.
Did you have a look at the link I provided?

Cheers

richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

Re: difficulties with simSetGraphUserData

Post by richardh » 27 Jan 2017, 16:10

Understand about pastebin not working for you.
Here is the scene in DropBox https://www.dropbox.com/s/0ole5spt9u2ln ... e.ttt?dl=0

I looked at the scene you sent, but it seems to use a different technique for graphing, not simAddGraphUserData. Very interesting.

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

Re: difficulties with simSetGraphUserData

Post by coppelia » 31 Jan 2017, 08:42

The scene I posted used simSetGraphUserData. The same API command as you do. simAddGraphUserData is not a valid API command.

Also, in your scene you have:

Code: Select all

simSetGraphUserData( gHandle, "LeftV", moveL)
But you don't have a single data stream named LeftV. Either replace it with Data, or rename the data stream to LeftV.

Cheers

richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

[Solved] Re: difficulties with simSetGraphUserData

Post by richardh » 01 Feb 2017, 09:27

I finally figured this one out. Thank you for you help.
a) The scene you posted gave me the clues. (sorry for typo about the function in one of my posts). There are three child scripts in it, and I only looked at two, which is why I said I couldn't find the function. For some reason, I didn't look at the one associated with the graph object. :(
b) The documentation, and your explanation above, is confusing. I finally realised that a "data stream name" is the name set inside the graph object when editing the scene. The default is "Data". So to change the default, I needed to double click on "Data" and change it to the name I wanted. The reason this is a bit confusing is that in all other situations where a script is linked to an object in the scene, it is necessary to explicitly get a handle to an object in the scene before being able to use the object in a script. So the name of the object is mentioned in the script only in the initiation phase and not (typically) in the actuation stage.
Perhaps in the documentation of the function simSetGraphUserData, you could add some words to the description, eg: The name of a data stream is specified in the graph object in the scene (default is 'Data').
c) It is also very unclear that as soon as simSetGraphUserData is used, it is also necessary to use simHandleGraph() with an explicit time at which the datum is to be associated. Perhaps in the description of simSetGraphUserData you could add some words like: Be sure to call simHandleGraph() to record the data and set the graph object to 'explicit handling'.

Regards,
Richard

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

Re: difficulties with simSetGraphUserData

Post by coppelia » 02 Feb 2017, 09:19

Normally, simHandleGraph is called for you, in the main script. In that case, you can record one value in each simulation step (independently whether it is a custom stream or not). When you explicitely handle the graph, then you have the possibility to record more than one new graph point in each simulation step.

Cheers

Post Reply