-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into compressed_image
- Loading branch information
Showing
31 changed files
with
636 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/*: | ||
ros__parameters: | ||
camera_id: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(nucleo_communicate) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif () | ||
|
||
# find dependencies | ||
find_package(ament_cmake REQUIRED) | ||
# uncomment the following section in order to fill in | ||
# further dependencies manually. | ||
# find_package(<dependency> REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(rclcpp_components REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
find_package(packet_interfaces REQUIRED) | ||
|
||
add_library(channel | ||
SHARED | ||
src/recv_data.cpp | ||
src/send_data.cpp | ||
src/serial_port.cpp | ||
src/channel.cpp | ||
) | ||
|
||
ament_target_dependencies(channel | ||
rclcpp | ||
rclcpp_components | ||
std_msgs | ||
packet_interfaces | ||
) | ||
|
||
target_include_directories(channel | ||
PRIVATE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:include> | ||
) | ||
|
||
rclcpp_components_register_node( | ||
channel | ||
PLUGIN "channel::Channel" | ||
EXECUTABLE nucleo-channel | ||
) | ||
|
||
install( | ||
TARGETS channel | ||
EXPORT channel_component | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib | ||
RUNTIME DESTINATION bin | ||
) | ||
|
||
install( | ||
DIRECTORY launch | ||
DESTINATION share/${PROJECT_NAME} | ||
) | ||
|
||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# nucleo_communicate | ||
|
||
Nucleoとの通信周り | ||
|
||
## Nodes | ||
|
||
- `Channel`: データのやり取り(TX/RX両方) | ||
|
||
## Executables | ||
|
||
- `nucleo-chanel`: `Channel`Nodeをspin | ||
|
||
## Launches | ||
|
||
- `channel_launch.py`: `Channel`Nodeを`device`namespaceでspin |
45 changes: 45 additions & 0 deletions
45
device/nucleo_communicate/include/nucleo_communicate/channel.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef NUCLEO_COMMUNICATE_CHANNEL_HPP | ||
#define NUCLEO_COMMUNICATE_CHANNEL_HPP | ||
|
||
#include <mutex> | ||
|
||
#include <packet_interfaces/msg/current.hpp> | ||
#include <packet_interfaces/msg/flex.hpp> | ||
#include <packet_interfaces/msg/power.hpp> | ||
#include <packet_interfaces/msg/voltage.hpp> | ||
#include <rclcpp/node.hpp> | ||
#include <rclcpp/node_options.hpp> | ||
#include <rclcpp/subscription.hpp> | ||
#include <std_msgs/msg/empty.hpp> | ||
|
||
#include "nucleo_communicate/serial_port.hpp" | ||
|
||
namespace channel { | ||
|
||
class Channel : public rclcpp::Node { | ||
private: | ||
nucleo_com::SerialPort serial; | ||
std::mutex serial_mutex; | ||
|
||
rclcpp::Subscription<std_msgs::msg::Empty>::SharedPtr quit_subscription; | ||
rclcpp::Subscription<packet_interfaces::msg::Power>::SharedPtr power_subscription; | ||
|
||
rclcpp::Publisher<packet_interfaces::msg::Flex>::SharedPtr flex1_publisher; | ||
rclcpp::Publisher<packet_interfaces::msg::Flex>::SharedPtr flex2_publisher; | ||
rclcpp::Publisher<packet_interfaces::msg::Current>::SharedPtr current_publisher; | ||
rclcpp::Publisher<packet_interfaces::msg::Voltage>::SharedPtr voltage_publisher; | ||
|
||
rclcpp::TimerBase::SharedPtr timer; | ||
|
||
void quit_subscription_callback(const std_msgs::msg::Empty& _msg); | ||
void power_subscription_callback(const packet_interfaces::msg::Power& msg); | ||
|
||
void timer_callback(); | ||
|
||
public: | ||
Channel(const rclcpp::NodeOptions& options = rclcpp::NodeOptions()); | ||
}; | ||
|
||
} | ||
|
||
#endif // NUCLEO_COMMUNICATE_CHANNEL_HPP |
25 changes: 25 additions & 0 deletions
25
device/nucleo_communicate/include/nucleo_communicate/recv_data.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef NUCLEO_COMMUNICATE_RECV_DATA_HPP | ||
#define NUCLEO_COMMUNICATE_RECV_DATA_HPP | ||
|
||
#include <array> | ||
#include <cstdint> | ||
#include <std_msgs/msg/detail/header__struct.hpp> | ||
|
||
namespace nucleo_com { | ||
|
||
struct RecvData { | ||
using BufferType = std::array<std::uint8_t, 8>; | ||
|
||
BufferType buffer; | ||
|
||
explicit RecvData(BufferType&& buf); | ||
|
||
auto flex1_value() const -> std::uint16_t; | ||
auto flex2_value() const -> std::uint16_t; | ||
auto current_value() const -> std::uint16_t; | ||
auto voltage_value() const -> std::uint16_t; | ||
}; | ||
|
||
} | ||
|
||
#endif // NUCLEO_COMMUNICATE_RECV_DATA_HPP |
25 changes: 25 additions & 0 deletions
25
device/nucleo_communicate/include/nucleo_communicate/send_data.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef NUCLEO_COMMUNICATE_SEND_DATA_HPP | ||
#define NUCLEO_COMMUNICATE_SEND_DATA_HPP | ||
|
||
#include <array> | ||
#include <cstdint> | ||
|
||
#include "packet_interfaces/msg/power.hpp" | ||
|
||
namespace nucleo_com { | ||
|
||
struct SendData { | ||
using BufferType = std::array<std::uint8_t, 16>; | ||
|
||
BufferType buffer; | ||
|
||
SendData() = delete; | ||
|
||
explicit SendData(BufferType&& buf); | ||
|
||
static auto from_msg(const packet_interfaces::msg::Power& msg) -> SendData; | ||
}; | ||
|
||
} | ||
|
||
#endif // NUCLEO_COMMUNICATE_SEND_DATA_HPP |
36 changes: 36 additions & 0 deletions
36
device/nucleo_communicate/include/nucleo_communicate/serial_port.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef NUCLEO_COMMUNICATE_SERIAL_PORT_HPP | ||
#define NUCLEO_COMMUNICATE_SERIAL_PORT_HPP | ||
|
||
#include <stdio.h> | ||
#include <string> | ||
#include <termios.h> | ||
|
||
#include "nucleo_communicate/recv_data.hpp" | ||
#include "nucleo_communicate/send_data.hpp" | ||
|
||
namespace nucleo_com { | ||
|
||
class SerialPort { | ||
private: | ||
FILE* serial; | ||
|
||
public: | ||
explicit SerialPort(const std::string& path = "/dev/ttyACM0"); | ||
|
||
~SerialPort(); | ||
|
||
// same as | ||
// https://os.mbed.com/docs/mbed-os/v6.16/apis/serial-uart-apis.html#configuration | ||
void setup(); | ||
|
||
// https://github.com/rogy-AquaLab/2024_umiusi_nucleo | ||
void send(const nucleo_com::SendData& data); | ||
|
||
auto receive() -> nucleo_com::RecvData; | ||
|
||
void quit(); | ||
}; | ||
|
||
} | ||
|
||
#endif // NUCLEO_COMMUNICATE_SERIAL_PORT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from launch import LaunchDescription | ||
from launch_ros.actions import Node | ||
|
||
|
||
def generate_launch_description(): | ||
channel = Node( | ||
package="nucleo_communicate", | ||
executable="nucleo-channel", | ||
namespace="device", | ||
remappings=[ | ||
("/device/flex_1", "/packet/sensors/flex_1"), | ||
("/device/flex_2", "/packet/sensors/flex_2"), | ||
("/device/current", "/packet/sensors/current"), | ||
("/device/voltage", "/packet/sensors/voltage"), | ||
# FIXME: /packet namespaceにremap | ||
("/device/power", "/device/order/power"), | ||
("/device/quit", "/device/order/quit") | ||
], | ||
) | ||
return LaunchDescription([channel]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>nucleo_communicate</name> | ||
<version>0.1.0</version> | ||
<description>Nucleoとの通信周り</description> | ||
<maintainer email="[email protected]">h1rono</maintainer> | ||
<license>MIT</license> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<depend>rclcpp</depend> | ||
<depend>rclcpp_components</depend> | ||
<depend>std_msgs</depend> | ||
<depend>packet_interfaces</depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
Oops, something went wrong.