-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate fake components, long live mock components (#762)
- Loading branch information
Showing
10 changed files
with
242 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...interface/doc/fake_components_userdoc.rst → ...interface/doc/mock_components_userdoc.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
hardware_interface/include/mock_components/generic_system.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Copyright (c) 2021 PickNik, 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. | ||
// | ||
// Author: Jafar Abdi, Denis Stogl | ||
|
||
#ifndef MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_ | ||
#define MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "hardware_interface/handle.hpp" | ||
#include "hardware_interface/hardware_info.hpp" | ||
#include "hardware_interface/system_interface.hpp" | ||
#include "hardware_interface/types/hardware_interface_return_values.hpp" | ||
#include "hardware_interface/types/hardware_interface_type_values.hpp" | ||
|
||
using hardware_interface::return_type; | ||
|
||
namespace mock_components | ||
{ | ||
using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn; | ||
|
||
class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::SystemInterface | ||
{ | ||
public: | ||
CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override; | ||
|
||
std::vector<hardware_interface::StateInterface> export_state_interfaces() override; | ||
|
||
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override; | ||
|
||
return_type read(const rclcpp::Time & time, const rclcpp::Duration & period) override; | ||
|
||
return_type write(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) override | ||
{ | ||
return return_type::OK; | ||
} | ||
|
||
protected: | ||
/// Use standard interfaces for joints because they are relevant for dynamic behavior | ||
/** | ||
* By splitting the standard interfaces from other type, the users are able to inherit this | ||
* class and simply create small "simulation" with desired dynamic behavior. | ||
* The advantage over using Gazebo is that enables "quick & dirty" tests of robot's URDF and | ||
* controllers. | ||
*/ | ||
const std::vector<std::string> standard_interfaces_ = { | ||
hardware_interface::HW_IF_POSITION, hardware_interface::HW_IF_VELOCITY, | ||
hardware_interface::HW_IF_ACCELERATION, hardware_interface::HW_IF_EFFORT}; | ||
|
||
const size_t POSITION_INTERFACE_INDEX = 0; | ||
|
||
struct MimicJoint | ||
{ | ||
std::size_t joint_index; | ||
std::size_t mimicked_joint_index; | ||
double multiplier = 1.0; | ||
}; | ||
std::vector<MimicJoint> mimic_joints_; | ||
|
||
/// The size of this vector is (standard_interfaces_.size() x nr_joints) | ||
std::vector<std::vector<double>> joint_commands_; | ||
std::vector<std::vector<double>> joint_states_; | ||
|
||
std::vector<std::string> other_interfaces_; | ||
/// The size of this vector is (other_interfaces_.size() x nr_joints) | ||
std::vector<std::vector<double>> other_commands_; | ||
std::vector<std::vector<double>> other_states_; | ||
|
||
std::vector<std::string> sensor_interfaces_; | ||
/// The size of this vector is (sensor_interfaces_.size() x nr_joints) | ||
std::vector<std::vector<double>> sensor_fake_commands_; | ||
std::vector<std::vector<double>> sensor_states_; | ||
|
||
std::vector<std::string> gpio_interfaces_; | ||
/// The size of this vector is (gpio_interfaces_.size() x nr_joints) | ||
std::vector<std::vector<double>> gpio_fake_commands_; | ||
std::vector<std::vector<double>> gpio_commands_; | ||
std::vector<std::vector<double>> gpio_states_; | ||
|
||
private: | ||
template <typename HandleType> | ||
bool get_interface( | ||
const std::string & name, const std::vector<std::string> & interface_list, | ||
const std::string & interface_name, const size_t vector_index, | ||
std::vector<std::vector<double>> & values, std::vector<HandleType> & interfaces); | ||
|
||
void initialize_storage_vectors( | ||
std::vector<std::vector<double>> & commands, std::vector<std::vector<double>> & states, | ||
const std::vector<std::string> & interfaces); | ||
|
||
template <typename InterfaceType> | ||
bool populate_interfaces( | ||
const std::vector<hardware_interface::ComponentInfo> & components, | ||
std::vector<std::string> & interfaces, std::vector<std::vector<double>> & storage, | ||
std::vector<InterfaceType> & target_interfaces, bool using_state_interfaces); | ||
|
||
bool use_fake_gpio_command_interfaces_; | ||
bool use_fake_sensor_command_interfaces_; | ||
|
||
double position_state_following_offset_; | ||
std::string custom_interface_with_following_offset_; | ||
size_t index_custom_interface_with_following_offset_; | ||
}; | ||
|
||
typedef GenericSystem GenericRobot; | ||
|
||
} // namespace mock_components | ||
|
||
#endif // MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_ |
Oops, something went wrong.