- How can I reproduce this issue at my end.
- Brief description of problem statement you are trying to solve.
How should I make the system object variables global?
    3 views (last 30 days)
  
       Show older comments
    
Hi all
I am writing a program in Matlab mfiles that has to run a third party software, CoppeliaSim. I write it in Object Oriented Programming in Matlab. I defined a class in a file and call the functions from the main file. the problem is the command 
obj.client.step() 
Because I have to define it in the first functions VrepConnectorZMQ, but I need to call it again in the ApplyControl function to use it in every loop for each step. in this case , I get the error :
Dot indexing is not supported for variables of this type.
So what should I do? it looks like calling a method of a method is not possible in Matlab! Am I right? 
How should I make the variable sim and client global?
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
        joint_pos=[];
    end
    methods
function obj = VrepConnectorZMQ()
            addpath("C:\Program Files\CoppeliaRobotics\CoppeliaSimEdu\programming\zmqRemoteApi\clients\matlab")
            javaaddpath('C:\Program Files\CoppeliaRobotics\CoppeliaSimEdu\programming\zmqRemoteApi\clients\matlab\jeromq.jar')
            client = RemoteAPIClient();
            client.setStepping(true);
            obj.sim = client.getObject('sim');			%RemoteAPI object
            obj.sim.startSimulation()
            obj.client.step();
            for i = 1:7 
                obj.robot_joints(i) = obj.sim.getObject(strcat('/LBR_iiwa_14_R820_joint',int2str(i)));
            end
            for i = 1:7
                obj.joint_pos(i) = obj.sim.getJointTargetPosition(obj.robot_joints(i));
            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 ApplyControl(obj, u,steptime)
            startTime = obj.sim.getSimulationTime();
            t = startTime;
            while t<steptime
                for i = 1:7
                    obj.sim.setJointTargetVelocity(obj.robot_joints(i), u(i));
                end
                t = obj.sim.getSimulationTime();
            end
        end
2 Comments
  Suvansh Arora
    
 on 30 Nov 2022
				In order to understand this better, I would need your help with the following information:
Answers (0)
See Also
Categories
				Find more on Startup and Shutdown in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
