ernestum / VSync

Library to synchronize variables between Arduinos and Processing sketches.
http://ernestum.github.io/VSync/
GNU General Public License v3.0
24 stars 4 forks source link

Stability issue when sending many values #2

Open mikkelsiggaard opened 7 years ago

mikkelsiggaard commented 7 years ago

First, thanks for a great library.

I have 48 values that I want to sync from Arduino to Processing, and the sending works great. But when I try to receive all 48 values in Processing the update speed is very slow - something like 10-15 seconds, but it varies a lot.

If I only try to sync 6 values the speed and stability is good.

Question 1: Are there a number of maximum recommended values to be kept in sync?

Question 2: Are there any ways to improve performance/stability?

ernestum commented 7 years ago

Hey,

I never tried to sync more than 8 values or so at a time. I suspect some buffering issue is responsible for the lag.

To know for sure I would need your Processing code and Arduino code to reproduce the problem. If you do provide it, please also tell me what Arduino board you are using and strip the Arduino code from anything that is hardware specific (because I obviously can not reproduce your hardware setup).

mikkelsiggaard commented 7 years ago

There shouldn't be anything hardware specific in the attached code. Infinitex_4.zip In the attached code i've only "activated" 6 sensors, but just delete the comment-things (don't know the technical term).

I'm using an Arduino Uno (a chinese copy) but it seems to work just fine. Link to the package I bought.

Background info: I have a sensor array where I set digital1 HIGH, reads all 6 analog values and set digital2 LOW. Same thing happens for digital2 and so on - (8 in total). So I have a matrix/grid of 8 (digital) by 6 (analog), which makes 48 different sensors in total.

ernestum commented 7 years ago

Hey,

I did not have time yet to try dig out an uno compatible board from the bottom of my hardware box but I had a quick glance at your code (nice code BTW):

I did not state this explicitly in the documentation but you only ever should have one instance of a ValueReceiver and a ValueSender on each side. Otherwise they can interfere with each other. That also explains why 6 values work: then you probably had just one sender/receiver pair active.

Please try using only one ValueSender<48> on the Arduino side and only one ValueReceiver on the Processing side and report back.

What project are you working at? I am always interested in hearing how others use my library.

mikkelsiggaard commented 7 years ago

Haha, thank you!

I've tried with a ValueSender<48> earlier, but actually can't remember the exact result. I'll try it again and see what it's like.

I'm doing a Technology Specialization on my master in Technology based Business Development, and wanted to use the newest technology in stretch sensing available to make two use cases as commercial as possible. The two use cases being body posture tracking and body language tracking. But I was kind of disappointed when I did a technology screening and it was basically all electronic sensors that was mounted on some textile. What I wanted was something fully embedded in the textile, so normal users could use it like any other textile, say a t-shirt. So, now I'm kind of developing a whole new technology, where I want a textile to be "spatially aware" of it's own form. This could be used in a tight fitting t-shirt which then would allow me to track the movements of a users torso with a pretty good resolution. The materials I'm using for this is something called Eeon Tex LTT-SPLA that has the ability to change it's surface resistance when it's stretched. I've then taking that textile and cut into little rectangles and placed them in a grid formation, so half of them measures stretch in the Y-dimension and the others in the X-dimension. So I have 48 of these small pieces of "magic" textile sown onto a normal piece of textile and have hooked it up with conductive threads. Then my hypothesis is that, when this is used where there is a tight fit, the value of each sensor is a measure of the curvature in that specific direction, at that specific point. If my hypothesis is correct then it should allow me to dynamically track the torso of a user in 3D, with a pretty good resolution.

mikkelsiggaard commented 7 years ago

I now know what the problem was. In the Arduino-code I was declaring the "observe"-values like this: image

Instead it needs to be in one line, since ";" declares a new instance of "observe" - or something like that.

Also, I now only have one ValueSender<48> and everything works good with all 48 values. I get an update rate at about 3-5 Hz (using a baud rate of 250000).

ernestum commented 7 years ago

Great that it works now! 3-5Hz is not too fast though ... is it enough for your project?

mikkelsiggaard commented 7 years ago

I managed to get the update rate fixed.

I've rewritten the Arduino code to use an array, that I want to sync because I've implemented some smoothing using arrays. I've basically used the Smoothing example, just using arrays. That means I'm not sending an array using Vsync, which work okay. But in the Processing code, I'm having trouble defining an observe-array(?) to receive the transmitted array.

So far I've tried to do it manually like this: receiver.observe("input[0]");receiver.observe("input[1]");receiver.observe("input[2]"); etc.

and like this:

for (int u = 0; u < 47; u++) { receiver.observe("input[p]"); }

Any ideas for how to do this a clever way? Or just to get it working?

ernestum commented 7 years ago

I did not completely understand what you did on the Arduino side with the arrays but it sounds cool! Most certainly something needs to be changed on the Processing side to make it work. The observe calls you cited above will certainly not work that way. In C++ I could work with pointers, but in Java there is no such thing as pointers so I had to use reflections to make it work conveniently. Do you know how to work with those?

mikkelsiggaard commented 7 years ago

I actually already solved it by not receiving it as an array, but just normal integers and it works fine as long as you don't screw up the order of values. I just assumed that it had to be the same "int [name]" both for the Processing and the Arduino code, but figured it out because the names aren't transmitted, or I could have seen values and names in the Serial Monitor :smile:

ernestum commented 7 years ago

Exactly. We do not ever send names and only rely on the order! Great that you got it working!

nigeltiany commented 7 years ago

This is not related to this issue, @erniejunior @mikkelsiggaard please checkout https://ap-sync.github.io/ inspired by VSync. Its still a work in progress

ernestum commented 7 years ago

Nice! Makes me happy that I could inspire you to improve upon my work!