Skip to content

system: allow setting sysid/compid #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions mavsdk/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ class System:
Port of the running mavsdk_server instance specified by
mavsdk_server_address.

sysid: int
MAVLink system ID of the mavsdk_server (1..255).

compid: int
MAVLink component ID of the mavsdk_server (1..255).

"""
def __init__(self, mavsdk_server_address=None, port=50051):
def __init__(self, mavsdk_server_address=None, port=50051, sysid=245, compid=190):
self._mavsdk_server_address = mavsdk_server_address
self._port = port
self._sysid = sysid
self._compid = compid

self._plugins = {}
self._server_process = None
Expand Down Expand Up @@ -94,7 +102,7 @@ async def connect(self, system_address=None):

if self._mavsdk_server_address is None:
self._mavsdk_server_address = 'localhost'
self._server_process = self._start_mavsdk_server(system_address,self._port)
self._server_process = self._start_mavsdk_server(system_address,self._port, self._sysid, self._compid)

await self._init_plugins(self._mavsdk_server_address, self._port)

Expand Down Expand Up @@ -168,7 +176,7 @@ def failure(self) -> failure.Failure:
if "failure" not in self._plugins:
raise RuntimeError(self.error_uninitialized("Failure"))
return self._plugins["failure"]

@property
def follow_me(self) -> follow_me.FollowMe:
if "follow_me" not in self._plugins:
Expand Down Expand Up @@ -272,7 +280,7 @@ def tune(self) -> tune.Tune:
return self._plugins["tune"]

@staticmethod
def _start_mavsdk_server(system_address=None,port=50051):
def _start_mavsdk_server(system_address, port, sysid, compid):
"""
Starts the gRPC server in a subprocess, listening on localhost:port
port parameter can be specified now to allow multiple mavsdk servers to be spawned via code
Expand All @@ -289,7 +297,10 @@ def _start_mavsdk_server(system_address=None,port=50051):

try:
with path(bin, 'mavsdk_server') as backend:
bin_path_and_args = [os.fspath(backend), "-p", str(port)]
bin_path_and_args = [os.fspath(backend),
"-p", str(port),
"--sysid", str(sysid),
"--compid", str(compid)]
if system_address:
bin_path_and_args.append(system_address)
p = subprocess.Popen(bin_path_and_args,
Expand Down