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

import hardware_interface #3

Merged
merged 1 commit into from
Sep 19, 2017
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
62 changes: 62 additions & 0 deletions hardware_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.5)
project(hardware_interface)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra)
endif()

find_package(ament_cmake REQUIRED)
find_package(rcutils REQUIRED)

add_library(
hardware_interface
SHARED
src/joint_command_handle.cpp
src/joint_state_handle.cpp
src/operation_mode_handle.cpp
src/robot_hardware.cpp
)
target_include_directories(
hardware_interface
PUBLIC
include)
ament_target_dependencies(
hardware_interface
"rcutils"
)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(hardware_interface PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")

install(
DIRECTORY include/
DESTINATION include
)

install(
TARGETS
hardware_interface
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

ament_add_gtest(test_macros test/test_macros.cpp)
target_include_directories(test_macros PRIVATE include)
endif()

ament_export_include_directories(
include
)
ament_export_libraries(
hardware_interface)
ament_package()
2 changes: 2 additions & 0 deletions hardware_interface/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
robot agnostic hardware_interface package.
This package will eventually be moved into its own repo.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2017 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.

#ifndef HARDWARE_INTERFACE__JOINT_COMMAND_HANDLE_HPP_
#define HARDWARE_INTERFACE__JOINT_COMMAND_HANDLE_HPP_

#include <string>

#include "hardware_interface/visibility_control.h"

#include "types/hardware_interface_return_values.hpp"

namespace hardware_interface
{
/** A handle used to read the state of a single joint. */
class JointCommandHandle
{
public:
HARDWARE_INTERFACE_PUBLIC
JointCommandHandle();

/**
* The commmand handles are passive in terms of ownership.
* That means that the handles are only allowed to read/write
* the storage, however are not allowed to delete or reallocate
* this memory.
* \param name The name of the joint
* \param cmd A pointer to the storage for this joint's command
*/
HARDWARE_INTERFACE_PUBLIC
JointCommandHandle(
const std::string & name,
double * cmd);

HARDWARE_INTERFACE_PUBLIC
const std::string &
get_name() const;

HARDWARE_INTERFACE_PUBLIC
double
get_cmd() const;

HARDWARE_INTERFACE_PUBLIC
void
set_cmd(double cmd);

private:
std::string name_;
double * cmd_;
};

} // namespace hardware_interface

#endif // HARDWARE_INTERFACE__JOINT_COMMAND_HANDLE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2017 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.

#ifndef HARDWARE_INTERFACE__JOINT_STATE_HANDLE_HPP_
#define HARDWARE_INTERFACE__JOINT_STATE_HANDLE_HPP_

#include <string>

#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/visibility_control.h"

namespace hardware_interface
{
/** A handle used to read the state of a single joint. */
class JointStateHandle
{
public:
HARDWARE_INTERFACE_PUBLIC
JointStateHandle();

/**
* The joint handles are passive in terms of ownership.
* That means that the handles are only allowed to read/write
* the storage, however are not allowed to delete or reallocate
* this memory.
* \param name The name of the joint
* \param pos A pointer to the storage for this joint's position
* \param vel A pointer to the storage for this joint's velocity
* \param eff A pointer to the storage for this joint's effort (force or torque)
*/
HARDWARE_INTERFACE_PUBLIC
JointStateHandle(
const std::string & name,
const double * pos,
const double * vel,
const double * eff);

HARDWARE_INTERFACE_PUBLIC
const std::string &
get_name() const;

HARDWARE_INTERFACE_PUBLIC
double
get_position() const;

HARDWARE_INTERFACE_PUBLIC
double
get_velocity() const;

HARDWARE_INTERFACE_PUBLIC
double
get_effort() const;

private:
std::string name_;
const double * pos_;
const double * vel_;
const double * eff_;
};

} // namespace hardware_interface

#endif // HARDWARE_INTERFACE__JOINT_STATE_HANDLE_HPP_
37 changes: 37 additions & 0 deletions hardware_interface/include/hardware_interface/macros.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2017 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.

#ifndef HARDWARE_INTERFACE__MACROS_HPP_
#define HARDWARE_INTERFACE__MACROS_HPP_

#include <stdexcept>
#include <string>

#ifdef _WIN32
#define __PRETTY_FUNCTION__ __FUNCTION__
#endif

#define THROW_ON_NULLPTR(pointer) \
if (!pointer) { \
throw std::runtime_error( \
std::string(__PRETTY_FUNCTION__) + " failed. "#pointer " is null."); \
} \

#define THROW_ON_NOT_NULLPTR(pointer) \
if (pointer) { \
throw std::runtime_error( \
std::string(__PRETTY_FUNCTION__) + " failed. "#pointer " would leak memory"); \
} \

#endif // HARDWARE_INTERFACE__MACROS_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2017 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.

#ifndef HARDWARE_INTERFACE__OPERATION_MODE_HANDLE_HPP_
#define HARDWARE_INTERFACE__OPERATION_MODE_HANDLE_HPP_

#include <string>

#include "hardware_interface/visibility_control.h"

namespace hardware_interface
{
/// Enum for Operation Mode.
/** Operation can either be active or inactive */
enum class HARDWARE_INTERFACE_PUBLIC_TYPE OperationMode: bool
{
ACTIVE = true,
INACTIVE = false
};

/// A handle for Operation Mode.
/** Used to set status to active or inactive for operation such as read/write. */
class OperationModeHandle
{
public:
HARDWARE_INTERFACE_PUBLIC
OperationModeHandle();

/// Constructor of Operation Mode.
/**
* The mode handles are passive in terms of ownership for the mode pointer.
* This means the handle is allowed to read and write the respective mode,
* however is not allowed to reallocate or delete the memory storage.
* \param name The name of the joint
* \param mode A pointer to the storage for this hardware's operation mode
*/
HARDWARE_INTERFACE_PUBLIC
OperationModeHandle(
const std::string & name,
OperationMode * mode);

HARDWARE_INTERFACE_PUBLIC
const std::string &
get_name() const;

HARDWARE_INTERFACE_PUBLIC
void
set_mode(OperationMode mode);

private:
std::string name_;
OperationMode * mode_;
};

} // namespace hardware_interface

#endif // HARDWARE_INTERFACE__OPERATION_MODE_HANDLE_HPP_
Loading