Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add IO states to state representation (cpp) #158

Merged
merged 9 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Release Versions:

## Upcoming changes (in development)

- feat: add IO states to state representation (cpp) (#158)
- build: add missing licenses (#170)
- feat(build): handle installation and linking of dependencies for pinocchio collision support (#161)
- build: update dockerfiles (#153)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.3.5
7.3.6
2 changes: 1 addition & 1 deletion demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(control_libraries 7.3.5 CONFIG REQUIRED)
find_package(control_libraries 7.3.6 CONFIG REQUIRED)

set(DEMOS_SCRIPTS
task_space_control_loop
Expand Down
2 changes: 1 addition & 1 deletion doxygen/doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Control Libraries"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 7.3.5
PROJECT_NUMBER = 7.3.6

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion protocol/clproto_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

project(clproto VERSION 7.3.5)
project(clproto VERSION 7.3.6)

# Default to C99
if(NOT CMAKE_C_STANDARD)
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# names of the environment variables that define osqp and openrobots include directories
osqp_path_var = 'OSQP_INCLUDE_DIR'

__version__ = "7.3.5"
__version__ = "7.3.6"
__libraries__ = ['state_representation', 'clproto', 'controllers', 'dynamical_systems', 'robot_model']
__include_dirs__ = ['include']

Expand Down
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

project(control_libraries VERSION 7.3.5)
project(control_libraries VERSION 7.3.6)

# Build options
option(BUILD_TESTING "Build all tests." OFF)
Expand Down
3 changes: 3 additions & 0 deletions source/state_representation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ set(EIGEN_MPL2_ONLY 1)
set(CORE_SOURCES
src/MathTools.cpp
src/State.cpp
src/IOState.cpp
src/DigitalIOState.cpp
src/AnalogIOState.cpp
src/space/SpatialState.cpp
src/space/cartesian/CartesianState.cpp
src/space/cartesian/CartesianPose.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#pragma once

#include "state_representation/IOState.hpp"

namespace state_representation {

class AnalogIOState : public IOState<double> {
public:
/**
* @brief Empty constructor for an analog IO state
*/
AnalogIOState();

/**
* @brief Constructor with name and number of analog IOs provided
* @param name The name of the associated IO state
* @param nb_ios The number of IOs for initialization
*/
explicit AnalogIOState(const std::string& name, unsigned int nb_ios = 0);

/**
* @brief Constructor with name and list of analog IO names provided
* @param name The name of the associated analog IO state
* @param io_name List of IO names
*/
AnalogIOState(const std::string& name, const std::vector<std::string>& io_names);

/**
* @brief Copy constructor of an analog IO state
* @param state The analog IO state to copy from
*/
AnalogIOState(const AnalogIOState& state);

/**
* @brief Constructor for a zero analog IO state
* @param name The name of the associated analog IO state
* @param nb_ios The number of analog IOs for initialization
* @return Analog IO state with zero data
*/
static AnalogIOState Zero(const std::string& name, unsigned int nb_ios);

/**
* @brief Constructor for a zero analog IO state
* @param name The name of the associated analog IO state
* @param names List of IO names
* @return Analog IO state with zero data
*/
static AnalogIOState Zero(const std::string& name, const std::vector<std::string>& names);

/**
* @brief Constructor for an analog IO state with random data
* @param name The name of the associated analog IO state
* @param nb_ios The number of analog IOs for initialization
* @return Analog IO state with random data
*/
static AnalogIOState Random(const std::string& name, unsigned int nb_ios);

/**
* @brief Constructor for an analog IO state with random data
* @param name The name of the associated analog IO state
* @param names List of IO names
* @return Analog IO state with random data
*/
static AnalogIOState Random(const std::string& name, const std::vector<std::string>& names);

/**
* @brief Copy assignment operator that has to be defined to the custom assignment operator
* @param state The state with value to assign
* @return Reference to the current state with new values
*/
AnalogIOState& operator=(const AnalogIOState& state);

/**
* @brief Return a copy of the analog IO state
*/
AnalogIOState copy() const;

/**
* @copybrief State::reset
*/
void reset() override;

/**
* @brief Set the analog IO state to zero data
*/
void set_zero();

/**
* @brief Overload the ostream operator for printing
* @param os The ostream to append the string representing the state to
* @param state The spatial state to print
* @return The appended ostream
*/
friend std::ostream& operator<<(std::ostream& os, const AnalogIOState& state);

protected:

/**
* @brief Swap the values of the IO states
* @param state1 IO state to be swapped with 2
* @param state2 IO state to be swapped with 1
*/
friend void swap(AnalogIOState& state1, AnalogIOState& state2);

/**
* @copydoc State::to_string
*/
std::string to_string() const override;
};

inline void swap(AnalogIOState& state1, AnalogIOState& state2) {
swap(static_cast<IOState<double>&>(state1), static_cast<IOState<double>&>(state2));
}

}// namespace state_representation
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#pragma once

#include "state_representation/IOState.hpp"

namespace state_representation {

class DigitalIOState : public IOState<bool> {
public:
/**
* @brief Empty constructor for a digital IO state
*/
DigitalIOState();

/**
* @brief Constructor with name and number of digital IOs provided
* @param name The name of the associated IO state
* @param nb_ios The number of IOs for initialization
*/
explicit DigitalIOState(const std::string& name, unsigned int nb_ios = 0);

/**
* @brief Constructor with name and list of digital IO names provided
* @param name The name of the associated digital IO state
* @param io_name List of IO names
*/
DigitalIOState(const std::string& name, const std::vector<std::string>& io_names);

/**
* @brief Copy constructor of a digital IO state
* @param state The digital IO state to copy from
*/
DigitalIOState(const DigitalIOState& state);

/**
* @brief Constructor for a zero digital IO state
* @param name The name of the associated digital IO state
* @param nb_ios The number of digital IOs for initialization
* @return Digital IO state with zero data
*/
static DigitalIOState Zero(const std::string& name, unsigned int nb_ios);

/**
* @brief Constructor for a zero digital IO state
* @param name The name of the associated digital IO state
* @param names List of IO names
* @return Digital IO state with zero data
*/
static DigitalIOState Zero(const std::string& name, const std::vector<std::string>& names);

/**
* @brief Constructor for a digital IO state with random data
* @param name The name of the associated digital IO state
* @param nb_ios The number of digital IOs for initialization
* @return Digital IO state with random data
*/
static DigitalIOState Random(const std::string& name, unsigned int nb_ios);

/**
* @brief Constructor for a digital IO state with random data
* @param name The name of the associated digital IO state
* @param names List of IO names
* @return Digital IO state with random data
*/
static DigitalIOState Random(const std::string& name, const std::vector<std::string>& names);

/**
* @brief Copy assignment operator that has to be defined to the custom assignment operator
* @param state The state with value to assign
* @return Reference to the current state with new values
*/
DigitalIOState& operator=(const DigitalIOState& state);

/**
* @brief Check if a digital IO is true by its name, if it exists
* @param name The name of the IO
* @throws IONotFoundException if the desired IO doesn't exist
* @return The value of the IO, if it exists
*/
bool is_true(const std::string& name) const;

/**
* @brief Check if a digital IO is true by its index, if it exists
* @param io_index The index of the IO
* @throws IONotFoundException if the desired IO doesn't exist
* @return The value of the IO, if it exists
*/
bool is_true(unsigned int io_index) const;

/**
* @brief Check if a digital IO is false by its name, if it exists
* @param name The name of the IO
* @throws IONotFoundException if the desired IO doesn't exist
* @return The value of the IO, if it exists
*/
bool is_false(const std::string& name) const;

/**
* @brief Check if a digital IO is false by its index, if it exists
* @param io_index The index of the IO
* @throws IONotFoundException if the desired IO doesn't exist
* @return The value of the IO, if it exists
*/
bool is_false(unsigned int io_index) const;

/**
* @brief Set the a digital IO to true by its name
* @param name The name of the IO
* @throws IONotFoundException if the desired IO doesn't exist
*/
void set_true(const std::string& name);

/**
* @brief Set the a digital IO to true by its index
* @param io_index The index of the IO
* @throws IONotFoundException if the desired IO doesn't exist
*/
void set_true(unsigned int io_index);

/**
* @brief Set the a digital IO to false by its name
* @param name The name of the IO
* @throws IONotFoundException if the desired IO doesn't exist
*/
void set_false(const std::string& name);

/**
* @brief Set the a digital IO to false by its index
* @param io_index The index of the IO
* @throws IONotFoundException if the desired IO doesn't exist
*/
void set_false(unsigned int io_index);

/**
* @brief Return a copy of the digital IO state
*/
DigitalIOState copy() const;

/**
* @copybrief State::reset
*/
void reset() override;

/**
* @brief Set all digital IOs false
*/
void set_false();

/**
* @brief Overload the ostream operator for printing
* @param os The ostream to append the string representing the state to
* @param state The spatial state to print
* @return The appended ostream
*/
friend std::ostream& operator<<(std::ostream& os, const DigitalIOState& state);

protected:
/**
* @brief Swap the values of the IO states
* @param state1 IO state to be swapped with 2
* @param state2 IO state to be swapped with 1
*/
friend void swap(DigitalIOState& state1, DigitalIOState& state2);

/**
* @copydoc State::to_string
*/
std::string to_string() const override;
};

inline void swap(DigitalIOState& state1, DigitalIOState& state2) {
swap(static_cast<IOState<bool>&>(state1), static_cast<IOState<bool>&>(state2));
}

}// namespace state_representation
Loading
Loading