Skip to content

Commit

Permalink
Support switching between Radio/UDP for robot communication (#3151)
Browse files Browse the repository at this point in the history
* Move unix and udp networking files into separate directories

* Add radio listener + sender

* Update NetworkService

* [pre-commit.ci lite] apply automatic fixes

* Fix include

* [pre-commit.ci lite] apply automatic fixes

* Fix help text

* Fix include

* Fix failing build

* Add docs

* [pre-commit.ci lite] apply automatic fixes

* Add enable radio flag to field test fixture

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
williamckha and pre-commit-ci-lite[bot] committed Mar 30, 2024
1 parent c6e5fa4 commit aaa16cb
Show file tree
Hide file tree
Showing 55 changed files with 620 additions and 538 deletions.
17 changes: 9 additions & 8 deletions src/software/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ cc_binary(
"//software/estop:arduino_util",
"//software/logger",
"//software/multithreading:observer_subject_adapter",
"//software/networking:threaded_proto_udp_listener",
"//software/networking:threaded_proto_udp_sender",
"//software/networking:threaded_proto_unix_listener",
"//software/networking/udp:threaded_proto_udp_listener",
"//software/networking/udp:threaded_proto_udp_sender",
"//software/networking/unix:threaded_proto_unix_listener",
"//software/sensor_fusion:threaded_sensor_fusion",
"//software/util/generic_factory",
"@boost//:program_options",
Expand All @@ -32,8 +32,8 @@ cc_binary(
srcs = ["er_force_simulator_main.cpp"],
deps = [
"//software:constants",
"//software/networking:threaded_proto_unix_listener",
"//software/networking:threaded_proto_unix_sender",
"//software/networking/unix:threaded_proto_unix_listener",
"//software/networking/unix:threaded_proto_unix_sender",
"//software/simulation:er_force_simulator",
"@boost//:program_options",
],
Expand All @@ -45,7 +45,7 @@ cc_binary(
deps = [
"//proto:tbots_cc_proto",
"//shared:constants",
"//software/networking:threaded_proto_udp_listener",
"//software/networking/udp:threaded_proto_udp_listener",
"@boost//:program_options",
],
)
Expand Down Expand Up @@ -89,8 +89,9 @@ pybind_library(
"//software/geom:segment",
"//software/geom:vector",
"//software/geom/algorithms",
"//software/networking:threaded_proto_udp_listener",
"//software/networking:threaded_proto_udp_sender",
"//software/networking/radio:threaded_proto_radio_sender",
"//software/networking/udp:threaded_proto_udp_listener",
"//software/networking/udp:threaded_proto_udp_sender",
"//software/uart:boost_uart_communication",
"//software/world",
"//software/world:field",
Expand Down
4 changes: 2 additions & 2 deletions src/software/backend/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ cc_library(
"//shared:constants",
"//software:constants",
"//software/logger",
"//software/networking:threaded_proto_unix_listener",
"//software/networking:threaded_proto_unix_sender",
"//software/networking/unix:threaded_proto_unix_listener",
"//software/networking/unix:threaded_proto_unix_sender",
"//software/util/generic_factory",
],
# We force linking so that the static variables required for the "factory"
Expand Down
4 changes: 2 additions & 2 deletions src/software/backend/unix_simulator_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "proto/sensor_msg.pb.h"
#include "proto/tbots_software_msgs.pb.h"
#include "software/backend/backend.h"
#include "software/networking/threaded_proto_unix_listener.hpp"
#include "software/networking/threaded_proto_unix_sender.hpp"
#include "software/networking/unix/threaded_proto_unix_listener.hpp"
#include "software/networking/unix/threaded_proto_unix_sender.hpp"

class UnixSimulatorBackend : public Backend, public Subject<TbotsProto::ThunderbotsConfig>
{
Expand Down
4 changes: 2 additions & 2 deletions src/software/er_force_simulator_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "proto/world.pb.h"
#include "software/constants.h"
#include "software/logger/logger.h"
#include "software/networking/threaded_proto_unix_listener.hpp"
#include "software/networking/threaded_proto_unix_sender.hpp"
#include "software/networking/unix/threaded_proto_unix_listener.hpp"
#include "software/networking/unix/threaded_proto_unix_sender.hpp"
#include "software/simulation/er_force_simulator.h"

int main(int argc, char **argv)
Expand Down
4 changes: 2 additions & 2 deletions src/software/field_tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ py_library(
deps = [
"//proto:import_all_protos",
"//software/logger:py_logger",
"//software/networking:threaded_unix_listener_py",
"//software/networking:threaded_unix_sender_py",
"//software/networking/unix:threaded_unix_listener_py",
"//software/networking/unix:threaded_unix_sender_py",
"//software/simulated_tests:tbots_test_runner",
"//software/simulated_tests:validation",
"//software/thunderscope",
Expand Down
8 changes: 8 additions & 0 deletions src/software/field_tests/field_test_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ def load_command_line_arguments():
help="Which channel to communicate over",
)

parser.add_argument(
"--enable_radio",
action="store_true",
default=False,
help="Whether to use radio (True) or Wi-Fi (False) for sending primitives to robots",
)

parser.add_argument(
"--estop_baudrate",
action="store",
Expand Down Expand Up @@ -372,6 +379,7 @@ def field_test_runner():
interface=args.interface,
estop_mode=estop_mode,
estop_path=estop_path,
enable_radio=args.enable_radio,
) as rc_friendly:
with Gamecontroller(
supress_logs=(not args.show_gamecontroller_logs), ci_mode=True
Expand Down
5 changes: 3 additions & 2 deletions src/software/jetson_nano/services/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ cc_library(
"//proto:tbots_cc_proto",
"//shared:robot_constants",
"//software/logger",
"//software/networking:threaded_proto_udp_listener",
"//software/networking:threaded_proto_udp_sender",
"//software/networking/radio:threaded_proto_radio_listener",
"//software/networking/udp:threaded_proto_udp_listener",
"//software/networking/udp:threaded_proto_udp_sender",
"@boost//:asio",
],
)
Expand Down
7 changes: 6 additions & 1 deletion src/software/jetson_nano/services/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ NetworkService::NetworkService(const std::string& ip_address,
{
sender = std::make_unique<ThreadedProtoUdpSender<TbotsProto::RobotStatus>>(
ip_address, robot_status_sender_port, multicast);
listener_primitive_set =

udp_listener_primitive_set =
std::make_unique<ThreadedProtoUdpListener<TbotsProto::PrimitiveSet>>(
ip_address, primitive_listener_port,
boost::bind(&NetworkService::primitiveSetCallback, this, _1), multicast);

radio_listener_primitive_set =
std::make_unique<ThreadedProtoRadioListener<TbotsProto::PrimitiveSet>>(
boost::bind(&NetworkService::primitiveSetCallback, this, _1));
}

TbotsProto::PrimitiveSet NetworkService::poll(TbotsProto::RobotStatus& robot_status)
Expand Down
9 changes: 6 additions & 3 deletions src/software/jetson_nano/services/network/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include "shared/constants.h"
#include "shared/robot_constants.h"
#include "software/jetson_nano/services/network/proto_tracker.h"
#include "software/networking/threaded_proto_udp_listener.hpp"
#include "software/networking/threaded_proto_udp_sender.hpp"
#include "software/networking/radio/threaded_proto_radio_listener.hpp"
#include "software/networking/udp/threaded_proto_udp_listener.hpp"
#include "software/networking/udp/threaded_proto_udp_sender.hpp"

class NetworkService
{
Expand Down Expand Up @@ -63,7 +64,9 @@ class NetworkService

std::unique_ptr<ThreadedProtoUdpSender<TbotsProto::RobotStatus>> sender;
std::unique_ptr<ThreadedProtoUdpListener<TbotsProto::PrimitiveSet>>
listener_primitive_set;
udp_listener_primitive_set;
std::unique_ptr<ThreadedProtoRadioListener<TbotsProto::PrimitiveSet>>
radio_listener_primitive_set;

unsigned int network_ticks = 0;
unsigned int thunderloop_ticks = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/software/logger/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ cc_library(
"//proto/message_translation:tbots_protobuf",
"//shared:constants",
"//software/logger:plotjuggler_sink",
"//software/networking:threaded_proto_udp_sender",
"//software/networking/udp:threaded_proto_udp_sender",
"@base64",
"@g3log",
],
Expand All @@ -135,7 +135,7 @@ cc_library(
deps = [
"//proto:visualization_cc_proto",
"//shared:constants",
"//software/networking:threaded_udp_sender",
"//software/networking/udp:threaded_udp_sender",
"@g3log",
],
)
Expand All @@ -153,7 +153,7 @@ cc_library(
"//proto:any_cc_proto",
"//proto:tbots_cc_proto",
"//shared:constants",
"//software/networking:threaded_unix_sender",
"//software/networking/unix:threaded_unix_sender",
"@base64",
"@g3log",
],
Expand Down
2 changes: 1 addition & 1 deletion src/software/logger/network_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "proto/robot_log_msg.pb.h"
#include "proto/visualization.pb.h"
#include "software/logger/log_merger.h"
#include "software/networking/threaded_proto_udp_sender.hpp"
#include "software/networking/udp/threaded_proto_udp_sender.hpp"


/**
Expand Down
2 changes: 1 addition & 1 deletion src/software/logger/plotjuggler_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "proto/visualization.pb.h"
#include "software/logger/custom_logging_levels.h"
#include "software/networking/threaded_udp_sender.h"
#include "software/networking/udp/threaded_udp_sender.h"


/**
Expand Down
2 changes: 1 addition & 1 deletion src/software/logger/protobuf_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "google/protobuf/any.pb.h"
#include "software/logger/custom_logging_levels.h"
#include "software/networking/threaded_unix_sender.h"
#include "software/networking/unix/threaded_unix_sender.h"

static const std::string TYPE_DELIMITER = "!!!";

Expand Down
2 changes: 1 addition & 1 deletion src/software/network_log_listener_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "proto/robot_log_msg.pb.h"
#include "proto/tbots_software_msgs.pb.h"
#include "shared/constants.h"
#include "software/networking/threaded_proto_udp_listener.hpp"
#include "software/networking/udp/threaded_proto_udp_listener.hpp"

/*
* This standalone program listens for RobotLog protos on the specified ip address
Expand Down
160 changes: 0 additions & 160 deletions src/software/networking/BUILD
Original file line number Diff line number Diff line change
@@ -1,165 +1,5 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "proto_udp_client",
hdrs = [
"proto_udp_client.hpp",
],
deps = [
"//software/logger",
"//software/util/typename",
],
)

cc_library(
name = "proto_udp_listener",
hdrs = [
"proto_udp_listener.hpp",
],
visibility = ["//visibility:private"],
deps = [
"//software/logger",
"//software/util/typename",
],
)

cc_library(
name = "udp_sender",
srcs = [
"udp_sender.cpp",
],
hdrs = [
"udp_sender.h",
],
visibility = ["//visibility:private"],
deps = [
"@boost//:asio",
],
)

cc_library(
name = "threaded_proto_udp_listener",
hdrs = [
"threaded_proto_udp_listener.hpp",
],
deps = [
":proto_udp_listener",
"@boost//:asio",
],
)

cc_library(
name = "threaded_proto_udp_sender",
hdrs = [
"threaded_proto_udp_sender.hpp",
],
deps = [
":udp_sender",
"@boost//:asio",
],
)

cc_library(
name = "unix_sender",
srcs = [
"unix_sender.cpp",
],
hdrs = [
"unix_sender.h",
],
visibility = ["//visibility:private"],
deps = [
"//software:constants",
"@boost//:asio",
],
)

cc_library(
name = "threaded_udp_sender",
srcs = [
"threaded_udp_sender.cpp",
],
hdrs = [
"threaded_udp_sender.h",
],
deps = [
":udp_sender",
],
)

cc_library(
name = "proto_unix_listener",
hdrs = [
"proto_unix_listener.hpp",
],
visibility = ["//visibility:private"],
deps = [
"//software:constants",
"//software/util/typename",
"@boost//:asio",
],
)

cc_library(
name = "threaded_unix_sender",
srcs = [
"threaded_unix_sender.cpp",
],
hdrs = [
"threaded_unix_sender.h",
],
deps = [
":unix_sender",
"@boost//:asio",
],
)

cc_library(
name = "threaded_proto_unix_sender",
hdrs = [
"threaded_proto_unix_sender.hpp",
],
deps = [
":unix_sender",
"@boost//:asio",
],
)

cc_library(
name = "threaded_proto_unix_listener",
hdrs = [
"threaded_proto_unix_listener.hpp",
],
deps = [
":proto_unix_listener",
"@boost//:asio",
],
)

py_library(
name = "threaded_unix_listener_py",
srcs = ["threaded_unix_listener.py"],
data = [
"//software:py_constants.so",
],
deps = [
"//proto:software_py_proto",
"//software/logger:py_logger",
],
)

py_library(
name = "threaded_unix_sender_py",
srcs = ["threaded_unix_sender.py"],
data = [
"//software:py_constants.so",
],
deps = [
"//proto:software_py_proto",
"//software/logger:py_logger",
],
)

py_library(
name = "ssl_proto_communication",
srcs = ["ssl_proto_communication.py"],
Expand Down
Loading

0 comments on commit aaa16cb

Please sign in to comment.