- 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
조회 수: 13 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Vinod
2015년 11월 24일
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
Vinod
2015년 11월 25일
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
2020년 3월 2일
Try adding flushinput(obj.u_in); before each new fread. I had similar problems, and clearing the buffer helped.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Input and Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!