Skip to content

Commit

Permalink
review suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Delicat <[email protected]>
  • Loading branch information
delihus committed Oct 15, 2024
1 parent a9700c8 commit 3e0efb9
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 37 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name: Run unit tests

on:
push:
workflow_dispatch:
# TODO: ENABLE WHEN READY
# pull_request:
Expand Down
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
20 changes: 20 additions & 0 deletions wibotic_connector_can/README.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 4 additions & 10 deletions wibotic_connector_can/cmake/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,18 @@ 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
${CMAKE_COMMAND} -E copy_directory
${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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
{
Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions wibotic_connector_can/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<package format="3">
<name>wibotic_connector_can</name>
<version>0.1.0</version>
<description>Integration Panther with Wibotic charger</description>
<description>Integration Husarion UGV with Wibotic charger</description>

<maintainer email="[email protected]">Husarion</maintainer>
<license>Apache License 2.0</license>

<url type="website">https://husarion.com/</url>
<url type="repository">https://github.com/husarion/panther_ros</url>
<url type="bugtracker">https://github.com/husarion/panther_ros/issues</url>
<url type="repository">https://github.com/husarion/wibotic_ros</url>
<url type="bugtracker">https://github.com/husarion/wibotic_ros/issues</url>

<author email="[email protected]">Jakub Delicat</author>

Expand Down
2 changes: 1 addition & 1 deletion wibotic_connector_can/src/wibotic_can_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions wibotic_connector_can/src/wibotic_can_driver_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
Expand All @@ -69,6 +69,7 @@ wibotic::WiBoticInfo WiboticCanDriverNode::GetWiboticInfo()
{
const auto update_time_ms = static_cast<std::size_t>(update_time_s_ * 1000);
wibotic_can_driver_->Spin(update_time_ms);

return wibotic_can_driver_->GetWiboticInfo();
}

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
17 changes: 17 additions & 0 deletions wibotic_connector_can/uavcan/20200.WiBoticInfo.uavcan
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3e0efb9

Please sign in to comment.