Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Define custom message for setting target angle.
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger committed May 8, 2024
1 parent f2b6ad2 commit 96f0f83
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.8)
#######################################################################################
project(robotem_rovne)
set(ROBOTEM_ROVNE_TARGET ${PROJECT_NAME}_node)
set(ROBOTEM_ROVNE_SRV_TARGET ${PROJECT_NAME})
#######################################################################################
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Werror -Wpedantic)
Expand All @@ -13,6 +14,13 @@ find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(mp-units REQUIRED)
find_package(rosidl_default_generators REQUIRED)
#######################################################################################
rosidl_generate_interfaces(${ROBOTEM_ROVNE_SRV_TARGET}
"srv/AngularTarget.srv"
)
#######################################################################################
rosidl_get_typesupport_target(cpp_typesupport_target ${ROBOTEM_ROVNE_SRV_TARGET} "rosidl_typesupport_cpp")
#######################################################################################
add_executable(${ROBOTEM_ROVNE_TARGET}
src/Node.cpp
Expand All @@ -29,10 +37,13 @@ target_compile_features(${ROBOTEM_ROVNE_TARGET} PRIVATE cxx_std_20)
target_link_libraries(${ROBOTEM_ROVNE_TARGET}
${rclcpp_LIBRARIES}
${mp-units_LIBRARIES}
${cpp_typesupport_target}
)
#######################################################################################
ament_target_dependencies(${ROBOTEM_ROVNE_TARGET} rclcpp std_msgs std_srvs)
#######################################################################################
ament_export_dependencies(rosidl_default_runtime)
#######################################################################################
install(TARGETS ${ROBOTEM_ROVNE_TARGET} DESTINATION lib/${PROJECT_NAME})
#######################################################################################
ament_package()
Expand Down
4 changes: 4 additions & 0 deletions include/robotem_rovne/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <rclcpp/rclcpp.hpp>

#include <std_srvs/srv/empty.hpp>
#include <robotem_rovne/srv/angular_target.hpp>

#include <mp-units/systems/si/si.h>
#include <mp-units/systems/angular/angular.h>
Expand Down Expand Up @@ -51,6 +52,9 @@ class Node : public rclcpp::Node
rclcpp::Service<std_srvs::srv::Empty>::SharedPtr _req_stop_service_server;
void init_req_stop_service_server();

rclcpp::Service<robotem_rovne::srv::AngularTarget>::SharedPtr _req_set_angular_target_service_server;
void init_req_set_angular_target_service_server();

static std::chrono::milliseconds constexpr CTRL_LOOP_RATE{50};
rclcpp::TimerBase::SharedPtr _ctrl_loop_timer;
void init_ctrl_loop();
Expand Down
4 changes: 4 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<buildtool_depend>rosidl_default_generators</buildtool_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>

<depend>rclcpp</depend>
<depend>std_msgs</depend>
<depend>std_srvs</depend>
Expand Down
12 changes: 12 additions & 0 deletions src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Node::Node()
{
init_req_start_service_server();
init_req_stop_service_server();
init_req_set_angular_target_service_server();

init_ctrl_loop();

Expand Down Expand Up @@ -63,6 +64,17 @@ void Node::init_req_stop_service_server()
});
}

void Node::init_req_set_angular_target_service_server()
{
_req_set_angular_target_service_server = create_service<robotem_rovne::srv::AngularTarget>(
"cmd_robot/set_angular_target",
[this](robotem_rovne::srv::AngularTarget::Request::SharedPtr request,
robotem_rovne::srv::AngularTarget::Response::SharedPtr /* response */)
{
RCLCPP_INFO(get_logger(), "set angular target request received: %0.2f", request->target_angle_rad);
});
}

void Node::init_ctrl_loop()
{
_ctrl_loop_timer = create_wall_timer(CTRL_LOOP_RATE, [this]() { this->ctrl_loop(); });
Expand Down
2 changes: 2 additions & 0 deletions srv/AngularTarget.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
float32 target_angle_rad
---

0 comments on commit 96f0f83

Please sign in to comment.