Alex Mikhalev
5 years ago
commit
74f6c2f631
10 changed files with 204 additions and 0 deletions
@ -0,0 +1,6 @@ |
|||||||
|
.vscode |
||||||
|
/build |
||||||
|
/install |
||||||
|
/log |
||||||
|
/src/*/build |
||||||
|
/src/*/cmake-build* |
@ -0,0 +1,43 @@ |
|||||||
|
# CMakeLists.txt file to configure build of uaspire_controls |
||||||
|
|
||||||
|
# Set minimum version of CMake required to build |
||||||
|
cmake_minimum_required(VERSION 3.10 FATAL_ERROR) |
||||||
|
|
||||||
|
# Find ament meta build system |
||||||
|
find_package(ament_cmake REQUIRED) |
||||||
|
|
||||||
|
# Create uaspire_controls project |
||||||
|
project(uaspire_controls |
||||||
|
DESCRIPTION "UASPIRE Controls" |
||||||
|
LANGUAGES CXX) |
||||||
|
|
||||||
|
# Setup C++ version and compiler flags |
||||||
|
if(NOT CMAKE_CXX_STANDARD) |
||||||
|
set(CMAKE_CXX_STANDARD 14) |
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
||||||
|
endif() |
||||||
|
|
||||||
|
if (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|AppleClang|Clang)") |
||||||
|
add_compile_options(-Wall -Wextra -Wpedantic) |
||||||
|
endif() |
||||||
|
|
||||||
|
# Find required packages |
||||||
|
find_package(rclcpp REQUIRED) |
||||||
|
find_package(std_msgs REQUIRED) |
||||||
|
find_package(uaspire_msgs REQUIRED) |
||||||
|
|
||||||
|
# Create targets and add target dependencies |
||||||
|
add_executable(uaspire_controls |
||||||
|
main.cc |
||||||
|
) |
||||||
|
ament_target_dependencies(uaspire_controls |
||||||
|
rclcpp |
||||||
|
std_msgs |
||||||
|
uaspire_msgs |
||||||
|
) |
||||||
|
|
||||||
|
# Install files to correct locations |
||||||
|
install(TARGETS uaspire_controls |
||||||
|
DESTINATION bin) |
||||||
|
|
||||||
|
ament_package() |
@ -0,0 +1,63 @@ |
|||||||
|
#include <functional> |
||||||
|
|
||||||
|
#include <rclcpp/rclcpp.hpp> |
||||||
|
#include <std_msgs/msg/string.hpp> |
||||||
|
#include <uaspire_msgs/msg/command.hpp> |
||||||
|
#include <uaspire_msgs/msg/sensors.hpp> |
||||||
|
|
||||||
|
namespace arg = std::placeholders; |
||||||
|
namespace ros = ::rclcpp; |
||||||
|
using UaspireCommand = ::uaspire_msgs::msg::Command; |
||||||
|
using UaspireSensors = ::uaspire_msgs::msg::Sensors; |
||||||
|
|
||||||
|
class ControlsNode : public ros::Node |
||||||
|
{ |
||||||
|
private: |
||||||
|
ros::Subscription<UaspireCommand>::SharedPtr _command_subscription; |
||||||
|
ros::Publisher<UaspireSensors>::SharedPtr _sensors_publisher; |
||||||
|
ros::WallRate _rate; |
||||||
|
|
||||||
|
public: |
||||||
|
RCLCPP_SHARED_PTR_DEFINITIONS(ControlsNode) |
||||||
|
|
||||||
|
ControlsNode() |
||||||
|
: Node("uaspire_controls"), |
||||||
|
_rate(1.0) |
||||||
|
{ |
||||||
|
_command_subscription = create_subscription<UaspireCommand>( |
||||||
|
"uaspire/commands", |
||||||
|
ros::QoS(10), |
||||||
|
std::bind(&ControlsNode::on_message, this, arg::_1) |
||||||
|
); |
||||||
|
_sensors_publisher = create_publisher<UaspireSensors>( |
||||||
|
"uaspire/sensors", |
||||||
|
ros::QoS(10) |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
void on_message(const UaspireCommand::SharedPtr cmd) |
||||||
|
{ |
||||||
|
RCLCPP_INFO(get_logger(), "Command received: %s", cmd->data.c_str()); |
||||||
|
} |
||||||
|
|
||||||
|
void loop() { |
||||||
|
while (ros::ok()) { |
||||||
|
UaspireSensors sensors; |
||||||
|
sensors.position = ros::Clock(RCL_STEADY_TIME).now().seconds(); |
||||||
|
_sensors_publisher->publish(sensors); |
||||||
|
RCLCPP_INFO(get_logger(), "loop"); |
||||||
|
ros::spin_some(shared_from_this()); |
||||||
|
_rate.sleep(); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
int main(int argc, char** argv) { |
||||||
|
ros::init(argc, argv); |
||||||
|
{ |
||||||
|
auto node = ControlsNode::make_shared(); |
||||||
|
node->loop(); |
||||||
|
} |
||||||
|
ros::shutdown(); |
||||||
|
return 0; |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
<?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>uaspire_controls</name> |
||||||
|
<version>0.0.1</version> |
||||||
|
<description>UASPIRE Controls</description> |
||||||
|
<maintainer email="alex@amikhalev.com">Alex Mikhalev</maintainer> |
||||||
|
<license>Apache License 2.0</license> |
||||||
|
<author>Alex Mikhalev</author> |
||||||
|
|
||||||
|
<buildtool_depend>ament_cmake</buildtool_depend> |
||||||
|
|
||||||
|
<build_depend>rclcpp</build_depend> |
||||||
|
<build_depend>std_msgs</build_depend> |
||||||
|
<build_depend>uaspire_msgs</build_depend> |
||||||
|
|
||||||
|
<exec_depend>rclcpp</exec_depend> |
||||||
|
<exec_depend>std_msgs</exec_depend> |
||||||
|
<exec_depend>uaspire_msgs</exec_depend> |
||||||
|
|
||||||
|
<export> |
||||||
|
<build_type>ament_cmake</build_type> |
||||||
|
</export> |
||||||
|
</package> |
@ -0,0 +1,26 @@ |
|||||||
|
# CMakeLists.txt file to configure build of uaspire_msgs |
||||||
|
|
||||||
|
# Set minimum version of CMake required to build |
||||||
|
cmake_minimum_required(VERSION 3.10 FATAL_ERROR) |
||||||
|
|
||||||
|
# Find ament meta build system |
||||||
|
find_package(ament_cmake REQUIRED) |
||||||
|
|
||||||
|
# Create uaspire_controls project |
||||||
|
project(uaspire_msgs |
||||||
|
DESCRIPTION "UASPIRE Messages" |
||||||
|
LANGUAGES C CXX) |
||||||
|
|
||||||
|
# Find required packages |
||||||
|
find_package(rosidl_default_generators REQUIRED) |
||||||
|
|
||||||
|
# Create targets and add target dependencies |
||||||
|
rosidl_generate_interfaces(${PROJECT_NAME} |
||||||
|
"msg/Command.msg" |
||||||
|
"msg/Sensors.msg" |
||||||
|
) |
||||||
|
|
||||||
|
# Install files to correct locations |
||||||
|
|
||||||
|
ament_export_dependencies(rosidl_default_runtime) |
||||||
|
ament_package() |
@ -0,0 +1,24 @@ |
|||||||
|
<?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>uaspire_msgs</name> |
||||||
|
<version>0.0.1</version> |
||||||
|
<description>UASPIRE Controls ROS Messages</description> |
||||||
|
<maintainer email="alex@amikhalev.com">Alex Mikhalev</maintainer> |
||||||
|
<license>Apache License 2.0</license> |
||||||
|
<author>Alex Mikhalev</author> |
||||||
|
|
||||||
|
<buildtool_depend>ament_cmake</buildtool_depend> |
||||||
|
<buildtool_depend>rosidl_default_generators</buildtool_depend> |
||||||
|
|
||||||
|
<build_depend>rclcpp</build_depend> |
||||||
|
<build_depend>std_msgs</build_depend> |
||||||
|
|
||||||
|
<exec_depend>rosidl_default_runtime</exec_depend> |
||||||
|
|
||||||
|
<member_of_group>rosidl_interface_packages</member_of_group> |
||||||
|
|
||||||
|
<export> |
||||||
|
<build_type>ament_cmake</build_type> |
||||||
|
</export> |
||||||
|
</package> |
Loading…
Reference in new issue