Page 1 of 1

B0 Communcation with Coppelia

Posted: 01 Sep 2020, 07:35
by macieksz@pro.onet.pl
Hello,

I tried to use B0Demo Scene and write a publisher using B0 in c++, they communicate but the unpacking in coppelia side is not correct as I send number bigger than zero from c++ B0 publisher but receive at coppelia after unpacking the same number 6.3372196379419e-10. Check the code used below. Can you please advise me?

C++ code:
static float i = 0;
std::string msg = std::to_string(i++);
pub.publish(msg);


Lua coppelia side:
function number_callback(msg)
local number=sim.unpackFloatTable(msg)[1]
end
sub_number=simB0.subscriberCreate(b0Node,numberTopicNumber,'number_callback')

simB0.subscriberDestroy(sub_number)

Re: B0 Communcation with Coppelia

Posted: 01 Sep 2020, 07:51
by macieksz@pro.onet.pl
I have another case as well (most probably the same reason):
if I use in :
C++:
static int i = 0;
Coppelia:
local number=sim.unpackUInt16Table(msg)[1]

I see numbers different than I am sending from the publisher

Re: B0 Communcation with Coppelia

Posted: 01 Sep 2020, 11:40
by macieksz@pro.onet.pl
ROS has concept of actions which service(request and reply) but with feedback especially in long-time taking processes like motion of robot. Does B0(ZeroMQ) has a this concept or have to implement it by ourselves?

Re: B0 Communcation with Coppelia

Posted: 01 Sep 2020, 14:20
by coppelia
Hello,

when unpacking a float (or double or int) on the CoppeliaSim side, it will do a binary unpacking, i.e. you will also to binary pack the value on the c/c++ side, e.g.

Code: Select all

float i=0.0f;
std::string msg((char*)&i,sizeof(i));
pub.publish(msg);
You can directly use the ROS or ROS2 interafce, or the BlueZero interface, which also has a service call mechanism.

Cheers

Re: B0 Communcation with Coppelia

Posted: 02 Sep 2020, 09:06
by macieksz@pro.onet.pl
How to do the binary unpacking on C++ server side if I am sending float from VREP client:
for example I used atof(req.c_str()) but did not work as expected but we have to unpack 100,000 points of ptcloud. what is the best method to unpack?

Re: B0 Communcation with Coppelia

Posted: 03 Sep 2020, 14:44
by coppelia
The unpacking on the C/C++ side is quite similar, e.g.:

Code: Select all

std::string msg; // containing the packed data
std::vector<float> floatData;
for (size_t i=0;i<msg.size()/sizeof(float);i++)
    floatData.push_back((float*)(&msg[0]+sizeof(float)*i));
Cheers