B0 Communcation with Coppelia

Typically: "How do I... ", "How can I... " questions
Post Reply
macieksz@pro.onet.pl
Posts: 16
Joined: 28 Jan 2018, 08:21

B0 Communcation with Coppelia

Post 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)

macieksz@pro.onet.pl
Posts: 16
Joined: 28 Jan 2018, 08:21

Re: B0 Communcation with Coppelia

Post 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

macieksz@pro.onet.pl
Posts: 16
Joined: 28 Jan 2018, 08:21

Re: B0 Communcation with Coppelia

Post 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?

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

Re: B0 Communcation with Coppelia

Post 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

macieksz@pro.onet.pl
Posts: 16
Joined: 28 Jan 2018, 08:21

Re: B0 Communcation with Coppelia

Post 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?

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

Re: B0 Communcation with Coppelia

Post 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

Post Reply