Skip to content
New issue

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

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

Already on GitHub? # to your account

team_communication: automatically detect target ip address #589

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import socket
from ipaddress import IPv4Address
from ipaddress import AddressValueError, IPv4Address
from typing import List, Optional

from rclpy.node import Node
Expand All @@ -11,7 +11,19 @@ def __init__(self, node: Node, logger, team_id, robot_id):

self.buffer_size: int = 1024
self.socket: Optional[socket.socket] = None
self.target_ip: IPv4Address = IPv4Address(node.get_parameter("target_ip").value)
if node.get_parameter("detect_target_ip").value:
try:
# automatically detect from subnet
import netifaces

self.target_ip: IPv4Address = IPv4Address(
netifaces.ifaddresses(node.get_parameter("wifi_interface"))[netifaces.AF_INET][0]["broadcast"]
)
except (ImportError, ValueError, KeyError, AddressValueError):
self.logger.warn("Could not detect broadcast address, falling back to configured address")
self.target_ip = None
if self.target_ip is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.target_ip may not exist at this point

self.target_ip: IPv4Address = IPv4Address(node.get_parameter("target_ip").value)

if self.target_ip.is_loopback:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you removed local_target_ports this whole block should also be removed

# local mode on loopback device, bind to port depending on bot id and team id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
team_comm:
ros__parameters:
# UDP broadcast address is the highest IP in the subnet e.g. 172.20.255.255
# Sets local mode if set to loopback (127.0.0.1)
# Automatically detect UDP broadcast address
detect_target_ip: true
wifi_interface: "wlp3s0"
# Fallback, only used if detect_target_ip is false. This should be the highest IP in the subnet e.g. 172.20.255.255
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only used if detect_target_ip is false this is false or irritating.

Its used:

  • if detect_target_ip is false
  • if detect_target_ip is true, but auto-detection failed

target_ip: 192.168.255.255

# Only used in non local mode with specific target_ip
target_port: 3737
receive_port: 3737

# Only used in local mode on loopback
# the team communication will bind to one of these ports and send to the other ports, depending on its bot_id
local_target_ports:
- 4001
- 4002
- 4003
- 4004

# Rate of published messages in Hz
rate: 10

Expand Down
Loading