f1tenth / f1tenth_gym_ros

Containerized ROS communication bridge for F1TENTH gym environment.
MIT License
154 stars 106 forks source link

ROS is ignoring drive_callback in gym_bridge.py #13

Closed IPavlak closed 4 years ago

IPavlak commented 4 years ago

Hello, I have encountered some really weird behaviour from ROS when I tried to run dummy-agent example. I am running Ubuntu 18.04.5 LTS, docker 19.03.12 . I started docker with sudo ./docker.sh and launched dummy agent with roslaunch f1tenth_gym_ros agent_template.launch, you can see the output on pics below (to make things simpler in drive_callback in gym_bridge.py i left only one line of code: print("in drive callback"). docker1 docker2 agent-dummy

Callback obviously did not fire, on pics below you can see the output of rostopic info /drive which was normal and the output of roswtf which indicated there really is an error. Also there is a pic of rqt_graph which does not show /drive topic. Note that all along rostopic echo /drive output showed AckermannDriveStamped messages being published from dummy-agent. rostopic_ack roswtf_ack rqt_ack

Now here is the twist, when I changed only a message type from AckermannDriveStamped to Odometry everything seemed to work as it should. Callback started to work and there was no error in roswtf output. You can see output of those commands in pics below. docker_odom rostopic_odom roswtf_odom rqt_odom

I don't understand what is going on and since I have never worked with AckermannDriveStamped I'm not sure if maybe I'm doing something wrong, although I don't know how message type can affect ROS in this way.

BhooshanDeshpande commented 4 years ago

I am also facing a similar issue. The 'roswtf' command is saying -- ERROR The following nodes should be connected but aren't: /rostopic_4415_1599984587224->/gym_bridge (/drive)

Screenshot 2020-09-13 04:12:54

I have tried with multi_node as well as master node, having the same result in both cases.

hzheng40 commented 4 years ago

Can I see some more details on how you're publishing the drive messages?

IPavlak commented 4 years ago

I haven't changed anything from dummy_agent_node.py except that I have put drive.drive.speed = 2.0 instead of drive.drive.speed = 0.0

IPavlak commented 4 years ago

In case when I'm publishing Odometry message I have the following code:

#!/usr/bin/env python
import rospy
from ackermann_msgs.msg import AckermannDriveStamped
from sensor_msgs.msg import LaserScan
from nav_msgs.msg import Odometry

class Agent(object):
    def __init__(self):
        self.drive_pub = rospy.Publisher('/drive', Odometry, queue_size=1)

        self.scan_sub = rospy.Subscriber('/scan', LaserScan, self.scan_callback, queue_size=1)

    def scan_callback(self, scan_msg):
        # print('got scan, now plan')
        drive = Odometry()
        self.drive_pub.publish(drive)

if __name__ == '__main__':
    rospy.init_node('dummy_agent')
    dummy_agent = Agent()
    rospy.spin()
travelbureau commented 4 years ago

We are able to replicate this bug. We are investigating what might be wrong as it did not occur during the last competition. It seems like it might be a network configuration issue, but we do not have a solution yet. For the time being you could develop your agent inside the docker container until we have a fix.

hzheng40 commented 4 years ago

I've pushed a new commit for the repo, could you please try out the new version? Please revert back to publishing an AckermannDriveStamped message. The issue was from the genpy library that handles the message generation in rospy and they recently had an update to the ros docker images that broke everything. For more details on the issue see here: https://github.com/osrf/docker_images/issues/452 .

IPavlak commented 4 years ago

Yes, now it works ! Thank you for your help

I had a minor bug while building docker:

E: Failed to fetch http://packages.ros.org/ros/ubuntu/pool/main/r/ros-melodic-map-server/ros-melodic-map-server_1.16.6-1bionic.20200820.221640_amd64.deb  404  Not Found [IP: 140.211.166.134 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing ?

I guess it is because docker has cached that command and did not execute it again, error persisted after I deleted catkin package, ran command docker system prune and cloned package again. I'm not really that familiar with docker but I fixed it by adding that command ( run apt-get update --fix-missing ) in DockerFile:

RUN apt-get update --fix-missing && \
    apt-get install -y \
    python-pip
RUN apt-get update --fix-missing
RUN apt-get install -y libzmq3-dev \
                       git \
                       build-essential \
                       autoconf \
                       libtool \
                       libeigen3-dev \
                       cmake \
                       vim \
                       ros-melodic-ackermann-msgs \
                       ros-melodic-map-server \
                       ros-melodic-genpy
hzheng40 commented 4 years ago

apt-get update --fix-missing is already in the Dockerfile. Since it was cached before when you built it, you can modify build_docker.sh to add the --no-cache argument after the build command for a fresh rebuild.

BhooshanDeshpande commented 3 years ago

Thanks @hzheng40 for fixing the issue. Also thanks @IPavlak for clearing about the post-fix bug. It all works now!