Matlab + legacyAPI cannot control script

Report crashes, strange behaviour, or apparent bugs
Post Reply
coppeliarmus
Posts: 3
Joined: 25 Aug 2024, 22:49

Matlab + legacyAPI cannot control script

Post by coppeliarmus »

Hi thanks to all for this awesome software, i am using coppeliasim edu 4.7.0 with matlab on windows.
i am able to connect and use the api to control the movements of joints and get the handles of the joints.
whenever i try to use the simxCallScriptFunction i get an error in coppeliasim saying that the script does not exists.
This is my code to get the handle for the main object

Code: Select all

[app.youBotHandle, rc] = app.getHandle('youBot');
            if rc == app.sim.simx_return_ok
                disp('youBot handle retrieved successfully.');
            else
                disp('Failed to retrieve youBot handle.');
            end
And this is the function is use to try to call the function printMessage from matlab

Code: Select all

function callYouBotScriptFunction(app)
            if app.clientID > -1 && app.youBotHandle > -1
        [returnCode, outInts, outFloats, outStrings, outBuffer] = app.sim.simxCallScriptFunction(...
            app.clientID, app.youBotHandle, app.sim.sim_scripttype_childscript, ...
            'printMessage', [], [], [], [], app.sim.simx_opmode_blocking);

        if returnCode == app.sim.simx_return_ok
            disp('Successfully called printMessage function using object handle.');
        else
            disp(['Failed to call printMessage function. Return code: ', num2str(returnCode)]);
        end
    else
        disp('Cannot call script function, handle or connection invalid.');
    end
        end
And this is my script in coppeliaSim

Code: Select all

function sysCall_init()
    sim = require('sim')

    -- do some initialization here
end

function printMessage(inInts, inFloats, inStrings, inBuffer)
    sim.addLog(sim.verbosity_scriptinfos, 'Hello from the child script!')
    -- You can also return values if needed
    return {}, {}, {"Message received and processed."}, ''
end
function sysCall_actuation()
    -- put your actuation code here
end

function sysCall_sensing()
    -- put your sensing code here
end

function sysCall_cleanup()
    -- do some clean-up here
end

-- See the user manual or the available code snippets for additional callback functions and details
Image
and this is the error i am getting in the log of coppeliasim:
"External call to simCallScriptFunction failed('printMessage@youbot'):script does not exist

i dont understand what am i doing wrong.

thanks in advance for your help

coppelia
Site Admin
Posts: 10504
Joined: 14 Dec 2012, 00:25

Re: Matlab + legacyAPI cannot control script

Post by coppelia »

Hello,

the legacy remote API that you are using is deprecated since a while. Try using the ZeroMQ remote API instead.

cheers

coppeliarmus
Posts: 3
Joined: 25 Aug 2024, 22:49

Re: Matlab + legacyAPI cannot control script

Post by coppeliarmus »

coppelia wrote: 26 Aug 2024, 07:23 Hello,

the legacy remote API that you are using is deprecated since a while. Try using the ZeroMQ remote API instead.

cheers
Thanks for your reply, i have indeed tryied.
Just inserted a connect button in a pretty empty app canvas, and it said it was connected.
but after a few seconds i got this message popping up on the sim.
Image

i have tested it also with a new sim instance but always getting that message.

could please helpout on this.

coppelia
Site Admin
Posts: 10504
Joined: 14 Dec 2012, 00:25

Re: Matlab + legacyAPI cannot control script

Post by coppelia »

What command exactly did you execute on MATLAB side for that message to display? How can I reproduce this?

Cheers

coppeliarmus
Posts: 3
Joined: 25 Aug 2024, 22:49

Re: Matlab + legacyAPI cannot control script

Post by coppeliarmus »

Sorry about the late reply, as it seems something was wrong with my scene.
I tested again with a fresh scene loaded, and the ZMQ connection was working perfectly.
Unfortunately i do not have the incriminated scene file anymore.
Sorry for the late reply again.

Post Reply