SVHDriverTest.cpp
Go to the documentation of this file.
1 //
3 // © Copyright 2022 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
4 // © Copyright 2022 FZI Forschungszentrum Informatik, Karlsruhe, Germany
5 //
6 // This file is part of the Schunk SVH Library.
7 //
8 // The Schunk SVH Library is free software: you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or (at your
11 // option) any later version.
12 //
13 // The Schunk SVH Library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 // Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // the Schunk SVH Library. If not, see <https://www.gnu.org/licenses/>.
20 //
22 
23 //----------------------------------------------------------------------
30 //----------------------------------------------------------------------
31 #include <boost/test/unit_test.hpp>
33 
43 
45 using namespace driver_svh;
46 
47 BOOST_AUTO_TEST_SUITE(ts_SVHDriver)
48 
50 
51 BOOST_AUTO_TEST_CASE(ConvertPosSettings)
52 {
53  std::cout << "Conversion test of Position Settings ....";
54 
55  // Reset Array Builder
56  g_payload.reset(40);
57 
58  // Create Structures
59  SVHPositionSettings test_pos_settings_in(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.1);
60  SVHPositionSettings test_pos_settings_out;
61 
62  // Conversion
63  g_payload << test_pos_settings_in;
64  g_payload >> test_pos_settings_out;
65 
66  BOOST_CHECK_EQUAL(test_pos_settings_in, test_pos_settings_out);
67 
68  std::cout << "Done" << std::endl;
69 }
70 
71 BOOST_AUTO_TEST_CASE(ConvertCurSettings)
72 {
73  std::cout << "Conversion test of Current Settings ....";
74 
75  // Reset Array Builder
76  g_payload.reset(40);
77 
78  // Create Structures
79  SVHCurrentSettings test_cur_settings_in(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.1);
80  SVHCurrentSettings test_cur_settings_out;
81 
82  // Conversion
83  g_payload << test_cur_settings_in;
84  g_payload >> test_cur_settings_out;
85 
86  BOOST_CHECK_EQUAL(test_cur_settings_in, test_cur_settings_out);
87 
88  std::cout << "Done" << std::endl;
89 }
90 
91 BOOST_AUTO_TEST_CASE(ConvertControlCommand)
92 {
93  std::cout << "Conversion test of Controll Command ....";
94 
95  // Reset Array Builder
96  g_payload.reset(40);
97 
98  // Create Structures
99  SVHControlCommand test_control_command_in(23);
100  SVHControlCommand test_control_command_out(0);
101 
102  // Conversion
103  g_payload << test_control_command_in;
104  g_payload >> test_control_command_out;
105 
106  BOOST_CHECK_EQUAL(test_control_command_in, test_control_command_out);
107 
108  std::cout << "Done" << std::endl;
109 }
110 
111 
112 BOOST_AUTO_TEST_CASE(ConvertControlFeedback)
113 {
114  std::cout << "Conversion test of ControllerFeedback ....";
115 
116  // Reset Array Builder
117  g_payload.reset(40);
118 
119  // Create Structures
120  SVHControllerFeedback test_controller_feedback_in(23, 42);
121  SVHControllerFeedback test_controller_feedback_out;
122 
123  // Conversion
124  g_payload << test_controller_feedback_in;
125  g_payload >> test_controller_feedback_out;
126 
127  BOOST_CHECK_EQUAL(test_controller_feedback_in, test_controller_feedback_out);
128 
129  std::cout << "Done" << std::endl;
130 }
131 
132 BOOST_AUTO_TEST_CASE(ConvertControllerState)
133 {
134  std::cout << "Converstion test of ControllerState ....";
135 
136  // Reset Array Builder
137  g_payload.reset(40);
138 
139  // Create Structures
140  SVHControllerState test_controller_state_in(0x001F, 0x001F, 0x0200, 0x02000, 0x0001, 0x0001);
141  SVHControllerState test_controller_state_out;
142 
143  // Conversion
144  g_payload << test_controller_state_in;
145  g_payload >> test_controller_state_out;
146 
147 
148  BOOST_CHECK_EQUAL(test_controller_state_in, test_controller_state_out);
149 
150  std::cout << "Done" << std::endl;
151 }
152 
153 BOOST_AUTO_TEST_CASE(ConvertEncoderSettings)
154 {
155  std::cout << "Converstion test of EncoderSettings ....";
156 
157  // Reset Array Builder
158  g_payload.reset(40);
159 
160  // Create Structures
161  SVHEncoderSettings test_encoder_settings_in(23);
162  SVHEncoderSettings test_encoder_settings_out;
163 
164  // Conversion
165  g_payload << test_encoder_settings_in;
166  g_payload >> test_encoder_settings_out;
167 
168  BOOST_CHECK_EQUAL(test_encoder_settings_in, test_encoder_settings_out);
169 
170  std::cout << "Done" << std::endl;
171 }
172 
173 BOOST_AUTO_TEST_CASE(ConvertControlCommandAllChannels)
174 {
175  std::cout << "Converstion test of ControlCommandAllChannels ....";
176 
177  // Reset Array Builder
178  g_payload.reset(40);
179 
180  // Create Structures
181  SVHControlCommandAllChannels test_control_command_in(0, 1, 2, 3, 4, 5, 6, 7, 8);
182  SVHControlCommandAllChannels test_control_command_out;
183 
184  // Conversion
185  g_payload << test_control_command_in;
186  g_payload >> test_control_command_out;
187 
188  BOOST_CHECK_EQUAL(test_control_command_in, test_control_command_out);
189 
190  std::cout << "Done" << std::endl;
191 }
192 
193 BOOST_AUTO_TEST_CASE(ConvertControllerFeedbackAllChannels)
194 {
195  std::cout << "Converstion test of ControllerFeedbackAllChannels ....";
196 
197  // Reset Array Builder
198  g_payload.reset(40);
199 
200  // Create Structures
201  SVHControllerFeedbackAllChannels test_controller_feedback_all_channels_in(
202  SVHControllerFeedback(0, 9),
203  SVHControllerFeedback(1, 10),
204  SVHControllerFeedback(2, 11),
205  SVHControllerFeedback(3, 12),
206  SVHControllerFeedback(4, 13),
207  SVHControllerFeedback(5, 14),
208  SVHControllerFeedback(6, 15),
209  SVHControllerFeedback(7, 16),
210  SVHControllerFeedback(8, 17));
211  SVHControllerFeedbackAllChannels test_controller_feedback_all_channels_out;
212 
213 
214  // Conversion
215  g_payload << test_controller_feedback_all_channels_in;
216  g_payload >> test_controller_feedback_all_channels_out;
217 
218  BOOST_CHECK_EQUAL(test_controller_feedback_all_channels_in,
219  test_controller_feedback_all_channels_out);
220 
221  std::cout << "Done" << std::endl;
222 }
223 
224 
225 BOOST_AUTO_TEST_CASE(ConvertSerialPacket)
226 {
227  std::cout << "Converstion test of Serial Packet ....";
228 
229  // Reset Array Builder
230  g_payload.reset(40);
231 
232  // Create Structures
233  ArrayBuilder packet;
234  SVHSerialPacket test_serial_packet_in(40, 5);
235  SVHSerialPacket test_serial_packet_out(40);
236  SVHPositionSettings test_pos_settings_in(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.1);
237  SVHPositionSettings test_pos_settings_out;
238 
239  // Conversion
240  g_payload << test_pos_settings_in;
241  // Insertion
242  test_serial_packet_in.data = g_payload.array;
243  // Converstion (this would be done by serialinterface)
244  packet << test_serial_packet_in;
245 
246  // std::cout << "Raw Serial Packet of Position settings: " << packet << std::endl;
247 
248  packet >> test_serial_packet_out;
249  g_payload.reset(40);
250  g_payload.appendWithoutConversion(test_serial_packet_out.data);
251  g_payload >> test_pos_settings_out;
252 
253  BOOST_CHECK_EQUAL(test_serial_packet_in, test_serial_packet_out);
254  BOOST_CHECK_EQUAL(test_pos_settings_in, test_pos_settings_out);
255 
256  // std::cout << "Original pos Settings: " << test_pos_settings_in << " Interpreted pos settings:
257  // "<< test_pos_settings_out <<std::endl;
258  std::cout << "Done" << std::endl;
259 }
260 
261 BOOST_AUTO_TEST_CASE(ControllerreceiveFeedback)
262 {
263  std::cout << "Controller receiving feedback Packet ....";
264 
265  // Reset Array Builder
266  // BEWARE OF ARRAY LENGTH!
267  g_payload.reset(64);
268 
269  // Create Structures
270  SVHController controller;
271  ArrayBuilder packet;
273  SVHSerialPacket test_serial_packet(64,
274  SVH_SET_CONTROL_COMMAND | static_cast<uint8_t>(channel << 4));
275  SVHControllerFeedback test_controller_feedback(23, 42);
276  // Conversion
277  g_payload << test_controller_feedback;
278 
279 
280  // Insertion
281  test_serial_packet.data = g_payload.array;
282 
283  // Emulate received packet
284  controller.receivedPacketCallback(test_serial_packet, 1);
285 
286  // Get packet from controller
287  SVHControllerFeedback feedback_out;
288  controller.getControllerFeedback(channel, feedback_out);
289 
290  BOOST_CHECK_EQUAL(test_controller_feedback, feedback_out);
291 
292  std::cout << "Done" << std::endl;
293 }
294 
295 
296 BOOST_AUTO_TEST_SUITE_END()
Structure for transmitting all controllcommands at once.
void receivedPacketCallback(const SVHSerialPacket &packet, unsigned int packet_count)
callback function for interpretation of packages
The SVHCurrentSettings save the current controller paramters for a single motor.
const uint8_t SVH_SET_CONTROL_COMMAND
Sets the target position of a channel.
bool getControllerFeedback(const SVHChannel &channel, SVHControllerFeedback &controller_feedback)
request the latest stored controllerfeedback (current, position) from the controller.
std::vector< uint8_t > array
array of template type TArray
std::vector< uint8_t > data
Payload of the package.
The SVHControllerFeedback saves the feedback of a single motor.
ControlCommands are given as a single target position for the position controller (given in ticks) ...
void appendWithoutConversion(const T &data)
add data without any byte conversion
ArrayBuilder g_payload(40)
BOOST_AUTO_TEST_CASE(ConvertPosSettings)
This class controls the the SCHUNK five finger hand.
Definition: SVHController.h:87
The SVHPositionSettings save the position controller paramters for a single motor.
void reset(size_t array_size=1)
Resets the Arraybuilder to initial state, all values will be deleted.
The SVHControllerState indicates the current state of the MeCoVis controller IC which is used in the ...
The SVHControllerFeedbackAllChannes saves the feedback of a all motors.
The SVHEncoderSettings hold the settings for the encoder scaling of each channel. ...
The SerialPacket holds the (non generated) header and data of one message to the SVH-Hardware.


schunk_svh_library
Author(s): Georg Heppner, Lars Pfotzer, Felix Exner, Johannes Mangler, Stefan Scherzinger, Pascal Becker
autogenerated on Fri Apr 14 2023 02:26:23