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

Initialize agent with args input #18

Open
wants to merge 13 commits into
base: galactic
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/build_agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ros_distribution: [ foxy, galactic ]
ros_distribution: [ galactic ]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modify custom branch before merge

runs-on: rpi-ros2-${{ matrix.ros_distribution }}
steps:
# - uses: ros-tooling/[email protected]
Expand All @@ -23,7 +23,7 @@ jobs:
with:
path: ros_ws/src/micro_ros_renesas_testbench
submodules: recursive
ref: ${{ matrix.ros_distribution }}
ref: feature/agent_API
token: ${{ secrets.PRIVATE_KEY }}
- name: Download dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ros_distribution: [ foxy, galactic ]
ros_distribution: [ galactic ]
runs-on: rpi-ros2-${{ matrix.ros_distribution }}
steps:
# - uses: ros-tooling/[email protected]
Expand All @@ -27,7 +27,7 @@ jobs:
with:
path: ros_ws/src/micro_ros_renesas_testbench
submodules: recursive
ref: ${{ matrix.ros_distribution }}
ref: feature/agent_API
token: ${{ secrets.PRIVATE_KEY }}
- name: Download dependencies
run: |
Expand Down
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ if(BUILD_TESTING)
find_package(fastrtps REQUIRED)
find_package(fastrtps_cmake_module REQUIRED)
find_package(microxrcedds_agent REQUIRED)
find_package(micro_ros_agent REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rmw REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(example_interfaces REQUIRED)

find_package(rosidl_typesupport_fastrtps_cpp REQUIRED)
find_package(rosidl_runtime_cpp REQUIRED)
find_package(rosidl_typesupport_cpp REQUIRED)
find_package(rmw_dds_common REQUIRED)
find_package(rmw_fastrtps_shared_cpp REQUIRED)
find_package(micro_ros_msgs REQUIRED)

# ament_lint_auto_find_test_dependencies()

ament_add_gtest(${PROJECT_NAME}_test
Expand All @@ -40,17 +48,20 @@ if(BUILD_TESTING)

string(TOUPPER $ENV{ROS_DISTRO} ROS_DISTRO)
target_compile_options(${PROJECT_NAME}_test PRIVATE -DROS_DISTRO_${ROS_DISTRO})
target_include_directories(${PROJECT_NAME}_test PRIVATE include src test)
target_include_directories(${PROJECT_NAME}_test PRIVATE include src test micro_ros_agent_INCLUDE_DIR)

target_link_libraries(${PROJECT_NAME}_test
fastcdr
fastrtps
microxrcedds_agent)
microxrcedds_agent
micro_ros_agent
)

ament_target_dependencies(${PROJECT_NAME}_test
fastcdr
fastrtps
microxrcedds_agent
micro_ros_agent
rclcpp
rmw
std_msgs
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<depend>example_interfaces</depend>

<depend>microxrcedds_agent</depend>
<depend>micro_ros_agent</depend>

<buildtool_depend>ament_cmake</buildtool_depend>

Expand Down
2 changes: 1 addition & 1 deletion requirements.repos
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repositories:
micro-ROS-Agent:
type: git
url: https://github.com/micro-ROS/micro-ROS-Agent.git
version: galactic
version: feature/stop_agent
Micro-XRCE-DDS-Agent:
type: git
url: https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
Expand Down
4 changes: 3 additions & 1 deletion test/micro_ros_renesas_testbench/test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class HardwareTestBase : public ::testing::Test

// Set domain id
rcl_allocator_t allocator = rcl_get_default_allocator();
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
init_options = rcl_get_zero_initialized_init_options();

ASSERT_EQ(rcl_init_options_init(&init_options, allocator), RCL_RET_OK);
rmw_init_options_t* rmw_options = rcl_init_options_get_rmw_init_options(&init_options);
Expand All @@ -126,6 +126,7 @@ class HardwareTestBase : public ::testing::Test
void TearDown() override {
agent->stop();
rclcpp::shutdown();
(void) rcl_init_options_fini(&init_options);
}

bool checkConnection(){
Expand Down Expand Up @@ -204,6 +205,7 @@ class HardwareTestBase : public ::testing::Test
std::shared_ptr<TestAgent> agent;
std::shared_ptr<rclcpp::Node> node;
rclcpp::InitOptions options;
rcl_init_options_t init_options;

std::string cwd;
std::string project_name;
Expand Down
60 changes: 39 additions & 21 deletions test/micro_ros_renesas_testbench/test_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <chrono>
#include <thread>

#include <agent/Agent.hpp>

class TestAgent
{
public:
Expand Down Expand Up @@ -73,61 +75,77 @@ class TestAgent
static std::string getIPAddress();

private:
std::shared_ptr<std::thread> agent_thread_;
uint16_t port_;
uros::agent::Agent& micro_ros_agent;
std::vector<const char*> agent_args;
std::string port_;
std::string dev_;
std::string command_;
std::string verbosity_;
};

TestAgent::TestAgent(uint16_t port, uint8_t verbosity = 6)
: micro_ros_agent(micro_ros_agent.getInstance())
{
port_ = port;
command_ = "ros2 run micro_ros_agent micro_ros_agent udp4 --port " + std::to_string(port_) + " -v" + std::to_string(verbosity);
verbosity_ = "-v" + std::to_string(verbosity);
port_ = std::to_string(port);

agent_args.push_back("");
agent_args.push_back("udp4");
agent_args.push_back("--port");
agent_args.push_back(port_.c_str());
agent_args.push_back(verbosity_.c_str());
}

TestAgent::TestAgent(std::string dev, uint8_t verbosity = 6)
: micro_ros_agent(micro_ros_agent.getInstance())
{
verbosity_ = "-v" + std::to_string(verbosity);
dev_ = dev;
command_ = "ros2 run micro_ros_agent micro_ros_agent serial --dev " + dev_ + " -v" + std::to_string(verbosity);

agent_args.push_back("");
agent_args.push_back("serial");
agent_args.push_back("--dev");
agent_args.push_back(dev_.c_str());
agent_args.push_back(verbosity_.c_str());
}

TestAgent::TestAgent(Transport transport, std::string args, uint8_t verbosity = 6)
: micro_ros_agent(micro_ros_agent.getInstance())
{
std::string transport_type;

verbosity_ = "-v" + std::to_string(verbosity);
agent_args.push_back("");

switch (transport)
{
case Transport::UDP_THREADX_TRANSPORT:
case Transport::UDP_FREERTOS_TRANSPORT:
transport_type = "udp4";
port_ = args;
agent_args.push_back("udp4");
agent_args.push_back("--port");
agent_args.push_back(port_.c_str());
break;
case Transport::SERIAL_TRANSPORT:
case Transport::USB_TRANSPORT:
transport_type = "serial";
dev_ = args;
agent_args.push_back("serial");
agent_args.push_back("--dev");
agent_args.push_back(dev_.c_str());
break;
default:
break;
}

command_ = "ros2 run micro_ros_agent micro_ros_agent " + transport_type + " " + args + " -v" + std::to_string(verbosity);
agent_args.push_back(verbosity_.c_str());
}

void TestAgent::start()
{
stop();
agent_thread_.reset(new std::thread(
[&]() -> void {
system(command_.c_str());
}
));
micro_ros_agent.create(agent_args.size(), const_cast<char**> (agent_args.data()));
agent_args.clear();
}

void TestAgent::stop()
{
system("pkill micro_ros_agent");
if(agent_thread_) {
agent_thread_->join();
}
micro_ros_agent.stop();
}

std::string TestAgent::getIPAddress(){
Expand Down