reiniscimurs / DRL-robot-navigation

Deep Reinforcement Learning for mobile robot navigation in ROS Gazebo simulator. Using Twin Delayed Deep Deterministic Policy Gradient (TD3) neural network, a robot learns to navigate to a random goal point in a simulated environment while avoiding obstacles.
MIT License
571 stars 119 forks source link

How to set up sources with an anaconda environment and Noetic branch? #8

Closed AgentEXPL closed 2 years ago

AgentEXPL commented 2 years ago

Hi, thanks for sharing the Noetic branch. I am testing this branch with an anaconda environment. First, I opened a terminal using non-conda env. Then complie workspace:

$ cd ~/DRL-robot-navigation/catkin_ws

Compile

$ catkin_make_isolated ----------(It succeeds!)

Next, I have created an conda env, activated it, and installed some modules as follows. conda activate py3.6.9

pip install torch==1.2.0 -f https://download.pytorch.org/whl/torch_stable.html pip install pyyaml pip install rospkg pip install squaternion pip install attr pip install attrs pip install netifaces defusedxml

Finally, I opened a new terminal and set up sources: ---------------------- (This two lines are added to activate conda env and source ROS) $ conda activate py3.6.9 $ source /opt/ros/noetic/setup.bash

$ export ROS_HOSTNAME=localhost $ export ROS_MASTER_URI=http://localhost:11311 $ export ROS_PORT_SIM=11311 $ export GAZEBO_RESOURCE_PATH=~/DRL-robot-navigation/catkin_ws/src/multi_robot_scenario/launch

$ ########### source ~/.bashrc (This line is deleted because it exits conda env py3.6.9 and turns to conda env base) $ cd ~/DRL-robot-navigation/catkin_ws $ source devel_isolated/setup.bash $ cd ~/DRL-robot-navigation/TD3 $ python3 velodyne_td3.py

The result is as follows, the following error occurs :

[ INFO] [1638523319.979820797]: Finished loading Gazebo ROS API Plugin. [ INFO] [1638523319.980631275]: waitForService: Service [/gazebo/set_physics_properties] has not been advertised, waiting... [INFO] [1638523320.065212, 0.000000]: Loading model XML from ros parameter robot_description [INFO] [1638523320.070311, 0.000000]: Waiting for service /gazebo/spawn_urdf_model [ INFO] [1638523320.797520126]: waitForService: Service [/gazebo/set_physics_properties] is now available. [ INFO] [1638523320.854882519]: Physics dynamic reconfigure ready. [INFO] [1638523320.976913, 0.000000]: Calling service /gazebo/spawn_urdf_model [ INFO] [1638523497.485188702, 0.201000000]: Camera Plugin: Using the 'robotNamespace' param: '/' [ INFO] [1638523497.486945746, 0.201000000]: Camera Plugin (ns = /) , set to "" [ INFO] [1638523497.497253932, 0.201000000]: Camera Plugin: The 'robotNamespace' param was empty [ INFO] [1638523497.498658911, 0.201000000]: Camera Plugin (ns = r1) , set to "" [INFO] [1638523498.697978, 0.201000]: Spawn status: SpawnModel: Successfully spawned entity [urdf_spawner-2] process has finished cleanly log file: /home/agent/.ros/log/770251f6-541a-11ec-aeed-e7829104ff20/urdf_spawner-2.log [ INFO] [1638523499.690473792, 0.201000000]: Laser Plugin: The 'robotNamespace' param was empty [ INFO] [1638523499.690532451, 0.201000000]: Starting Laser Plugin (ns = r1) [ INFO] [1638523499.691076904, 0.201000000]: Laser Plugin (ns = r1) , set to "" [ INFO] [1638523499.697194393, 0.201000000]: Velodyne laser plugin missing , defaults to no clipping [ INFO] [1638523499.698738449, 0.201000000]: Velodyne laser plugin ready, 16 lasers [ INFO] [1638523499.710498725, 0.201000000]: Starting plugin DiffDrive(ns = r1/) [ INFO] [1638523499.710623456, 0.201000000]: DiffDrive(ns = r1/): = Debug [ INFO] [1638523499.711047215, 0.201000000]: DiffDrive(ns = r1/): = [DEBUG] [1638523499.711102141, 0.201000000]: DiffDrive(ns = r1/): = cmd_vel [DEBUG] [1638523499.711116354, 0.201000000]: DiffDrive(ns = r1/): = odom [DEBUG] [1638523499.711153205, 0.201000000]: DiffDrive(ns = r1/): = odom [DEBUG] [1638523499.711164916, 0.201000000]: DiffDrive(ns = r1/): = base_link [DEBUG] [1638523499.711235821, 0.201000000]: DiffDrive(ns = r1/): = false [ WARN] [1638523499.711250520, 0.201000000]: DiffDrive(ns = r1/): missing default is true [DEBUG] [1638523499.711290227, 0.201000000]: DiffDrive(ns = r1/): = true [DEBUG] [1638523499.711344992, 0.201000000]: DiffDrive(ns = r1/): = 0.29999999999999999 [DEBUG] [1638523499.711362835, 0.201000000]: DiffDrive(ns = r1/): = 0.17999999999999999 [DEBUG] [1638523499.711377474, 0.201000000]: DiffDrive(ns = r1/): = 1.8 [DEBUG] [1638523499.711391185, 0.201000000]: DiffDrive(ns = r1/): = 20 [DEBUG] [1638523499.711405342, 0.201000000]: DiffDrive(ns = r1/): = 50 [DEBUG] [1638523499.711453639, 0.201000000]: DiffDrive(ns = r1/): = world := 1 [DEBUG] [1638523499.711485094, 0.201000000]: DiffDrive(ns = r1/): = left_hub_joint [DEBUG] [1638523499.711499787, 0.201000000]: DiffDrive(ns = r1/): = right_hub_joint [ WARN] [1638523499.711518908, 0.201000000]: GazeboRosDiffDrive Plugin (ns = ) missing , defaults to 1 [ INFO] [1638523499.711922234, 0.201000000]: DiffDrive(ns = r1/): Advertise joint_states [ INFO] [1638523499.712257380, 0.201000000]: DiffDrive(ns = r1/): Try to subscribe to cmd_vel [ INFO] [1638523499.713753381, 0.201000000]: DiffDrive(ns = r1/): Subscribe to cmd_vel [ INFO] [1638523499.714150768, 0.201000000]: DiffDrive(ns = r1/): Advertise odom on odom [ INFO] [1638523499.721365047, 0.201000000]: GazeboRosJointStatePublisher is going to publish joint: chassis_swivel_joint [ INFO] [1638523499.721390973, 0.201000000]: GazeboRosJointStatePublisher is going to publish joint: swivel_wheel_joint [ INFO] [1638523499.721424750, 0.201000000]: GazeboRosJointStatePublisher is going to publish joint: left_hub_joint [ INFO] [1638523499.721433820, 0.201000000]: GazeboRosJointStatePublisher is going to publish joint: right_hub_joint [ INFO] [1638523499.721446512, 0.201000000]: Starting GazeboRosJointStatePublisher Plugin (ns = r1/)!, parent name: r1 [DEBUG] [1638523499.732124524, 0.211000000]: Trying to publish message of type [sensor_msgs/LaserScan/90c7ef2dc6895d81024acba2ac42f369] on a publisher with type [sensor_msgs/LaserScan/90c7ef2dc6895d81024acba2ac42f369] [DEBUG] [1638523499.793156774, 0.222000000]: Trying to publish message of type [nav_msgs/Odometry/cd5e73d190d741a2f92e81eda573aca7] on a publisher with type [nav_msgs/Odometry/cd5e73d190d741a2f92e81eda573aca7] [DEBUG] [1638523499.793237857, 0.222000000]: Trying to publish message of type [sensor_msgs/JointState/3066dcd76a6cfaef579bd0f34173e9fd] on a publisher with type [sensor_msgs/JointState/3066dcd76a6cfaef579bd0f34173e9fd] [DEBUG] [1638523499.807064731, 0.235000000]: Trying to publish message of type [sensor_msgs/CameraInfo/c9a58c1b0b154e0e6da7578cb991d214] on a publisher with type [sensor_msgs/CameraInfo/c9a58c1b0b154e0e6da7578cb991d214] Exception in thread /r1/odom: Traceback (most recent call last): File "/home/agent/anaconda3/envs/py3.6.9/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/home/agent/anaconda3/envs/py3.6.9/lib/python3.6/threading.py", line 864, in run self._target(self._args, **self._kwargs) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_pubsub.py", line 185, in robust_connect_subscriber conn.receive_loop(receive_cb) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 846, in receive_loop self.close() File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 858, in close self.socket.close() AttributeError: 'NoneType' object has no attribute 'close'

Exception in thread /r1/front_laser/scan: Traceback (most recent call last): File "/home/agent/anaconda3/envs/py3.6.9/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/home/agent/anaconda3/envs/py3.6.9/lib/python3.6/threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_pubsub.py", line 185, in robust_connect_subscriber conn.receive_loop(receive_cb) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 846, in receive_loop self.close() File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 858, in close self.socket.close() AttributeError: 'NoneType' object has no attribute 'close'

AgentEXPL commented 2 years ago

I'm sorry for the bad type setting. For simpliciy, the first question is whether the way of setting up sources in anaconda env is correct?

Finally, I opened a new terminal and set up sources:

---------------------- (This two lines are added to activate conda env and source ROS) $ conda activate py3.6.9 $ source /opt/ros/noetic/setup.bash $ export ROS_HOSTNAME=localhost $ export ROS_MASTER_URI=http://localhost:11311 $ export ROS_PORT_SIM=11311 $ export GAZEBO_RESOURCE_PATH=~/DRL-robot-navigation/catkin_ws/src/multi_robot_scenario/launch $ ########### source ~/.bashrc (This line is deleted because it exits conda env py3.6.9 and turns to conda env base) $ cd ~/DRL-robot-navigation/catkin_ws $ source devel_isolated/setup.bash $ cd ~/DRL-robot-navigation/TD3 $ python3 velodyne_td3.py

AgentEXPL commented 2 years ago

The second question is that the robot is moving normally in RViz, however, the following result is showing in the terminal. Is there any problems? Or, it goes well?


Exception in thread /r1/odom: Traceback (most recent call last): File "/home/agent/anaconda3/envs/py3.6.9/lib/python3.6/threading.py", line 916 , in _bootstrap_inner self.run() File "/home/agent/anaconda3/envs/py3.6.9/lib/python3.6/threading.py", line 864 , in run self._target(*self._args, **self._kwargs) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_pubsub.py", line 185, in robust_connect_subscriber conn.receive_loop(receive_cb) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", li ne 846, in receive_loop self.close() File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", li ne 858, in close self.socket.close() AttributeError: 'NoneType' object has no attribute 'close'

.............................................. Average Reward over 10 Evaluation Episodes, Epoch 1: -71.071544, 0.400000 .............................................. Exception in thread /r1/front_laser/scan: Traceback (most recent call last): File "/home/agent/anaconda3/envs/py3.6.9/lib/python3.6/threading.py", line 916 , in _bootstrap_inner self.run() File "/home/agent/anaconda3/envs/py3.6.9/lib/python3.6/threading.py", line 864 , in run self._target(*self._args, **self._kwargs) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_pubsub.py", line 185, in robust_connect_subscriber conn.receive_loop(receive_cb) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", li ne 846, in receive_loop self.close() File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", li ne 858, in close self.socket.close() AttributeError: 'NoneType' object has no attribute 'close'

reiniscimurs commented 2 years ago

Sorry, I don't know that much about development in conda, so I can't help you there. I don't think that is something I will be working on. If you manage to figure it out, please let me know, we can create another branch for conda development.

As for the second issue, please take a look at #5, that is the laser issue that I am talking about. I just put the noetic branch up and haven't figured out all the kinks yet.

AgentEXPL commented 2 years ago

I'm sorry that I found few materials about how to deal with ROS and conda, especially for those which execute ros as subprocesses in python scripts.

I think the way above is OK to source ROS in conda, since the network is able to be normally trained and evaluated, while the following results can be normally shown. The only problem is the second issue. After deploying the newest code (which is submitted 3 days ago), the second issue still remains. But I think this issue is not a big trouble.


Average Reward over 10 Evaluation Episodes, Epoch 1: -71.071544, 0.400000

By the way, if the defined robot is replaced by turtlebot3, the project works well without the second issue.

reiniscimurs commented 2 years ago

After deploying the newest code (which is submitted 3 days ago)

That seems to be the code from the main branch. Did you try the code from noetic branch (updated 2 days ago)? That one should work but let me know if there is an issue. Also good to know that it all works with turtlebot as well.

AgentEXPL commented 2 years ago

Sorry for misleading. Noetic branch was actually used. I downloaded the branch with chrome and obtained a zip called "DRL-robot-navigation-Noetic.zip" in 14:45, 2021/12/4 Beijing Time.

To avoid mistakes, I re-downloaded and checked the Noetic branch today. The same issue occurs. (Note that the warning occurs after serveral episodes.)