robotiq_3f_gripper_ethercat_client.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016, Toyota Research Institute. All rights reserved.
2 
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 
6 // 1. Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 
9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 
13 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 // POSSIBILITY OF SUCH DAMAGE.
24 
26 
28 
29 // See Robotiq's documentation for the register mapping
30 
31 // An effort to keep the lines less than 100 char long
33 {
35  int slave_no)
36  : manager_(manager)
37  , slave_no_(slave_no)
38 {}
39 
40 /*
41  See support.robotiq.com -> manual for the register output meanings
42 */
44 {
45  uint8_t map[15] = {0}; // array containing all 15 output registers
46 
47  // Pack the Action Request register byte
48  map[0] = (output.rACT & 0x1) | (output.rMOD << 0x1) & 0x6 | ((output.rGTO << 0x3) & 0x8) | ((output.rATR << 0x4) & 0x10);
49 
50  // Pack the Gripper Options register byte
51  map[1] = ((output.rICF << 0x2) & 0x4) | ((output.rICS << 0x3) & 0x8);
52 
53  // map[2] is empty
54 
55  // Requested Position, Speed and Force (Finger A).
56  map[3] = output.rPRA;
57  map[4] = output.rSPA;
58  map[5] = output.rFRA;
59 
60  // Finger B
61  map[6] = output.rPRB;
62  map[7] = output.rSPB;
63  map[8] = output.rFRB;
64 
65  // Finger C
66  map[9] = output.rPRC;
67  map[10] = output.rSPC;
68  map[11] = output.rFRC;
69 
70  // Scissor Mode
71  map[12] = output.rPRS;
72  map[13] = output.rSPS;
73  map[14] = output.rFRS;
74 
75  for (unsigned i = 0; i < 15; ++i)
76  {
77  manager_.write(slave_no_, i, map[i]);
78  }
79 }
80 
82 {
83  uint8_t map[15];
84 
85  for (unsigned i = 0; i < 15; ++i)
86  {
87  map[i] = manager_.readInput(slave_no_, i);
88  }
89 
90  // Decode Input Registers
91  GripperInput input;
92 
93  // Gripper Status
94  input.gACT = map[0] & 0x1;
95  input.gMOD = (map[0] >> 0x1) & 0x3;
96  input.gGTO = (map[0] >> 0x3) & 0x1;
97  input.gIMC = (map[0] >> 0x4) & 0x3;
98  input.gSTA = (map[0] >> 0x6) & 0x3;
99 
100  // Object Status
101  input.gDTA = map[1] & 0x3;
102  input.gDTB = (map[1] >> 0x2) & 0x3;
103  input.gDTC = (map[1] >> 0x4) & 0x3;
104  input.gDTS = (map[1] >> 0x6) & 0x3;
105 
106  // Fault Status
107  input.gFLT = map[2] & 0xF;
108 
109  // Requested Position, Speed and Force (Finger A).
110  input.gPRA = map[3];
111  input.gPOA = map[4];
112  input.gCUA = map[5];
113 
114  // Finger B
115  input.gPRB = map[6];
116  input.gPOB = map[7];
117  input.gCUB = map[8];
118 
119  // Finger C
120  input.gPRC = map[9];
121  input.gPOC = map[10];
122  input.gCUC = map[11];
123 
124  // Scissor Mode
125  input.gPRS = map[12];
126  input.gPOS = map[13];
127  input.gCUS = map[14];
128 
129  return input;
130 }
131 
133 {
134  uint8_t map[15];
135  for (unsigned i = 0; i < 15; ++i)
136  {
137  map[i] = manager_.readOutput(slave_no_, i);
138  }
139 
140  GripperOutput output;
141  output.rACT = map[0] & 1;
142  output.rMOD = (map[0] >> 0x1) & 0x6;
143  output.rGTO = (map[0] >> 0x3) & 0x1;
144  output.rATR = (map[0] >> 0x4) & 0x1;
145 
146  output.rICF = (map[1] >> 0x2) & 0x4;
147  output.rICS = (map[1] >> 0x3) & 0x8;
148 
149  // Finger A
150  output.rPRA = map[3];
151  output.rSPA = map[4];
152  output.rFRA = map[5];
153 
154  // Finger B
155  output.rPRB = map[6];
156  output.rSPB = map[7];
157  output.rFRB = map[8];
158 
159  // Finger C
160  output.rPRC = map[9];
161  output.rSPC = map[10];
162  output.rFRC = map[11];
163 
164  // Scissor Mode
165  output.rPRS = map[12];
166  output.rSPS = map[13];
167  output.rFRS = map[14];
168 
169  return output;
170 }
171 } // end of robotiq_3f_gripper_control namespace
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput GripperOutput
Robotiq3FGripperEtherCatClient(robotiq_ethercat::EtherCatManager &manager, int slave_no)
Constructs a control interface to a 3F Robotiq gripper on the given ethercat network and the given sl...
unsigned char uint8_t
uint8_t readOutput(int slave_no, uint8_t channel) const
GripperOutput readOutputs() const
Reads set of output-register values from the gripper.
GripperInput readInputs() const
Reads set of input-register values from the gripper.
void write(int slave_no, uint8_t channel, uint8_t value)
uint8_t readInput(int slave_no, uint8_t channel) const
void writeOutputs(const GripperOutput &output)
Write the given set of control flags to the memory of the gripper.
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotInput GripperInput


robotiq_3f_gripper_control
Author(s): Nicolas Lauzier (Robotiq inc.), Allison Thackston
autogenerated on Tue Jun 1 2021 02:29:58