dji-sdk / RoboMaster-SDK

DJI RoboMaster Python SDK and Sample Code for RoboMaster EP.
Apache License 2.0
327 stars 150 forks source link

Multi drone connection using SDK #85

Open aarsht7 opened 1 year ago

aarsht7 commented 1 year ago

How to reproduce the issue:

Things you might notice during the above procedure.

THE ERROR

At very first execution of this example from github, I got the following error

Traceback (most recent call last):
  File "test-2.py", line 17, in <module>
    multi_drone.initialize(robot_num=2)
  File "/home/aarsh/.local/lib/python3.8/site-packages/multi_robomaster/multi_robot.py", line 272, in initialize
    self._robot_host_list = self._client.scan_multi_robot(robot_num)
  File "/home/aarsh/.local/lib/python3.8/site-packages/multi_robomaster/tool.py", line 320, in scan_multi_robot
    return self._conn.scan_multi_robot(num)
  File "/home/aarsh/.local/lib/python3.8/site-packages/multi_robomaster/tool.py", line 266, in scan_multi_robot
    robot_host_list = self._scan_host(num)
  File "/home/aarsh/.local/lib/python3.8/site-packages/multi_robomaster/tool.py", line 232, in _scan_host
    subnets, address = get_subnets()
  File "/home/aarsh/.local/lib/python3.8/site-packages/multi_robomaster/tool.py", line 106, in get_subnets
    broadcast = ipinfo['broadcast']
KeyError: 'broadcast'

After having good view on the code downloaded from the pip install and the code on this github repo, I find its not the same. For starter, you can go to the PyPi robomaster download latest whl and check the line 106 in multi_robomaster/tool.py and same file multi_robomaster/tool.py line 103 on github. You notice the error producing line broadcast = ipinfo['broadcast'] is not present on the github version.

After some printing and debugging and chatting with the dev team of dji @dji-dev , I realise it was giving the error because of the multiple physical and virtual network cards (self, LAN, wifi, docker and few more) available on the system. After that I tried to iterate over only wifi using the wifi adapter name in this for loop. But I get the following Error

[Errno 22] Invalid argument
  File "/home/aarsh/.local/lib/python3.8/site-packages/multi_robomaster/tool.py", line 258, in _scan_host
    self._sock.sendto(b'command', (ip, self.local_port))
  File "/home/aarsh/.local/lib/python3.8/site-packages/multi_robomaster/tool.py", line 271, in scan_multi_robot
    robot_host_list = self._scan_host(num)
  File "/home/aarsh/.local/lib/python3.8/site-packages/multi_robomaster/tool.py", line 325, in scan_multi_robot
    return self._conn.scan_multi_robot(num)
  File "/home/aarsh/.local/lib/python3.8/site-packages/multi_robomaster/multi_robot.py", line 272, in initialize
    self._robot_host_list = self._client.scan_multi_robot(robot_num)
  File "/home/aarsh/DJI/tt/SDK/test-2.py", line 18, in <module>
    multi_drone.initialize(robot_num=2)
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
OSError: [Errno 22] Invalid argument

Here I am stuck and have no idea what to try next. Any help would be appreciated. Thanks.

hummelslei commented 1 year ago

https://github.com/dji-sdk/RoboMaster-SDK/blob/ff6646e115ab125af3207a4ed3df42cc76c795b2/src/multi_robomaster/tool.py#L175 please modify local_ip to be equal to your actual local IP address. For example 192.168.10.2

aarsht7 commented 1 year ago

Thank you @hummelslei . I will give it a try and update you about it by tomorrow. 👍🏻

aarsht7 commented 1 year ago

Hello @hummelslei , The solution did not worked for me. I am still getting the same error.

hummelslei commented 1 year ago

The solution recommended by our R&D is as follows. Please modify it according to the recommended method. Modify demo image Modify library: image

aarsht7 commented 1 year ago

Hello @hummelslei This works BUT I had to make one more change in the code. I can make a pull request to this repo with all the changes I made to work it without any problem. NOTE : this changes will not affect already working codes. the changes will only trigger when it is required. I can also document for the website (in English) Once again Thanks Hummels 👍🏻