Skip to content

/home/runner/work/dynamixel_hardware_interface/dynamixel_hardware_interface/include/dynamixel_hardware_interface/address_table_base.hpp#

Base class for the address tabele. More...

Namespaces#

Name
dynamixel_hardware_interface

Classes#

Name
class dynamixel_hardware_interface::AddressTableBase
base class for address table class
class dynamixel_hardware_interface::Address

Detailed Description#

Base class for the address tabele.

Author: Masaya Kataoka (ms.kataoka@gmail.com)

Version: 0.1

Date: 2021-05-01

Copyright: Copyright (c) OUXT Polaris 2021

Source code#

// Copyright (c) 2021 OUXT Polaris
//
// 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.

#ifndef DYNAMIXEL_HARDWARE_INTERFACE__ADDRESS_TABLE_BASE_HPP_
#define DYNAMIXEL_HARDWARE_INTERFACE__ADDRESS_TABLE_BASE_HPP_

#include <boost/optional.hpp>
#include <cmath>
#include <dynamixel_hardware_interface/constants.hpp>
#include <limits>

namespace dynamixel_hardware_interface
{
class Address
{
public:
  Address(uint16_t address, PacketByteSize byte_size) : address(address), byte_size(byte_size) {}
  Address() : address(0), byte_size(PacketByteSize::INVALID) {}
  const uint16_t address;
  const PacketByteSize byte_size;
  bool exists() const
  {
    if (byte_size == PacketByteSize::INVALID) {
      return false;
    }
    return true;
  }
};

class AddressTableBase
{
public:
  explicit AddressTableBase(
    Address ADDR_TORQUE_ENABLE, Address ADDR_GOAL_POSITION, Address ADDR_MOVING_SPEED,
    Address ADDR_PRESENT_POSITION, Address ADDR_PRESENT_SPEED, Address ADDR_PRESENT_LOAD,
    Address ADDR_PRESENT_VOLTAGE, Address ADDR_PRESENT_TEMPERATURE, Address ADDR_MAX_POSITION_LIMIT,
    Address ADDR_MIN_POSITION_LIMIT)
  : ADDR_TORQUE_ENABLE(ADDR_TORQUE_ENABLE),
    ADDR_GOAL_POSITION(ADDR_GOAL_POSITION),
    ADDR_MOVING_SPEED(ADDR_MOVING_SPEED),
    ADDR_PRESENT_POSITION(ADDR_PRESENT_POSITION),
    ADDR_PRESENT_SPEED(ADDR_PRESENT_SPEED),
    ADDR_PRESENT_LOAD(ADDR_PRESENT_LOAD),
    ADDR_PRESENT_VOLTAGE(ADDR_PRESENT_VOLTAGE),
    ADDR_PRESENT_TEMPERATURE(ADDR_PRESENT_TEMPERATURE),
    ADDR_MAX_POSITION_LIMIT(ADDR_MAX_POSITION_LIMIT),
    ADDR_MIN_POSITION_LIMIT(ADDR_MIN_POSITION_LIMIT)
  {
  }
  Address getAddress(const Operation & operaiton) const
  {
    switch (operaiton) {
      case Operation::TORQUE_ENABLE:
        return ADDR_TORQUE_ENABLE;
      case Operation::GOAL_POSITION:
        return ADDR_GOAL_POSITION;
      case Operation::MOVING_SPEED:
        return ADDR_MOVING_SPEED;
      case Operation::PRESENT_POSITION:
        return ADDR_PRESENT_POSITION;
      case Operation::PRESENT_SPEED:
        return ADDR_PRESENT_SPEED;
      case Operation::PRESENT_LOAD:
        return ADDR_PRESENT_LOAD;
      case Operation::PRESENT_VOLTAGE:
        return ADDR_PRESENT_VOLTAGE;
      case Operation::PRESENT_TEMPERATURE:
        return ADDR_PRESENT_TEMPERATURE;
      case Operation::MAX_POSITION_LIMIT:
        return ADDR_MAX_POSITION_LIMIT;
      case Operation::MIN_POSITION_LIMIT:
        return ADDR_MIN_POSITION_LIMIT;
      default:
        return Address();
    }
  }
  bool addressExists(const Operation & operation) const { return getAddress(operation).exists(); }

private:
  AddressTableBase() = delete;
  const Address ADDR_TORQUE_ENABLE;
  const Address ADDR_GOAL_POSITION;
  const Address ADDR_MOVING_SPEED;
  const Address ADDR_PRESENT_POSITION;
  const Address ADDR_PRESENT_SPEED;
  const Address ADDR_PRESENT_LOAD;
  const Address ADDR_PRESENT_VOLTAGE;
  const Address ADDR_PRESENT_TEMPERATURE;
  const Address ADDR_MAX_POSITION_LIMIT;
  const Address ADDR_MIN_POSITION_LIMIT;
};
}  // namespace dynamixel_hardware_interface

#endif  // DYNAMIXEL_HARDWARE_INTERFACE__ADDRESS_TABLE_BASE_HPP_

Updated on 17 July 2023 at 01:42:11 UTC