-
Notifications
You must be signed in to change notification settings - Fork 13
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
timonegk
wants to merge
2
commits into
main
Choose a base branch
from
fix/team_comm_auto_detect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−12
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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: | ||
self.target_ip: IPv4Address = IPv4Address(node.get_parameter("target_ip").value) | ||
|
||
if self.target_ip.is_loopback: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you removed |
||
# local mode on loopback device, bind to port depending on bot id and team id | ||
|
14 changes: 4 additions & 10 deletions
14
bitbots_team_communication/bitbots_team_communication/config/team_communication_config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Its used:
|
||
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 | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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