- obj.u_in = udp(someHost, somePort) % open a UDP connection to your robot end effector
- data1 = fread(obj.u_in,12)
- physically move the robot end effector
- [~] = fread(obj.u_in,obj.u_in.BytesAvailable) % throw away the bytes in the buffer
- data2 = fread(obj.u_in,12)
Problem receving countinously data with a UDP socket connection
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have to read the position coordinates of the end-effector of a robotic device freely moving in space. The (x,y,z) coordinates are sent via UDP to my PC as binary single variables. In run this code:
u_in=udp(in_ip,in_port,'LocalPort',in_port); u_in.DatagramTerminateMode = 'on'; u_in.ReadAsyncMode = 'continuous'; u_in.DatagramReceivedFcn = @obj.stateManager; fopen(u_in); obj.u_in = u_in;
The statemachine callback function is:
function obj = stateManager(obj,~,~)
data = fread(obj.u_in,12); data = typecast(uint8([data]'), 'single');
end
The problem is that fread returns always the same values althougth the robotic system sent different position coordinates. I tried to use flushinput, but the problem persists. The only way to get a new value is to close (fclose(obj.u_in)) and re-open the connection but this is unpractical for me since I have to read data continuously from my device.
Does anyone know how to solve this problem?
0 commentaires
Réponses (2)
Vinod
le 24 Nov 2015
Based on your description I wonder if this is just that your device is continually sending the same value that is filling up your UDP buffer.
Try this to isolate the problem:
Post back if you see data1 and data2 to be the same.
2 commentaires
Vinod
le 25 Nov 2015
We have very extensive tests for UDP and I am not sure that FREAD is the root cause here. The other application you mention may be doing things to filter the UDP data to only provide you the outputs when the position has changed (as opposed to all the data on the UDP bus.)
It would be difficult to reproduce this problem at MathWorks since we do not have your hardware. Is there a way to reproduce the issue you are seeing without the robot end effector? Alternatively perhaps you can work with technical support over a screen-share to identify the source of the problem. Create a new tech support case here .
Raymond Chitwood
le 2 Mar 2020
Try adding flushinput(obj.u_in); before each new fread. I had similar problems, and clearing the buffer helped.
0 commentaires
Voir également
Catégories
En savoir plus sur Commercial & Off-Highway Vehicles dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!