gtfactslab / CrazySim

A Crazyflie simulator for testing CFLib Python code, ROS 2 nodes through Crazyswarm2, custom crazyflie-firmware modules, or perform a flight demo on the crazyflie-python-client.
GNU General Public License v3.0
72 stars 15 forks source link

Connection failure for 3 or more crazyflies #1

Closed kevinaubertlomellini closed 7 months ago

kevinaubertlomellini commented 9 months ago

I install the simulator and is working very well with 1 or 2 crazyflies. However, when I try to use 3 or more crazyflies on Gazebo. The program is not able to connect all the crazyflies, just making a connection for 1 or 2 at much. For example for 3 crazyflies on the Gazebo simulator I obtain the next when I launch the command ros2 launch crazyflie launch.py backend:=cflib: [INFO] [launch]: All log files can be found below /home/kevin/.ros/log/2024-02-07-12-56-40-422276-UBUNTU-ROG-112994 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [motion_capture_tracking_node-1]: process started with pid [112995] [INFO] [teleop-2]: process started with pid [112997] [INFO] [joy_node-3]: process started with pid [112999]marhes [INFO] [crazyflie_server.py-4]: process started with pid [113001] [INFO] [rviz2-5]: process started with pid [113021] [motion_capture_tracking_node-1] logClouds=0 [teleop-2] [INFO] [1707335800.789703037] [teleop]: Mode changed to cmd_vel_world [rviz2-5] [INFO] [1707335801.642947720] [rviz2]: Stereo is NOT SUPPORTED [rviz2-5] [INFO] [1707335801.643116350] [rviz2]: OpenGl version: 4.6 (GLSL 4.6) [rviz2-5] [INFO] [1707335801.703454938] [rviz2]: Stereo is NOT SUPPORTED [crazyflie_server.py-4] [INFO] [1707335803.003786589] [crazyflie_server]: udp://0.0.0.0:19851 is fully connected! As you can see, the program can only connect to 1 crazy fly and then it freezes. On the other hand on the gazebo command I obtain the next one: Starting gazebo gui [Msg] OdometryPublisher publishing odometry on [/cf_2/odom] [Msg] OdometryPublisher publishing odometry with covariance on [/model/crazyflie_2/odometry_with_covariance] [Msg] OdometryPublisher publishing Pose_V (TF) on [/model/crazyflie_2/pose] [Msg] Init subs and Pubs done : [Msg] Received firmware handshake message... [Wrn] [Model.hh:69] Skipping serialization / deserialization for models with //pose/@relative_to attribute. [Wrn] [Component.hh:144] Trying to serialize component with data type [N3sdf3v135WorldE], which doesn't have operator<<. Component will not be serialized. libEGL warning: egl: failed to create dri2 screen libEGL warning: egl: failed to create dri2 screen [Msg] Received CfLib handshake message... [Msg] Received CfLib handshake message... [Msg] Received CfLib handshake message...

I try installing the program in different computers but the result is the same. Do you know how to solve this problem? Thank you in advance

llanesc commented 9 months ago

Do you have cf_1, cf_2, and cf_3 enabled set to true in crazyswarm2/crazyflie/config/crazyflies.yaml? I tried spawning 3 and connecting them and here's what I got.

Screenshot from 2024-02-07 15-28-49

kevinaubertlomellini commented 9 months ago

Yes, the 3 crazyflies are enabled set to true in crazyswarm2/crazyflie/config/crazyflies.yaml. This is what I have: Screenshot from 2024-02-07 13-46-23 It get connected with 1 or 2 crazyflies and then it freezes there.

llanesc commented 9 months ago

Could you test if the CFLib swarm features are working? You can do this by running the crazyflie-lib-python/examples/swarm/swarmSequenceCircle.py example with the following modifications:

URI0 = 'udp://0.0.0.0:19850'
URI1 = 'udp://0.0.0.0:19851'
URI2 = 'udp://0.0.0.0:19852'
URI3 = 'udp://0.0.0.0:19853'
URI4 = 'udp://0.0.0.0:19854'

You will need to spawn 5 agents so use this command in the firmware:

bash tools/crazyflie-simulation/simulator_files/gazebo/launch/sitl_multiagent_square.sh -n 5 -m crazyflie
kevinaubertlomellini commented 9 months ago

I run the script but nothing happen: Screenshot from 2024-02-07 14-19-44

llanesc commented 9 months ago

I seem to get similar behavior when I do 16 Crazyflies. There could be some dropouts or timeouts not being met because the simulator plugin slows down. What are your CPU specs? I could easily do up to 12-15 drones with a 16 core CPU. I'll investigate this a bit further and see if I can make the communication more robust.

kevinaubertlomellini commented 9 months ago

My CPU has 6 core. I am going to try it in a computer with higher capacity. Thanks

llanesc commented 9 months ago

I removed the cflib comm delay feature and added a wait_dequeue_bulk instead of try_dequeue in sendCfLibThread(). I can now repeatedly run 16 agents. Could you pull the latest main, rebuild, and try running 3 again?

kevinaubertlomellini commented 9 months ago

With this change, the simulator is letting me have 3 crazyflies and sometimes 4. However, if I open another program like the screen recording one, the communication to the crazyflies starts to fail and they crash even when there is only one crazyflie on the Gazebo. It would be very helpful if the communication could be improved to need fewer resources. Thank you

llanesc commented 9 months ago

The issue may be related to timeouts on receiving packets on the CFLib side. Screen recording software can momentarily increase resource consumption and cause a lag on the Gazebo end. You can confirm this if you see a drop in the percentage on the bottom right in Gazebo. I've never experienced this on my machine, so I wasn't aware it was occurring. It's good that you have brought this issue to my attention. I've recently been working on removing the plugin entirely and replacing it with a module in the firmware directly that bridges the gap with Gazebo. I'll keep this issue open while I work on improving communications.

However, there is a bottleneck in that the firmware runs best when the Gazebo real time factor is close to 100%. This is a much larger fix that is related to the firmware requiring lock stepping so that the firmware runs synchronized with the sim time. I'm bringing this issue up with Bitcraze to see if we can come up with a solution. In the mean time you can increase the max step size in crazyflie-firmware/tools/crazyflie-simulation/simulator_files/gazebo/worlds/crazysim_default.sdf to something like 0.002 and change the IMU rate in the models/crazyflie/crazyflie.sdf.jinja to 500Hz. That may improve your performance while you use recording software.

khunglong207 commented 5 months ago

@llanesc I am having this error, even though I have increased the coefficient, the plane will fly unstable and will not follow the trajectory I want, do you have any ideas to fix them?

llanesc commented 5 months ago

@khunglong207 what is your Gazebo real time factor, how many drones are you flying, and what are your pc specs?

khunglong207 commented 5 months ago

@llanesc about 80% in the gazebo, I tried with 2 drones, I'm using a xeon chip with 24 cores, 48 ​​threads, 128gb ram but no graphics card because it's a server

llanesc commented 5 months ago

@khunglong207 That's a lot of computing power. It could be the lack of graphics (see https://github.com/gtfactslab/CrazySim/issues/8). Maybe you can just run Gazebo on headless mode (https://gazebosim.org/api/sim/8/headless_rendering.html). You would need to modify the launch script to add the command.

khunglong207 commented 5 months ago

@llanesc I have a question about crazysim_default.sdf change max step size about 0.002, but the drone fly not stable. so how i change max step size in file?

llanesc commented 5 months ago

@khunglong207 If your Gazebo real time factor is being slowed by rendering then max step size probably doesn't matter.

khunglong207 commented 5 months ago

@Llanes, @.***> The gazebo coefficient is over 95% but nothing appears on the backend on rviz, I don't know why.

Tải xuống Outlook dành cho Androidhttps://aka.ms/AAb9ysg


From: Christian Llanes @.> Sent: Wednesday, May 29, 2024 9:40:01 PM To: gtfactslab/CrazySim @.> Cc: Nguyen Duc Huy 20207119 @.>; Mention @.> Subject: Re: [gtfactslab/CrazySim] Connection failure for 3 or more crazyflies (Issue #1)

@khunglong207https://github.com/khunglong207 If your Gazebo real time factor is being slowed by rendering then max step size probably doesn't matter.

— Reply to this email directly, view it on GitHubhttps://github.com/gtfactslab/CrazySim/issues/1#issuecomment-2137584034, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BB5RIHJKFIZDTIWWY6YG5ZLZEXSEDAVCNFSM6AAAAABC6PR5YKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZXGU4DIMBTGQ. You are receiving this because you were mentioned.Message ID: @.***>

khunglong207 commented 5 months ago

@llanesc datn@datn-hust:~/CrazySim/ros2_ws$ ros2 launch crazyflie launch.py backend:=cflib [INFO] [launch]: All log files can be found below /home/datn/.ros/log/2024-05-30-23-17-47-213641-datn-hust-25495 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [motion_capture_tracking_node-1]: process started with pid [25496] [INFO] [teleop-2]: process started with pid [25498] [INFO] [joy_node-3]: process started with pid [25500] [INFO] [crazyflie_server.py-4]: process started with pid [25502] [INFO] [rviz2-5]: process started with pid [25504] [teleop-2] [INFO] [1717085867.492339632] [teleop]: Mode changed to cmd_vel_world [motion_capture_tracking_node-1] logClouds=0 [crazyflie_server.py-4] Got link error callback [Error communicating with the Crazyflie [crazyflie_server.py-4] Exception:[Errno 111] Connection refused [crazyflie_server.py-4] [crazyflie_server.py-4] Traceback (most recent call last): [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crtp/udpdriver.py", line 151, in run [crazyflie_server.py-4] packet = self._socket.recv(1024) [crazyflie_server.py-4] ConnectionRefusedError: [Errno 111] Connection refused [crazyflie_server.py-4] ] in state [1] [crazyflie_server.py-4] Exception in thread Thread-12: [crazyflie_server.py-4] Traceback (most recent call last): [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crtp/udpdriver.py", line 151, in run [crazyflie_server.py-4] Got link error callback [Error communicating with the Crazyflie [crazyflie_server.py-4] Exception:[Errno 111] Connection refused [crazyflie_server.py-4] [crazyflie_server.py-4] Traceback (most recent call last): [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crtp/udpdriver.py", line 151, in run [crazyflie_server.py-4] packet = self._socket.recv(1024) [crazyflie_server.py-4] ConnectionRefusedError: [Errno 111] Connection refused [crazyflie_server.py-4] ] in state [1] [crazyflie_server.py-4] Exception in thread Thread-11: [crazyflie_server.py-4] Traceback (most recent call last): [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crtp/udpdriver.py", line 151, in run [crazyflie_server.py-4] packet = self._socket.recv(1024) [crazyflie_server.py-4] ConnectionRefusedError: [Errno 111] Connection refused [crazyflie_server.py-4] [crazyflie_server.py-4] During handling of the above exception, another exception occurred: [crazyflie_server.py-4] [crazyflie_server.py-4] Traceback (most recent call last): [crazyflie_server.py-4] packet = self._socket.recv(1024) [crazyflie_server.py-4] File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner [crazyflie_server.py-4] ConnectionRefusedError: [Errno 111] Connection refused [crazyflie_server.py-4] [crazyflie_server.py-4] During handling of the above exception, another exception occurred: [crazyflie_server.py-4] [crazyflie_server.py-4] Traceback (most recent call last): [crazyflie_server.py-4] File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner [crazyflie_server.py-4] self.run() [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crtp/udpdriver.py", line 162, in run [crazyflie_server.py-4] self.run() [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crtp/udpdriver.py", line 162, in run [crazyflie_server.py-4] self._link_error_callback( [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crazyflie/init.py", line 197, in _link_error_cb [crazyflie_server.py-4] self._link_error_callback( [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crazyflie/init.py", line 197, in _link_error_cb [crazyflie_server.py-4] self.link.close() [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crtp/udpdriver.py", line 94, in close [crazyflie_server.py-4] self.link.close() [crazyflie_server.py-4] File "/home/datn/CrazySim/crazyflie-lib-python/cflib/crtp/udpdriver.py", line 94, in close [crazyflie_server.py-4] self.socket.send(b'\xF4') [crazyflie_server.py-4] ConnectionRefusedError: [Errno 111] Connection refused [crazyflie_server.py-4] self.socket.send(b'\xF4') [crazyflie_server.py-4] ConnectionRefusedError: [Errno 111] Connection refused [rviz2-5] [INFO] [1717085868.410432541] [rviz2]: Stereo is NOT SUPPORTED [rviz2-5] [INFO] [1717085868.410630336] [rviz2]: OpenGl version: 4.3 (GLSL 4.3) [rviz2-5] [INFO] [1717085868.434005622] [rviz2]: Stereo is NOT SUPPORTED [crazyflie_server.py-4] [INFO] [1717085868.742374535] [crazyflie_server]: udp://0.0.0.0:19850 is fully connected!

llanesc commented 5 months ago

@khunglong207 It could be a few things.

  1. Did you launch the same number of crazyflies you have active in the crazyflies.yaml file?
  2. The OS hasn't closed the ports yet from a prior attempt. Should just give it a few seconds before launching Gazebo again.
  3. Do you see any errors (red lines) on the Gazebo launch script terminal? Maybe post that output here to debug.
khunglong207 commented 5 months ago

@llanesc

  1. yes, the same number of crazyflies, active in the crazyflies.yaml file
  2. i try it but is not works this video: https://drive.google.com/file/d/1R5fozzVGiVR_NzaoVnt6pSLjqP8NFzrF/view?usp=sharing
llanesc commented 5 months ago

@khunglong207 Could you try a few things:

  1. Restart your computer and test it again. It could be that the port is still open from a prior run.
  2. If that doesn't work can you go to the launch script you are running and change line 87 to this
    gz sim -s -r ${src_path}/tools/crazyflie-simulation/simulator_files/gazebo/worlds/${world}.sdf -v 4 &

    so that the verbosity level is 4. Then just try again and paste the Gazebo launch script terminal output in here.