Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ install/
.catkin_tools/
*.pyc
*.vscode/
__pycache__/
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cd omron_ws/src

Install dependencies
```sh
sudo apt install ros-humble-navigation2 ros-humble-nav2-bringup ros-humble-slam-toolbox ros-humble-teleop-twist-joy ros-humble-joy
sudo apt install ros-jazzy-navigation2 ros-jazzy-nav2-bringup ros-jazzy-slam-toolbox ros-jazzy-teleop-twist-joy ros-jazzy-joy
```

Clone the repositories into the `src` folder by
Expand Down Expand Up @@ -58,19 +58,21 @@ ros2 launch amr_ros amr_core.launch.py

```sh
source install/setup.bash
ros2 launch amr_ros ld250.launch.py
ros2 launch amr_ros ld250.launch.py use_nav2:=false use_rviz:=false
```

### Start Nav2 SLAM and open the Nav2 RViz view for mapping

```sh
source install/setup.bash
ros2 launch amr_ros ld250.launch.py use_nav2:=true use_slam:=true
```
RViz starts by default; pass `use_rviz:=false` to disable it.

The SLAM launch publishes a map with a 1 m unknown border on `map`; the unmodified SLAM grid is available on `slam_map_raw`. The default Nav2 planner does not plan through unknown space in SLAM mode. Padding does not add obstacle observations, and does not establish that navigation is safe. Custom SLAM parameters must use the default `/map` topic for this padding pipeline.

Both costmaps use `/scan` by default. For a namespaced robot, configure both costmap observation-source topics to its actual laser scan topic. Verify live obstacles and inflation in both costmaps before navigation.


```sh
source install/setup.bash
ros2 launch amr_nav2 nav2_rviz.launch.py
ros2 launch amr_ros ld250.launch.py
```

### Start Nav2 localization with a map from amr_nav2/maps and open the Nav2 RViz view
Expand All @@ -80,11 +82,23 @@ source install/setup.bash
ros2 launch amr_ros ld250.launch.py use_nav2:=true use_localization:=true map:=my_map.yaml
```

### Undock separately

Navigation and velocity commands do not initiate undocking. With the hardware interface running, undocking is a separate `nav2_msgs/action/UndockRobot` action. It requires verified contact docking, exclusive control, fresh docking feedback, and stationary telemetry. `driver.undocking.contact_dock_confirmed` is read at startup; `driver.undocking.exclusive_control_confirmed` also defaults to false. Set these confirmations only after verifying the corresponding conditions.

When parking manually, ensure the robot is properly positioned and its display shows the charging state. The dock's yellow charging light alone does not confirm that the robot has registered the charging state.

For an explicitly authorized, supervised departure, send one goal:

```sh
source install/setup.bash
ros2 launch amr_nav2 nav2_rviz.launch.py
ros2 action send_goal /undock_robot nav2_msgs/action/UndockRobot "{dock_type: 'omron', max_undocking_time: 30.0}" --feedback
```

Proceed with navigation only after successful action completion and independent confirmation that the robot has stopped and is undocked. Do not retry a failed or uncertain departure automatically; investigate and verify the physical state first. The previously observed stale-feedback failure remains unresolved.

If a goal is rejected, the driver logs the reason in the launch terminal; the action client reports only that the goal was rejected.


## LD90

Expand Down
52 changes: 52 additions & 0 deletions amr_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(amr_msgs REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
Expand All @@ -23,6 +25,9 @@ find_package(visualization_msgs REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(libaria CONFIG REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(yaml_cpp_vendor REQUIRED)
find_package(yaml-cpp REQUIRED)

set(AMR_CORE_ARIA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../libaria")

Expand All @@ -37,22 +42,69 @@ ament_target_dependencies(${PROJECT_NAME}
rclcpp_action
tf2_ros
std_msgs
std_srvs
nav_msgs
sensor_msgs
geometry_msgs
control_msgs
visualization_msgs
amr_msgs
nav2_msgs
ament_index_cpp

)
target_link_libraries(${PROJECT_NAME}
libaria::ArNetworking
nlohmann_json::nlohmann_json
)

add_executable(amr_deadzone_writer src/deadzone_calibration.cpp)
target_link_libraries(amr_deadzone_writer libaria::ArNetworking nlohmann_json::nlohmann_json)
add_executable(amr_deadzone_calibration src/deadzones.cpp)
ament_target_dependencies(amr_deadzone_calibration ament_index_cpp)
target_link_libraries(amr_deadzone_calibration libaria::ArNetworking nlohmann_json::nlohmann_json yaml-cpp)
add_executable(amr_hardware_probe src/configuration_probe.cpp)
target_link_libraries(amr_hardware_probe libaria::ArNetworking nlohmann_json::nlohmann_json)

install(TARGETS
${PROJECT_NAME}
amr_deadzone_writer
amr_deadzone_calibration
amr_hardware_probe
DESTINATION lib/${PROJECT_NAME}
)
install(DIRECTORY include/ DESTINATION include)

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_cmake_pytest REQUIRED)
find_package(tf2_msgs REQUIRED)
ament_add_gtest(test_robot_interface
test/test_config_interface.cpp
test/test_debug_interface.cpp
test/test_docking_interface.cpp
test/test_drive_command_policy.cpp
test/test_drive_ratio_mapping.cpp
test/test_drive_interface.cpp
test/test_drive_tcp_sender.cpp
test/test_map_interface.cpp
)
ament_target_dependencies(test_robot_interface
rclcpp amr_msgs tf2_ros tf2_msgs std_msgs std_srvs nav_msgs geometry_msgs
)
target_link_libraries(test_robot_interface libaria::ArNetworking nlohmann_json::nlohmann_json)
target_compile_definitions(test_robot_interface PRIVATE AMR_CORE_EXECUTABLE="$<TARGET_FILE:amr_core>")
add_dependencies(test_robot_interface amr_core)

ament_add_gtest(test_hybrid_config test/test_hybrid_config.cpp)
target_link_libraries(test_hybrid_config libaria::ArNetworking nlohmann_json::nlohmann_json)
ament_add_pytest_test(test_hardware_capture test/test_hardware_capture.py
APPEND_ENV "AMR_DEADZONE_WRITER=$<TARGET_FILE:amr_deadzone_writer>"
"AMR_DEADZONE_CALIBRATION=$<TARGET_FILE:amr_deadzone_calibration>"
)
ament_add_pytest_test(test_drive_pulse_offline test/test_drive_pulse_offline.py)
endif()

ament_export_include_directories(include)
ament_export_dependencies(libaria nlohmann_json ament_index_cpp yaml_cpp_vendor yaml-cpp nav2_msgs)
ament_package()
116 changes: 116 additions & 0 deletions amr_core/include/amr_core/core_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
#include <rclcpp/rclcpp.hpp>
#include <memory>
#include <string>
#include <mutex>
#include <cmath>
#include <stdexcept>
#include <nav2_msgs/action/undock_robot.hpp>
#include <rclcpp_action/rclcpp_action.hpp>
#include <std_srvs/srv/trigger.hpp>

#include "amr_core/interfaces/status_interface.hpp"
#include "amr_core/interfaces/laser_interface.hpp"
#include "amr_core/interfaces/drive_interface.hpp"
#include "amr_core/interfaces/map_interface.hpp"
#include "amr_core/utils/robot_session.hpp"

class CoreNode : public rclcpp::Node
{
Expand All @@ -29,6 +37,40 @@ class CoreNode : public rclcpp::Node
publish_main_laser_ = getOrDeclareParameter<bool>("laser.main_laser.enabled", true);
publish_low_laser_ = getOrDeclareParameter<bool>("laser.low_laser.enabled", false);

if (getOrDeclareParameter<bool>("map.ros_service.enabled", false))
{
try
{
map_session_ = std::make_unique<amr_core::RobotSession>();
if (!map_session_->connect({ host_, port_, user_, password_, protocol_ }) ||
!map_session_->client().dataExists("getMapName"))
throw std::runtime_error("Connected getMapName service required");
map_interface_ = std::make_unique<amr_core::MapInterface>(map_session_->client());
const auto service_name = getOrDeclareParameter<std::string>("map.ros_service.name", "map/get_active_map");
map_server_ = create_service<std_srvs::srv::Trigger>(service_name,
[this](const std::shared_ptr<std_srvs::srv::Trigger::Request>,
std::shared_ptr<std_srvs::srv::Trigger::Response> response) {
std::lock_guard<std::mutex> lock(map_mutex_);
try
{
response->message = map_interface_->getName();
response->success = true;
}
catch (const std::exception&)
{
response->success = false;
response->message = "Active map query failed";
}
});
}
catch (const std::exception& ex)
{
map_interface_.reset();
map_session_.reset();
RCLCPP_ERROR(this->get_logger(), "Map interface initialization failed: %s", ex.what());
}
}

if (publish_status_)
{
try
Expand Down Expand Up @@ -72,6 +114,7 @@ class CoreNode : public rclcpp::Node
{
driver_ = std::make_shared<DriverInterface>(this->shared_from_this());
driver_->initialize(host_, port_, user_, password_, protocol_);
initializeUndockAction();
}
catch (const std::exception& ex)
{
Expand All @@ -83,6 +126,67 @@ class CoreNode : public rclcpp::Node
}

private:
using Undock = nav2_msgs::action::UndockRobot;
using UndockGoal = rclcpp_action::ServerGoalHandle<Undock>;

void initializeUndockAction()
{
docking_ = driver_->dockingInterface();
dock_type_ = getOrDeclareParameter<std::string>("driver.undocking.dock_type", "omron");
if (dock_type_.empty()) throw std::invalid_argument("driver.undocking.dock_type must not be empty");
getOrDeclareParameter<bool>("driver.undocking.exclusive_control_confirmed", false);
undock_server_ = rclcpp_action::create_server<Undock>(shared_from_this(), "undock_robot",
[this](const rclcpp_action::GoalUUID&, std::shared_ptr<const Undock::Goal> goal) {
std::lock_guard<std::mutex> lock(undock_mutex_);
const char* reason = nullptr;
if (undock_goal_)
reason = "another undocking goal is active";
else if (!goal->dock_type.empty() && goal->dock_type != dock_type_)
reason = "dock_type does not match the configured dock type";
else if (docking_->reserveUndock(get_parameter("driver.undocking.contact_dock_confirmed").as_bool(),
get_parameter("driver.undocking.exclusive_control_confirmed").as_bool(),
goal->max_undocking_time, &reason))
return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
RCLCPP_WARN(get_logger(), "Undock goal rejected: %s", reason ? reason : "reservation failed");
return rclcpp_action::GoalResponse::REJECT;
},
[this](std::shared_ptr<UndockGoal> goal) {
std::lock_guard<std::mutex> lock(undock_mutex_);
if (goal != undock_goal_ || !docking_->cancelUndock()) return rclcpp_action::CancelResponse::REJECT;
undock_cancel_requested_ = true;
return rclcpp_action::CancelResponse::ACCEPT;
},
[this](std::shared_ptr<UndockGoal> goal) {
std::lock_guard<std::mutex> lock(undock_mutex_);
undock_goal_ = std::move(goal);
undock_cancel_requested_ = false;
docking_->beginUndock();
});
undock_timer_ = create_wall_timer(std::chrono::milliseconds(50), [this]() { publishUndock(); });
}

void publishUndock()
{
std::lock_guard<std::mutex> lock(undock_mutex_);
if (!undock_goal_) return;
const auto status = docking_->operationStatus();
if (!status.terminal)
{
undock_goal_->publish_feedback(std::make_shared<Undock::Feedback>());
return;
}
if (undock_cancel_requested_ && !undock_goal_->is_canceling()) return;
auto result = std::make_shared<Undock::Result>();
result->success = status.success;
result->error_code = status.success ? Undock::Result::NONE : Undock::Result::FAILED_TO_CONTROL;
result->error_msg = status.success ? "" : status.message;
if (undock_goal_->is_canceling()) undock_goal_->canceled(result);
else if (status.success) undock_goal_->succeed(result);
else undock_goal_->abort(result);
undock_goal_.reset();
docking_->finishUndock();
}

/**
* @brief Helper function to get a parameter value or declare it with a default if it doesn't exist.
* @tparam T Parameter type.
Expand All @@ -104,6 +208,11 @@ class CoreNode : public rclcpp::Node
}

private:
std::unique_ptr<amr_core::RobotSession> map_session_;
std::unique_ptr<amr_core::MapInterface> map_interface_;
std::mutex map_mutex_;
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr map_server_;

// Status information
std::shared_ptr<StatusInterface> status_interface_;

Expand All @@ -112,6 +221,13 @@ class CoreNode : public rclcpp::Node

// DriverInterface
std::shared_ptr<DriverInterface> driver_;
std::shared_ptr<amr_core::DockingInterface> docking_;
rclcpp_action::Server<Undock>::SharedPtr undock_server_;
rclcpp::TimerBase::SharedPtr undock_timer_;
std::shared_ptr<UndockGoal> undock_goal_;
std::mutex undock_mutex_;
bool undock_cancel_requested_{ false };
std::string dock_type_;

// Parameters
std::string host_;
Expand Down
Loading
Loading