|
| 1 | +// Copyright 2021 RT Corporation |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef RT_MANIPULATORS_LIB_INCLUDE_HARDWARE_JOINTS_HPP_ |
| 16 | +#define RT_MANIPULATORS_LIB_INCLUDE_HARDWARE_JOINTS_HPP_ |
| 17 | + |
| 18 | +#include <map> |
| 19 | +#include <memory> |
| 20 | +#include <string> |
| 21 | +#include <thread> |
| 22 | +#include <vector> |
| 23 | + |
| 24 | +#include "joint.hpp" |
| 25 | + |
| 26 | +namespace hardware_joints { |
| 27 | + |
| 28 | +using group_name_t = std::string; |
| 29 | +using joint_name_t = std::string; |
| 30 | +using group_map_t = std::map<group_name_t, std::shared_ptr<joint::JointGroup>>; |
| 31 | +using dxl_id_t = uint8_t; |
| 32 | +using position_t = double; |
| 33 | +using velocity_t = double; |
| 34 | +using current_t = double; |
| 35 | +using voltage_t = double; |
| 36 | +using temperature_t = int8_t; |
| 37 | + |
| 38 | +// ハードウェアのジョイント情報を持つクラス |
| 39 | +class Joints{ |
| 40 | + public: |
| 41 | + Joints() {} |
| 42 | + ~Joints() {} |
| 43 | + const group_map_t groups() const; |
| 44 | + void append_group(const group_name_t & group_name, const joint::JointGroup & group); |
| 45 | + void append_joint(const joint_name_t & joint_name, const joint::Joint & joint); |
| 46 | + std::shared_ptr<joint::JointGroup> group(const group_name_t & name); |
| 47 | + std::shared_ptr<joint::Joint> joint(const joint_name_t & name); |
| 48 | + std::shared_ptr<joint::Joint> joint(const dxl_id_t & id); |
| 49 | + bool has_group(const group_name_t & name); |
| 50 | + bool has_joint(const joint_name_t & name); |
| 51 | + bool has_joint(const dxl_id_t & id); |
| 52 | + bool get_position(const dxl_id_t & id, position_t & position); |
| 53 | + bool get_position(const joint_name_t & joint_name, position_t & position); |
| 54 | + bool get_positions(const group_name_t & group_name, std::vector<position_t> & positions); |
| 55 | + bool get_velocity(const dxl_id_t & id, velocity_t & velocity); |
| 56 | + bool get_velocity(const joint_name_t & joint_name, velocity_t & velocity); |
| 57 | + bool get_velocities(const group_name_t & group_name, std::vector<velocity_t> & velocities); |
| 58 | + bool get_current(const dxl_id_t & id, current_t & current); |
| 59 | + bool get_current(const joint_name_t & joint_name, current_t & current); |
| 60 | + bool get_currents(const group_name_t & group_name, std::vector<current_t>& currents); |
| 61 | + bool get_voltage(const dxl_id_t id, voltage_t & voltage); |
| 62 | + bool get_voltage(const joint_name_t & joint_name, voltage_t & voltage); |
| 63 | + bool get_voltages(const group_name_t & group_name, std::vector<voltage_t>& voltages); |
| 64 | + bool get_temperature(const dxl_id_t & id, temperature_t & temperature); |
| 65 | + bool get_temperature(const joint_name_t & joint_name, temperature_t & temperature); |
| 66 | + bool get_temperatures(const group_name_t & group_name, std::vector<temperature_t>& temperatures); |
| 67 | + bool set_position(const dxl_id_t & id, const position_t & position); |
| 68 | + bool set_position(const joint_name_t & joint_name, const position_t & position); |
| 69 | + bool set_positions(const group_name_t & group_name, const std::vector<position_t> & positions); |
| 70 | + bool set_velocity(const dxl_id_t & id, const velocity_t & velocity); |
| 71 | + bool set_velocity(const joint_name_t & joint_name, const velocity_t & velocity); |
| 72 | + bool set_velocities(const group_name_t & group_name, const std::vector<velocity_t>& velocities); |
| 73 | + |
| 74 | + private: |
| 75 | + group_map_t joint_groups_; |
| 76 | + std::map<joint_name_t, std::shared_ptr<joint::Joint>> all_joints_; |
| 77 | + std::map<dxl_id_t, std::shared_ptr<joint::Joint>> all_joints_ref_from_id_; |
| 78 | +}; |
| 79 | + |
| 80 | +} // namespace hardware_joints |
| 81 | + |
| 82 | +#endif // RT_MANIPULATORS_LIB_INCLUDE_HARDWARE_JOINTS_HPP_ |
0 commit comments