Sharing data across program nodes

I’m trying to share information across nodes within a program. One program node should take information in, and then all subsequent nodes should be able to see that information.

I don’t want to use an installation node because the information should not be shared across programs (i.e. if you save the current program and make a new one, users should start from scratch again).

How can I safely do this? I’ve considered using a manager class with a Singleton pattern, but am unsure how safe this approach is.

Thanks

Hello,

Is this the type of link you’re trying to recreate?

The child node can access the content of the parent node.

See: URCap Sample: URCap CustomAPI

Kind regards

Hi Thomas,

It’s more like if you created two parent nodes somewhere in the program tree and made changes to the first one, the stored state of the first should be the same as the second (changes are carried across).

Hello,

Alright, I know.

I believe that with the base I provided, you should be able to modify this URCap to achieve what you want.

Kind regards

What kind of information do you want to share between these two program nodes?
An integer? A boolean? Something else…?

I’m getting users to define a number of positions so I can construct a grid or line of points that the entire program will be able to use. So, depending on some selections, a user will define some points and then they will be stored as an array: double[][].

So far I’m sending each point as a double[]to my data model and storing individually, but I don’t know how to get this info to be shared across other program nodes. I want the user to only have to define their points once.

I considered getting the user to define points in the installation node, but this doesn’t fit my project requirements.

Right or wrong (I’m self-taught on Java so someone with more experience could tell me I’m an idiot) I’ve just stored values to static classes when I need other nodes to access the data. It’s only valid for the duration of the robot’s power cycle, but you could fairly easily make a method to pull from the first node’s datamodel and subsequently populate the static class. Then other nodes can read the doubles out of the static class and construct the poses from there.

I’ve also thought of doing that. The main problem is as you say: That the poses don’t last over power cycles. That method is in my back pocket as a last resort…

Have you considered adding another node that serves only this purpose? Just let it be a sort of container node (parent) that stores the positions, and the user then inserts most/all of the other nodes inside this one? Then the main parent node can just pass the data into all the child nodes via a traversal.

That’s half the idea. What I want is the positions to only have to be defined once. That means that both children should be able to see the data, and also any other program node of the same type if the user chooses to insert one into the tree down the line.

Then I would make 2 nodes. One is just the data container node. Insert this into the tree first. Then all your other nodes get added into this one. Whenever a position is added, you call something like parent.setSomeFancyData(). In the parent node, you make a method, call it passModelToChildren() which passes a copy of its model into all the child nodes.

I’ve done similar in my CAPs as well. I added a TimerTask in the container node that monitors its childCount, so I get a sort of “onNodeAdded” listener. This allows me to pass a copy of the model into new nodes that get inserted as well.

You’ll need to implement a custom API, for which there are tutorials on the forum, give it a search.

I’d be more tempted to just go the static class method myself. Good luck!

One last thing. Sorry I’ve only been developing caps for a few weeks. If I want to create a new cap and import the one we’ve been discussing, in which directory should I place the new one relative to the cap we’ve been discussing? Using ./newURCap.sh makes a new URCap in my home folder, but that means I cannot import the service class of my other cap.

So you want 2 completely separate CAPs here, or just 2 separate nodes? An important distinction, because you don’t need 2 CAPs just to have 2 selectable nodes on the left.

Just two separate nodes. They can be within the same cap.

Then I would just copy the three files from your existing program node (Contribution, View, Service) and change the names of the files. Then in your activator, just register the service of that new name.

Sweet as. Thank you!