Clear Filters
Clear Filters

How should I make the system object variables global?

2 views (last 30 days)
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
Suvansh Arora on 30 Nov 2022
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 on 30 Nov 2022
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();

Sign in to comment.

Answers (0)

Categories

Find more on Software Development Tools in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!