Skip to content

Commit

Permalink
Test/airdrop conn 04 24 (#163)
Browse files Browse the repository at this point in the history
* dev config for SITL

* add readme network command

* add integration test for airdrop conn

* fix default network mode host

* fix lint
  • Loading branch information
Tyler-Lentz authored Apr 24, 2024
1 parent 8439d0c commit 1e1f9f3
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 8 deletions.
5 changes: 2 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
// also: need to run obcpp with sudo or add tuas user to dialout group with
// `sudo usermod -aG dialout tuas && newgrp && bash`
// "runArgs": ["--device=/dev/ttyACM0"],
// "runArgs": [
// "--network=host"
// ],

// Enable network mode host if on Linux and testing airdrop connectivity
// "appPort": [ "45906:45906/udp", "45907:45907/udp" ], // port forward airdrop ports for local testing
// "runArgs": [
// "--network=host"
// ],

"extensions.verifySignature": false,

"customizations": {
"vscode": {
"settings": {
Expand Down
8 changes: 6 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
"configurations": [
{
"name": "CMake",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"includePath": [
"${workspaceFolder}/include"
],
"cppStandard": "c++20"
}
],
"version": 4
}
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,13 @@ int x = 0; // NOLINT
### Formatting
No formatter has been added yet. Formatting will be enforced once one is set up.
## Jetson Setup
### Network is Unreachable
If you are having problems sending UDP broadcast packets from the jetson, ensure that the default gateway ip is set correctly. You can use the following command to do this:
```
route add default gw 192.168.1.1
```
2 changes: 1 addition & 1 deletion configs/dev-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"network": {
"mavlink": {
"connect": "tcp://172.17.0.1:5760"
"connect": "tcp://127.0.0.1:14552"
},
"gcs": {
"port": 5010
Expand Down
26 changes: 26 additions & 0 deletions docker/Dockerfile.sitl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM amd64/ubuntu:22.04

# set up user
ARG USERNAME=tuas USER_UID=1000 USER_GID=1000 DEBIAN_FRONTEND=noninteractive
RUN groupadd -f --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
RUN usermod -a -G dialout $USERNAME

USER $USERNAME

# Steps from https://ardupilot.org/dev/docs/building-setup-linux.html#building-setup-linux

WORKDIR /home/$USERNAME

RUN sudo apt-get update && sudo apt-get install git && sudo apt-get install git
RUN git clone --recurse-submodules https://github.com/ArduPilot/ardupilot.git

WORKDIR ./ardupilot

RUN Tools/environment_install/install-prereqs-ubuntu.sh -y
RUN source ~/.profile

# wipe parameters
RUN timeout 3 ./sim_vehicle.py -w

ENTRYPOINT ./sim_vehicle.py -v ArduPlane -f quadplane --console --map
4 changes: 3 additions & 1 deletion include/airdrop/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdint.h>

/**********************************************************************************************
* LAST UPDATED: 2024/04/15 by Tyler Lentz
* LAST UPDATED: 2024/04/24 by Tyler Lentz
*
* This file defines the packet definitions for Airdrop communications. It is used in two
* separate repositories:
Expand Down Expand Up @@ -103,6 +103,8 @@ inline int validate_packet_as(enum ad_packet_hdr hdr, ad_packet_t packet) {
case ACK_REVOKE:
case ABOUT_TO_RELEASE:
case HEARTBEAT:
case SEND_LATLNG:
case ACK_LATLNG:
return (packet.data >= BOTTLE_A && packet.data <= BOTTLE_E);
default:
return 0;
Expand Down
2 changes: 1 addition & 1 deletion protos
Submodule protos updated 1 files
+9 −1 obc.proto
2 changes: 2 additions & 0 deletions src/network/airdrop_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ void AirdropClient::_receiveWorker() {
continue;
}

VLOG_F(TRACE, "RECEIVED AIRDROP PACKET %d %d", (int)packet.hdr, (int)packet.data);

Lock lock(this->recv_mut);
this->recv_queue.emplace(packet);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,22 @@ target_add_loguru(airdrop_pathing_2)
target_include_directories(airdrop_pathing_2 PRIVATE ${ImageMagick_INCLUDE_DIRS})
target_link_libraries(airdrop_pathing_2 PRIVATE -Wl,--copy-dt-needed-entries ${ImageMagick_LIBRARIES})

add_executable(airdrop_packets "airdrop_packets.cpp")
target_link_libraries(airdrop_packets PRIVATE obcpp_lib)
target_include_directories(airdrop_packets PRIVATE ${INCLUDE_DIRECTORY})
target_add_protobuf(airdrop_packets)
target_add_torch(airdrop_packets)
target_add_torchvision(airdrop_packets)
target_add_json(airdrop_packets)
target_add_opencv(airdrop_packets)
target_add_httplib(airdrop_packets)
target_add_mavsdk(airdrop_packets)
target_add_matplot(airdrop_packets)
target_add_loguru(airdrop_packets)

target_include_directories(airdrop_packets PRIVATE ${ImageMagick_INCLUDE_DIRS})
target_link_libraries(airdrop_packets PRIVATE -Wl,--copy-dt-needed-entries ${ImageMagick_LIBRARIES})

# airdrop_sockets
# add_executable(airdrop_sockets src/network/airdrop_sockets.c tests/integration/airdrop_sockets.c)
# target_include_directories(airdrop_sockets PRIVATE ${INCLUDE_DIRECTORY})
Expand Down
59 changes: 59 additions & 0 deletions tests/integration/airdrop_packets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <thread>
#include <chrono>

extern "C" {
#include "airdrop/packet.h"
#include "network/airdrop_sockets.h"
}

#include "network/airdrop_client.hpp"
#include "utilities/logging.hpp"

using namespace std::chrono_literals;

int main(int argc, char** argv) {
initLogging("/workspaces/obcpp/logs", true, argc, argv);

ad_socket_result_t result = make_ad_socket(AD_OBC_PORT, AD_PAYLOAD_PORT);

if (result.is_err) {
std::cerr << "SOCKET ERROR: " << result.data.err << std::endl;
std::exit(1);
}

AirdropClient airdrop(result.data.res);
airdrop.send(ad_latlng_packet_t {.hdr=SEND_LATLNG, .bottle=BOTTLE_A, .lat=32.12345, .lng=76.98765});
std::this_thread::sleep_for(5s);
LOG_F(INFO, "Checking for ack latlng...");
while (true) {
auto packet = airdrop.receive();
if (!packet) {
break;
}
LOG_F(INFO, "test %d %d", static_cast<int>(packet->data), static_cast<int>(packet->hdr));
}
LOG_F(INFO, "Done with checking for ack latlng");
airdrop.send(ad_packet_t {.hdr=SIGNAL, .data=BOTTLE_A});
std::this_thread::sleep_for(1s);
while (true) {
auto packet = airdrop.receive();
if (!packet) {
break;
}
LOG_F(INFO, "test2 %d %d", static_cast<int>(packet->data), static_cast<int>(packet->hdr));
}
airdrop.send(ad_packet_t {.hdr=REVOKE, .data=BOTTLE_A});
std::this_thread::sleep_for(1s);
while (true) {
auto packet = airdrop.receive();
if (!packet) {
break;
}
LOG_F(INFO, "test2 %d %d", static_cast<int>(packet->data), static_cast<int>(packet->hdr));
}

while (true) {
std::cout << "stop\n";
std::this_thread::sleep_for(1s);
}
}

0 comments on commit 1e1f9f3

Please sign in to comment.