Problem about sim.getStringSignal

Typically: "How do I... ", "How can I... " questions
Post Reply
Beiguagua
Posts: 24
Joined: 10 Feb 2023, 02:09

Problem about sim.getStringSignal

Post by Beiguagua »

Hello,
I wrote the following code in the arm's child script

Code: Select all

stringSignalName='/IRB4600_executedMovId'
sim.setStringSignal(stringSignalName,'ready')
I write the following code in c++, I get an error when I run it

Code: Select all

std::string signalName = "/IRB4600_executedMovId";
auto tmp = sim.getStringSignal(signalName);

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

Re: Problem about sim.getStringSignal

Post by coppelia »

Hello,

what does the error say?

Cheers

Beiguagua
Posts: 24
Joined: 10 Feb 2023, 02:09

Re: Problem about sim.getStringSignal

Post by Beiguagua »

coppelia wrote: 08 Mar 2023, 11:51 Hello,

what does the error say?

Cheers
Thanks for your reply.
The error say, Unhandled exception at 0x00007FFE2A2BCD29 in BinPacking.exe: Microsoft C++ exception: jsoncons::conv_error at memory location 0x000000282590E0E0.

Thanks.

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

Re: Problem about sim.getStringSignal

Post by coppelia »

Does this produce an error?

Code: Select all

int main()
{
    RemoteAPIClient client;
    auto sim = client.getObject().sim();
    std::string signalName = "/IRB4600_executedMovId";
    auto tmp = sim.getStringSignal(signalName);
    return 0;
}
Cheers

Beiguagua
Posts: 24
Joined: 10 Feb 2023, 02:09

Re: Problem about sim.getStringSignal

Post by Beiguagua »

coppelia wrote: 14 Mar 2023, 07:47 Does this produce an error?

Code: Select all

int main()
{
    RemoteAPIClient client;
    auto sim = client.getObject().sim();
    std::string signalName = "/IRB4600_executedMovId";
    auto tmp = sim.getStringSignal(signalName);
    return 0;
}
Cheers
Hello,
Whether I need to start emulation?
When I didn't start the simulation, the error was, Unhandled exception at 0x00007FFE2A2BCD29 in BinPacking.exe: Microsoft C++ exception: jsoncons::json_runtime_error<std::out_of_range,void> at memory location 0x0000004FB491E5C8.
When I start the simulation, the error was, Unhandled exception at 0x00007FFE2A2BCD29 in BinPacking.exe: Microsoft C++ exception: jsoncons::conv_error at memory location 0x000000B519B1E270.
In coppeliasim, I wrote the following code in the sysCall_init function of the IRB4600 child script.

Code: Select all

stringSignalName='/IRB4600_executedMovId'
sim.setStringSignal(stringSignalName,'ready')

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

Re: Problem about sim.getStringSignal

Post by coppelia »

Hello,

actually you are right, there is a bug with that function. That function is special since its script counterpart can return nil (when the signal is not defined), or a string/buffer (when the signal is defined). That cannot easily be automatically translated to c++ via the generator tool. We have pushed a fix to zmqRemoteApi, but you may as well simply replace the function definition in RemoteAPIObjects.cpp with following:

Code: Select all

    std::vector<uint8_t> sim::getStringSignal(std::string signalName,bool* validSignal/*nullptr*/)
    {
        std::vector<uint8_t> retVal;
        auto r = this->_client->call("sim.getStringSignal", {signalName.c_str()});
        if (r.empty())
        {
            if (validSignal!=nullptr)
                validSignal[0]=false;
        }
        else if(r[0].is_string())
        {
            if (validSignal!=nullptr)
                validSignal[0]=true;
            std::string r2=r[0].as<std::string>();
            retVal.assign(r2.begin(),r2.end());
        }
        else if(r[0].is_byte_string())
        {
            if (validSignal!=nullptr)
                validSignal[0]=true;
            retVal=r[0].as<std::vector<uint8_t>>();
        }
        else
        {
            if (validSignal!=nullptr)
                validSignal[0]=false;
        }
        return retVal;
    }
If the signal is printable, the use e.g. following:

Code: Select all

    std::vector<uint8_t> sig = sim.getStringSignal("testSignal");
    printf("Signal: %s\n",std::string(sig.begin(),sig.end()).c_str());
Cheers

Post Reply