Node for Publishing csv file and node to subscribe [closed]

asked 2020-06-24 05:24:10 -0600

subarashi gravatar image

Dear community. I hope you all doing well. I am developing a big project using ROS and Raspberry pi. I have one Raspberry pi as a master and two raspberry pi as slaves. So in the Raspi Master, I upload a CSV file containing something like this

  • No;Material;Task
  • 1;Hola;Cebo
  • 2;Hola;Cebo52
  • 3;Hola;Cebo25
  • 4;Hola2;Cebo2
  • 5;Hola;Cebo53
  • 6;Hola;Cebo54

So, the first node must publish the data of the CSV file. If the "Material" is "Hola" then publish "Cebo" with TOPIC1 in otherwise if the "Material" is "Hola2" then publish "Cebo2" with TOPIC2.

The second node must subscribe from the previous node and publish for rosserial Arduino.

My problem now is when I publish the CSV file, the subscriber(which is subscribing only to TOPIC1) receives the second line and not the first line. I do not know why. Please take a look at my code. Btw, after read the CSV the publisher node must stop publishing.

#!/usr/bin/env python
import serial
import rospy
import csv
import os
import rospkg
from std_msgs.msg import String
from time import sleep

rospack = rospkg.RosPack()

def Assignment_of_task():
      with open(rospack.get_path('haive_project')+'/script/test_2.csv','r') as csv_file:
             csv_reader = csv.DictReader(csv_file)
             for line in csv_reader:
                  if line['Material'] == 'Hola':
                     command = line['command']

if __name__ == '__main__':
     rospy.init_node('Selector_node', anonymous=True)
     pub = rospy.Publisher('Assigning_task', String, queue_size=10)
     rate = rospy.Rate(10)
     except rospy.ROSInterruptException:

#!/usr/bin/env python
import serial
import rospy
from std_msgs.msg import String
from time import sleep

class Haive_1001(object):
  def __init__(self):
      self.sub = rospy.Subscriber("Assigning_task", String, self.callback)
      self.haive1001 = String()

  def callback(self, coordinates):

      self.haive1001 = coordinates

if __name__ == "__main__":
    rospy.init_node('Haive_1001_node', anonymous=True)
    pub = rospy.Publisher('data_for_Arduino_DUE', String, queue_size=10)
    rate = rospy.Rate(10) # 10hz
    haive_class = Haive_1001()
edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by subarashi
close date 2020-09-14 05:52:08.714295


Are you sure that your subscriber is correctly subscribed to the topic before the publisher sends the first message? Is the first message being published in the topic? I have faced some problems with synchronization in both sides, either the subscriber not yet subscribed to the topic when you start sending messages, either the topic is not correctly initialized when the publisher starts sending messages. I would check this, and also I would try to play with queue_size. Try to set it to one.

Mermy gravatar image Mermy  ( 2020-07-27 08:58:54 -0600 )edit