Skip to content

Commit a964916

Browse files
author
Shota Aoki
authored
リファクタリング:hardware_jointsクラスの追加 (#5)
* 可変長配列が初期化できていなかったので修正 * ジョイント情報を集約したhardware_jointsクラスを作成 * 型のエイリアス名を変更 * get, set関数をhardware_jointsに移植 * 不要になった関数と変数を削除 * HardwareJointsクラスの名前空間をhardware_jointsに修正
1 parent b002fbb commit a964916

File tree

5 files changed

+485
-271
lines changed

5 files changed

+485
-271
lines changed

rt_manipulators_lib/include/hardware.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <vector>
2525

2626
#include "joint.hpp"
27+
#include "hardware_joints.hpp"
2728

2829
namespace rt_manipulators_cpp {
2930

@@ -94,9 +95,6 @@ class Hardware {
9495

9596
private:
9697
bool parse_config_file(const std::string& config_yaml);
97-
bool joint_groups_contain(const std::string& group_name);
98-
bool all_joints_contain(const std::string& joint_name);
99-
bool all_joints_contain_id(const uint8_t id);
10098
bool write_operating_mode(const std::string& group_name);
10199
bool limit_goal_velocity_by_present_position(const std::string& group_name);
102100
bool create_sync_read_group(const std::string& group_name);
@@ -119,9 +117,7 @@ class Hardware {
119117

120118
std::shared_ptr<dynamixel::PortHandler> port_handler_;
121119
std::shared_ptr<dynamixel::PacketHandler> packet_handler_;
122-
std::map<JointGroupName, std::shared_ptr<joint::JointGroup>> joint_groups_;
123-
std::map<JointName, std::shared_ptr<joint::Joint>> all_joints_;
124-
std::map<uint8_t, std::shared_ptr<joint::Joint>> all_joints_ref_from_id_;
120+
hardware_joints::Joints joints_;
125121
std::map<JointGroupName, std::shared_ptr<dynamixel::GroupSyncRead>> sync_read_groups_;
126122
std::map<JointGroupName, std::shared_ptr<dynamixel::GroupSyncWrite>> sync_write_groups_;
127123
std::map<JointGroupName, uint16_t> addr_sync_read_position_;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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_

rt_manipulators_lib/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_library(${library_name}
77
SHARED
88
hardware.cpp
99
joint.cpp
10+
hardware_joints.cpp
1011
)
1112
set_target_properties(${library_name} PROPERTIES VERSION 1.0.0 SOVERSION 1)
1213

0 commit comments

Comments
 (0)