commit 74f6c2f631c9d44cf97056a302ca2abf259a85b4 Author: Alex Mikhalev Date: Wed Sep 25 14:56:05 2019 -0700 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5d43964 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.vscode +/build +/install +/log +/src/*/build +/src/*/cmake-build* \ No newline at end of file diff --git a/src/uaspire_controls/CMakeLists.txt b/src/uaspire_controls/CMakeLists.txt new file mode 100644 index 0000000..21fd101 --- /dev/null +++ b/src/uaspire_controls/CMakeLists.txt @@ -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() diff --git a/src/uaspire_controls/main.cc b/src/uaspire_controls/main.cc new file mode 100644 index 0000000..d1cb770 --- /dev/null +++ b/src/uaspire_controls/main.cc @@ -0,0 +1,63 @@ +#include + +#include +#include +#include +#include + +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::SharedPtr _command_subscription; + ros::Publisher::SharedPtr _sensors_publisher; + ros::WallRate _rate; + +public: + RCLCPP_SHARED_PTR_DEFINITIONS(ControlsNode) + + ControlsNode() + : Node("uaspire_controls"), + _rate(1.0) + { + _command_subscription = create_subscription( + "uaspire/commands", + ros::QoS(10), + std::bind(&ControlsNode::on_message, this, arg::_1) + ); + _sensors_publisher = create_publisher( + "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; +} diff --git a/src/uaspire_controls/package.xml b/src/uaspire_controls/package.xml new file mode 100644 index 0000000..37bbdc9 --- /dev/null +++ b/src/uaspire_controls/package.xml @@ -0,0 +1,24 @@ + + + + uaspire_controls + 0.0.1 + UASPIRE Controls + Alex Mikhalev + Apache License 2.0 + Alex Mikhalev + + ament_cmake + + rclcpp + std_msgs + uaspire_msgs + + rclcpp + std_msgs + uaspire_msgs + + + ament_cmake + + \ No newline at end of file diff --git a/src/uaspire_msgs/CMakeLists.txt b/src/uaspire_msgs/CMakeLists.txt new file mode 100644 index 0000000..947a8f9 --- /dev/null +++ b/src/uaspire_msgs/CMakeLists.txt @@ -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() diff --git a/src/uaspire_msgs/main.cc b/src/uaspire_msgs/main.cc new file mode 100644 index 0000000..33c14ce --- /dev/null +++ b/src/uaspire_msgs/main.cc @@ -0,0 +1,3 @@ +int main() { + return 0; +} diff --git a/src/uaspire_msgs/msg/Command.msg b/src/uaspire_msgs/msg/Command.msg new file mode 100644 index 0000000..ae72173 --- /dev/null +++ b/src/uaspire_msgs/msg/Command.msg @@ -0,0 +1 @@ +string data diff --git a/src/uaspire_msgs/msg/Sensors.msg b/src/uaspire_msgs/msg/Sensors.msg new file mode 100644 index 0000000..672ea19 --- /dev/null +++ b/src/uaspire_msgs/msg/Sensors.msg @@ -0,0 +1 @@ +float32 position diff --git a/src/uaspire_msgs/package.xml b/src/uaspire_msgs/package.xml new file mode 100644 index 0000000..669ab68 --- /dev/null +++ b/src/uaspire_msgs/package.xml @@ -0,0 +1,24 @@ + + + + uaspire_msgs + 0.0.1 + UASPIRE Controls ROS Messages + Alex Mikhalev + Apache License 2.0 + Alex Mikhalev + + ament_cmake + rosidl_default_generators + + rclcpp + std_msgs + + rosidl_default_runtime + + rosidl_interface_packages + + + ament_cmake + + \ No newline at end of file diff --git a/uaspire.code-workspace b/uaspire.code-workspace new file mode 100644 index 0000000..caa4f56 --- /dev/null +++ b/uaspire.code-workspace @@ -0,0 +1,13 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "src/uaspire_controls" + } + ], + "settings": { + "ros.distro": "dashing" + } +} \ No newline at end of file