diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 5d608dc..a3b6052 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,28 +1,30 @@ -## Issue Description +## Description +### Problem: +Provide a clear description of the issue -Please provide a clear and concise description of the issue. +### Goal: +The purpose of this issue is to enhance the codebase by including comprehensive exception tests. These tests will ensure that the system properly handles cases where an invalid or missing IP address is provided, and they will verify that all potential problems during the connection establishment are appropriately handled. -### Steps to Reproduce (if applicable) +### Proposed Changes: -If the issue is a bug, include steps to reproduce the problem: +1. Add test cases to check for invalid or missing IP addresses before starting the UDP connection. +2. Verify that exceptions are raised when attempting to establish a connection without a valid IP address. +3. Test the system's response to various connection-related problems, such as network unavailability or port conflicts, to ensure graceful handling of such scenarios. -1. Step 1 -2. Step 2 -3. ... +### Expected Benefits: +By adding these exceptions tests, we can achieve the following benefits: -### Expected Behavior +Improve the robustness and reliability of the system by catching potential issues during connection establishment. +Reduce the likelihood of unexpected failures and errors, which will facilitate easier debugging and maintenance. +Enhance the overall stability of the system, providing a more seamless experience for end-users. -A clear and concise description of what you expected to happen. -### Screenshots (if applicable) +## Steps to Reproduce +Set up the testing environment to isolate the code related to IP address validation and UDP connection establishment. +Design test cases to cover scenarios where an invalid or missing IP address is provided. +Implement the tests and ensure they raise appropriate exceptions when necessary. +Create test cases to simulate various connection-related problems and validate the system's response. +Run the test suite and observe the results, ensuring that all tests pass successfully. -If the issue is related to the UI, consider including screenshots to help explain the problem. - -### Environment (if applicable) - -- OS: [e.g., Windows 10, macOS Big Sur] -- Browser: [e.g., Chrome, Firefox] - -### Additional Context - -Add any other context about the issue here. \ No newline at end of file +## Additional Notes +Any additional information or context relevant to the issue can be added here. diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..e39d27b --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,28 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Code Quality +run-name: Run Lint Checks +on: [push, pull_request] +jobs: + cpplint: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + + - name: Set up Python 3.7 + uses: actions/setup-python@v3 + with: + python-version: 3.7 + + - name: Update pip + run: python -m pip install --upgrade pip + + - name: Install dependencies + run: pip install cpplint flake8 + + - name: Lint with flake8 + run: flake8 + + - name: Lint with cpplint + run: cpplint --recursive . diff --git a/littlebot_base/include/littlebot_base/littlebot_hardware.hpp b/littlebot_base/include/littlebot_base/littlebot_hardware.hpp index 700374b..3a35edc 100644 --- a/littlebot_base/include/littlebot_base/littlebot_hardware.hpp +++ b/littlebot_base/include/littlebot_base/littlebot_hardware.hpp @@ -1,7 +1,8 @@ -#ifndef LITTLEBOT_BASE__LITTLEBOT_HARDWARE_HPP_ -#define LITTLEBOT_BASE__LITTLEBOT_HARDWARE_HPP_ +// @ Copyright 2023 Nestor Neto + +#ifndef LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_LITTLEBOT_HARDWARE_HPP_ +#define LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_LITTLEBOT_HARDWARE_HPP_ -#include #include #include #include @@ -26,25 +27,23 @@ #include "rclcpp/time.hpp" -using namespace std::chrono_literals; - -namespace littlebot_base -{ -class LittlebotHardware -: public hardware_interface::BaseInterface -{ - -public: +namespace littlebot_base { +class LittlebotHardware : public + hardware_interface::BaseInterface { + public: RCLCPP_SHARED_PTR_DEFINITIONS(LittlebotHardware) HARDWARE_INTERFACE_PUBLIC - hardware_interface::return_type configure(const hardware_interface::HardwareInfo & info) override; + hardware_interface::return_type + configure(const hardware_interface::HardwareInfo & info) override; HARDWARE_INTERFACE_PUBLIC - std::vector export_state_interfaces() override; + std::vector + export_state_interfaces() override; HARDWARE_INTERFACE_PUBLIC - std::vector export_command_interfaces() override; + std::vector + export_command_interfaces() override; HARDWARE_INTERFACE_PUBLIC hardware_interface::return_type start() override; @@ -58,7 +57,7 @@ class LittlebotHardware HARDWARE_INTERFACE_PUBLIC hardware_interface::return_type write() override; -private: + private: // Store the command for the simulated robot double left_command_velocity_ = 0; double right_command_velocity_ = 0; @@ -76,9 +75,8 @@ class LittlebotHardware // Serial device serial::Serial serial_device_; std::string message_protocol_; - }; } // namespace littlebot_base -#endif // LITTLEBOT_BASE__LITTLEBOT_HARDWARE_HPP_ \ No newline at end of file +#endif // LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_LITTLEBOT_HARDWARE_HPP_ diff --git a/littlebot_base/include/littlebot_base/protocol.hpp b/littlebot_base/include/littlebot_base/protocol.hpp index 388fe4d..1181bf6 100755 --- a/littlebot_base/include/littlebot_base/protocol.hpp +++ b/littlebot_base/include/littlebot_base/protocol.hpp @@ -7,8 +7,8 @@ * * */ -#ifndef _BASE__COMMUNICATION_PROTOCOL_HPP_ -#define _BASE__COMMUNICATION_PROTOCOL_HPP_ +#ifndef LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_PROTOCOL_HPP_ +#define LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_PROTOCOL_HPP_ #include #include @@ -25,7 +25,7 @@ #include -namespace littlebot{ +namespace littlebot { class Protocol { public: @@ -34,7 +34,7 @@ class Protocol { * @brief Constructor of the serial class * */ - Protocol(std::string port); + explicit Protocol(std::string port); /** * @brief Destroyer of the serial class @@ -72,7 +72,7 @@ class Protocol { const int kLengthBuffer_ = 200; /** Port */ - serial::Serial port_ ; + serial::Serial port_; /** Buffer */ std::string msg_protocol_; @@ -80,8 +80,7 @@ class Protocol { /** */ float velocity_read_[2]; float velocity_write_[2]; - }; -} // namespace serial +} // namespace littlebot -#endif // _BASE__COMMUNICATION_PROTOCOL_HPP_ +#endif // LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_PROTOCOL_HPP_ diff --git a/littlebot_base/include/littlebot_base/reader.hpp b/littlebot_base/include/littlebot_base/reader.hpp index 5feb526..db266be 100755 --- a/littlebot_base/include/littlebot_base/reader.hpp +++ b/littlebot_base/include/littlebot_base/reader.hpp @@ -1,10 +1,9 @@ // Copyright 2022 Nestor -#ifndef LITTLEBOT_BASE_READER_HPP_ -#define LITTLEBOT_BASE_READER_HPP_ +#ifndef LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_READER_HPP_ +#define LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_READER_HPP_ #include -#include #include #include #include @@ -21,29 +20,29 @@ #define LITTLEBOT_BASE_READER_PUBLIC __attribute__((visibility("default"))) namespace littlebot_base { - class Reader : public rclcpp::Node - { - public: - LITTLEBOT_BASE_READER_PUBLIC - explicit Reader(const rclcpp::NodeOptions &options); - - LITTLEBOT_BASE_READER_PUBLIC - explicit Reader(const rclcpp::NodeOptions & options, serial::Serial *serial); - - protected: - void on_timer(); - - private: - size_t count_; - rclcpp::Publisher::SharedPtr pub1_; - rclcpp::Publisher::SharedPtr pub2_; - rclcpp::Publisher::SharedPtr pub3_; - rclcpp::Publisher::SharedPtr pub4_; - rclcpp::TimerBase::SharedPtr timer_; - std::string message_; - serial::Serial *serial_; - }; - -} // namespace littlebot_base - -#endif // LITTLEBOT_BASE_READER_HPP_ + +class Reader : public rclcpp::Node { + public: + LITTLEBOT_BASE_READER_PUBLIC + explicit Reader(const rclcpp::NodeOptions &options); + + LITTLEBOT_BASE_READER_PUBLIC + explicit Reader(const rclcpp::NodeOptions & options, serial::Serial *serial); + + protected: + void on_timer(); + + private: + size_t count_; + rclcpp::Publisher::SharedPtr pub1_; + rclcpp::Publisher::SharedPtr pub2_; + rclcpp::Publisher::SharedPtr pub3_; + rclcpp::Publisher::SharedPtr pub4_; + rclcpp::TimerBase::SharedPtr timer_; + std::string message_; + serial::Serial *serial_; +}; + +} // namespace littlebot_base + +#endif // LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_READER_HPP_ diff --git a/littlebot_base/include/littlebot_base/writer.hpp b/littlebot_base/include/littlebot_base/writer.hpp index bcebe38..a1f967c 100755 --- a/littlebot_base/include/littlebot_base/writer.hpp +++ b/littlebot_base/include/littlebot_base/writer.hpp @@ -1,12 +1,10 @@ - // Copyright Nestor 2022 -#ifndef LITTLEBOT_BASE_WRITER_HPP_ -#define LITTLEBOT_BASE_WRITER_HPP_ +#ifndef LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_WRITER_HPP_ +#define LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_WRITER_HPP_ #include #include -#include #include #include #include @@ -22,40 +20,42 @@ #define LITTLEBOT_BASE_WRITER_CPP_LOCAL __attribute__ ((visibility("hidden"))) namespace littlebot_base { - class Writer : public rclcpp::Node { - public: - LITTLEBOT_BASE_WRITER_CPP_PUBLIC - explicit Writer(const rclcpp::NodeOptions & options); - - LITTLEBOT_BASE_WRITER_CPP_PUBLIC - explicit Writer(const rclcpp::NodeOptions & options, serial::Serial *serial); - - protected: - void writerTimer(); - - private: - /* Command right velocity subscriber*/ - rclcpp::Subscription::SharedPtr cmd_right_vel_sub_; - /* Command right velocity subscriber*/ - rclcpp::Subscription::SharedPtr cmd_left_vel_sub_; - - rclcpp::Publisher::SharedPtr pub1_; - rclcpp::Publisher::SharedPtr pub2_; - rclcpp::Publisher::SharedPtr pub3_; - rclcpp::Publisher::SharedPtr pub4_; - - std::stringstream msg_protocol_; - std::string send_msg_; - - /*Right velocite variable*/ - float right_vel_; - /*Left velocite variable*/ - float left_vel_; - /*Serial port object*/ - serial::Serial *serial_; - /* */ - rclcpp::TimerBase::SharedPtr timer_writer_; - }; +class Writer : public rclcpp::Node { + public: + LITTLEBOT_BASE_WRITER_CPP_PUBLIC + explicit Writer(const rclcpp::NodeOptions & options); + + LITTLEBOT_BASE_WRITER_CPP_PUBLIC + explicit Writer(const rclcpp::NodeOptions & options, serial::Serial *serial); + + protected: + void writerTimer(); + + private: + /* Command right velocity subscriber*/ + rclcpp::Subscription::SharedPtr + cmd_right_vel_sub_; + /* Command right velocity subscriber*/ + rclcpp::Subscription::SharedPtr + cmd_left_vel_sub_; + + rclcpp::Publisher::SharedPtr pub1_; + rclcpp::Publisher::SharedPtr pub2_; + rclcpp::Publisher::SharedPtr pub3_; + rclcpp::Publisher::SharedPtr pub4_; + + std::stringstream msg_protocol_; + std::string send_msg_; + + /*Right velocite variable*/ + float right_vel_; + /*Left velocite variable*/ + float left_vel_; + /*Serial port object*/ + serial::Serial *serial_; + /* */ + rclcpp::TimerBase::SharedPtr timer_writer_; +}; } // namespace littlebot_base -#endif // LITTLEBOT_BASE_WRITER_HPP_ +#endif // LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_WRITER_HPP_ diff --git a/littlebot_base/src/littlebot_base_composition.cpp b/littlebot_base/src/littlebot_base_composition.cpp index 5c5262b..f242b01 100755 --- a/littlebot_base/src/littlebot_base_composition.cpp +++ b/littlebot_base/src/littlebot_base_composition.cpp @@ -1,16 +1,4 @@ -// Copyright 2016 Open Source Robotics Foundation, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// @ Copyright 2023 Nestor Neto #include @@ -22,8 +10,7 @@ #include -int main(int argc, char * argv[]) -{ +int main(int argc, char * argv[]) { setvbuf(stdout, NULL, _IONBF, BUFSIZ); rclcpp::init(argc, argv); @@ -40,7 +27,7 @@ int main(int argc, char * argv[]) // exec.add_node(reader); exec.add_node(writer); - + exec.spin(); rclcpp::shutdown(); diff --git a/littlebot_base/src/littlebot_hardware.cpp b/littlebot_base/src/littlebot_hardware.cpp index 902ab02..19544ec 100644 --- a/littlebot_base/src/littlebot_hardware.cpp +++ b/littlebot_base/src/littlebot_hardware.cpp @@ -1,4 +1,5 @@ -#include +// @ Copyright 2023 Nestor Neto + #include #include #include @@ -9,13 +10,10 @@ #include "littlebot_base/littlebot_hardware.hpp" -namespace littlebot_base -{ +namespace littlebot_base { hardware_interface::return_type LittlebotHardware::configure( - const hardware_interface::HardwareInfo & info) -{ - if (configure_default(info) != hardware_interface::return_type::OK) - { + const hardware_interface::HardwareInfo & info) { + if (configure_default(info) != hardware_interface::return_type::OK) { return hardware_interface::return_type::ERROR; } @@ -24,34 +22,35 @@ hardware_interface::return_type LittlebotHardware::configure( serial_port_ = info_.hardware_parameters["device"]; encoder_ppr = std::stoi(info_.hardware_parameters["encoder_PPR"]); - RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), "Port: %s", serial_port_.c_str()); + RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), + "Port: %s", serial_port_.c_str()); serial_device_.OpenPort(serial_port_); serial_device_.SetFlowControl(serial::FlowControl::Software); - for (const hardware_interface::ComponentInfo & joint : info_.joints) - { + for (const hardware_interface::ComponentInfo & joint : info_.joints) { // Littlebot has exactly two states and one command interface on each joint - if (joint.command_interfaces.size() != 1) - { + if (joint.command_interfaces.size() != 1) { RCLCPP_FATAL( rclcpp::get_logger("LittlebotHardware"), - "Joint '%s' has %d command interfaces found. 1 expected.", joint.name.c_str(), + "Joint '%s' has %d command interfaces found. 1 expected.", + joint.name.c_str(), joint.command_interfaces.size()); return hardware_interface::return_type::ERROR; } - if (joint.command_interfaces[0].name != hardware_interface::HW_IF_VELOCITY) - { + if + (joint.command_interfaces[0].name != hardware_interface::HW_IF_VELOCITY) { RCLCPP_FATAL( rclcpp::get_logger("LittlebotHardware"), - "Joint '%s' have %s command interfaces found. '%s' expected.", joint.name.c_str(), - joint.command_interfaces[0].name.c_str(), hardware_interface::HW_IF_VELOCITY); + "Joint '%s' have %s command interfaces found. '%s' expected.", + joint.name.c_str(), + joint.command_interfaces[0].name.c_str(), + hardware_interface::HW_IF_VELOCITY); return hardware_interface::return_type::ERROR; } - if (joint.state_interfaces.size() != 2) - { + if (joint.state_interfaces.size() != 2) { RCLCPP_FATAL( rclcpp::get_logger("LittlebotHardware"), "Joint '%s' has %d state interface. 2 expected.", joint.name.c_str(), @@ -59,22 +58,22 @@ hardware_interface::return_type LittlebotHardware::configure( return hardware_interface::return_type::ERROR; } - if (joint.state_interfaces[0].name != hardware_interface::HW_IF_POSITION) - { + if (joint.state_interfaces[0].name != hardware_interface::HW_IF_POSITION) { RCLCPP_FATAL( rclcpp::get_logger("LittlebotHardware"), - "Joint '%s' have '%s' as first state interface. '%s' and '%s' expected.", + "Joint '%s' have '%s' first state interface. '%s' and '%s' expected.", joint.name.c_str(), joint.state_interfaces[0].name.c_str(), hardware_interface::HW_IF_POSITION); return hardware_interface::return_type::ERROR; } - if (joint.state_interfaces[1].name != hardware_interface::HW_IF_VELOCITY) - { + if (joint.state_interfaces[1].name != hardware_interface::HW_IF_VELOCITY) { RCLCPP_FATAL( rclcpp::get_logger("LittlebotHardware"), - "Joint '%s' have '%s' as second state interface. '%s' expected.", joint.name.c_str(), - joint.state_interfaces[1].name.c_str(), hardware_interface::HW_IF_VELOCITY); + "Joint '%s' have '%s' as second state interface. '%s' expected.", + joint.name.c_str(), + joint.state_interfaces[1].name.c_str(), + hardware_interface::HW_IF_VELOCITY); return hardware_interface::return_type::ERROR; } } @@ -84,8 +83,8 @@ hardware_interface::return_type LittlebotHardware::configure( } -std::vector LittlebotHardware::export_state_interfaces() -{ +std::vector + LittlebotHardware::export_state_interfaces() { std::vector state_interfaces; state_interfaces.emplace_back(hardware_interface::StateInterface( @@ -102,58 +101,64 @@ std::vector LittlebotHardware::export_state_ } -std::vector LittlebotHardware::export_command_interfaces() -{ +std::vector + LittlebotHardware::export_command_interfaces() { std::vector command_interfaces; command_interfaces.emplace_back(hardware_interface::CommandInterface( - left_wheel_name_, hardware_interface::HW_IF_VELOCITY, &left_command_velocity_)); + left_wheel_name_, + hardware_interface::HW_IF_VELOCITY, + &left_command_velocity_)); + command_interfaces.emplace_back(hardware_interface::CommandInterface( - right_wheel_name_, hardware_interface::HW_IF_VELOCITY, &right_command_velocity_)); + right_wheel_name_, + hardware_interface::HW_IF_VELOCITY, + &right_command_velocity_)); return command_interfaces; } -hardware_interface::return_type LittlebotHardware::start() -{ - RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), "Starting ...please wait..."); +hardware_interface::return_type LittlebotHardware::start() { + RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), + "Starting ...please wait..."); status_ = hardware_interface::status::STARTED; - RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), "System Successfully started!"); + RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), + "System Successfully started!"); return hardware_interface::return_type::OK; } -hardware_interface::return_type LittlebotHardware::stop() -{ - RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), "Stopping ...please wait..."); +hardware_interface::return_type LittlebotHardware::stop() { + RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), + "Stopping ...please wait..."); status_ = hardware_interface::status::STOPPED; - RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), "System successfully stopped!"); + RCLCPP_INFO(rclcpp::get_logger("LittlebotHardware"), + "System successfully stopped!"); return hardware_interface::return_type::OK; } -hardware_interface::return_type LittlebotHardware::read() -{ +hardware_interface::return_type LittlebotHardware::read() { std::size_t split_character; std::size_t begin_character; std::size_t end_character; std::string final_mgs; std::string med_msg; do { - serial_device_.ReceiveMsg(&message_protocol_); // "" + serial_device_.ReceiveMsg(&message_protocol_); begin_character = message_protocol_.find("<"); end_character = message_protocol_.find(">"); } while (begin_character != 0 || end_character == std::string::npos); message_protocol_.erase(0, 1); - final_mgs = message_protocol_.substr(0, end_character); + final_mgs = message_protocol_.substr(0, end_character); split_character = final_mgs.find("#"); med_msg = final_mgs.substr(0, split_character); @@ -179,20 +184,19 @@ hardware_interface::return_type LittlebotHardware::read() } -hardware_interface::return_type LittlebotHardware::write() -{ +hardware_interface::return_type LittlebotHardware::write() { std::stringstream msg_protocol; - msg_protocol << left_wheel_name_ << "#" << right_wheel_name_ << "#"; + msg_protocol << left_wheel_name_ << "#" << right_wheel_name_ << "#"; std::string send_msg = msg_protocol.str(); serial_device_.SendMsg(&send_msg); return hardware_interface::return_type::OK; } -} // namespace ros2_control_demo_hardware +} // namespace littlebot_base #include "pluginlib/class_list_macros.hpp" PLUGINLIB_EXPORT_CLASS( - littlebot_base::LittlebotHardware, hardware_interface::SystemInterface) \ No newline at end of file + littlebot_base::LittlebotHardware, hardware_interface::SystemInterface) diff --git a/littlebot_base/src/protocol.cpp b/littlebot_base/src/protocol.cpp index 16fe93c..3b14d1b 100755 --- a/littlebot_base/src/protocol.cpp +++ b/littlebot_base/src/protocol.cpp @@ -1,30 +1,28 @@ +// @ Copyright 2023 Nestor Neto + #include "littlebot_base/protocol.hpp" -namespace littlebot{ - -Protocol::Protocol(){} +namespace littlebot { +Protocol::Protocol() {} -Protocol::Protocol(std::string port)/*: port_()*/ { +Protocol::Protocol(std::string port) { port_.OpenPort(port.c_str()); } +Protocol::~Protocol() {} -Protocol::~Protocol(){} - - -void Protocol::Read(void){ +void Protocol::Read(void) { float *a, *b; port_.ReceiveMsg(&msg_protocol_); - a = (float *) (msg_protocol_.c_str()); - b = (float *) (msg_protocol_.c_str() + 4); + a = reinterpret_cast (msg_protocol_.c_str()); + b = reinterpret_cast (msg_protocol_.c_str() + 4); velocity_read_[0] = *a; velocity_read_[1] = *b; std::cout << msg_protocol_ << std::endl; } - -void Protocol::Write(void){ +void Protocol::Write(void) { // unsigned int i; // char vel_dir[sizeof(float)]; // char vel_lef[sizeof(float)]; @@ -42,12 +40,11 @@ void Protocol::Write(void){ // for (i = 0; i < sizeof(float); i++){ // vel_lef[i] = *(ptr + i); // } - + // msg << vel_dir << '#' << vel_lef; // port_.SendMsg(std::make_shared(msg.str())); } - void Protocol::SetVelocity(float dir, float lef) { velocity_write_[0] = dir; velocity_write_[1] = lef; @@ -58,4 +55,4 @@ void Protocol::GetVelocity(float *dir, float *lef) { *dir = velocity_read_[0]; *lef = velocity_read_[1]; } -} +} // namespace littlebot diff --git a/littlebot_base/src/reader.cpp b/littlebot_base/src/reader.cpp index 4085d68..d0f2342 100755 --- a/littlebot_base/src/reader.cpp +++ b/littlebot_base/src/reader.cpp @@ -1,6 +1,6 @@ // Copyright 2022-2023 Nestor -#include +#include // NOLINT #include #include #include @@ -12,17 +12,16 @@ #include "littlebot_base/reader.hpp" -using namespace std::chrono_literals; +using namespace std::chrono_literals; // NOLINT namespace littlebot_base { Reader::Reader(const rclcpp::NodeOptions & options) - : Node("", options) + : Node("", options) {} Reader::Reader(const rclcpp::NodeOptions & options, serial::Serial *serial) : Node("reader", "littlebot_base", options), count_(0), serial_(serial) { - pub1_ = create_publisher("vel_left", 10); pub2_ = create_publisher("vel_right", 10); pub3_ = create_publisher("pos_left", 10); @@ -44,13 +43,13 @@ namespace littlebot_base { std::string med_msg; do { - serial_->ReceiveMsg(&message_); // "" + serial_->ReceiveMsg(&message_); found_begin_char = message_.find("<"); found_end_char = message_.find(">"); } while (found_begin_char != 0); message_.erase(0, 1); - final_mgs = message_.substr(0, message_.find(">")); + final_mgs = message_.substr(0, message_.find(">")); found = final_mgs.find("#"); diff --git a/littlebot_base/src/writer.cpp b/littlebot_base/src/writer.cpp index f1c594a..1691688 100755 --- a/littlebot_base/src/writer.cpp +++ b/littlebot_base/src/writer.cpp @@ -1,6 +1,6 @@ // Copyright Nestor 2022-2023 -#include +#include // NOLINT #include #include #include @@ -12,52 +12,54 @@ #include "littlebot_base/writer.hpp" -using namespace std::chrono_literals; +using namespace std::chrono_literals; // NOLINT namespace littlebot_base { Writer::Writer(const rclcpp::NodeOptions & options) - : Node("", options) + : Node("", options) {} Writer::Writer(const rclcpp::NodeOptions & options, serial::Serial *serial) - : Node("robot","littlebot_base", options), serial_(serial){ - + : Node("robot", "littlebot_base", options), serial_(serial) { + setvbuf(stdout, NULL, _IONBF, BUFSIZ); auto vel_right_callback = [this](example_interfaces::msg::Float32::ConstSharedPtr vel) -> void { right_vel_ = vel->data; - msg_protocol_ << "W" << left_vel_ << "#" << right_vel_ << "#"; + msg_protocol_ << "W" << left_vel_ << "#" << right_vel_ << "#"; send_msg_ = msg_protocol_.str(); this->serial_->SendMsg(&send_msg_); }; - + auto vel_left_callback = [this](example_interfaces::msg::Float32::ConstSharedPtr vel) -> void { left_vel_ = vel->data; - msg_protocol_ << "W" << left_vel_ << "#" << right_vel_ << "#"; + msg_protocol_ << "W" << left_vel_ << "#" << right_vel_ << "#"; send_msg_ = msg_protocol_.str(); this->serial_->SendMsg(&send_msg_); }; cmd_right_vel_sub_ = - create_subscription("cmd_right_vel", 10, vel_right_callback); + create_subscription("cmd_right_vel", + 10, vel_right_callback); cmd_left_vel_sub_ = - create_subscription("cmd_left_vel", 10, vel_left_callback); + create_subscription("cmd_left_vel", + 10, vel_left_callback); pub1_ = create_publisher("vel_left", 10); pub2_ = create_publisher("vel_right", 10); pub3_ = create_publisher("pos_left", 10); pub4_ = create_publisher("pos_right", 10); - timer_writer_ = create_wall_timer(1000ms, std::bind(&Writer::writerTimer, this)); + timer_writer_ = + create_wall_timer(1000ms, std::bind(&Writer::writerTimer, this)); } void Writer::writerTimer() { - - // msg_protocol << left_vel_ << "#" << right_vel_ << "#"; + // msg_protocol << left_vel_ << "#" << right_vel_ << "#"; // std::string send_msg = msg_protocol.str(); // this->serial_->SendMsg(&send_msg); } diff --git a/littlebot_base/test/teste_load_littlebot_hardeware.cpp b/littlebot_base/test/teste_load_littlebot_hardeware.cpp index cf88f02..b6317fa 100644 --- a/littlebot_base/test/teste_load_littlebot_hardeware.cpp +++ b/littlebot_base/test/teste_load_littlebot_hardeware.cpp @@ -1,6 +1,7 @@ -TEST_F(TestGenericSystem, load_generic_system_2dof) -{ +// Copyright 2023 Nestor Neto + +TEST_F(TestGenericSystem, load_generic_system_2dof) { auto urdf = ros2_control_test_assets::urdf_head + hardware_system_2dof_ + ros2_control_test_assets::urdf_tail; ASSERT_NO_THROW(TestableResourceManager rm(urdf)); -} \ No newline at end of file +} // NOLINT \ No newline at end of file diff --git a/littlebot_bringup/CMakeLists.txt b/littlebot_bringup/CMakeLists.txt index c965c78..fb61c19 100755 --- a/littlebot_bringup/CMakeLists.txt +++ b/littlebot_bringup/CMakeLists.txt @@ -4,7 +4,7 @@ find_package(ament_cmake REQUIRED) install( - DIRECTORY config launch + DIRECTORY launch DESTINATION share/${PROJECT_NAME} ) diff --git a/littlebot_bringup/launch/littlebot_bringup.launch.py b/littlebot_bringup/launch/littlebot_bringup.launch.py index 5bb2f39..e4f1f5d 100644 --- a/littlebot_bringup/launch/littlebot_bringup.launch.py +++ b/littlebot_bringup/launch/littlebot_bringup.launch.py @@ -12,7 +12,7 @@ # def generate_launch_description(): # description_path = get_package_share_path('littlebot_description') -# urdf_model_path = description_path / 'urdf/littlebot_description.urdf.xacro' +# model_path = description_path / 'urdf/littlebot_description.urdf.xacro' # rviz_config_path = description_path / 'config/littlebot_description.rviz' # use_sim_time = LaunchConfiguration('use_sim_time', default='false') @@ -23,15 +23,15 @@ # default_value='false', # choices=['true', 'false'], # description='Use simulation (Gazebo) clock if true') - + # joint_gui_arg = DeclareLaunchArgument( -# name='joint_gui', -# default_value='true', +# name='joint_gui', +# default_value='true', # choices=['true', 'false'], # description='Flag to enable joint_state_publisher_gui') # model_arg = DeclareLaunchArgument( -# name='model', +# name='model', # default_value=str(urdf_model_path), # description='Absolute path to robot urdf file') @@ -43,7 +43,7 @@ # # Parameters # #----------------------------------------------------------------------------- # robot_description = ParameterValue( -# Command(['xacro ', LaunchConfiguration('model')]), +# Command(['xacro ', LaunchConfiguration('model')]), # value_type=str) # # Nodes @@ -53,7 +53,7 @@ # executable='robot_state_publisher', # name='robot_state_publisher', # parameters=[ -# {'robot_description': robot_description}, +# {'robot_description': robot_description}, # {'use_sim_time': use_sim_time}], # output='screen' # ) @@ -89,4 +89,4 @@ # joint_state_publisher_gui_node, # robot_state_publisher_node, # rviz_node -# ]) +# ]) diff --git a/littlebot_control/config/teleop_interactive_markers.yaml b/littlebot_control/config/teleop_interactive_markers.yaml deleted file mode 100755 index 25799e1..0000000 --- a/littlebot_control/config/teleop_interactive_markers.yaml +++ /dev/null @@ -1,7 +0,0 @@ -twist_server_node: - ros__parameters: - link_name: base_link - robot: husky - linear_scale: 1.0 - max_positive_linear_velocity: 1.0 - max_negative_linear_velocity: -1.0 \ No newline at end of file diff --git a/littlebot_control/config/teleop_logitech.yaml b/littlebot_control/config/teleop_logitech.yaml deleted file mode 100755 index 4ad87ae..0000000 --- a/littlebot_control/config/teleop_logitech.yaml +++ /dev/null @@ -1,64 +0,0 @@ -# Teleop configuration for Logitech F710 Gamepad using the x-pad configuration. -# Left thumb-stick up/down for velocity, left/right for twist -# LB for enable -# RB for enable-turbo -# -# (LB) (RB) -# (LT) (RT) -# _=====_ D( .)X _=====_ -# / _____ \ / _____ \ -# +.-'_____'-.---------------------------.-'_____'-.+ -# / | | '. .' | | \ -# / ___| /|\ |___ \ (back)(Lgtc)(strt) / ___| (Y) |___ \ -# / | | | ; __ __ ; | | | -# | | <--- ---> | | (__) . (__) | | (X) (B)| | -# | |___ | ___| ; MODE VIBE ; |___ ____| / -# |\ | \|/ | / _ ___ _ \ | (A) | /| -# | \ |_____| .','" "', |___| ,'" "', '. |_____| .' | -# | '-.______.-' / \ANALOG/ \ '-._____.-' | -# | | LJ |------| RJ | | -# | /\ / \ /\ | -# | / '.___.' '.___.' \ | -# | / \ | -# \ / \ / -# \________/ \_________/ -# -# BUTTON Value -# LB 4 -# RB 5 -# A 0 -# B 1 -# X 2 -# Y 3 -# -# AXIS Value -# Left Horiz. 0 -# Left Vert. 1 -# Right Horiz. 3 -# Right Vert. 4 -# Left Trigger 2 -# Right Trigger 5 -# D-pad Horiz. 6 -# D-pad Vert. 7 - -joy_teleop/teleop_twist_joy_node: - ros__parameters: - axis_linear: - x: 1 - scale_linear: - x: 0.4 - scale_linear_turbo: - x: 1.0 - axis_angular: - yaw: 0 - scale_angular: - yaw: 0.6 - scale_angular_turbo: - yaw: 1.2 - enable_button: 4 - enable_turbo_button: 5 -joy_teleop/joy_node: - ros__parameters: - deadzone: 0.1 - autorepeat_rate: 20.0 - dev: /dev/input/f710 diff --git a/littlebot_control/config/teleop_ps4.yaml b/littlebot_control/config/teleop_ps4.yaml deleted file mode 100755 index 6d02e48..0000000 --- a/littlebot_control/config/teleop_ps4.yaml +++ /dev/null @@ -1,77 +0,0 @@ -# Teleop configuration for PS4 joystick using the x-pad configuration. -# Left thumb-stick up/down for velocity, left/right for twist -# Left shoulder button for enable -# Right shoulder button for enable-turbo -# -# L1 R1 -# L2 R2 -# _=====_ _=====_ -# / _____ \ / _____ \ -# +.-'_____'-.------------------------------.-'_____'-.+ -# / | | '. S O N Y .' | _ | \ -# / ___| /|\ |___ \ / ___| /_\ |___ \ (Y) -# / | | | ; ; | _ _ || -# | | <--- ---> | | | ||_| (_)|| (X) (B) -# | |___ | ___| ; ; |___ ___|| -# |\ | \|/ | / _ ____ _ \ | (X) | /| (A) -# | \ |_____| .','" "', (_PS_) ,'" "', '. |_____| .' | -# | '-.______.-' / \ / \ '-._____.-' | -# | | LJ |--------| RJ | | -# | /\ / \ /\ | -# | / '.___.' '.___.' \ | -# | / \ | -# \ / \ / -# \________/ \_________/ -# -# ^ x -# | -# | -# y <-----+ Accelerometer axes -# \ -# \ -# > z (out) -# -# BUTTON Value -# L1 4 -# L2 6 -# R1 5 -# R2 7 -# A 1 -# B 2 -# X 0 -# Y 3 -# -# AXIS Value -# Left Horiz. 0 -# Left Vert. 1 -# Right Horiz. 2 -# Right Vert. 5 -# L2 3 -# R2 4 -# D-pad Horiz. 9 -# D-pad Vert. 10 -# Accel x 7 -# Accel y 6 -# Accel z 8 - -joy_teleop/teleop_twist_joy_node: - ros__parameters: - axis_linear: - x: 1 - scale_linear: - x: 0.4 - scale_linear_turbo: - x: 1.0 - axis_angular: - yaw: 0 - scale_angular: - yaw: 0.6 - scale_angular_turbo: - yaw: 1.2 - enable_button: 4 - enable_turbo_button: 5 -joy_teleop/joy_node: - ros__parameters: - deadzone: 0.1 - autorepeat_rate: 20.0 - dev: /dev/input/ps4 \ No newline at end of file diff --git a/littlebot_control/launch/littlebot_control.launch.py b/littlebot_control/launch/littlebot_control.launch.py index 6b89fc3..438b537 100755 --- a/littlebot_control/launch/littlebot_control.launch.py +++ b/littlebot_control/launch/littlebot_control.launch.py @@ -3,35 +3,22 @@ from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare + def generate_launch_description(): filepath_config_twist_mux = PathJoinSubstitution( [FindPackageShare('littlebot_control'), 'config', 'twist_mux.yaml'] ) - # filepath_config_interactive_markers = PathJoinSubstitution( - # [FindPackageShare('littlebot_control'), 'config', 'teleop_interactive_markers.yaml'] - # ) - - - # node_interactive_marker_twist_server = Node( - # package='interactive_marker_twist_server', - # executable='marker_server', - # name='twist_server_node', - # remappings={('cmd_vel', 'twist_marker_server/cmd_vel')}, - # parameters=[filepath_config_interactive_markers], - # output='screen', - # ) - node_twist_mux = Node( package='twist_mux', executable='twist_mux', output='screen', - remappings={('/cmd_vel_out', '/littlebot_velocity_controller/cmd_vel_unstamped')}, + remappings={('/cmd_vel_out', + '/littlebot_velocity_controller/cmd_vel_unstamped')}, parameters=[filepath_config_twist_mux] ) ld = LaunchDescription() - # ld.add_action(node_interactive_marker_twist_server) ld.add_action(node_twist_mux) - return ld \ No newline at end of file + return ld diff --git a/littlebot_description/launch/littlebot_description.launch.py b/littlebot_description/launch/littlebot_description.launch.py index 8631568..7dd6287 100755 --- a/littlebot_description/launch/littlebot_description.launch.py +++ b/littlebot_description/launch/littlebot_description.launch.py @@ -12,48 +12,45 @@ def generate_launch_description(): description_path = get_package_share_path('littlebot_description') - urdf_model_path = description_path / 'urdf/littlebot_description.urdf.xacro' + model_path = description_path / 'urdf/littlebot_description.urdf.xacro' rviz_config_path = description_path / 'config/littlebot_description.rviz' - use_sim_time = LaunchConfiguration('use_sim_time', default='false') + use_sim_time = LaunchConfiguration('use_sim_time', default='false') # Launch arguments - #----------------------------------------------------------------------------- - time_arg = DeclareLaunchArgument( + time_arg = DeclareLaunchArgument( 'use_sim_time', default_value='false', choices=['true', 'false'], description='Use simulation (Gazebo) clock if true') - - joint_gui_arg = DeclareLaunchArgument( - name='joint_gui', - default_value='true', + + joint_gui_arg = DeclareLaunchArgument( + name='joint_gui', + default_value='true', choices=['true', 'false'], description='Flag to enable joint_state_publisher_gui') model_arg = DeclareLaunchArgument( - name='model', - default_value=str(urdf_model_path), + name='model', + default_value=str(model_path), description='Absolute path to robot urdf file') - rviz_arg = DeclareLaunchArgument( + rviz_arg = DeclareLaunchArgument( name='rvizconfig', default_value=str(rviz_config_path), description='Absolute path to rviz config file') # Parameters - #----------------------------------------------------------------------------- robot_description = ParameterValue( - Command(['xacro ', LaunchConfiguration('model')]), + Command(['xacro ', LaunchConfiguration('model')]), value_type=str) # Nodes - #----------------------------------------------------------------------------- robot_state_publisher_node = Node( package='robot_state_publisher', executable='robot_state_publisher', name='robot_state_publisher', parameters=[ - {'robot_description': robot_description}, + {'robot_description': robot_description}, {'use_sim_time': use_sim_time}], output='screen' ) @@ -79,7 +76,6 @@ def generate_launch_description(): ) # Return - #----------------------------------------------------------------------------- return LaunchDescription([ time_arg, joint_gui_arg, @@ -89,4 +85,4 @@ def generate_launch_description(): joint_state_publisher_gui_node, robot_state_publisher_node, rviz_node - ]) + ]) diff --git a/littlebot_description/launch/littlebot_description_sim.launch.py b/littlebot_description/launch/littlebot_description_sim.launch.py index ea7d953..f8e8028 100755 --- a/littlebot_description/launch/littlebot_description_sim.launch.py +++ b/littlebot_description/launch/littlebot_description_sim.launch.py @@ -5,30 +5,30 @@ from launch.substitutions import LaunchConfiguration from launch_ros.actions import Node + def generate_launch_description(): - use_sim_time = LaunchConfiguration('use_sim_time', default='false') - urdf_file_name = 'urdf/littlebot_description.urdf' + use_sim_time = LaunchConfiguration('use_sim_time', default='false') + urdf_file_name = 'urdf/littlebot_description.urdf' - print("urdf_file_name : {}".format(urdf_file_name)) + print("urdf_file_name : {}".format(urdf_file_name)) - urdf = os.path.join( - get_package_share_directory('littlebot_description'), - urdf_file_name) + urdf = os.path.join( + get_package_share_directory('littlebot_description'), + urdf_file_name) - return LaunchDescription([ + return LaunchDescription([ - DeclareLaunchArgument( - 'use_sim_time', - default_value='true', - description='Use simulation (Gazebo) clock if true'), + DeclareLaunchArgument( + 'use_sim_time', + default_value='true', + description='Use simulation (Gazebo) clock if true'), - Node( - package='robot_state_publisher', - executable='robot_state_publisher', - name='robot_state_publisher', - arguments=[urdf], - parameters=[{'use_sim_time': use_sim_time}], - output='screen') - ]) - \ No newline at end of file + Node( + package='robot_state_publisher', + executable='robot_state_publisher', + name='robot_state_publisher', + arguments=[urdf], + parameters=[{'use_sim_time': use_sim_time}], + output='screen') + ]) diff --git a/littlebot_localization/config/littlebot_localization.yaml b/littlebot_localization/config/littlebot_localization.yaml index 781e7ce..2f0f35d 100755 --- a/littlebot_localization/config/littlebot_localization.yaml +++ b/littlebot_localization/config/littlebot_localization.yaml @@ -3,15 +3,15 @@ ekf_node: odom_frame: odom base_link_frame: base_link world_frame: odom - + publish_tf: true two_d_mode: true frequency: 50.0 odom0: odom - odom0_config: [false, false, false, - false, false, false, - true, true, true, + odom0_config: [true, true, false, + false, false, true, + true, true, false, false, false, true, false, false, false] odom0_differential: false @@ -19,10 +19,10 @@ ekf_node: imu0: imu/data_raw imu0_config: [false, false, false, - true, true, true, false, false, false, - true, true, true, - false, false, false] - imu0_differential: true + false, false, false, + false, false, true, + true, false, false] + imu0_differential: false imu0_queue_size: 10 imu0_remove_gravitational_acceleration: true diff --git a/littlebot_localization/launch/littlebot_localization.launch.py b/littlebot_localization/launch/littlebot_localization.launch.py index 9bd4850..89e4774 100755 --- a/littlebot_localization/launch/littlebot_localization.launch.py +++ b/littlebot_localization/launch/littlebot_localization.launch.py @@ -1,5 +1,5 @@ -from launch import LaunchContext, LaunchDescription -from launch.substitutions import EnvironmentVariable, PathJoinSubstitution +from launch import LaunchDescription +from launch.substitutions import PathJoinSubstitution from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare @@ -8,8 +8,7 @@ def generate_launch_description(): config_littlebot_ekf = PathJoinSubstitution( [FindPackageShare('littlebot_localization'), - 'config', - 'littlebot_localization.yaml'], + 'config', 'littlebot_localization.yaml'], ) node_ekf = Node( @@ -38,4 +37,4 @@ def generate_launch_description(): ld = LaunchDescription() ld.add_action(node_ekf) - return ld \ No newline at end of file + return ld diff --git a/littlebot_navigation/launch/littlebot_navigation.launch.py b/littlebot_navigation/launch/littlebot_navigation.launch.py index c5f6633..cb1ffd9 100644 --- a/littlebot_navigation/launch/littlebot_navigation.launch.py +++ b/littlebot_navigation/launch/littlebot_navigation.launch.py @@ -18,7 +18,7 @@ from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription -from launch.actions import DeclareLaunchArgument, GroupAction, SetEnvironmentVariable +from launch.actions import DeclareLaunchArgument, GroupAction from launch.actions import IncludeLaunchDescription from launch.launch_description_sources import PythonLaunchDescriptionSource from launch.substitutions import LaunchConfiguration @@ -27,7 +27,6 @@ def generate_launch_description(): # Configurations - #----------------------------------------- use_sim_time = LaunchConfiguration('use_sim_time', default='false') map_dir = LaunchConfiguration( @@ -45,11 +44,10 @@ def generate_launch_description(): 'littlebot_navigation2.yaml')) # Path to lauch folder of the nav2_bringup package - #----------------------------------------- - nav2_launch_file_dir = os.path.join(get_package_share_directory('nav2_bringup'), + nav2_launch_file_dir = os.path.join( + get_package_share_directory('nav2_bringup'), 'launch') - return LaunchDescription([ DeclareLaunchArgument( 'map', @@ -65,12 +63,14 @@ def generate_launch_description(): 'use_sim_time', default_value='false', description='Use simulation (Gazebo) clock if true'), - + GroupAction([ - SetRemap(src='/cmd_vel', dst='/littlebot_velocity_controller/cmd_vel'), + SetRemap(src='/cmd_vel', + dst='/littlebot_velocity_controller/cmd_vel'), SetRemap(src='/odom', dst='/odometry/filtered'), IncludeLaunchDescription( - PythonLaunchDescriptionSource([nav2_launch_file_dir, '/bringup_launch.py']), + PythonLaunchDescriptionSource([nav2_launch_file_dir, + '/bringup_launch.py']), launch_arguments={ 'map': map_dir, 'use_sim_time': use_sim_time, diff --git a/littlebot_teleop/CMakeLists.txt b/littlebot_teleop/CMakeLists.txt index 4bc4412..d4fe6b7 100644 --- a/littlebot_teleop/CMakeLists.txt +++ b/littlebot_teleop/CMakeLists.txt @@ -54,7 +54,7 @@ install( ) install(DIRECTORY - launch config + launch DESTINATION share/${PROJECT_NAME}/ ) diff --git a/littlebot_teleop/include/littlebot_teleop/teleop.hpp b/littlebot_teleop/include/littlebot_teleop/teleop.hpp index b98d105..ce37a81 100644 --- a/littlebot_teleop/include/littlebot_teleop/teleop.hpp +++ b/littlebot_teleop/include/littlebot_teleop/teleop.hpp @@ -1,12 +1,11 @@ +// Copyright 2023 Nestor Neto -// Copyright Nestor 2022 - -#ifndef LITTLEBOT_TELEOP_TELEOP_HPP_ -#define LITTLEBOT_TELEOP_TELEOP_HPP_ +#ifndef LITTLEBOT_TELEOP_INCLUDE_LITTLEBOT_TELEOP_TELEOP_HPP_ +#define LITTLEBOT_TELEOP_INCLUDE_LITTLEBOT_TELEOP_TELEOP_HPP_ #include #include -#include +#include // NOLINT #include #include #include @@ -19,24 +18,22 @@ #define LITTLEBOT_TELEOP_CPP_PUBLIC __attribute__ ((visibility("default"))) namespace littlebot_teleop { - class Teleop : public rclcpp::Node { - public: - LITTLEBOT_TELEOP_CPP_PUBLIC - explicit Teleop(const rclcpp::NodeOptions & options); - - protected: - void teleopPublisher(void); - - private: - rclcpp::Subscription::SharedPtr sub_joy_; - rclcpp::Publisher::SharedPtr pub_twist_; - rclcpp::TimerBase::SharedPtr timer_; - - float x_joy_value_; - float z_joy_value_; - - - }; +class Teleop : public rclcpp::Node { + public: + LITTLEBOT_TELEOP_CPP_PUBLIC + explicit Teleop(const rclcpp::NodeOptions & options); + + protected: + void teleopPublisher(void); + + private: + rclcpp::Subscription::SharedPtr sub_joy_; + rclcpp::Publisher::SharedPtr pub_twist_; + rclcpp::TimerBase::SharedPtr timer_; + + float x_joy_value_; + float z_joy_value_; +}; } // namespace littlebot_teleop -#endif // LITTLEBOT_TELEOP_TELEOP_HPP_/ +#endif // LITTLEBOT_TELEOP_INCLUDE_LITTLEBOT_TELEOP_TELEOP_HPP_/ diff --git a/littlebot_teleop/src/teleop.cpp b/littlebot_teleop/src/teleop.cpp index db909fd..024fd94 100644 --- a/littlebot_teleop/src/teleop.cpp +++ b/littlebot_teleop/src/teleop.cpp @@ -1,30 +1,30 @@ -// Copyright Nestor 2022-2023 - +// Copyright 2023 Nestor Neto #include "littlebot_teleop/teleop.hpp" -using namespace std::chrono_literals; +using namespace std::chrono_literals; // NOLINT namespace littlebot_teleop { Teleop::Teleop(const rclcpp::NodeOptions & options) - : Node("littlebot_teleop","", options){ - + : Node("littlebot_teleop" , "", options) { + auto joy_callback = [this](sensor_msgs::msg::Joy::ConstSharedPtr joy) -> void { z_joy_value_ = joy->axes[0]; x_joy_value_ = joy->axes[3]; }; - + sub_joy_ = create_subscription("joy", 10, joy_callback); - pub_twist_ = + pub_twist_ = this->create_publisher( "joy_teleop/cmd_vel", 10); - timer_ = create_wall_timer(100ms, std::bind(&Teleop::teleopPublisher, this)); + timer_ = + create_wall_timer(100ms, std::bind(&Teleop::teleopPublisher, this)); } void Teleop::teleopPublisher() { @@ -36,4 +36,4 @@ namespace littlebot_teleop { } // namespace littlebot_teleop -RCLCPP_COMPONENTS_REGISTER_NODE(littlebot_teleop::Teleop) +RCLCPP_COMPONENTS_REGISTER_NODE(littlebot_teleop::Teleop)