Thank you very much for your help! Now, I can launch two cfzmqs.
After receiving the second Crazyradio, I tried to connect the two Crazyflies, but unfortunately, I got problems with the ZMQ-server.
I am using the following library
https://github.com/fagg/matlab-zmq to establish a connection between MATLAB and ZMQ. The MATLAB functions used to communicate with cfzmq (which I has from
https://github.com/MOHAMMADZAHD93/CrzayMatlab ) are as follows:
Code: Select all
% function to start the ZMQ-client and to create sockets
function [socketcomm, socketcont, socketcomm2, socketcont2] = ZMQSERVER()
system('start cmd.exe @cmd /k "cfzmq -p 2000"')
% Command socket:
contextcomm = zmq.core.ctx_new();
socketcomm = zmq.core.socket(contextcomm, 'ZMQ_REQ');
addresscomm = 'tcp://127.0.0.1:2000';
zmq.core.connect(socketcomm, addresscomm);
% Log socket:
contextlog = zmq.core.ctx_new();
socketlog = zmq.core.socket(contextlog, 'ZMQ_SUB');
addresslog = 'tcp://127.0.0.1:2001';
zmq.core.connect(socketlog, addresslog);
zmq.core.setsockopt(socketlog,'ZMQ_SUBSCRIBE','');
% Param Socket:
contextparam = zmq.core.ctx_new();
socketparam = zmq.core.socket(contextparam, 'ZMQ_SUB');
addressparam = 'tcp://127.0.0.1:2002';
zmq.core.connect(socketparam, addressparam);
zmq.core.setsockopt(socketparam,'ZMQ_SUBSCRIBE','');
% Connection socket:
contextconn = zmq.core.ctx_new();
socketconn = zmq.core.socket(contextconn, 'ZMQ_SUB');
addressconn = 'tcp://127.0.0.1:2003';
zmq.core.connect(socketconn, addressconn);
zmq.core.setsockopt(socketconn,'ZMQ_SUBSCRIBE','');
% Control socket:
contextcont = zmq.core.ctx_new();
socketcont = zmq.core.socket(contextcont, 'ZMQ_PUSH');
addresscont = 'tcp://127.0.0.1:2004';
zmq.core.connect(socketcont, addresscont);
% second Crazyflie
system('start cmd.exe @cmd /k "cfzmq -p 3000"')
% Command socket:
contextcomm2 = zmq.core.ctx_new();
socketcomm2 = zmq.core.socket(contextcomm2, 'ZMQ_REQ');
addresscomm2 = 'tcp://127.0.0.1:3000';
zmq.core.connect(socketcomm2, addresscomm2);
% Log socket:
contextlog2 = zmq.core.ctx_new();
socketlog2 = zmq.core.socket(contextlog2, 'ZMQ_SUB');
addresslog2 = 'tcp://127.0.0.1:3001';
zmq.core.connect(socketlog2, addresslog2);
zmq.core.setsockopt(socketlog2,'ZMQ_SUBSCRIBE','');
% Param Socket:
contextparam2 = zmq.core.ctx_new();
socketparam2 = zmq.core.socket(contextparam2, 'ZMQ_SUB');
addressparam2 = 'tcp://127.0.0.1:3002';
zmq.core.connect(socketparam2, addressparam2);
zmq.core.setsockopt(socketparam2,'ZMQ_SUBSCRIBE','');
% Connection socket:
contextconn2 = zmq.core.ctx_new();
socketconn2 = zmq.core.socket(contextconn2, 'ZMQ_SUB');
addressconn2 = 'tcp://127.0.0.1:3003';
zmq.core.connect(socketconn2, addressconn2);
zmq.core.setsockopt(socketconn2,'ZMQ_SUBSCRIBE','');
% Control socket:
contextcont2 = zmq.core.ctx_new();
socketcont2 = zmq.core.socket(contextcont2, 'ZMQ_PUSH');
addresscont2 = 'tcp://127.0.0.1:3004';
zmq.core.connect(socketcont2, addresscont2);
end
Code: Select all
% function to connect
function result = ConnectCrazyzmq(socketcomm, uri)
connectcmd=['{"version": 1,"cmd": "connect","uri": "',uri,'"}'];
zmq.core.send(socketcomm, uint8(connectcmd));
pause(5)
result=char(zmq.core.recv(socketcomm,40000,'ZMQ_DONTWAIT'));
end
Code: Select all
% function to send commands
function sendcommandsCrazy(socketcont, Thrust, roll, pitch, yaw)
Msg=['{"version": 1,"roll": ',num2str(roll),',"pitch": ',num2str(pitch),...
',"yaw": ',num2str(yaw),',"thrust": ',num2str(Thrust),'}'];
zmq.core.send(socketcont, uint8(Msg));
end
Every time I get the error message "error using recv Resource temporarily unavailable" in MATLAB. This comes from the function "ConnectCrazyzmq()" in the line with "zmq.core.recv(...)". I tried many different values for 40000 and I also vary the pause, but unfortunately without success so far. I would be very pleased, if someone could help me solving this problem.
I use the URI "radio://0/80/2M" for the first and the URI"radio://1/100/2M" for the second Crazyflie. Is this correct?