Publisher node for Flaot64MultiArray message type does not publish to subscriber node

asked 2022-02-08 22:29:42 -0500

distro gravatar image

updated 2022-02-09 03:44:20 -0500

I made a test code to see if a node I create actually publishes Float64MultiArray message type to my created topic zones. When I run my publisher node as can be seen in my repo here, and I rostopic echo /zones I see that the topic has been created and is being published to. The code seen below has the test subscriber node and when ran does what it's supposed to do(which is to subscribe to zones). It also succesfully subscribes o the topic.

#!/usr/bin/python3
import rospy
from std_msgs.msg import Float64MultiArray
from rospy.numpy_msg import numpy_msg
import numpy as np

#v=Float64MultiArray()
#def callback(msg):

class num:
    def __init__(self):
        self.data=Float64MultiArray()
        self.doen=[0,0]
    def callback(self,msg):
        #print(msg)
        self.doen=[msg.data[0],msg.data[1]]
        #print(msg.data[0])
        #print(self.data.data[0])

    def get_it_done(self):
        rospy.init_node("array_listener")
        #v=rospy.wait_for_message("zones",Float64MultiArray)
        rospy.Subscriber("zones",Float64MultiArray,self.callback)
        #rospy.spin()
        while not rospy.is_shutdown():
            print(self.doen)


regis=num()
regis.get_it_done()

I have thus tried to use this concept for the actual code I'm working on. I even used the same callback I used as seen above. For whatever reason though, the publisher node for zones topic is unable to communicate with the sybscriber node. m rqt_graph shows that my subcriber node is not subscribed at all. I have no clue why please see the script that contains my subscriber node in my repo here. To not waste time, please focus on the callback function choose_marker. and the segment of code in the function ArnoldLogistic_coverage, that's giving me the issue:

m_storage = n_storage+1
            print("new set")
            if self.memory>40:
                print("map_zoner")
                print("data_to_send", data_to_send)
                self.goal.pose.position.x = self.data_to_send[0]
                self.goal.pose.position.y = self.data_to_send[1]
                self.pub.publish(self.goal)
                rospy.sleep(0.5)
                reach = len(self.route)
                while reach >= 19:  # 19
                    self.pub.publish(self.goal)
                    rospy.sleep(0.5)
                    reach = len(self.route)
                    print("reach: ", reach)

The error that runs when the if statement is satisfied is an indexError that states that self.data to send is still an empty list(because the nodes aren't communicating). My rqt_graph also shows no communication. I have no clue whats going on. I had thought the issue was perhaps I was running the both nodes under the same launch file. separating them did nothing.

edit retag flag offensive close merge delete

Comments

I am unclear as to what your error is? I tried to clone your repo and launch (following instructions in your readme and installing a bunch of packages I was missing). Gazebo seems to launch fine and so does RVIZ and the robot is moving. The only discrepancy is that the laser data and map do not align and the robot is never able to get to its goal. To fix that you must define a transform from odom to map frame.

Akhil Kurup gravatar image Akhil Kurup  ( 2022-02-08 23:12:51 -0500 )edit

Please elaborate as to which subscriber node (name) is having the issue

Akhil Kurup gravatar image Akhil Kurup  ( 2022-02-08 23:13:31 -0500 )edit

@Akhil Kurup I have never had an issue with my laser data and map. Not sure what you particular issue is with that. My rviz and gazebo run just fine. My code is what the issue is here. Maybe I'm confused by your inquiry could you please elaborate?

distro gravatar image distro  ( 2022-02-09 03:20:27 -0500 )edit

@Akhil Kurup The name of the node is controller_3 as seen in the driver() function. The node publishes and subscribes to various topics

distro gravatar image distro  ( 2022-02-09 03:22:42 -0500 )edit

@Akhil Kurup My repo isnt really meant to be cloned right now as I still have a bunch of things in my codes I need to update or fix. Maybe thats whats giving you issues. It might be easier to look at the codes I sent in the links to see if I'm doing something wrong. A second eye is what I need. The publisher is found in the script map_zoner.py the subscriber is found in the script class_arnoldLogistic. I already have the links in my question.

distro gravatar image distro  ( 2022-02-09 03:42:50 -0500 )edit