Skip to content

Commit

Permalink
Merge branch 'feature/workflow' into devel/ros2-foxy
Browse files Browse the repository at this point in the history
  • Loading branch information
NestorDP committed Aug 11, 2023
2 parents 293c28b + 7450692 commit 3f9d8ad
Show file tree
Hide file tree
Showing 26 changed files with 329 additions and 482 deletions.
42 changes: 22 additions & 20 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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.
## Additional Notes
Any additional information or context relevant to the issue can be added here.
28 changes: 28 additions & 0 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -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 .
34 changes: 16 additions & 18 deletions littlebot_base/include/littlebot_base/littlebot_hardware.hpp
Original file line number Diff line number Diff line change
@@ -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 <chrono>
#include <memory>
#include <sstream>
#include <string>
Expand All @@ -26,25 +27,23 @@
#include "rclcpp/time.hpp"


using namespace std::chrono_literals;

namespace littlebot_base
{
class LittlebotHardware
: public hardware_interface::BaseInterface<hardware_interface::SystemInterface>
{

public:
namespace littlebot_base {
class LittlebotHardware : public
hardware_interface::BaseInterface<hardware_interface::SystemInterface> {
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<hardware_interface::StateInterface> export_state_interfaces() override;
std::vector<hardware_interface::StateInterface>
export_state_interfaces() override;

HARDWARE_INTERFACE_PUBLIC
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
std::vector<hardware_interface::CommandInterface>
export_command_interfaces() override;

HARDWARE_INTERFACE_PUBLIC
hardware_interface::return_type start() override;
Expand All @@ -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;
Expand All @@ -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_
#endif // LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_LITTLEBOT_HARDWARE_HPP_
15 changes: 7 additions & 8 deletions littlebot_base/include/littlebot_base/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <errno.h>
#include <fcntl.h>
Expand All @@ -25,7 +25,7 @@
#include <libserial/serial.hpp>


namespace littlebot{
namespace littlebot {

class Protocol {
public:
Expand All @@ -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
Expand Down Expand Up @@ -72,16 +72,15 @@ class Protocol {
const int kLengthBuffer_ = 200;

/** Port */
serial::Serial port_ ;
serial::Serial port_;

/** Buffer */
std::string msg_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_
57 changes: 28 additions & 29 deletions littlebot_base/include/littlebot_base/reader.hpp
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <chrono>
#include <iostream>
#include <memory>
#include <utility>
Expand All @@ -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<example_interfaces::msg::Float32>::SharedPtr pub1_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub2_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub3_;
rclcpp::Publisher<example_interfaces::msg::Float32>::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<example_interfaces::msg::Float32>::SharedPtr pub1_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub2_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub3_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub4_;
rclcpp::TimerBase::SharedPtr timer_;
std::string message_;
serial::Serial *serial_;
};

} // namespace littlebot_base

#endif // LITTLEBOT_BASE_INCLUDE_LITTLEBOT_BASE_READER_HPP_
78 changes: 39 additions & 39 deletions littlebot_base/include/littlebot_base/writer.hpp
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <sstream>
#include <chrono>
#include <iostream>
#include <memory>
#include <utility>
Expand All @@ -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<example_interfaces::msg::Float32>::SharedPtr cmd_right_vel_sub_;
/* Command right velocity subscriber*/
rclcpp::Subscription<example_interfaces::msg::Float32>::SharedPtr cmd_left_vel_sub_;

rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub1_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub2_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub3_;
rclcpp::Publisher<example_interfaces::msg::Float32>::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<example_interfaces::msg::Float32>::SharedPtr
cmd_right_vel_sub_;
/* Command right velocity subscriber*/
rclcpp::Subscription<example_interfaces::msg::Float32>::SharedPtr
cmd_left_vel_sub_;

rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub1_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub2_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub3_;
rclcpp::Publisher<example_interfaces::msg::Float32>::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_
19 changes: 3 additions & 16 deletions littlebot_base/src/littlebot_base_composition.cpp
Original file line number Diff line number Diff line change
@@ -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 <memory>

Expand All @@ -22,8 +10,7 @@

#include <libserial/serial.hpp>

int main(int argc, char * argv[])
{
int main(int argc, char * argv[]) {
setvbuf(stdout, NULL, _IONBF, BUFSIZ);

rclcpp::init(argc, argv);
Expand All @@ -40,7 +27,7 @@ int main(int argc, char * argv[])

// exec.add_node(reader);
exec.add_node(writer);

exec.spin();
rclcpp::shutdown();

Expand Down
Loading

0 comments on commit 3f9d8ad

Please sign in to comment.