How should I make the system object variables global?

조회 수: 1 (최근 30일)
Farzad Torabi
Farzad Torabi 2022년 11월 24일
댓글: Farzad Torabi 2022년 11월 30일
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
Suvansh Arora
Suvansh Arora 2022년 11월 30일
In order to understand this better, I would need your help with the following information:
  • How can I reproduce this issue at my end.
  • Brief description of problem statement you are trying to solve.
Farzad Torabi
Farzad Torabi 2022년 11월 30일
dear Suvansh
I doubt about reproducing, you need to have CoppeliaSim software too. EDU or paid version. but anyhow, I found the solution : I had to add obj before client to make it global. it resolved on matlab side. but I need to resolve the other part which is the integration and stepping. It looks like that when I use the function ApplyControl, I have to use the obj.client.step() repeatedly, but wherever I put it, the connection between Matlab and CoppeliaSim is lot after the first increment
obj.client = RemoteAPIClient();

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by