ts_SVHDriver.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of the SCHUNK SVH Driver suite.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
00012 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00013 //
00014 // -- END LICENSE BLOCK ------------------------------------------------
00015 
00016 //----------------------------------------------------------------------
00023 //----------------------------------------------------------------------
00024 #include <icl_comm/ByteOrderConversion.h>
00025 #include <boost/test/unit_test.hpp>
00026 
00027 #include <driver_svh/SVHPositionSettings.h>
00028 #include <driver_svh/SVHCurrentSettings.h>
00029 #include <driver_svh/SVHSerialPacket.h>
00030 #include <driver_svh/SVHControllerState.h>
00031 #include <driver_svh/SVHControlCommand.h>
00032 #include <driver_svh/SVHControllerFeedback.h>
00033 #include <driver_svh/SVHEncoderSettings.h>
00034 #include <driver_svh/SVHController.h>
00035 #include <driver_svh/SVHFingerManager.h>
00036 
00037 using icl_comm::ArrayBuilder;
00038 using namespace driver_svh;
00039 
00040 BOOST_AUTO_TEST_SUITE(ts_SVHDriver)
00041 
00042 ArrayBuilder payload(40);
00043 
00044 BOOST_AUTO_TEST_CASE(ConvertPosSettings)
00045 {
00046   std::cout << "Conversion test of Position Settings ....";
00047 
00048   // Reset Array Builder
00049   payload.reset(40);
00050 
00051   // Create Structures
00052   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);
00053   SVHPositionSettings test_pos_settings_out;
00054 
00055   // Conversion
00056   payload << test_pos_settings_in;
00057   payload >> test_pos_settings_out;
00058 
00059   BOOST_CHECK_EQUAL(test_pos_settings_in,test_pos_settings_out);
00060 
00061   std::cout << "Done" << std::endl;
00062 }
00063 
00064 BOOST_AUTO_TEST_CASE(ConvertCurSettings)
00065 {
00066   std::cout << "Conversion test of Current Settings ....";
00067 
00068   // Reset Array Builder
00069   payload.reset(40);
00070 
00071   // Create Structures
00072   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);
00073   SVHCurrentSettings test_cur_settings_out;
00074 
00075   // Conversion
00076   payload << test_cur_settings_in;
00077   payload >> test_cur_settings_out;
00078 
00079   BOOST_CHECK_EQUAL(test_cur_settings_in,test_cur_settings_out);
00080 
00081   std::cout << "Done" << std::endl;
00082 }
00083 
00084 BOOST_AUTO_TEST_CASE(ConvertControlCommand)
00085 {
00086   std::cout << "Conversion test of Controll Command ....";
00087 
00088   // Reset Array Builder
00089   payload.reset(40);
00090 
00091   // Create Structures
00092   SVHControlCommand test_control_command_in(23);
00093   SVHControlCommand test_control_command_out(0);
00094 
00095   // Conversion
00096   payload << test_control_command_in;
00097   payload >> test_control_command_out;
00098 
00099   BOOST_CHECK_EQUAL(test_control_command_in,test_control_command_out);
00100 
00101   std::cout << "Done" << std::endl;
00102 }
00103 
00104 
00105 BOOST_AUTO_TEST_CASE(ConvertControlFeedback)
00106 {
00107   std::cout << "Conversion test of ControllerFeedback ....";
00108 
00109   // Reset Array Builder
00110   payload.reset(40);
00111 
00112   // Create Structures
00113   SVHControllerFeedback test_controller_feedback_in(23,42);
00114   SVHControllerFeedback test_controller_feedback_out;
00115 
00116   // Conversion
00117   payload << test_controller_feedback_in;
00118   payload >> test_controller_feedback_out;
00119 
00120   BOOST_CHECK_EQUAL(test_controller_feedback_in,test_controller_feedback_out);
00121 
00122   std::cout << "Done" << std::endl;
00123 }
00124 
00125 BOOST_AUTO_TEST_CASE(ConvertControllerState)
00126 {
00127   std::cout << "Converstion test of ControllerState ....";
00128 
00129   // Reset Array Builder
00130   payload.reset(40);
00131 
00132   // Create Structures
00133   SVHControllerState test_controller_state_in(0x001F,0x001F,0x0200,0x02000,0x0001,0x0001);
00134   SVHControllerState test_controller_state_out;
00135 
00136   // Conversion
00137   payload << test_controller_state_in;
00138   payload >> test_controller_state_out;
00139 
00140 
00141 
00142   BOOST_CHECK_EQUAL(test_controller_state_in,test_controller_state_out);
00143 
00144   std::cout << "Done" << std::endl;
00145 }
00146 
00147 BOOST_AUTO_TEST_CASE(ConvertEncoderSettings)
00148 {
00149   std::cout << "Converstion test of EncoderSettings ....";
00150 
00151   // Reset Array Builder
00152   payload.reset(40);
00153 
00154   // Create Structures
00155   SVHEncoderSettings test_encoder_settings_in(23);
00156   SVHEncoderSettings test_encoder_settings_out;
00157 
00158   // Conversion
00159   payload << test_encoder_settings_in;
00160   payload >> test_encoder_settings_out;
00161 
00162   BOOST_CHECK_EQUAL(test_encoder_settings_in,test_encoder_settings_out);
00163 
00164   std::cout << "Done" << std::endl;
00165 }
00166 
00167 BOOST_AUTO_TEST_CASE(ConvertControlCommandAllChannels)
00168 {
00169   std::cout << "Converstion test of ControlCommandAllChannels ....";
00170 
00171   // Reset Array Builder
00172   payload.reset(40);
00173 
00174   // Create Structures
00175   SVHControlCommandAllChannels test_control_command_in(0,1,2,3,4,5,6,7,8);
00176   SVHControlCommandAllChannels test_control_command_out;
00177 
00178     // Conversion
00179   payload << test_control_command_in;
00180   payload >> test_control_command_out;
00181 
00182   BOOST_CHECK_EQUAL(test_control_command_in,test_control_command_out);
00183 
00184   std::cout << "Done" << std::endl;
00185 }
00186 
00187 BOOST_AUTO_TEST_CASE(ConvertControllerFeedbackAllChannels)
00188 {
00189   std::cout << "Converstion test of ControllerFeedbackAllChannels ....";
00190 
00191   // Reset Array Builder
00192   payload.reset(40);
00193 
00194   // Create Structures
00195   SVHControllerFeedbackAllChannels test_controller_feedback_all_channels_in(SVHControllerFeedback(0,9),
00196                                                                              SVHControllerFeedback(1,10),
00197                                                                              SVHControllerFeedback(2,11),
00198                                                                              SVHControllerFeedback(3,12),
00199                                                                              SVHControllerFeedback(4,13),
00200                                                                              SVHControllerFeedback(5,14),
00201                                                                              SVHControllerFeedback(6,15),
00202                                                                              SVHControllerFeedback(7,16),
00203                                                                              SVHControllerFeedback(8,17));
00204   SVHControllerFeedbackAllChannels test_controller_feedback_all_channels_out;
00205 
00206 
00207 
00208   // Conversion
00209   payload << test_controller_feedback_all_channels_in;
00210   payload >> test_controller_feedback_all_channels_out;
00211 
00212   BOOST_CHECK_EQUAL(test_controller_feedback_all_channels_in,test_controller_feedback_all_channels_out);
00213 
00214   std::cout << "Done" << std::endl;
00215 }
00216 
00217 
00218 BOOST_AUTO_TEST_CASE(ConvertSerialPacket)
00219 {
00220 
00221   std::cout << "Converstion test of Serial Packet ....";
00222 
00223   // Reset Array Builder
00224   payload.reset(40);
00225 
00226   // Create Structures
00227   ArrayBuilder packet;
00228   SVHSerialPacket test_serial_packet_in(40,5);
00229   SVHSerialPacket test_serial_packet_out(40);
00230   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);
00231   SVHPositionSettings test_pos_settings_out;
00232 
00233   // Conversion
00234   payload << test_pos_settings_in;
00235   // Insertion
00236   test_serial_packet_in.data = payload.array;
00237   // Converstion (this would be done by serialinterface)
00238   packet << test_serial_packet_in;
00239 
00240  // std::cout << "Raw Serial Packet of Position settings: " << packet << std::endl;
00241 
00242   packet >> test_serial_packet_out;
00243   payload.reset(40);
00244   payload.appendWithoutConversion(test_serial_packet_out.data);
00245   payload >> test_pos_settings_out;
00246 
00247   BOOST_CHECK_EQUAL(test_serial_packet_in,test_serial_packet_out);
00248   BOOST_CHECK_EQUAL(test_pos_settings_in,test_pos_settings_out);
00249 
00250   //std::cout << "Original pos Settings: " << test_pos_settings_in << " Interpreted pos settings: "<< test_pos_settings_out <<std::endl;
00251   std::cout << "Done" << std::endl;
00252 }
00253 
00254 BOOST_AUTO_TEST_CASE(ControllerreceiveFeedback)
00255 {
00256 
00257   std::cout << "Controller receiving feedback Packet ....";
00258 
00259   // Initialize logging
00260   icl_core::logging::initialize();
00261 
00262   // Reset Array Builder
00263   // BEWARE OF ARRAY LENGTH!
00264   payload.reset(64);
00265 
00266   // Create Structures
00267   SVHController controller;
00268   ArrayBuilder packet;
00269   SVHChannel channel = eSVH_INDEX_FINGER_DISTAL;
00270   SVHSerialPacket test_serial_packet(64,SVH_SET_CONTROL_COMMAND|static_cast<uint8_t>(channel << 4));
00271   SVHControllerFeedback test_controller_feedback(23,42);
00272   // Conversion
00273   payload << test_controller_feedback;
00274 
00275 
00276   // Insertion
00277   test_serial_packet.data = payload.array;
00278 
00279   // Emulate received packet
00280   controller.receivedPacketCallback(test_serial_packet,1);
00281 
00282   // Get packet from controller
00283   SVHControllerFeedback feedback_out;
00284   controller.getControllerFeedback(channel,feedback_out);
00285 
00286   BOOST_CHECK_EQUAL(test_controller_feedback,feedback_out);
00287 
00288   std::cout << "Done" << std::endl;
00289 }
00290 
00291 
00292 
00293 BOOST_AUTO_TEST_SUITE_END()


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19