ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

[message_filters, Noetic, move_base]The callback function is not reached by message_filters.

asked 2022-12-07 21:34:04 -0500

donguri gravatar image

updated 2023-06-18 09:44:05 -0500

lucasw gravatar image

I am trying to use message_filters to use GPS and move_base status topic at the same time.

Below is the current test-cord.

No error is output, but the robot does not move because the callback function is not reached.

Do you know what could be causing this?

#! /usr/bin/env python3

import rospy
from geometry_msgs.msg import PoseStamped
#import tf
from sensor_msgs.msg import NavSatFix
import numpy as np
import math
import time
from geometry_msgs.msg import Quaternion
from calcxy import calc_xy
from actionlib_msgs.msg import GoalStatusArray
import message_filters

# Define publisher, subscriber topic name
DEFAULT_SUBSCRIBER_TOPIC_0 = "/ublox/fix" 
DEFAULT_SUBSCRIBER_TOPIC_1 = "/move_base/status" 


class Goal:

    #initialization
    def __init__(self):
        rospy.init_node('message_filters_test', anonymous=True)
        self.ps_pub = rospy.Publisher('move_base_simple/goal', PoseStamped, queue_size=1)

        # From ROS parameter (set in launch file)
        subscriber_topic_0 = rospy.get_param("~subscriber_topic_0", DEFAULT_SUBSCRIBER_TOPIC_0)
        subscriber_topic_1 = rospy.get_param("~subscriber_topic_1", DEFAULT_SUBSCRIBER_TOPIC_1)

        # Creating subscriber, subscribe (recieve) from topic
        # message_filters version
        self.sub_0 = message_filters.Subscriber(subscriber_topic_0, NavSatFix)
        self.sub_1 = message_filters.Subscriber(subscriber_topic_1, GoalStatusArray)

        # message_filters
        fps = 100
        delay = 1/fps*0.5
        ts = message_filters.ApproximateTimeSynchronizer([self.sub_0, self.sub_1], 10, delay)
        ts.registerCallback(self.callback)

        print("Goal.__init__")

        self.time = 0


    def callback(self, gps, robot):

        print("Goal.callback")

        if self.time == 0:
            gps_status = gps.status.status
            print("GPS_STATUS")
            print(gps_status)
            if gps.status.status == -1:
                self.time = self.time + 1
                """
                GPS Settings
                """
            else:
                pass 

        elif self.time == 1:
            self.time = self.time + 1
            """
            calculation
            """

            # mone_base_simple/goal
            rospy.sleep(1.0)

            now = rospy.Time.now()
            goal_point = PoseStamped()

            goal_point.pose.position.x = 0.5
            goal_point.pose.position.y = 0
            goal_point.pose.position.z = 0.0
            goal_point.pose.orientation.w = 1.0
            goal_point.header.stamp = now 
            goal_point.header.frame_id = 'map'

            self.ps_pub.publish(goal_point)

        elif self.time == 2:

            len_list = robot.status_list
            if len(len_list) == 1:
                robot_status = robot.status_list[0].status
                print("ROBOT_STATUS")
                print(robot_status)
                if robot_status == 3:
                    self.time = self.time + 1
                    print("SUCCESS")
                else :
                    pass
            else :
                pass

        elif self.time == 3:

            self.time = self.time + 1

            # mone_base_simple/goal
            rospy.sleep(1.0)

            now = rospy.Time.now()
            goal_point = PoseStamped()

            goal_point.pose.position.x = 1.5
            goal_point.pose.position.y = 0
            goal_point.pose.position.z = 0.0
            goal_point.pose.orientation.w = 1.0
            goal_point.header.stamp = now 
            goal_point.header.frame_id = 'map'

            self.ps_pub.publish(goal_point)

        else:
            pass


        #robot_status=robot.header.seq
        #print(robot_status)


if __name__ == '__main__':


    try:
        set_goal_node = Goal()
        print("__name__")
        rospy.spin()
    except rospy.ROSInterruptException: pass

output

Goal.__init__
__name__

The output shows that the callback function has not been reached.

Do you know how to solve this?

Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-12-10 10:11:06 -0500

Mike Scheutzow gravatar image

updated 2022-12-10 13:39:21 -0500

In your previous question #q410100 you were informed that the /move_base_simple and /move_base/status topics are not related to each other, yet here you are asking a new question about your fundamentally incorrect use of the move_base API?

Please do a google search to understand what /move_base_simple does.

Update: It is not documented on the ros wiki that /move_base_simple/goal will publish status on /move_base/status (in fact, the actual words imply it will NOT do that.) But in order to explain what you are saying, I looked at the move_base source code, and the internal implementation makes a call to the move_base ActionServer. move_base has done this since at least kinetic.

edit flag offensive delete link more

Comments

Thanks for the reply.

First of all I forgot to try your answer about my last question. My apologies.

Here is my excuse.

Earlier you taught me how to use actionlib.

But now that I know how to get /move_base/status, I thought it would be possible to use it, and I was obsessed with creating the code for it.

So, I actually input the target ① and ② into goal_point = PoseStamped() and moved the robot. The robot correctly moved to goal ① and /move_base/status output 3. Finally, I confirmed that the robot arrived at target ②.

From the above, I thought I could create a waypoint code without using actionlib.

donguri gravatar image donguri  ( 2022-12-10 12:06:24 -0500 )edit

Now I want to incorporate another topic, "/ublox/fix".

I have heard that message_filters can be used to synchronize the two topics and incorporate them into a single function.

Currently, I am thinking that I am just using message_filters incorrectly and that if I use them correctly, the code in question will work correctly.

In parallel, I will attempt to code using the actionlib that you taught me last time.

I am of the opinion that the more types of test-cords the better.

I am hoping that the robot will work exactly as I want it to, whether it is the code I asked about or the code you taught me.

donguri gravatar image donguri  ( 2022-12-10 12:07:35 -0500 )edit

I looked into /move_base_simple/goal and /move_base/status.

I assume that /move_base_simple/goal is the topic that is output when the target point is specified in "2DNavGoal" in rviz, right?

And /move_base/status outputs the current status of the robot. For example, if the robot moves after the target point is specified with "2DNavGoal", status=1; if it reaches the target, status=0 or 3; if an error occurs on the way, status=4.

The code I created is very simple: I send the target point (/move_base_simple/goal) to the robot. If the robot's status (/move_base/status) is 3, it sends another target point (/move_base_simple/goal).

Is this usage not ok?

donguri gravatar image donguri  ( 2022-12-10 12:22:49 -0500 )edit

I updated my answer with new information.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-12-10 13:27:49 -0500 )edit

I understand.

I will try to run the robot again the way you showed me in your last question.

Thank you for your time.

donguri gravatar image donguri  ( 2022-12-10 22:00:55 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-12-07 21:34:04 -0500

Seen: 67 times

Last updated: Dec 10 '22