ethercatcpp
common.h
Go to the documentation of this file.
1 /* File: common.h
2  * This file is part of the program ethercatcpp-shadow
3  * Program description : EtherCAT driver library for shadow hand.
4  * Copyright (C) 2018-2022 - Robin Passama (CNRS/LIRMM) Arnaud Meline
5  * (CNRS/LIRMM) Benjamin Navarro (CNRS/LIRMM). All Right reserved.
6  *
7  * This software is free software: you can redistribute it and/or modify
8  * it under the terms of the CeCILL-C license as published by
9  * the CEA CNRS INRIA, either version 1
10  * of the License, or (at your option) any later version.
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * CeCILL-C License for more details.
15  *
16  * You should have received a copy of the CeCILL-C License
17  * along with this software. If not, it can be found on the official
18  * website of the CeCILL licenses family (http://www.cecill.info/index.en.html).
19  */
28 #pragma once
29 
30 #include <cstdint>
31 #include <array>
32 
34 
35 // Number of motors in shadow hand
36 constexpr int NUM_MOTORS = 20;
37 // Number of ADC sensors in the robot.
38 constexpr int SENSORS_NUM_0220 = 36;
39 // Number of ADC positions sensors (0..25)
40 constexpr int POSITION_SENSOR_NUM = 26;
41 
44 enum class HandType { Right, Left };
45 
48 enum class HandID {
49  LirmmRight,
50  LirmmLeft,
51  Count
52 };
53 
56 constexpr std::array<uint32_t, static_cast<int>(HandID::Count)>
58  842, // LirmmRight
59  858 // LirmmLeft
60 };
61 
64 constexpr std::array<HandType, static_cast<int>(HandID::Count)> hand_types = {
65  HandType::Right, // LirmmRight
66  HandType::Left // LirmmLeft
67 };
68 
71 enum class BiotacMode {
74 };
75 
78 enum class ControlMode { Torque, PWM };
79 
83  int16_t Pac0{0};
84  int16_t Pac1{0};
85  int16_t Pdc{0};
86 };
87 
91  int16_t Tac{0};
92  int16_t Tdc{0};
93 };
94 
97 struct BiotacElectrodes : public std::array<int16_t, 19> {
99  fill(0);
100  }
101 };
102 
108 enum class JointNames {
109  FFJ4,
110  FFJ3,
111  FFJ2,
112  MFJ4,
113  MFJ3,
114  MFJ2,
115  RFJ4,
116  RFJ3,
117  RFJ2,
118  LFJ5,
119  LFJ4,
120  LFJ3,
121  LFJ2,
122  THJ5,
123  THJ4,
124  THJ3,
125  THJ2,
126  WRJ2,
127  WRJ1,
128 };
129 
132 enum class JointGroupsNames {
133  FirstFinger,
134  MiddleFinger,
135  RingFinger,
136  LittleFinger,
137  Thumb,
138  Wrist
139 };
140 
141 constexpr std::size_t first_finger_joint_count = 3;
142 constexpr std::size_t middle_finger_joint_count = 3;
143 constexpr std::size_t ring_finger_joint_count = 3;
144 constexpr std::size_t little_finger_joint_count = 4;
145 constexpr std::size_t thumb_finger_joint_count = 4;
146 constexpr std::size_t wrist_joint_count = 2;
147 constexpr std::size_t joint_count =
151 constexpr std::size_t joint_groups_count = 6;
152 constexpr std::size_t biotac_count = 5;
153 
154 constexpr std::array<const char*, joint_count> joint_names{
155  "FFJ4", "FFJ3", "FFJ2", "MFJ4", "MFJ3", "MFJ2", "RFJ4",
156  "RFJ3", "RFJ2", "LFJ5", "LFJ4", "LFJ3", "LFJ2", "THJ5",
157  "THJ4", "THJ3", "THJ2", "WRJ2", "WRJ1"};
158 
159 constexpr std::array<const char*, joint_groups_count> joint_groups_names{
160  "FirstFinger", "MiddleFinger", "RingFinger",
161  "LittleFinger", "Thumb", "Wrist"};
162 
163 constexpr std::size_t index_of(JointNames name) {
164  return static_cast<std::size_t>(name);
165 }
166 
167 constexpr std::size_t index_of(JointGroupsNames name) {
168  return static_cast<std::size_t>(name);
169 }
170 
171 constexpr std::size_t index_of(HandID id) {
172  return static_cast<std::size_t>(id);
173 }
174 
175 struct RawHandState {
177  joint_torques.fill(0);
178  raw_joint_positions.fill(0);
179  joint_positions.fill(0.);
183  }
184 
185  std::array<int16_t, joint_count> joint_torques;
186  std::array<uint16_t, joint_count> raw_joint_positions;
187  std::array<double, joint_count> joint_positions;
188  std::array<BiotacPressures, biotac_count> biotac_presures;
189  std::array<BiotacTemperatures, biotac_count> biotac_temperatures;
190  std::array<BiotacElectrodes, biotac_count> biotac_electrodes;
191 };
192 
194  explicit RawHandCommand(ControlMode mode) : control_mode{mode} {
195  joint_torques.fill(0);
196  joint_pwm.fill(0);
197  }
198 
200  std::array<int16_t, joint_count> joint_torques;
201  std::array<int16_t, joint_count> joint_pwm;
202 };
203 
204 } // namespace ethercatcpp::shadow
ethercatcpp::shadow::index_of
constexpr std::size_t index_of(JointNames name)
Definition: common.h:163
ethercatcpp::shadow::JointNames
JointNames
Shadow hand joint names.
Definition: common.h:108
ethercatcpp::shadow::JointGroupsNames::FirstFinger
@ FirstFinger
ethercatcpp::shadow::JointNames::THJ2
@ THJ2
ethercatcpp::shadow::JointNames::THJ5
@ THJ5
ethercatcpp::shadow::BiotacElectrodes::BiotacElectrodes
BiotacElectrodes()
Definition: common.h:98
ethercatcpp::shadow::RawHandState::biotac_temperatures
std::array< BiotacTemperatures, biotac_count > biotac_temperatures
Definition: common.h:189
ethercatcpp::shadow::HandType
HandType
Describes the hand type: right or left.
Definition: common.h:44
ethercatcpp::shadow::HandID::LirmmLeft
@ LirmmLeft
ethercatcpp::shadow::RawHandCommand::joint_torques
std::array< int16_t, joint_count > joint_torques
Definition: common.h:200
ethercatcpp::shadow::HandID::LirmmRight
@ LirmmRight
ethercatcpp::shadow::HandType::Left
@ Left
ethercatcpp::shadow::JointGroupsNames::MiddleFinger
@ MiddleFinger
ethercatcpp::shadow::JointNames::LFJ3
@ LFJ3
ethercatcpp::shadow::RawHandState::biotac_presures
std::array< BiotacPressures, biotac_count > biotac_presures
Definition: common.h:188
ethercatcpp::shadow::JointNames::FFJ2
@ FFJ2
ethercatcpp::shadow::wrist_joint_count
constexpr std::size_t wrist_joint_count
Definition: common.h:146
ethercatcpp::shadow::HandID
HandID
List of known Shadow hands with their respective serial number.
Definition: common.h:48
ethercatcpp::shadow::middle_finger_joint_count
constexpr std::size_t middle_finger_joint_count
Definition: common.h:142
ethercatcpp::shadow::RawHandCommand::RawHandCommand
RawHandCommand(ControlMode mode)
Definition: common.h:194
ethercatcpp::shadow::JointGroupsNames
JointGroupsNames
All available joints groups on a Shadow hand.
Definition: common.h:132
ethercatcpp::shadow::POSITION_SENSOR_NUM
constexpr int POSITION_SENSOR_NUM
Definition: common.h:40
ethercatcpp::shadow::NUM_MOTORS
constexpr int NUM_MOTORS
Definition: common.h:36
ethercatcpp::shadow::RawHandCommand::joint_pwm
std::array< int16_t, joint_count > joint_pwm
Definition: common.h:201
ethercatcpp::shadow::JointNames::WRJ1
@ WRJ1
ethercatcpp::shadow::JointNames::WRJ2
@ WRJ2
ethercatcpp::shadow::BiotacTemperatures
All raw temperature measurements given by a Biotac.
Definition: common.h:90
ethercatcpp::shadow::JointNames::MFJ2
@ MFJ2
ethercatcpp::shadow::RawHandState
Definition: common.h:175
ethercatcpp::shadow::BiotacElectrodes
All raw impedance electrodes measurements given by a Biotac.
Definition: common.h:97
ethercatcpp::shadow::JointNames::RFJ2
@ RFJ2
ethercatcpp::shadow::HandID::Count
@ Count
Keep at the end.
ethercatcpp::shadow::JointNames::FFJ3
@ FFJ3
ethercatcpp::shadow::joint_names
constexpr std::array< const char *, joint_count > joint_names
Definition: common.h:154
ethercatcpp::shadow::SENSORS_NUM_0220
constexpr int SENSORS_NUM_0220
Definition: common.h:38
ethercatcpp::shadow::first_finger_joint_count
constexpr std::size_t first_finger_joint_count
Definition: common.h:141
ethercatcpp::shadow::JointNames::FFJ4
@ FFJ4
ethercatcpp::shadow::JointNames::RFJ3
@ RFJ3
ethercatcpp::shadow::JointGroupsNames::Thumb
@ Thumb
ethercatcpp::shadow::ControlMode
ControlMode
Describes the hand control mode: torque or direct PWM motor control.
Definition: common.h:78
ethercatcpp::shadow::ControlMode::PWM
@ PWM
ethercatcpp::shadow::JointNames::MFJ4
@ MFJ4
ethercatcpp::shadow::JointNames::LFJ5
@ LFJ5
ethercatcpp::shadow::BiotacMode::WithElectrodes
@ WithElectrodes
Electrodes datas are updated.
ethercatcpp::shadow::RawHandState::RawHandState
RawHandState()
Definition: common.h:176
ethercatcpp::shadow::BiotacTemperatures::Tdc
int16_t Tdc
Mesured temperature.
Definition: common.h:92
ethercatcpp::shadow::JointNames::MFJ3
@ MFJ3
ethercatcpp::shadow::thumb_finger_joint_count
constexpr std::size_t thumb_finger_joint_count
Definition: common.h:145
ethercatcpp::shadow
Definition: common.h:33
ethercatcpp::shadow::RawHandState::joint_positions
std::array< double, joint_count > joint_positions
Definition: common.h:187
ethercatcpp::shadow::JointNames::LFJ4
@ LFJ4
ethercatcpp::shadow::JointGroupsNames::Wrist
@ Wrist
ethercatcpp::shadow::little_finger_joint_count
constexpr std::size_t little_finger_joint_count
Definition: common.h:144
ethercatcpp::shadow::RawHandState::raw_joint_positions
std::array< uint16_t, joint_count > raw_joint_positions
Definition: common.h:186
ethercatcpp::shadow::BiotacPressures::Pac0
int16_t Pac0
First mesured dynamics presures.
Definition: common.h:83
ethercatcpp::shadow::JointNames::LFJ2
@ LFJ2
ethercatcpp::shadow::RawHandCommand::control_mode
ControlMode control_mode
Definition: common.h:199
ethercatcpp::shadow::BiotacMode::WithoutElectrodes
@ WithoutElectrodes
Only presure and temperature are updated.
ethercatcpp::shadow::ControlMode::Torque
@ Torque
ethercatcpp::shadow::BiotacPressures
All raw pressure measurements given by a Biotac.
Definition: common.h:82
ethercatcpp::shadow::joint_count
constexpr std::size_t joint_count
Definition: common.h:147
ethercatcpp::shadow::JointNames::THJ4
@ THJ4
ethercatcpp::shadow::JointGroupsNames::LittleFinger
@ LittleFinger
ethercatcpp::shadow::RawHandCommand
Definition: common.h:193
ethercatcpp::shadow::BiotacMode
BiotacMode
Describes the Biotac working mode: with or without the electrodes.
Definition: common.h:71
ethercatcpp::shadow::JointNames::THJ3
@ THJ3
ethercatcpp::shadow::joint_groups_count
constexpr std::size_t joint_groups_count
Definition: common.h:151
ethercatcpp::shadow::biotac_count
constexpr std::size_t biotac_count
Definition: common.h:152
ethercatcpp::shadow::BiotacTemperatures::Tac
int16_t Tac
Mesured dynamics temperature.
Definition: common.h:91
ethercatcpp::shadow::HandType::Right
@ Right
ethercatcpp::shadow::BiotacPressures::Pdc
int16_t Pdc
Mesured presure.
Definition: common.h:85
ethercatcpp::shadow::joint_groups_names
constexpr std::array< const char *, joint_groups_count > joint_groups_names
Definition: common.h:159
ethercatcpp::shadow::hand_serial_numbers
constexpr std::array< uint32_t, static_cast< int >HandID::Count)> hand_serial_numbers
List of serial numbers corresponding to HandIDs.
Definition: common.h:57
ethercatcpp::shadow::RawHandState::biotac_electrodes
std::array< BiotacElectrodes, biotac_count > biotac_electrodes
Definition: common.h:190
ethercatcpp::shadow::ring_finger_joint_count
constexpr std::size_t ring_finger_joint_count
Definition: common.h:143
ethercatcpp::shadow::JointNames::RFJ4
@ RFJ4
ethercatcpp::shadow::hand_types
constexpr std::array< HandType, static_cast< int >HandID::Count)> hand_types
List of hand types corresponding to HandIDs.
Definition: common.h:64
ethercatcpp::shadow::RawHandState::joint_torques
std::array< int16_t, joint_count > joint_torques
Definition: common.h:185
ethercatcpp::shadow::BiotacPressures::Pac1
int16_t Pac1
Second mesured dynamics presures.
Definition: common.h:84
ethercatcpp::shadow::JointGroupsNames::RingFinger
@ RingFinger