Problem with simROS.subscribe

Typically: "How do I... ", "How can I... " questions
Post Reply
pme1976
Posts: 19
Joined: 07 Feb 2018, 18:06

Problem with simROS.subscribe

Post by pme1976 »

Hello. I have created node (in python) that publishes messages nav_msgs/Odometry. In my CoppeliaSim model there is child script for receiving this messages:

Code: Select all

function atlans_callback(msg)
    local t = simROS.getTime()
    if file_sub~=nil then    
        file_sub:write(tostring(t)..' '..tostring(msg.header.stamp)..'\n')            
    end
end

function sysCall_init()
    local SUBSCRIBE_FILE_NAME = '/path/to/file/subscribe.txt'
    atlans_subscriber = simROS.subscribe('/atlans/odometry', 'nav_msgs/Odometry', 'atlans_callback', 1)
    simROS.subscriberTreatUInt8ArrayAsString(atlans_subscriber)
    file_sub = io.open(SUBSCRIBE_FILE_NAME,'w')
end

function sysCall_cleanup()
    if file_sub ~= nil then
        file_sub:close()
    end  
end
The frequency the node publishes messages is 100 Hz. I expect the differences of neaby entries in the file to be about 0.01. But the value jumps from 1E-4 to 0.05. What is the cause of this problem?

fferri
Posts: 1229
Joined: 09 Sep 2013, 19:28

Re: Problem with simROS.subscribe

Post by fferri »

But the value jumps from 1E-4 to 0.05. What is the cause of this problem?
which value?

pme1976
Posts: 19
Joined: 07 Feb 2018, 18:06

Re: Problem with simROS.subscribe

Post by pme1976 »

"the differences of neaby entries in the file". The value: t_ros_(i+1)-t_ros_(i).

fferri
Posts: 1229
Joined: 09 Sep 2013, 19:28

Re: Problem with simROS.subscribe

Post by fferri »

You write two values in the file.

Which one are you referring to? The one rerturned by simROS.getTime() or the one in msg.header.stamp?

pme1976
Posts: 19
Joined: 07 Feb 2018, 18:06

Re: Problem with simROS.subscribe

Post by pme1976 »

Hi, fferri. Sorry for my stupidity. The frequency of callback function calling is interesting for me (simROS.getTime()). I wrote a Python node that subscribing to the topic. The problem remained. The frequency of receiving messages is several times less than 100 Hz. As I understand it, the problem is described in https://stackoverflow.com/questions/408 ... g-messages. Its solution is that the tcp_nodelay parameter in the rospy.Subscriber constructor have to be set to True. However, this parameter is not present in the ROS plugin for Coppeliasim.

fferri
Posts: 1229
Joined: 09 Sep 2013, 19:28

Re: Problem with simROS.subscribe

Post by fferri »

I added a transport_hints param to simROS.subscribe. You can use it as:

Code: Select all

sub=simROS.subscribe('/atlans/odometry','nav_msgs/Odometry','callback',1,{tcpNoDelay=true})
but I don't think that is going to make a difference, as -according to ROS documentation- the tcpNoDelay hint only affects the latency of the connection.

Also, your target rate of 100Hz depends on how heavy the simulation it is, as ros::spinOnce is called in the main simulation loop (in the instancepass event).

pme1976
Posts: 19
Joined: 07 Feb 2018, 18:06

Re: Problem with simROS.subscribe

Post by pme1976 »

Hi, fferri. Thank you so much.

Post Reply