simxGetIntSignal C++ API function with simxDefaultSubscriber to

Typically: "How do I... ", "How can I... " questions
Post Reply
Florent
Posts: 14
Joined: 20 Mar 2020, 23:22

simxGetIntSignal C++ API function with simxDefaultSubscriber to

Post by Florent »

Hello,

I am developping a project to control a scene using the C++ API. In my scene I have several laser sensor and I want to get the values of the sensors using the simxGetIntSignal function. As topic, I use simxDefaultSubscriber. Here is roughly the way I am doing it:

Code: Select all


b0client->simxGetIntSignal("LaserSensor1", b0client->simxDefaultSubscriber(getSignals_CB));
b0client->simxGetIntSignal("LaserSensor2", b0client->simxDefaultSubscriber(getSignals_CB));
//etc...

//CallBack function
void getSignals_CB(std::vector<msgpack::object>* msg)
{
    b0client->print(msg);
    //Do stuff depending on the signal source
}

The problem here is that 1 callback function is used for 1 signal. When the callback is called, i don't know to which signal it refers.
How can I do to use a generic callback function and then use like a "switch(SignalSource)" inside to do something depending on the signal?
Is there a way to "upgrade" the callback function for knowing the signal source?
Or do I have to write a callback function for each signal?

Thanks a lot,

Florent Pausé

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

Re: simxGetIntSignal C++ API function with simxDefaultSubscriber to

Post by coppelia »

Hello Florent,

using the B0-based remote API, you have several possibilities:
  • you can use a callback for each signal as you mentioned it
  • you can use a string signal that codes all sensor values inside of the same signal, e.g. sim.setStringSignal('sensors',sim.packFloatTable(sensorReadings)). You'll have to unpack the string signal on the client side however.
  • but most flexible is probably to call a script function via simxCallScriptFunction: the called function can then perform some basic task (i.e. no lengthly operations though) and return the desired set of data to the called. That function can also be called in a streaming operations.
Cheers

Post Reply