|
| 1 | +// Copyright 2022 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_DYNAMIXEL_P_HPP_ |
| 16 | +#define RT_MANIPULATORS_LIB_INCLUDE_DYNAMIXEL_P_HPP_ |
| 17 | + |
| 18 | +#include <string> |
| 19 | +#include <vector> |
| 20 | + |
| 21 | +#include "dynamixel_base.hpp" |
| 22 | + |
| 23 | +namespace dynamixel_p { |
| 24 | + |
| 25 | +class DynamixelP : public dynamixel_base::DynamixelBase { |
| 26 | + public: |
| 27 | + explicit DynamixelP(const uint8_t id, const int home_position = 0); |
| 28 | + |
| 29 | + bool read_operating_mode(const dynamixel_base::comm_t & comm, uint8_t & mode); |
| 30 | + bool write_operating_mode(const dynamixel_base::comm_t & comm, const uint8_t mode); |
| 31 | + bool read_current_limit(const dynamixel_base::comm_t & comm, double & limit_ampere); |
| 32 | + bool read_max_position_limit(const dynamixel_base::comm_t & comm, double & limit_radian); |
| 33 | + bool read_min_position_limit(const dynamixel_base::comm_t & comm, double & limit_radian); |
| 34 | + |
| 35 | + bool write_torque_enable(const dynamixel_base::comm_t & comm, const bool enable); |
| 36 | + |
| 37 | + bool write_velocity_i_gain(const dynamixel_base::comm_t & comm, const unsigned int gain); |
| 38 | + bool write_velocity_p_gain(const dynamixel_base::comm_t & comm, const unsigned int gain); |
| 39 | + bool write_position_d_gain(const dynamixel_base::comm_t & comm, const unsigned int gain); |
| 40 | + bool write_position_i_gain(const dynamixel_base::comm_t & comm, const unsigned int gain); |
| 41 | + bool write_position_p_gain(const dynamixel_base::comm_t & comm, const unsigned int gain); |
| 42 | + |
| 43 | + bool write_profile_acceleration( |
| 44 | + const dynamixel_base::comm_t & comm, const double acceleration_rpss); |
| 45 | + bool write_profile_velocity( |
| 46 | + const dynamixel_base::comm_t & comm, const double velocity_rps); |
| 47 | + |
| 48 | + unsigned int to_profile_acceleration(const double acceleration_rpss); |
| 49 | + unsigned int to_profile_velocity(const double velocity_rps); |
| 50 | + double to_position_radian(const int position); |
| 51 | + double to_velocity_rps(const int velocity); |
| 52 | + double to_current_ampere(const int current); |
| 53 | + double to_voltage_volt(const int voltage); |
| 54 | + unsigned int from_position_radian(const double position_rad); |
| 55 | + unsigned int from_velocity_rps(const double velocity_rps); |
| 56 | + unsigned int from_current_ampere(const double current_ampere); |
| 57 | + |
| 58 | + bool auto_set_indirect_address_of_present_position(const dynamixel_base::comm_t & comm); |
| 59 | + bool auto_set_indirect_address_of_present_velocity(const dynamixel_base::comm_t & comm); |
| 60 | + bool auto_set_indirect_address_of_present_current(const dynamixel_base::comm_t & comm); |
| 61 | + bool auto_set_indirect_address_of_present_input_voltage(const dynamixel_base::comm_t & comm); |
| 62 | + bool auto_set_indirect_address_of_present_temperature(const dynamixel_base::comm_t & comm); |
| 63 | + bool auto_set_indirect_address_of_goal_position(const dynamixel_base::comm_t & comm); |
| 64 | + bool auto_set_indirect_address_of_goal_velocity(const dynamixel_base::comm_t & comm); |
| 65 | + bool auto_set_indirect_address_of_goal_current(const dynamixel_base::comm_t & comm); |
| 66 | + |
| 67 | + unsigned int indirect_addr_of_present_position(void); |
| 68 | + unsigned int indirect_addr_of_present_velocity(void); |
| 69 | + unsigned int indirect_addr_of_present_current(void); |
| 70 | + unsigned int indirect_addr_of_present_input_voltage(void); |
| 71 | + unsigned int indirect_addr_of_present_temperature(void); |
| 72 | + unsigned int indirect_addr_of_goal_position(void); |
| 73 | + unsigned int indirect_addr_of_goal_velocity(void); |
| 74 | + unsigned int indirect_addr_of_goal_current(void); |
| 75 | + |
| 76 | + unsigned int start_address_for_indirect_read(void); |
| 77 | + unsigned int length_of_indirect_data_read(void); |
| 78 | + unsigned int next_indirect_addr_read(void) const; |
| 79 | + |
| 80 | + unsigned int start_address_for_indirect_write(void); |
| 81 | + unsigned int length_of_indirect_data_write(void); |
| 82 | + unsigned int next_indirect_addr_write(void) const; |
| 83 | + |
| 84 | + bool extract_present_position_from_sync_read( |
| 85 | + const dynamixel_base::comm_t & comm, const std::string & group_name, |
| 86 | + double & position_rad); |
| 87 | + bool extract_present_velocity_from_sync_read( |
| 88 | + const dynamixel_base::comm_t & comm, const std::string & group_name, |
| 89 | + double & velocity_rps); |
| 90 | + bool extract_present_current_from_sync_read( |
| 91 | + const dynamixel_base::comm_t & comm, const std::string & group_name, |
| 92 | + double & current_ampere); |
| 93 | + bool extract_present_input_voltage_from_sync_read( |
| 94 | + const dynamixel_base::comm_t & comm, const std::string & group_name, |
| 95 | + double & voltage_volt); |
| 96 | + bool extract_present_temperature_from_sync_read( |
| 97 | + const dynamixel_base::comm_t & comm, const std::string & group_name, |
| 98 | + int & temperature_deg); |
| 99 | + |
| 100 | + void push_back_position_for_sync_write( |
| 101 | + const double position_rad, std::vector<uint8_t> & write_data); |
| 102 | + void push_back_velocity_for_sync_write( |
| 103 | + const double velocity_rps, std::vector<uint8_t> & write_data); |
| 104 | + void push_back_current_for_sync_write( |
| 105 | + const double current_ampere, std::vector<uint8_t> & write_data); |
| 106 | + |
| 107 | + protected: |
| 108 | + int HOME_POSITION_; |
| 109 | + unsigned int total_length_of_indirect_addr_read_; |
| 110 | + unsigned int total_length_of_indirect_addr_write_; |
| 111 | + uint16_t indirect_addr_of_present_position_; |
| 112 | + uint16_t indirect_addr_of_present_velocity_; |
| 113 | + uint16_t indirect_addr_of_present_current_; |
| 114 | + uint16_t indirect_addr_of_present_input_voltage_; |
| 115 | + uint16_t indirect_addr_of_present_temperature_; |
| 116 | + uint16_t indirect_addr_of_goal_position_; |
| 117 | + uint16_t indirect_addr_of_goal_velocity_; |
| 118 | + uint16_t indirect_addr_of_goal_current_; |
| 119 | + |
| 120 | + bool set_indirect_address_read( |
| 121 | + const dynamixel_base::comm_t & comm, const uint16_t addr, const uint16_t len, |
| 122 | + uint16_t & indirect_addr); |
| 123 | + bool set_indirect_address_write( |
| 124 | + const dynamixel_base::comm_t & comm, const uint16_t addr, const uint16_t len, |
| 125 | + uint16_t & indirect_addr); |
| 126 | +}; |
| 127 | + |
| 128 | +} // namespace dynamixel_p |
| 129 | + |
| 130 | +#endif // RT_MANIPULATORS_LIB_INCLUDE_DYNAMIXEL_P_HPP_ |
0 commit comments