ZeroMQ for Matlab with OOP error

Typically: "How do I... ", "How can I... " questions
Post Reply
Fery64
Posts: 88
Joined: 02 Feb 2022, 15:58

ZeroMQ for Matlab with OOP error

Post by Fery64 »

Hi All

I am changing my code from remAPI to ZeroMQ and I am facing an error when I try to write it in Object Oriented Programming style

Code: Select all

classdef VrepConnectorZMQ


    properties
        sim;				%Similar to fd
        client;			%Used for server connection and server requests
        robot_joints = []	%List of joint handles
        		%Integration step used for simulation
    end

    methods

        function obj = VrepConnectorZMQ()
            addpath vrep_lib/;						%Adding the APIs to the path
            client = RemoteAPIClient();
            client.setStepping(true);               	
            obj.sim = client.getObject('sim');			%RemoteAPI object
            obj.sim.startSimulation();

            for i = 1:7 
                [~,obj.robot_joints(i)] = obj.sim.getObject(strcat('/LBR_iiwa_14_R820_joint',int2str(i)));
            end
        
            for i = 1:7
                [~, joint_pos] = obj.sim.simxGetJointPosition(obj.clientID, obj.robot_joints(i), obj.sim.simx_opmode_streaming);
            end
            % When simulation is not running, ZMQ message handling could be a bit
            % slow, since the idle loop runs at 8 Hz by default. So let's make
            % sure that the idle loop runs at full speed for this program:
            defaultIdleFps = sim.getInt32Param(sim.intparam_idle_fps);
            sim.setInt32Param(sim.intparam_idle_fps, 0);
        end

        function q = GetState(obj)
            q = zeros(7,1);
            for i=1:7
                [~, q(i)] = obj.sim.simxGetJointPosition(obj.robot_joints(i));
            end
        end



    end
end
The error I get in Matlab is :

Code: Select all

Output argument "varargout{2}" (and possibly others) not assigned a value in the execution with "RemoteAPIObject/subsref"
function.

Error in VrepConnectorZMQ (line 21)
                [~,obj.robot_joints(i)] = obj.sim.getObject(strcat('./LBR_iiwa_14_R820_joint',int2str(i)));

Error in main (line 78)
robot = VrepConnectorZMQ();
 


I should add that it is not clear, how to install the ZeroMQ library on Matlab from the link https://www.coppeliarobotics.com/helpFi ... erview.htm
It is only mentioned what to do for Octave , and I had to copy and paste the files RemoteAPIObject.m and cbor.m and RemoteAPIClient.m to the running directory. But only out of guessing. Should I add it to another certain directory that is not explained in help?

fferri
Posts: 1309
Joined: 09 Sep 2013, 19:28

Re: ZeroMQ for Matlab with OOP error

Post by fferri »

What are you trying to do with this
Fery64 wrote: 20 Nov 2022, 17:46

Code: Select all

[~,obj.robot_joints(i)] = obj.sim.getObject(strcat('/LBR_iiwa_14_R820_joint',int2str(i)));
line of code? sim.getObject returns only one value...
Fery64 wrote: 20 Nov 2022, 17:46 I should add that it is not clear, how to install the ZeroMQ library on Matlab from the link https://www.coppeliarobotics.com/helpFi ... erview.htm
It is only mentioned what to do for Octave
Looks clear to me.

It is best to add the directory containing the .m files to the MATLAB's path.
Copy/pasting code and files is not a good way of coding.

Fery64
Posts: 88
Joined: 02 Feb 2022, 15:58

Re: ZeroMQ for Matlab with OOP error

Post by Fery64 »

I am only trying to get the joint names, in order to later in the code use them to assign joint velocity. but it is not the matter now, the problem is that I get error in Matlab over the getObject command when using ZeroMQ command

and I think when I say it's not clear to me, "looks clear to me" is not a helpful answer. Shall you then explain me what exactly I should do?

fferri
Posts: 1309
Joined: 09 Sep 2013, 19:28

Re: ZeroMQ for Matlab with OOP error

Post by fferri »

There are no libraries to manually install for MATLAB.

Fery64
Posts: 88
Joined: 02 Feb 2022, 15:58

Re: ZeroMQ for Matlab with OOP error

Post by Fery64 »

Why do I get this error? Shall you help with this? this is the main topic of my question :

Code: Select all

Output argument "varargout{2}" (and possibly others) not assigned a value in the execution with "RemoteAPIObject/subsref"
function.

Error in VrepConnectorZMQ (line 21)
                [~,obj.robot_joints(i)] = obj.sim.getObject(strcat('./LBR_iiwa_14_R820_joint',int2str(i)));

Error in main (line 78)
robot = VrepConnectorZMQ();

fferri
Posts: 1309
Joined: 09 Sep 2013, 19:28

Re: ZeroMQ for Matlab with OOP error

Post by fferri »

I've already answered to you about that: sim.getObject returns only one value. Therefore don't try to assign multiple values to the result of it.

Have also a look at the examples: https://github.com/CoppeliaRobotics/zmq ... ts/matlab/

Post Reply