Skip to content

Commit b002fbb

Browse files
author
Shota Aoki
authored
速度制御機能とサンプルの追加 (#4)
* for-loopをconst 参照に書き換えて、不要なコピーと値の書き換えを防ぐ * サーボの速度、電流、電圧、温度をsync_readする機能を実装 * READMEの更新 * S17のread_preset_valuesサンプル追加 * ライブラリ:関数名の誤記修正 * サンプル:ID、ジョイント名でパラメータを読み取るサンプルを追加 * Operating Mode切り替え機能を実装。 goal_velocityの書き込みに対応 * goal_velocityを書き込むサンプルを追加 * start_thread()を実行しなければ、目標速度をセットできない * 角度リミットに達したらgoal_velocityを0にする。 goal_velocityを0にし忘れても良いように、安全な終了処理を実装 * 速度制御時の角度リミット値にマージンを加算できる * 速度制御時は、positionのsync_readを必須にする * connect状態のフラグを追加して、disconnect関数の連続実行を防ぐ * x7_write_velocityを修正 * s17_write_velocityを追加 * READMEを更新 * READMEを更新 * velocity pi gain設定機能を追加 * s17_write_velocityに速度PIDゲインの設定コードを追加 * READMEにvelocity_pi_gainの使い方を追記 * 目次の更新 * 微修正 * constの付け忘れを修正 * READMEにサーボモータのposition limitを確認すること、という文を追記 * max/min_pos_limit_marginをpos_limit_marginに統合 * forearmをwristに変更 * READMEにライブラリとサンプルの変更点を反映
1 parent cae2fbb commit b002fbb

File tree

10 files changed

+782
-29
lines changed

10 files changed

+782
-29
lines changed

rt_manipulators_lib/include/hardware.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class Hardware {
6262
bool set_position(const uint8_t id, const double position);
6363
bool set_position(const std::string& joint_name, const double position);
6464
bool set_positions(const std::string& group_name, std::vector<double>& positions);
65+
bool set_velocity(const uint8_t id, const double velocity);
66+
bool set_velocity(const std::string& joint_name, const double velocity);
67+
bool set_velocities(const std::string& group_name, std::vector<double>& velocities);
6568
bool write_max_acceleration_to_group(const std::string& group_name,
6669
const double acceleration_rpss);
6770
bool write_max_velocity_to_group(const std::string& group_name, const double velocity_rps);
@@ -71,6 +74,10 @@ class Hardware {
7174
const uint16_t d);
7275
bool write_position_pid_gain_to_group(const std::string& group_name, const uint16_t p,
7376
const uint16_t i, const uint16_t d);
77+
bool write_velocity_pi_gain(const uint8_t id, const uint16_t p, const uint16_t i);
78+
bool write_velocity_pi_gain(const std::string& joint_name, const uint16_t p, const uint16_t i);
79+
bool write_velocity_pi_gain_to_group(const std::string& group_name, const uint16_t p,
80+
const uint16_t i);
7481

7582
protected:
7683
bool write_byte_data(const uint8_t id, const uint16_t address, const uint8_t write_data);
@@ -82,12 +89,16 @@ class Hardware {
8289
bool write_double_word_data(const uint8_t id, const uint16_t address, const uint32_t write_data);
8390
bool write_double_word_data_to_group(const std::string& group_name, const uint16_t address,
8491
const uint32_t write_data);
92+
bool read_byte_data(const uint8_t id, const uint16_t address, uint8_t& read_data);
93+
bool read_double_word_data(const uint8_t id, const uint16_t address, uint32_t& read_data);
8594

8695
private:
8796
bool parse_config_file(const std::string& config_yaml);
8897
bool joint_groups_contain(const std::string& group_name);
8998
bool all_joints_contain(const std::string& joint_name);
9099
bool all_joints_contain_id(const uint8_t id);
100+
bool write_operating_mode(const std::string& group_name);
101+
bool limit_goal_velocity_by_present_position(const std::string& group_name);
91102
bool create_sync_read_group(const std::string& group_name);
92103
bool create_sync_write_group(const std::string& group_name);
93104
bool set_indirect_address(const std::string& group_name, const uint16_t addr_indirect_start,
@@ -102,8 +113,9 @@ class Hardware {
102113
double dxl_current_to_ampere(const int16_t current) const;
103114
double dxl_voltage_to_volt(const int16_t voltage) const;
104115
uint32_t radian_to_dxl_pos(const double position);
105-
uint32_t to_dxl_acceleration(const double acceleration_rpss);
106116
uint32_t to_dxl_velocity(const double velocity_rps);
117+
uint32_t to_dxl_acceleration(const double acceleration_rpss);
118+
uint32_t to_dxl_profile_velocity(const double velocity_rps);
107119

108120
std::shared_ptr<dynamixel::PortHandler> port_handler_;
109121
std::shared_ptr<dynamixel::PacketHandler> packet_handler_;
@@ -117,7 +129,7 @@ class Hardware {
117129
std::map<JointGroupName, uint16_t> addr_sync_read_current_;
118130
std::map<JointGroupName, uint16_t> addr_sync_read_voltage_;
119131
std::map<JointGroupName, uint16_t> addr_sync_read_temperature_;
120-
std::map<JointGroupName, uint16_t> address_indirect_goal_position_;
132+
bool is_connected_;
121133
bool thread_enable_;
122134
std::shared_ptr<std::thread> read_write_thread_;
123135
};

rt_manipulators_lib/include/joint.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ namespace joint {
2323

2424
class Joint {
2525
public:
26-
Joint(const uint8_t id, const uint8_t operating_mode);
26+
Joint(const uint8_t id, const uint8_t operating_mode,
27+
const double max_position_limit, const double min_position_limit);
2728
uint8_t id() const;
2829
uint8_t operating_mode() const;
30+
double max_position_limit() const;
31+
double min_position_limit() const;
2932
void set_present_position(const double position_radian);
3033
void set_present_velocity(const double velocity_rps);
3134
void set_present_current(const double current_ampere);
@@ -37,17 +40,22 @@ class Joint {
3740
double get_present_voltage() const;
3841
int8_t get_present_temperature() const;
3942
void set_goal_position(const double position_radian);
43+
void set_goal_velocity(const double velocity_rps);
4044
double get_goal_position() const;
45+
double get_goal_velocity() const;
4146

4247
private:
4348
uint8_t id_;
4449
uint8_t operating_mode_;
50+
double max_position_limit_;
51+
double min_position_limit_;
4552
double present_position_;
4653
double present_velocity_;
4754
double present_current_;
4855
double present_voltage_;
4956
int8_t present_temperature_;
5057
double goal_position_;
58+
double goal_velocity_;
5159
};
5260

5361
class JointGroup {

0 commit comments

Comments
 (0)