Skip to content
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

Compatibility for Docker on macOS #848

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
32 changes: 18 additions & 14 deletions webots_ros2_driver/scripts/webots_tcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,33 @@ def get_host_ip():
return fields[2]
sys.exit('Unable to get host IP address.')
except subprocess.CalledProcessError:
sys.exit('Unable to get host IP address. \'ip route\' could not be executed.')
sys.exit('Unable to get host IP address. \'ip route\' could not be executed. Make sure that iproute2 is installed.')


HOST = get_host_ip() # Connect to host of the VM
PORT = 2000 # Port to connect to
def host_shared_folder():
shared_folder_list = os.environ['WEBOTS_SHARED_FOLDER'].split(':')
return shared_folder_list[0]


host_ip = None
host_port = None

tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
launch_arguments = ''
for arg in sys.argv:
if arg.endswith('.py') or arg == '':
continue
elif arg.endswith('.wbt'):
for arg in sys.argv[1:]:
if arg.endswith('.wbt'):
world_name = arg
elif "--host_ip=" in arg:
host_ip = arg.replace("--host_ip=", "")
elif "--host_port=" in arg:
host_port = int(arg.replace("--host_port=", ""))
else:
launch_arguments = launch_arguments + ' ' + arg

host_ip = get_host_ip() if host_ip is None else host_ip
host_port = 2000 if host_port is None else host_port

def host_shared_folder():
shared_folder_list = os.environ['WEBOTS_SHARED_FOLDER'].split(':')
return shared_folder_list[0]


while tcp_socket.connect_ex((HOST, PORT)) != 0:
tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while tcp_socket.connect_ex((host_ip, host_port)) != 0:
print('WARNING: Unable to start Webots. Please start the local simulation server on your host machine. Next connection '
'attempt in 1 second.', file=sys.stderr)
time.sleep(1)
Expand Down
2 changes: 1 addition & 1 deletion webots_ros2_driver/webots_ros2_driver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_host_ip():
return fields[2]
sys.exit('Unable to get host IP address.')
except subprocess.CalledProcessError:
sys.exit('Unable to get host IP address. \'ip route\' could not be executed.')
sys.exit('Unable to get host IP address. \'ip route\' could not be executed. Make sure that iproute2 is installed.')


def controller_protocol():
Expand Down
4 changes: 2 additions & 2 deletions webots_ros2_driver/webots_ros2_driver/webots_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@

class WebotsController(ExecuteProcess):
def __init__(self, output='screen', respawn=False, remappings=[],
namespace='', parameters=[], robot_name='', port='1234', **kwargs):
namespace='', parameters=[], robot_name='', ip_address='', port='1234', **kwargs):
webots_controller = (os.path.join(get_package_share_directory('webots_ros2_driver'), 'scripts', 'webots-controller'))

protocol = controller_protocol()
ip_address = controller_ip_address() if (protocol == 'tcp') else ''
ip_address = controller_ip_address() if (ip_address == '' and protocol == 'tcp') else ip_address

robot_name_option = [] if not robot_name else ['--robot-name=' + robot_name]
ip_address_option = [] if not ip_address else ['--ip-address=' + ip_address]
Expand Down
12 changes: 11 additions & 1 deletion webots_ros2_driver/webots_ros2_driver/webots_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def perform(self, context):

class WebotsLauncher(ExecuteProcess):
def __init__(self, output='screen', world=None, gui=True, mode='realtime', stream=False, ros2_supervisor=False,
port='1234', **kwargs):
port='1234', host_ip=None, host_port=2000, **kwargs):
if sys.platform == 'win32':
kalle264 marked this conversation as resolved.
Show resolved Hide resolved
print('WARNING: Native webots_ros2 compatibility with Windows is deprecated and will be removed soon. Please use a '
'WSL (Windows Subsystem for Linux) environment instead.', file=sys.stderr)
Expand Down Expand Up @@ -100,6 +100,14 @@ def __init__(self, output='screen', world=None, gui=True, mode='realtime', strea
stream_argument = "--stream=" + stream
port_argument = '--port=' + port

host_ip_argument = ""
if host_ip is not None:
host_ip_argument = "--host_ip=" + host_ip

host_port_argument = ""
if host_port is not None:
host_port_argument = "--host_port=" + str(host_port)
kalle264 marked this conversation as resolved.
Show resolved Hide resolved

xvfb_run_prefix = []

if 'WEBOTS_OFFSCREEN' in os.environ:
Expand Down Expand Up @@ -138,6 +146,8 @@ def __init__(self, output='screen', world=None, gui=True, mode='realtime', strea
webots_path,
stream_argument,
port_argument,
host_ip_argument,
host_port_argument,
no_rendering,
stdout,
stderr,
Expand Down