From 3e0efb90a4c8af458e16a7cb8c3df3e4338f334f Mon Sep 17 00:00:00 2001 From: Jakub Delicat Date: Tue, 15 Oct 2024 15:56:42 +0000 Subject: [PATCH] review suggestions Signed-off-by: Jakub Delicat --- .github/workflows/run-unit-tests.yaml | 1 + README.md | 36 +++++++++++-------- wibotic_connector_can/README.md | 20 +++++++++++ wibotic_connector_can/cmake/SuperBuild.cmake | 14 +++----- .../uavcan_types/wibotic/WiBoticInfo.hpp | 3 +- .../wibotic_can_driver.hpp | 6 ++-- wibotic_connector_can/package.xml | 6 ++-- .../src/wibotic_can_driver.cpp | 2 +- .../src/wibotic_can_driver_node.cpp | 14 ++++++-- .../unit/test_wibotic_can_driver_node.cpp | 2 +- .../uavcan/20200.WiBoticInfo.uavcan | 17 +++++++++ 11 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 wibotic_connector_can/README.md create mode 100644 wibotic_connector_can/uavcan/20200.WiBoticInfo.uavcan diff --git a/.github/workflows/run-unit-tests.yaml b/.github/workflows/run-unit-tests.yaml index 7f23a7f..4281cd2 100644 --- a/.github/workflows/run-unit-tests.yaml +++ b/.github/workflows/run-unit-tests.yaml @@ -2,6 +2,7 @@ name: Run unit tests on: + push: workflow_dispatch: # TODO: ENABLE WHEN READY # pull_request: diff --git a/README.md b/README.md index db63b3e..46dab28 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,33 @@ # wibotic_ros -The repository contains `wibotic_connector_can` and `wibotic_msgs` packages. It reads a CAN Bus thanks to the uavcan library and sends the measurements to ROS 2. +The repository contains `wibotic_connector_can` and `wibotic_msgs` packages. It reads a CAN Bus thanks to the uavcan library and sends the measurements from [Wibotic Wireless Charger](https://husarion.com/manuals/panther/panther-wch/) to ROS 2. -## ROS Nodes +## Quick start -### wibotic_connector_can +### Add can interface -It reads a CAN Bus thanks to the uavcan library and sends the measurements to ROS 2. +```bash +sudo slcand -o -s6 -t hw -S 3000000 /dev/ttyACM0 +sudo ip link set up can0 type can bitrate 500000 +``` -#### Publishes +### Create workspace -- `wibotic_info` [*wibotic_msgs/WiboticInfo*]: Wibotic charger measurements. +```bash +mkdir ~/husarion_ws +cd ~/husarion_ws +git clone -b ros2 https://github.com/husarion/wibotic_ros.git src/wibotic_ros +``` -#### Parameters +### Build -- `~can_iface_name` [*string*, default: **can0**]: CAN BUS interface used for Wibotic receiver. -- `uavcan_node_id_` [*int*, default: **20**]: Uavcan node ID. -- `uavcan_node_name_` [*string*, default: **can0**]: Uavcan node name. -- `update_time_s_` [*string*, default: **can0**]: The period of reading WiboticInfo on a CAN BUS. +```bash +sudo rosdep init +rosdep update --rosdistro $ROS_DISTRO +rosdep install --from-paths src -y -i -## Add can interface +source /opt/ros/$ROS_DISTRO/setup.bash +colcon build --symlink-install --packages-up-to wibotic_connector_can --cmake-args -DCMAKE_BUILD_TYPE=Release -```bash -sudo slcand -o -s6 -t hw -S 3000000 /dev/ttyACM0 -sudo ip link set up can0 type can bitrate 500000 +source install/setup.bash ``` diff --git a/wibotic_connector_can/README.md b/wibotic_connector_can/README.md new file mode 100644 index 0000000..f78c181 --- /dev/null +++ b/wibotic_connector_can/README.md @@ -0,0 +1,20 @@ +# wibotic_connector_can + +It reads a CAN Bus thanks to the uavcan library and sends the measurements to ROS 2. + +## ROS Nodes + +### wibotic_connector_can + +It reads a CAN Bus thanks to the uavcan library and sends the measurements to ROS 2. + +#### Publishes + +- `wibotic_info` [*wibotic_msgs/WiboticInfo*]: Wibotic charger measurements. + +#### Parameters + +- `~can_iface_name` [*string*, default: **can0**]: CAN BUS interface used for Wibotic receiver. +- `~uavcan_node_id_` [*int*, default: **20**]: Uavcan node ID. +- `~uavcan_node_name_` [*string*, default: **can0**]: Uavcan node name. +- `~update_time_s_` [*string*, default: **can0**]: The period of reading WiboticInfo on a CAN BUS. diff --git a/wibotic_connector_can/cmake/SuperBuild.cmake b/wibotic_connector_can/cmake/SuperBuild.cmake index 565b837..3676904 100644 --- a/wibotic_connector_can/cmake/SuperBuild.cmake +++ b/wibotic_connector_can/cmake/SuperBuild.cmake @@ -30,16 +30,11 @@ ExternalProject_Add( STEP_TARGETS build) ExternalProject_Add( - ep_platform_specific_components # Name of the external project + ep_platform_specific_components GIT_REPOSITORY - https://github.com/OpenCyphal-Garage/platform_specific_components/ # Repository - # URL - GIT_TAG 4745ef59f57b7e1c34705b127ea8c7a35e3874c1 # Specific commit - PREFIX - ${CMAKE_CURRENT_BINARY_DIR}/ep_platform_specific_components # Directory - # where external - # project will - # be + https://github.com/OpenCyphal-Garage/platform_specific_components/ + GIT_TAG 4745ef59f57b7e1c34705b127ea8c7a35e3874c1 + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ep_platform_specific_components CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND @@ -47,7 +42,6 @@ ExternalProject_Add( ${CMAKE_CURRENT_BINARY_DIR}/ep_platform_specific_components/src/ep_platform_specific_components/linux/libuavcan/include ${CMAKE_INSTALL_PREFIX}/include ${INSTALL_DIR}) -# Make sure that the install directory is created install(DIRECTORY ${INSTALL_DIR} DESTINATION ${CMAKE_INSTALL_PREFIX}) ExternalProject_Add( diff --git a/wibotic_connector_can/include/wibotic_connector_can/uavcan_types/wibotic/WiBoticInfo.hpp b/wibotic_connector_can/include/wibotic_connector_can/uavcan_types/wibotic/WiBoticInfo.hpp index f5d8f20..cab9c2e 100644 --- a/wibotic_connector_can/include/wibotic_connector_can/uavcan_types/wibotic/WiBoticInfo.hpp +++ b/wibotic_connector_can/include/wibotic_connector_can/uavcan_types/wibotic/WiBoticInfo.hpp @@ -17,7 +17,8 @@ * * Autogenerated, do not edit. * - * Source file: /home/husarion/ros2_ws/src/wibotic/20200.WiBoticInfo.uavcan + * Source file: + * https://github.com/husarion/wibotic_ros/tree/ros2/wibotic_connector_can/uavcan/20200.WiBoticInfo.uavcan */ #ifndef WIBOTIC_WIBOTICINFO_HPP_INCLUDED diff --git a/wibotic_connector_can/include/wibotic_connector_can/wibotic_can_driver.hpp b/wibotic_connector_can/include/wibotic_connector_can/wibotic_can_driver.hpp index 0107635..192ecdc 100644 --- a/wibotic_connector_can/include/wibotic_connector_can/wibotic_can_driver.hpp +++ b/wibotic_connector_can/include/wibotic_connector_can/wibotic_can_driver.hpp @@ -44,7 +44,7 @@ class WiboticCanDriverInterface * * @exception std::runtime_error Thrown if can interface cannot be found. * */ - virtual void SetUavCanSettings( + virtual void ConfigureUavCan( const std::string & can_iface_name, std::size_t node_id, const std::string & node_name) = 0; /** @@ -92,7 +92,7 @@ class WiboticCanDriverInterface * @brief Class for the Wibotic CAN driver. * * This class inherits from the `WiboticCanDriverInterface` and implements its methods. - * Class communicates with CAN interface and gets WiboticInfo messages. + * Class communicates with CAN interface using libuavcan and gets WiboticInfo messages. */ class WiboticCanDriver : public WiboticCanDriverInterface { @@ -108,7 +108,7 @@ class WiboticCanDriver : public WiboticCanDriverInterface * * @exception std::runtime_error Thrown if can interface cannot be found. * */ - void SetUavCanSettings( + void ConfigureUavCan( const std::string & can_iface_name, std::size_t node_id, const std::string & node_name) override; diff --git a/wibotic_connector_can/package.xml b/wibotic_connector_can/package.xml index 6a4be9e..f81abb3 100644 --- a/wibotic_connector_can/package.xml +++ b/wibotic_connector_can/package.xml @@ -3,14 +3,14 @@ wibotic_connector_can 0.1.0 - Integration Panther with Wibotic charger + Integration Husarion UGV with Wibotic charger Husarion Apache License 2.0 https://husarion.com/ - https://github.com/husarion/panther_ros - https://github.com/husarion/panther_ros/issues + https://github.com/husarion/wibotic_ros + https://github.com/husarion/wibotic_ros/issues Jakub Delicat diff --git a/wibotic_connector_can/src/wibotic_can_driver.cpp b/wibotic_connector_can/src/wibotic_can_driver.cpp index c1cffb4..0e230f6 100644 --- a/wibotic_connector_can/src/wibotic_can_driver.cpp +++ b/wibotic_connector_can/src/wibotic_can_driver.cpp @@ -16,7 +16,7 @@ namespace wibotic_connector_can { -void WiboticCanDriver::SetUavCanSettings( +void WiboticCanDriver::ConfigureUavCan( const std::string & can_iface_name, std::size_t node_id, const std::string & node_name) { can_iface_name_ = can_iface_name; diff --git a/wibotic_connector_can/src/wibotic_can_driver_node.cpp b/wibotic_connector_can/src/wibotic_can_driver_node.cpp index 37df40c..67236e1 100644 --- a/wibotic_connector_can/src/wibotic_can_driver_node.cpp +++ b/wibotic_connector_can/src/wibotic_can_driver_node.cpp @@ -46,7 +46,7 @@ void WiboticCanDriverNode::DeclareParameters() this->declare_parameter("can_iface_name", "can0"); this->declare_parameter("uavcan_node_id", 20); this->declare_parameter("uavcan_node_name", "com.wibotic.ros_connector"); - this->declare_parameter("update_time_s", 1.0); + this->declare_parameter("update_time_s", 0.2); } void WiboticCanDriverNode::GetParameters() @@ -59,7 +59,7 @@ void WiboticCanDriverNode::GetParameters() void WiboticCanDriverNode::CreateWiboticCanDriver() { - wibotic_can_driver_->SetUavCanSettings(can_iface_name_, uavcan_node_id_, uavcan_node_name_); + wibotic_can_driver_->ConfigureUavCan(can_iface_name_, uavcan_node_id_, uavcan_node_name_); wibotic_can_driver_->CreateUavCanNode(); wibotic_can_driver_->CreateWiboticInfoSubscriber(); wibotic_can_driver_->Activate(); @@ -69,6 +69,7 @@ wibotic::WiBoticInfo WiboticCanDriverNode::GetWiboticInfo() { const auto update_time_ms = static_cast(update_time_s_ * 1000); wibotic_can_driver_->Spin(update_time_ms); + return wibotic_can_driver_->GetWiboticInfo(); } @@ -78,8 +79,15 @@ void WiboticCanDriverNode::WiboticInfoTimerCallback() throw std::runtime_error("Trying to get WiboticInfo message from nonexisting driver."); } + wibotic::WiBoticInfo wibotic_info; + try { + wibotic_info = GetWiboticInfo(); + } catch (const std::runtime_error & e) { + // Skip if there is no messages. + return; + } + try { - auto wibotic_info = GetWiboticInfo(); wibotic_info_pub_->publish(ConvertWiboticInfoToMsg(wibotic_info)); } catch (const std::runtime_error & e) { RCLCPP_WARN(this->get_logger(), e.what()); diff --git a/wibotic_connector_can/test/unit/test_wibotic_can_driver_node.cpp b/wibotic_connector_can/test/unit/test_wibotic_can_driver_node.cpp index 550b64b..36d7749 100644 --- a/wibotic_connector_can/test/unit/test_wibotic_can_driver_node.cpp +++ b/wibotic_connector_can/test/unit/test_wibotic_can_driver_node.cpp @@ -36,7 +36,7 @@ class MockWiboticCanDriver : public wibotic_connector_can::WiboticCanDriverInter { public: MOCK_METHOD( - void, SetUavCanSettings, (const std::string &, std::size_t, const std::string &), (override)); + void, ConfigureUavCan, (const std::string &, std::size_t, const std::string &), (override)); MOCK_METHOD(void, CreateUavCanNode, (), (override)); MOCK_METHOD(void, CreateWiboticInfoSubscriber, (), (override)); MOCK_METHOD(void, Activate, (), (override)); diff --git a/wibotic_connector_can/uavcan/20200.WiBoticInfo.uavcan b/wibotic_connector_can/uavcan/20200.WiBoticInfo.uavcan new file mode 100644 index 0000000..88d5fbe --- /dev/null +++ b/wibotic_connector_can/uavcan/20200.WiBoticInfo.uavcan @@ -0,0 +1,17 @@ +# +# WiBotic periodic information. +# + +# +# Primary parameters. +# Some fields can be set to NAN if their values are unknown. +# +float16 VMonBatt +float16 IBattery +float16 VRect +float16 VMonCharger +float16 TBoard +float16 TargetIBatt +float16 ICharger +float16 ISingleCharger2 +float16 ISingleCharger3