Ask Your Question
0

Why my publisher node stops when subscriber node start?

asked 2019-06-11 22:40:15 -0500

ZazAa gravatar image

updated 2019-06-12 00:33:17 -0500

jayess gravatar image

Hi all,

I currently working on creating a GPR system based on Walabot sensor. The data that I want to publish is the raw signal from Walabot which consist of two-row array of amplitude and timeaxis value with 4096 columns for each row. Hence, using float32multiarray i was hoping that i could send the array over to subscriber node for signal processing. I followed the normal procedure of roscore -> publisher -> subscriber.

As soon as I turn on subscriber, my publisher immediately stops. The frustrating part is both terminal of publisher and subscriber didn't print out want error that has happened which leads to more confusion.

I have tested the way is publish and subscribe to Float32MultiArray message type using simple array. The way I did work but when I do the complicated node is does not work. I included my simple publisher and subscriber that use Float32MultiArray as message type.

Here is video of my problem

Hope anyone could help in this. Thank you!

This is my publisher node.

#!/usr/bin/env python
from __future__ import print_function  # WalabotAPI works on both Python 2 an 3.
from sys import platform
from os import system
from imp import load_source
from os.path import join
import rospy
from std_msgs.msg import Float32MultiArray


modulePath = join('/usr', 'share', 'walabot', 'python', 'WalabotAPI.py')
wlbt = load_source('WalabotAPI', modulePath)

wlbt.Init()

def DataCollect():
    # wlbt.SetArenaX - input parameters
    xArenaMin, xArenaMax, xArenaRes = -10, 10, 0.5
    # wlbt.SetArenaY - input parameters
    yArenaMin, yArenaMax, yArenaRes = -10, 10, 0.5
    # wlbt.SetArenaZ - input parameters
    zArenaMin, zArenaMax, zArenaRes = 5, 11, 0.5

    # Initializes walabot lib
    wlbt.SetSettingsFolder()

    # Establish a connection between the Walabot and the computer
    wlbt.ConnectAny()

    # Set sensor profile
    wlbt.SetProfile(wlbt.PROF_SHORT_RANGE_IMAGING)
    # Set arena by Cartesian coordinates, with arena resolution
    wlbt.SetArenaX(xArenaMin, xArenaMax, xArenaRes)
    wlbt.SetArenaY(yArenaMin, yArenaMax, yArenaRes)
    wlbt.SetArenaZ(zArenaMin, zArenaMax, zArenaRes)
    wlbt.SetThreshold(50)

    # Set filtering to none
    wlbt.SetDynamicImageFilter(wlbt.FILTER_TYPE_NONE)

    pair = wlbt.GetAntennaPairs()

    # Start the Walabot device
    wlbt.Start()

    pub = rospy.Publisher('rawSignal', Float32MultiArray, queue_size=1000)
    rospy.init_node('walabotRawSignal', anonymous=False)


    while not rospy.is_shutdown():
        rospy.sleep(2.0)
        try:
            wlbt.Trigger()
            targets = wlbt.GetSignal((pair[4]))
            rawSignalArray = Float32MultiArray(data=targets)
            pub.publish(rawSignalArray)
            rospy.loginfo(rawSignalArray)
        except rospy.ROSInterruptException:
            pass

    wlbt.Stop()
    wlbt.Disconnect()
    print("Terminate successfully")

if __name__ == '__main__':
    DataCollect()

This is my subscriber node:

#!/usr/bin/env python
import rospy
from std_msgs.msg import Float32MultiArray

def callback(data):
    rospy.loginfo(data.data)

def processRawSignal():
    rospy.init_node('processRawSignal', anonymous=True)
    rospy.Subscriber("rawSignal", Float32MultiArray, callback)
    rospy.spin()

if __name__ == '__main__':
    processRawSignal()

My simple testing of using Float32MultiArray message in Publisher and Subscriber Publisher:

#!/usr/bin/env python

import rospy
from std_msgs.msg import Float32MultiArray

def talker():
    pub = rospy.Publisher('chatter', Float32MultiArray, queue_size=1000)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        hello_str = [1,2,3,4,5]
        array = Float32MultiArray(data=hello_str)
        rospy.loginfo(array)
        pub.publish(array)
        rate.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

Subscriber:

#!/usr/bin/env python
import ...
(more)
edit retag flag offensive close merge delete

Comments

The publisher also stop when I use rostopic echo

ZazAa gravatar imageZazAa ( 2019-06-11 22:43:41 -0500 )edit

What is a "GPR system?"

jayess gravatar imagejayess ( 2019-06-12 00:35:01 -0500 )edit

ground penetrating radar system

ZazAa gravatar imageZazAa ( 2019-06-12 01:01:25 -0500 )edit
3
rawSignalArray = Float32MultiArray(data=targets)

what is the contents of targets? Float32MultiArray is not a simple msg, it needs all of its fields properly setup for it to work. Refer to the documentation. Only setting data is probably not going to work.

Please also note: usage of msgs from std_mgs is discouraged. It would be better to use a more semantically meaningful message type (a Float32MultiArray could carry anything, not just a scan of a GPR sensor).

gvdhoorn gravatar imagegvdhoorn ( 2019-06-12 02:33:05 -0500 )edit

Thank you for your reply.

targets is a arrray with 2 rows * 4096 columns of data with raw signal amplitude and time (nanoseconds).

I just notice that when I add another row to my simple publisher, the same problem happens. It is probably because the way I setting the publisher and I also don't really know how to properly subscribe to it either. I have tried the documentation before this but I don't know how to set the parameter as it has parameters inside parameters.

Yeah I'm kinda new in using ros and a terrible programmer. I just wanted to publish a 2*4096 array. I thought Float32MultiArray would do the trick since there isn't other message type that could carry array. Float32MultiArray seems doesn't have many documentation on it in the internet which makes it even harder for me to properly set it up.

ZazAa gravatar imageZazAa ( 2019-06-12 12:20:06 -0500 )edit
1

There are a few Q&As that deal with *MultiArray messages. Most are C++ though, so you'll have to adapt a bit. See #q234028 for one such question.

You must initialise the various fields properly. Otherwise it probably won't work.

gvdhoorn gravatar imagegvdhoorn ( 2019-06-12 12:47:30 -0500 )edit

Yeah that's the problem. I'm pretty weak in C++. I looking for a python alternative. While I have the chance, can I ask regarding the question that you just suggested. Since I'm just gonna post 2*4096 array of amplitude value and time, do I need to define the stride? What is stride anyway? I think I getting the idea but I can't wrapped my head around the 'stride' and this code here. Is it necessary to go through row by row and col by col?

dat.layout.dim[0].stride = H*W;
dat.layout.dim[1].stride = W;
dat.layout.data_offset = 0;
std::vector<int> vec(W*H, 0);
for (int i=0; i<H; i++)
    for (int j=0; j<W; j++)
        vec[i*W + j] = array[i][j];
dat.data = vec;
ZazAa gravatar imageZazAa ( 2019-06-12 12:56:00 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-06-17 12:37:01 -0500

ZazAa gravatar image

The cause to my problem is that my publishing message doesn't have the same row of array as my subscriber's. Hence, the node stop. To solve this, experts advised my to make custom message to carry the message that I want. I created msg file to carry two array that I want and it works. I would advise the readers to do the same to avoid from being frustrated in using Float32MultiArray like me. Just do custom message. Don't think too much about it. Goodluck!

edit flag offensive delete link more

Comments

2

I would advise the readers to do the same to avoid from being frustrated in using Float32MultiArray like me.

That was not why we suggested you use a custom message.

Just do custom message. Don't think too much about it.

In fact: future readers: please do think about it.

Designing messages is not to be taken lightly, as it can significantly affect the consumers of your datastreams.

gvdhoorn gravatar imagegvdhoorn ( 2019-06-17 13:07:21 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-06-11 22:34:04 -0500

Seen: 223 times

Last updated: Jun 17