1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*      File: shadow_hand.h
 *       This file is part of the program ethercatcpp-shadow
 *       Program description : EtherCAT driver library for shadow hand.
 *       Copyright (C) 2018-2022 -  Robin Passama (CNRS/LIRMM) Arnaud Meline
 * (CNRS/LIRMM) Benjamin Navarro (CNRS/LIRMM). All Right reserved.
 *
 *       This software is free software: you can redistribute it and/or modify
 *       it under the terms of the CeCILL-C license as published by
 *       the CEA CNRS INRIA, either version 1
 *       of the License, or (at your option) any later version.
 *       This software is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *       CeCILL-C License for more details.
 *
 *       You should have received a copy of the CeCILL-C License
 *       along with this software. If not, it can be found on the official
 * website of the CeCILL licenses family (http://www.cecill.info/index.en.html).
 */
/**
 * @file ethercatcpp/shadow_hand.h
 * @author Arnaud Meline (original developer)
 * @author Robin Passama (design and refactoring)
 * @brief Header file for complete ShadowHand ethercat driver
 * @date October 2018 - December 2022
 * @ingroup ethercatcpp-shadow
 */
#pragma once

#include <ethercatcpp/shadow/common.h>
#include <ethercatcpp/core.h>

#include <math-utils/interpolator.h>

#include <memory>

/*! \namespace ethercatcpp
 *
 * Root namespace for common and general purpose ethercatcpp packages
 */
namespace ethercatcpp {

/**
 * It is the main driver, only used this one to control a shadow hand because
 * Shadow hand is composed with two slaves (a fake and a controller). This class
 * describe the full controller and permit communication between the shadow hand
 * controller and an ethercat bus.
 * @brief This class describe the full EtherCAT driver for the shadow hand.
 *
 */
class ShadowHand : public BusDevice {
public:
    /**
     * @brief Constructor of ShadowHand class
     * @details The constructor must have an information on witch hand is used
     * (left or right) and if user needs biotacs eletrode data or not.
     * @param [in] hand_id tells if this is a left or right hand
     * @param [in] biotac_electrode_mode is a BiotacMode which indicates if user
     * need biotac electrodes data
     * @param [in] control_mode the control mode for the hand: torque or PWM
     * @param [in] joint_position_interpolator interpolator used to get joint
     * position in radians from raw units (encoder counts)
     */
    ShadowHand(shadow::HandID hand_id, shadow::BiotacMode biotac_electrode_mode,
               shadow::ControlMode control_mode,
               std::unique_ptr<
                   math::Interpolator<std::array<uint16_t, shadow::joint_count>,
                                      std::array<double, shadow::joint_count>>>
                   joint_position_interpolator);

    /**
     * @brief Constructor of ShadowHand class
     * @details The constructor must have an information on witch hand is used
     * (left or right) and if user needs biotacs eletrode data or not.
     * @param [in] hand_id tells if this is a left or right hand
     * @param [in] biotac_electrode_mode is a BiotacMode which indicates if user
     * need biotac electrodes data
     * @param [in] control_mode the control mode for the hand: torque or PWM
     */
    ShadowHand(shadow::HandID hand_id, shadow::BiotacMode biotac_electrode_mode,
               shadow::ControlMode control_mode);

    ~ShadowHand();

    /**
     * @brief read only access to hand state
     *
     * @return const RawHandState&
     */
    const shadow::RawHandState& state() const;

    /**
     * @brief read only access to hand command
     *
     * @return const RawHandState&
     */
    const shadow::RawHandCommand& command() const;

    /**
     * @brief read/write access to hand command
     *
     * @return const RawHandState&
     */
    shadow::RawHandCommand& command();

    /**
     * @brief read torques of hand's joints
     *
     */
    void read_joints_torques();

    /**
     * @brief read raw positions of hand's joints
     *
     */
    void read_raw_joints_positions();

    /**
     * @brief read positions of hand's joints
     *
     */
    void read_joints_positions();

    /**
     * @brief read pressure of biotac sensors
     *
     */
    void read_biotacs_pressures();

    /**
     * @brief read temperatures of biotac sensors
     *
     */
    void read_biotacs_temperatures();

    /**
     * @brief read contact electrodes values of biotac sensors
     *
     */
    void read_biotacs_electrodes();

    /**
     * @brief read all hand state data
     *
     */
    void read();

    /**
     * @brief write joints commands
     *
     */
    void write_joints_commands();

    /**
     * @brief write joints commands
     * @details same as write_joints_commands()
     * @see write_joints_commands()
     */
    void write();

    // Printing all datas
    /**
     * @brief Function used to print all fingers positions.
     */
    void print_fingers_positions();
    /**
     * @brief Function used to print all fingers torques.
     */
    void print_fingers_torques();
    /**
     * @brief Function used to print all biotacs datas (presure, temperature and
     * electrode impedance) for all fingers. Electrodes impedances datas are
     * updated anly if class is contruct with "WITH_BIOTACS_ELECTRODES" flag.
     */
    void print_biotacs_data();

    static std::unique_ptr<
        math::Interpolator<std::array<uint16_t, shadow::joint_count>,
                           std::array<double, shadow::joint_count>>>
    default_joint_calibrator(shadow::HandID hand_id);

private:
    class pImpl;
    std::unique_ptr<pImpl> impl_;

    shadow::RawHandState state_;
    shadow::RawHandCommand command_;

    pImpl& impl() {
        return *impl_;
    }
};

} // namespace ethercatcpp