diff --git a/CMakeLists.txt b/CMakeLists.txt index f178c8c26ec65b626e0b407d4327c125fb54a153..91e5836611acc1be51c1a226b94d0cf4a0ffd16e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,9 @@ find_package("ArmarXCore" REQUIRED ) include(${ArmarXCore_CMAKE_DIR}/ArmarXProject.cmake) +depends_on_armarx_package(ArmarXGui) +depends_on_armarx_package(MemoryX) +depends_on_armarx_package(VisionX) armarx_project("RobotAPI") @@ -17,3 +20,5 @@ add_subdirectory(interface) install_project() + +add_subdirectory(scenarios) \ No newline at end of file diff --git a/README.txt b/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..f3b3611ca8958eb5cb7e65846a2639fd68855f88 --- /dev/null +++ b/README.txt @@ -0,0 +1 @@ +Stub to make the package tool work. diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..65df063943986e0bdf4c4ecf5e822d953a402fd7 --- /dev/null +++ b/data/.gitkeep @@ -0,0 +1,4 @@ +Git can only track files and not directory. + +Therefore this file is added to all empty directories +which need to be available after a Git clone. diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/etc/cmake/.gitkeep b/etc/cmake/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..65df063943986e0bdf4c4ecf5e822d953a402fd7 --- /dev/null +++ b/etc/cmake/.gitkeep @@ -0,0 +1,4 @@ +Git can only track files and not directory. + +Therefore this file is added to all empty directories +which need to be available after a Git clone. diff --git a/gpl-2.0.txt b/gpl-2.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..d159169d1050894d3ea3b98e1c965c4058208fe1 --- /dev/null +++ b/gpl-2.0.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/interface/slice/.gitkeep b/interface/slice/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..65df063943986e0bdf4c4ecf5e822d953a402fd7 --- /dev/null +++ b/interface/slice/.gitkeep @@ -0,0 +1,4 @@ +Git can only track files and not directory. + +Therefore this file is added to all empty directories +which need to be available after a Git clone. diff --git a/scenarios/CMakeLists.txt b/scenarios/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a2af915ff2dae8e5f67ab8a06f366d36a393987a --- /dev/null +++ b/scenarios/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_subdirectory(WeissHapticSensorsUnitTest) \ No newline at end of file diff --git a/scenarios/WeissHapticSensorsUnitTest/CMakeLists.txt b/scenarios/WeissHapticSensorsUnitTest/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d5c59fb93f7908f76a35a7221b991f3956cdcdcf --- /dev/null +++ b/scenarios/WeissHapticSensorsUnitTest/CMakeLists.txt @@ -0,0 +1,14 @@ + +set(SCENARIO_COMPONENTS + WeissHapticSensorsUnitApp + WeissHapticSensorApp) + + +# optional 3rd parameter: "path/to/global/config.cfg" +armarx_scenario("WeissHapticSensorsUnitTest" "${SCENARIO_COMPONENTS}") + +#set(SCENARIO_CONFIGS +# config/ComponentName.optionalString.cfg +# ) +# optional 3rd parameter: "path/to/global/config.cfg" +#armarx_scenario_from_configs("WeissHapticSensorsUnitTest" "${SCENARIO_CONFIGS}") diff --git a/scenarios/WeissHapticSensorsUnitTest/config/WeissHapticSensorApp.cfg b/scenarios/WeissHapticSensorsUnitTest/config/WeissHapticSensorApp.cfg new file mode 100644 index 0000000000000000000000000000000000000000..1f85d7c5cbdd1c0cbc11253d177937916a2a7581 --- /dev/null +++ b/scenarios/WeissHapticSensorsUnitTest/config/WeissHapticSensorApp.cfg @@ -0,0 +1,104 @@ +# ================================================================== +# ArmarX properties +# ================================================================== + +# ArmarX.CachePath: Path for cache files +# Attributes: +# - Default: ${HOME}/.armarx/mongo/.cache +# - Case sensitivity: no +# - Required: no +# ArmarX.CachePath = ${HOME}/.armarx/mongo/.cache + + +# ArmarX.DataPath: Semicolon-separated search list for data files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.DataPath = "" + + +# ArmarX.Verbosity: Global logging level for whole application +# Attributes: +# - Default: Verbose +# - Case sensitivity: no +# - Required: no +# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning} +# ArmarX.Verbosity = Verbose + + +# ArmarX.DisableLogging: Turn logging off in whole application +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# - Possible values: {0, 1, false, no, true, yes} +# ArmarX.DisableLogging = 0 + + +# ArmarX.ApplicationName: Application name +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.ApplicationName = "" + + +# ArmarX.Config: Comma-separated list of configuration files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.Config = "" + + +# ================================================================== +# ArmarX.HapticUnitObserver properties +# ================================================================== + +# ArmarX.HapticUnitObserver.HapticTopicName: Name of the HapticUnit Topic +# Attributes: +# - Case sensitivity: no +# - Required: yes +ArmarX.HapticUnitObserver.HapticTopicName = "HapticValues" + + +# ArmarX.HapticUnitObserver.MinimumLoggingLevel: Local logging level only for this component +# Attributes: +# - Default: Undefined +# - Case sensitivity: no +# - Required: no +# - Possible values: {Error, Fatal, Info, Undefined, Verbose, Warning} +# ArmarX.HapticUnitObserver.MinimumLoggingLevel = Undefined + + +# ArmarX.HapticUnitObserver.ObjectName: Name of IceGrid well-known object +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.HapticUnitObserver.ObjectName = "" + + +# ================================================================== +# ArmarX.WeissHapticSensorListener properties +# ================================================================== + +# ArmarX.WeissHapticSensorListener.MinimumLoggingLevel: Local logging level only for this component +# Attributes: +# - Default: Undefined +# - Case sensitivity: no +# - Required: no +# - Possible values: {Error, Fatal, Info, Undefined, Verbose, Warning} +# ArmarX.WeissHapticSensorListener.MinimumLoggingLevel = Undefined + + +# ArmarX.WeissHapticSensorListener.ObjectName: Name of IceGrid well-known object +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.WeissHapticSensorListener.ObjectName = "" + + + diff --git a/scenarios/WeissHapticSensorsUnitTest/config/WeissHapticSensorsUnitApp.cfg b/scenarios/WeissHapticSensorsUnitTest/config/WeissHapticSensorsUnitApp.cfg new file mode 100644 index 0000000000000000000000000000000000000000..1758548b76a87189af145e83a809582e17327a4e --- /dev/null +++ b/scenarios/WeissHapticSensorsUnitTest/config/WeissHapticSensorsUnitApp.cfg @@ -0,0 +1,55 @@ +# ================================================================== +# ArmarX properties +# ================================================================== + +# ArmarX.CachePath: Path for cache files +# Attributes: +# - Default: ${HOME}/.armarx/mongo/.cache +# - Case sensitivity: no +# - Required: no +# ArmarX.CachePath = ${HOME}/.armarx/mongo/.cache + + +# ArmarX.DataPath: Semicolon-separated search list for data files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.DataPath = "" + + +# ArmarX.Verbosity: Global logging level for whole application +# Attributes: +# - Default: Verbose +# - Case sensitivity: no +# - Required: no +# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning} +# ArmarX.Verbosity = Verbose + + +# ArmarX.DisableLogging: Turn logging off in whole application +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# - Possible values: {0, 1, false, no, true, yes} +# ArmarX.DisableLogging = 0 + + +# ArmarX.ApplicationName: Application name +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.ApplicationName = "" + + +# ArmarX.Config: Comma-separated list of configuration files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.Config = "" + + + diff --git a/scenarios/WeissHapticSensorsUnitTest/startScenario.sh b/scenarios/WeissHapticSensorsUnitTest/startScenario.sh new file mode 100755 index 0000000000000000000000000000000000000000..3cae8d5150708a0164ee9e161c747e726e42118c --- /dev/null +++ b/scenarios/WeissHapticSensorsUnitTest/startScenario.sh @@ -0,0 +1,6 @@ +export SCRIPT_PATH=/localhome/vmmaster/armarx/Core/build/bin +# Components +$SCRIPT_PATH/startApplication.sh /localhome/vmmaster/armarx/RobotAPI/build/bin/WeissHapticSensorsUnitAppRun --Ice.Config=config/WeissHapticSensorsUnitApp.cfg & + +$SCRIPT_PATH/startApplication.sh /localhome/vmmaster/armarx/RobotAPI/build/bin/WeissHapticSensorAppRun --Ice.Config=config/WeissHapticSensorApp.cfg & + diff --git a/scenarios/WeissHapticSensorsUnitTest/stopScenario.sh b/scenarios/WeissHapticSensorsUnitTest/stopScenario.sh new file mode 100755 index 0000000000000000000000000000000000000000..99e852378bc989e2878c4f529f74dbfd45e30b6c --- /dev/null +++ b/scenarios/WeissHapticSensorsUnitTest/stopScenario.sh @@ -0,0 +1,25 @@ +if test -z "$1" +then + KILL_SIGNAL=2 +else + KILL_SIGNAL=$1 +fi + +skill () +{ + EXECUTABLE_STR=`ps aux | grep "$1 \-\-Ice.Default" | grep -v grep | awk '{print $2}'` + if [ ${#EXECUTABLE_STR} == 0 ] + then + echo skipping $1 + else + echo killing $1 + kill -s $2 ${EXECUTABLE_STR} + fi +} + +echo SENDING ${KILL_SIGNAL} TO ALL PROCESSES + +skill WeissHapticSensorsUnitAppRun ${KILL_SIGNAL} + +skill WeissHapticSensorAppRun ${KILL_SIGNAL} + diff --git a/source/RobotAPI/CMakeLists.txt b/source/RobotAPI/CMakeLists.txt index 59796017c05137bcf7667a83e6cd36006671660c..602631618f7001892a3d75cae0bf1cf744fd6373 100644 --- a/source/RobotAPI/CMakeLists.txt +++ b/source/RobotAPI/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(core) add_subdirectory(motioncontrol) add_subdirectory(applications) add_subdirectory(units) -#add_subdirectory(armarx-objects) +add_subdirectory(armarx-objects) add_subdirectory(statecharts) +add_subdirectory(drivers) diff --git a/source/RobotAPI/applications/CMakeLists.txt b/source/RobotAPI/applications/CMakeLists.txt index 828e1afa50b2f9505dfdb83a9f97ad1c5d06503d..c896fc61147005e454e20729d7569437d312acd2 100644 --- a/source/RobotAPI/applications/CMakeLists.txt +++ b/source/RobotAPI/applications/CMakeLists.txt @@ -5,3 +5,6 @@ add_subdirectory(MotionControlTest) add_subdirectory(TCPControlUnit) add_subdirectory(MovePlatform) add_subdirectory(MovePlatformToLandmark) + +add_subdirectory(WeissHapticSensorsUnit) +add_subdirectory(WeissHapticSensor) \ No newline at end of file diff --git a/source/RobotAPI/applications/WeissHapticSensor/CMakeLists.txt b/source/RobotAPI/applications/WeissHapticSensor/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e08a3f6d4ec46d0b3417ef9746b60dda744a1300 --- /dev/null +++ b/source/RobotAPI/applications/WeissHapticSensor/CMakeLists.txt @@ -0,0 +1,15 @@ +armarx_component_set_name("WeissHapticSensorApp") + +find_package(Eigen3 QUIET) +armarx_build_if(Eigen3_FOUND "Eigen3 not available") + +if (Eigen3_FOUND) + include_directories( + ${Eigen3_INCLUDE_DIR}) +endif() + +set(COMPONENT_LIBS ArmarXInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreEigen3Variants WeissHapticSensorListener RobotAPIUnits) + +set(EXE_SOURCE main.cpp WeissHapticSensorApp.h) + +armarx_add_component_executable("${EXE_SOURCE}") diff --git a/source/RobotAPI/applications/WeissHapticSensor/WeissHapticSensorApp.h b/source/RobotAPI/applications/WeissHapticSensor/WeissHapticSensorApp.h new file mode 100644 index 0000000000000000000000000000000000000000..c5812ade6b568e8aed6571b785ea4f4d58e303f5 --- /dev/null +++ b/source/RobotAPI/applications/WeissHapticSensor/WeissHapticSensorApp.h @@ -0,0 +1,56 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * ArmarX 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 + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::application::WeissHapticSensor + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#ifndef _ARMARX_APPLICATION_RobotAPI_WeissHapticSensor_H +#define _ARMARX_APPLICATION_RobotAPI_WeissHapticSensor_H + + +#include <RobotAPI/armarx-objects/WeissHapticSensorListener/WeissHapticSensorListener.h> + +#include <Core/core/application/Application.h> +#include <RobotAPI/units/HapticObserver.h> + +namespace armarx +{ + /** + * @class WeissHapticSensorApp + * @brief A brief description + * + * Detailed Description + */ + class WeissHapticSensorApp : + virtual public armarx::Application + { + /** + * @see armarx::Application::setup() + */ + void setup(const ManagedIceObjectRegistryInterfacePtr& registry, + Ice::PropertiesPtr properties) + { + registry->addObject( Component::create<WeissHapticSensorListener>(properties) ); + registry->addObject( Component::create<HapticObserver>(properties) ); + } + }; +} + +#endif diff --git a/source/RobotAPI/applications/WeissHapticSensor/main.cpp b/source/RobotAPI/applications/WeissHapticSensor/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..edff60ba31440bbdcb1e8908eacfd3ebd57ac4fb --- /dev/null +++ b/source/RobotAPI/applications/WeissHapticSensor/main.cpp @@ -0,0 +1,33 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * ArmarX 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 + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::application::WeissHapticSensor + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#include "WeissHapticSensorApp.h" +#include <Core/core/logging/Logging.h> + +int main(int argc, char* argv[]) +{ + armarx::ApplicationPtr app = armarx::Application::createInstance < armarx::WeissHapticSensorApp > (); + app->setName("WeissHapticSensor"); + + return app->main(argc, argv); +} diff --git a/source/RobotAPI/applications/WeissHapticSensorsUnit/CMakeLists.txt b/source/RobotAPI/applications/WeissHapticSensorsUnit/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d2d552863d973ec5ba41238a790810b5f7ff8f2d --- /dev/null +++ b/source/RobotAPI/applications/WeissHapticSensorsUnit/CMakeLists.txt @@ -0,0 +1,15 @@ +armarx_component_set_name("WeissHapticSensorsUnitApp") + +find_package(Eigen3 QUIET) +armarx_build_if(Eigen3_FOUND "Eigen3 not available") + +if (Eigen3_FOUND) + include_directories( + ${Eigen3_INCLUDE_DIR}) +endif() + +set(COMPONENT_LIBS ArmarXInterfaces ArmarXCore ArmarXCoreEigen3Variants WeissHapticSensor) + +set(EXE_SOURCE main.cpp) + +armarx_add_component_executable("${EXE_SOURCE}") diff --git a/source/RobotAPI/applications/WeissHapticSensorsUnit/WeissHapticSensorsUnitApp.h b/source/RobotAPI/applications/WeissHapticSensorsUnit/WeissHapticSensorsUnitApp.h new file mode 100644 index 0000000000000000000000000000000000000000..fba3b1a793e7963b95932e033863113ba0630ec8 --- /dev/null +++ b/source/RobotAPI/applications/WeissHapticSensorsUnit/WeissHapticSensorsUnitApp.h @@ -0,0 +1,55 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * ArmarX 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 + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::application::WeissHapticSensorsUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#ifndef _ARMARX_APPLICATION_RobotAPI_WeissHapticSensorsUnit_H +#define _ARMARX_APPLICATION_RobotAPI_WeissHapticSensorsUnit_H + + +// #include <RobotAPI/armarx-objects/@MyComponent@.h> + +#include <Core/core/application/Application.h> +#include <RobotAPI/drivers/WeissHapticSensor/WeissHapticSensorsUnit.h> + +namespace armarx +{ + /** + * @class WeissHapticSensorsUnitApp + * @brief A brief description + * + * Detailed Description + */ + class WeissHapticSensorsUnitApp : + virtual public armarx::Application + { + /** + * @see armarx::Application::setup() + */ + void setup(const ManagedIceObjectRegistryInterfacePtr& registry, + Ice::PropertiesPtr properties) + { + registry->addObject( Component::create<WeissHapticSensorsUnit>(properties) ); + } + }; +} + +#endif diff --git a/source/RobotAPI/applications/WeissHapticSensorsUnit/main.cpp b/source/RobotAPI/applications/WeissHapticSensorsUnit/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..383d05876e7eadfd48ab4faeb807d8443f9fba7f --- /dev/null +++ b/source/RobotAPI/applications/WeissHapticSensorsUnit/main.cpp @@ -0,0 +1,33 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * ArmarX 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 + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::application::WeissHapticSensorsUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#include "WeissHapticSensorsUnitApp.h" +#include <Core/core/logging/Logging.h> + +int main(int argc, char* argv[]) +{ + armarx::ApplicationPtr app = armarx::Application::createInstance < armarx::WeissHapticSensorsUnitApp > (); + app->setName("WeissHapticSensorsUnit"); + + return app->main(argc, argv); +} diff --git a/source/RobotAPI/armarx-objects/CMakeLists.txt b/source/RobotAPI/armarx-objects/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..dc89e3a90eb6b211fb0b93856eee897ff374afbb --- /dev/null +++ b/source/RobotAPI/armarx-objects/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_subdirectory(WeissHapticSensorListener) \ No newline at end of file diff --git a/source/RobotAPI/armarx-objects/WeissHapticSensorListener/CMakeLists.txt b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..613112f8e1fae0115c71e6fd745abc90bf2bf20a --- /dev/null +++ b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/CMakeLists.txt @@ -0,0 +1,19 @@ +armarx_component_set_name("WeissHapticSensorListener") + +find_package(Eigen3 QUIET) +armarx_build_if(Eigen3_FOUND "Eigen3 not available") + +if (Eigen3_FOUND) + include_directories( + ${Eigen3_INCLUDE_DIR}) +endif() + +set(COMPONENT_LIBS ArmarXInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreEigen3Variants RobotAPIInterfaces) + +set(SOURCES WeissHapticSensorListener.cpp) +set(HEADERS WeissHapticSensorListener.h) + +armarx_add_component("${SOURCES}" "${HEADERS}") + +# add unit tests +#add_subdirectory(test) diff --git a/source/RobotAPI/armarx-objects/WeissHapticSensorListener/WeissHapticSensorListener.cpp b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/WeissHapticSensorListener.cpp new file mode 100644 index 0000000000000000000000000000000000000000..80bd04d05aa08ddb997ca632f329781b27a60ff1 --- /dev/null +++ b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/WeissHapticSensorListener.cpp @@ -0,0 +1,65 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * ArmarX 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 + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::WeissHapticSensorListener + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#include "WeissHapticSensorListener.h" + + +using namespace armarx; + + +void WeissHapticSensorListener::onInitComponent() +{ + this->usingTopic("HapticValues"); + ARMARX_LOG << "WeissHapticSensorListener::onInitComponent()"; +} + + +void WeissHapticSensorListener::onConnectComponent() +{ + +} + + +void WeissHapticSensorListener::onDisconnectComponent() +{ + +} + + +void WeissHapticSensorListener::onExitComponent() +{ + +} + +PropertyDefinitionsPtr WeissHapticSensorListener::createPropertyDefinitions() +{ + return PropertyDefinitionsPtr(new WeissHapticSensorListenerPropertyDefinitions( + getConfigIdentifier())); +} + +void armarx::WeissHapticSensorListener::reportSensorValues(const std::string& type, const armarx::MatrixFloatBasePtr& values, const Ice::Current&) +{ + ARMARX_LOG << deactivateSpam(1) << "WeissHapticSensorListener::reportSensorValues" << MatrixFloatPtr::dynamicCast(values)->toEigen(); + +} + diff --git a/source/RobotAPI/armarx-objects/WeissHapticSensorListener/WeissHapticSensorListener.h b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/WeissHapticSensorListener.h new file mode 100644 index 0000000000000000000000000000000000000000..2287e9060a7aecbad51b90976a7b0f15b7b931c6 --- /dev/null +++ b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/WeissHapticSensorListener.h @@ -0,0 +1,101 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * ArmarX 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 + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::WeissHapticSensorListener + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#ifndef _ARMARX_COMPONENT_RobotAPI_WeissHapticSensorListener_H +#define _ARMARX_COMPONENT_RobotAPI_WeissHapticSensorListener_H + + +#include <Core/core/Component.h> +#include <RobotAPI/interface/units/HapticUnit.h> +#include <Core/util/variants/eigen3/MatrixVariant.h> +#include <Core/util/variants/eigen3/VariantObjectFactories.h> + +namespace armarx +{ + /** + * @class WeissHapticSensorListenerPropertyDefinitions + * @brief + * @ingroup Components + */ + class WeissHapticSensorListenerPropertyDefinitions: + public ComponentPropertyDefinitions + { + public: + WeissHapticSensorListenerPropertyDefinitions(std::string prefix): + ComponentPropertyDefinitions(prefix) + { + //defineRequiredProperty<std::string>("PropertyName", "Description"); + //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description"); + } + }; + + /** + * @class WeissHapticSensorListener + * @brief A brief description + * + * Detailed Description + */ + class WeissHapticSensorListener : + virtual public armarx::Component, + virtual public armarx::HapticUnitListener + { + public: + /** + * @see armarx::ManagedIceObject::getDefaultName() + */ + virtual std::string getDefaultName() const + { + return "WeissHapticSensorListener"; + } + + virtual void reportSensorValues(const ::std::string& type, const ::armarx::MatrixFloatBasePtr& values, const ::Ice::Current& = ::Ice::Current()); + + protected: + /** + * @see armarx::ManagedIceObject::onInitComponent() + */ + virtual void onInitComponent(); + + /** + * @see armarx::ManagedIceObject::onConnectComponent() + */ + virtual void onConnectComponent(); + + /** + * @see armarx::ManagedIceObject::onDisconnectComponent() + */ + virtual void onDisconnectComponent(); + + /** + * @see armarx::ManagedIceObject::onExitComponent() + */ + virtual void onExitComponent(); + + /** + * @see PropertyUser::createPropertyDefinitions() + */ + virtual PropertyDefinitionsPtr createPropertyDefinitions(); + }; +} + +#endif diff --git a/source/RobotAPI/armarx-objects/WeissHapticSensorListener/test/CMakeLists.txt b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2c89a2d67c402d97784d7a903af9de0c6191150f --- /dev/null +++ b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/test/CMakeLists.txt @@ -0,0 +1,5 @@ + +# Libs required for the tests +SET(LIBS ${LIBS} ArmarXCore WeissHapticSensorListener) + +armarx_add_test(WeissHapticSensorListenerTest WeissHapticSensorListenerTest.cpp "${LIBS}") \ No newline at end of file diff --git a/source/RobotAPI/armarx-objects/WeissHapticSensorListener/test/WeissHapticSensorListenerTest.cpp b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/test/WeissHapticSensorListenerTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..089961daf9fcd32354f8b52cb28ad509c22503cb --- /dev/null +++ b/source/RobotAPI/armarx-objects/WeissHapticSensorListener/test/WeissHapticSensorListenerTest.cpp @@ -0,0 +1,38 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * ArmarX 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 + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::WeissHapticSensorListener + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::WeissHapticSensorListener + +#define ARMARX_BOOST_TEST + +#include <RobotAPI/Test.h> +#include <RobotAPI/armarx-objects/WeissHapticSensorListener/WeissHapticSensorListener.h> + +#include <iostream> + +BOOST_AUTO_TEST_CASE(testExample) +{ + armarx::WeissHapticSensorListener instance; + + BOOST_CHECK_EQUAL(true, true); +} diff --git a/source/RobotAPI/drivers/CMakeLists.txt b/source/RobotAPI/drivers/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..802a6b533e8945574afb9e92d9d86a1d0e41fe19 --- /dev/null +++ b/source/RobotAPI/drivers/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(WeissHapticSensor) diff --git a/source/RobotAPI/drivers/Types.h b/source/RobotAPI/drivers/Types.h new file mode 100644 index 0000000000000000000000000000000000000000..1b3690f88038ea8330950f56c0cdb2adb1f99c64 --- /dev/null +++ b/source/RobotAPI/drivers/Types.h @@ -0,0 +1,49 @@ +#ifndef TYPES_H +#define TYPES_H + +typedef struct +{ + unsigned char id; + unsigned int len; + unsigned char *data; +} msg_t; + + +typedef enum { + E_SUCCESS = 0, // No error + E_NOT_AVAILABLE, // Device, service or data is not available + E_NO_SENSOR, // No sensor connected + E_NOT_INITIALIZED, // The device is not initialized + E_ALREADY_RUNNING, // Service is already running + E_FEATURE_NOT_SUPPORTED, // The asked feature is not supported + E_INCONSISTENT_DATA, // One or more dependent parameters mismatch + E_TIMEOUT, // Timeout error + E_READ_ERROR, // Error while reading from a device + E_WRITE_ERROR, // Error while writing to a device + E_INSUFFICIENT_RESOURCES, // No memory available + E_CHECKSUM_ERROR, // Checksum error + E_NO_PARAM_EXPECTED, // No parameters expected + E_NOT_ENOUGH_PARAMS, // Not enough parameters + E_CMD_UNKNOWN, // Unknown command + E_CMD_FORMAT_ERROR, // Command format error + E_ACCESS_DENIED, // Access denied + E_ALREADY_OPEN, // The interface is already open + E_CMD_FAILED, // Command failed + E_CMD_ABORTED, // Command aborted + E_INVALID_HANDLE, // invalid handle + E_NOT_FOUND, // device not found + E_NOT_OPEN, // device not open + E_IO_ERROR, // I/O error + E_INVALID_PARAMETER, // invalid parameter + E_INDEX_OUT_OF_BOUNDS, // index out of bounds + E_CMD_PENDING, // Command was received correctly, but the execution needs more time. If the command was completely processed, another status message is returned indicating the command's result + E_OVERRUN, // Data overrun + E_RANGE_ERROR, // Range error + E_AXIS_BLOCKED, // Axis is blocked + E_FILE_EXISTS // File already exists +} status_t; + + +//const char* status_to_str( status_t status ); + +#endif // TYPES_H diff --git a/source/RobotAPI/drivers/WeissHapticSensor/AbstractInterface.cpp b/source/RobotAPI/drivers/WeissHapticSensor/AbstractInterface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e1248b9240375b32f7463db1bd64c1f9db5483d2 --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/AbstractInterface.cpp @@ -0,0 +1,244 @@ +#include "AbstractInterface.h" +#include "Response.h" +#include "Checksum.h" +#include "Types.h" +#include "TransmissionException.h" +#include <string.h> +#include <iostream> +#include <stdio.h> +#include <stdexcept> + + +AbstractInterface::AbstractInterface() : + connected(false) { +} + +AbstractInterface::~AbstractInterface() { + // TODO Auto-generated destructor stub +} + + +Response AbstractInterface::submitCmd( unsigned char id, unsigned char *payload, unsigned int len, bool pending ) +{ + /*int res; + + // Check if we're connected + if ( !connected ) + { + throw TransmissionException("Interface not connected"); + } + + // Send command + res = send( id, len, payload ); + if ( res < 0 ) + { + throw TransmissionException("Message send failed"); + }*/ + fireAndForgetCmd(id, payload, len, pending); + return receive(pending, id); +} + +void AbstractInterface::fireAndForgetCmd( unsigned char id, unsigned char *payload, unsigned int len, bool pending ) +{ + + int res; + + // Check if we're connected + if ( !connected ) + { + throw TransmissionException("Interface not connected"); + } + + // Send command + res = send( id, len, payload ); + if ( res < 0 ) + { + throw TransmissionException("Message send failed"); + } +} + +Response AbstractInterface::receiveWithoutChecks() +{ + int res; + status_t status; + msg_t msg; + + // Receive response data + res = receive( &msg ); + if ( res < 0 ) + { + throw TransmissionException("Message receive failed"); + } + + status = (status_t) make_short( msg.data[0], msg.data[1] ); + + return Response(res, msg.id, status, msg.data, msg.len); +} + +Response AbstractInterface::receive(bool pending, unsigned char expectedId) +{ + int res; + status_t status; + msg_t msg; + + // Receive response. Repeat if pending. + do + { + // Receive response data + res = receive( &msg ); + if ( res < 0 ) + { + throw TransmissionException("Message receive failed"); + } + + // Check response ID + if ( msg.id != expectedId ) + { + //std::strstream strStream; + //strStream << "Response ID ()" << msg.id << ") does not match submitted command ID (" << id << ")"; + //throw std::runtime_error(strStream.str()); + throw TransmissionException(str(boost::format("Response ID (%02X) does not match submitted command ID (%02X)") % (int)msg.id % (int)expectedId)); + } + + if ( pending ) + { + if ( msg.len < 2 ) + { + throw TransmissionException("No status code received"); + } + + status = (status_t) make_short( msg.data[0], msg.data[1] ); + } + } + while( pending && status == E_CMD_PENDING ); + + status = (status_t) make_short( msg.data[0], msg.data[1] ); + + return Response(res, msg.id, status, msg.data, msg.len); +} + +int AbstractInterface::receive( msg_t *msg ) +{ + int res; + unsigned char header[3]; // 1 byte command, 2 bytes payload length + unsigned short checksum = 0x50f5; // Checksum over preamble (0xaa 0xaa 0xaa) + unsigned int sync; + + // Syncing - necessary for compatibility with serial interface + sync = 0; + while( sync != MSG_PREAMBLE_LEN ) + { + res = read( header, 1 ); + if ( res > 0 && header[0] == MSG_PREAMBLE_BYTE ) + { + sync++; + } + else + { + sync = 0; + } + } + + // Read header + res = read( header, 3 ); + if ( res < 3 ) + { + throw TransmissionException(str(boost::format("Failed to receive header data (%d bytes read)") % res)); + } + + // Calculate checksum over header + checksum = Checksum::Update_crc16( header, 3, checksum ); + + // Get message id of received + msg->id = header[0]; + + // Get payload size of received message + msg->len = make_short( header[1], header[2] ); + + // Allocate space for payload and checksum + msg->data.resize( msg->len + 2u ); + //if ( !msg->data ) return -1; + + // Read payload and checksum + int maxReads = 10; + int remaining = msg->len + 2; + int dataOffset = 0; + while ( maxReads > 0 && remaining > 0) + { + int read = this->read( msg->data.data() + dataOffset, remaining ); + dataOffset += read; + remaining -= read; + maxReads--; + if (remaining > 0) { + //fprintf( stderr, "Partial message received, waiting 100µs\n" ); + usleep(100); + } + } + if (remaining > 0) + { + throw TransmissionException(str(boost::format("Not enough data (%d, expected %d), Command = %02X") % res % (msg->len + 2) % msg->id)); + } + /* + res = interface->read( msg->data, msg->len + 2 ); + if ( res < (int) (msg->len + 2) ) + { + fprintf( stderr, "Not enough data (%d, expected %d)\n", res, msg->len + 2 ); + fprintf( stderr, "Command = %X\n", msg->id ); + return -1; + }*/ + + // Check checksum + checksum = Checksum::Update_crc16( msg->data.data(), msg->len + 2, checksum ); + if ( checksum != 0 ) + { + throw TransmissionException("Checksum error"); + } + + return msg->len + 8; +} + +int AbstractInterface::send(unsigned char id, unsigned int len, unsigned char *data) +{ + unsigned char header[MSG_PREAMBLE_LEN + 3]; + unsigned short crc; + int i, res; + + // Preamble + for ( i = 0; i < MSG_PREAMBLE_LEN; i++ ) header[i] = MSG_PREAMBLE_BYTE; + + // Command ID + header[MSG_PREAMBLE_LEN] = id; + + // Length + header[MSG_PREAMBLE_LEN + 1] = lo( len ); + header[MSG_PREAMBLE_LEN + 2] = hi( len ); + + // Checksum + crc = Checksum::Crc16( header, 6 ); + crc = Checksum::Update_crc16( data, len, crc ); + + + unsigned char *buf = new unsigned char[ 6 + len + 2 ]; + memcpy( buf, header, 6 ); + memcpy( buf + 6, data, len ); + memcpy( buf + 6 + len, (unsigned char *) &crc, 2 ); + + res = write( buf, 6 + len + 2 ); + if ( res < 6 + (int)len + 2 ) + { + close(); + throw TransmissionException("Failed to submit message checksum"); + //cerr << "Failed to submit message checksum" << endl; + } + + delete[] buf; + + return len + 8; +} + + + + +ostream& operator<<(ostream &strm, const AbstractInterface &a) { + return strm << a.toString(); +} diff --git a/source/RobotAPI/drivers/WeissHapticSensor/AbstractInterface.h b/source/RobotAPI/drivers/WeissHapticSensor/AbstractInterface.h new file mode 100644 index 0000000000000000000000000000000000000000..5c01b9fc52b83107aee10ec9e706379a9c604863 --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/AbstractInterface.h @@ -0,0 +1,57 @@ +#ifndef ABSTRACTINTERFACE_H +#define ABSTRACTINTERFACE_H + +#include <string> +#include "Types.h" + + +#define MSG_PREAMBLE_BYTE 0xaa +#define MSG_PREAMBLE_LEN 3 + +// Combine bytes to different types +#define make_short( lowbyte, highbyte ) ( (unsigned short)lowbyte | ( (unsigned short)highbyte << 8 ) ) +#define make_signed_short( lowbyte, highbyte ) ( (signed short) ( (unsigned short) lowbyte | ( (unsigned short) highbyte << 8 ) ) ) +#define make_int( lowbyte, mid1, mid2, highbyte ) ( (unsigned int) lowbyte | ( (unsigned int) mid1 << 8 ) | ( (unsigned int) mid2 << 16 ) | ( (unsigned int) highbyte << 24 ) ) +#define make_float( result, byteptr ) memcpy( &result, byteptr, sizeof( float ) ) + +// Byte access +#define hi( x ) (unsigned char) ( ((x) >> 8) & 0xff ) // Returns the upper byte of the passed short +#define lo( x ) (unsigned char) ( (x) & 0xff ) // Returns the lower byte of the passed short + + + +struct Response; + +class AbstractInterface +{ +public: + AbstractInterface(); + virtual ~AbstractInterface(); + virtual int open() = 0; + virtual void close() = 0; + virtual int read( unsigned char *buf, unsigned int len) = 0; + virtual int write( unsigned char *buf, unsigned int len) = 0; + + bool IsConnected() const { return connected; } + + virtual std::string toString() const = 0; + + int send(unsigned char id, unsigned int len, unsigned char *data); + int receive( msg_t *msg ); + Response submitCmd( unsigned char id, unsigned char *payload, unsigned int len, bool pending ); + Response receive(bool pending, unsigned char expectedId); + Response receiveWithoutChecks(); + void fireAndForgetCmd( unsigned char id, unsigned char *payload, unsigned int len, bool pending ); + + +protected: + bool connected; + +private: + friend std::ostream& operator<<(std::ostream&, const AbstractInterface&); +}; + +std::ostream& operator<<(std::ostream &strm, const AbstractInterface &a); + + +#endif // ABSTRACTINTERFACE_H diff --git a/source/RobotAPI/drivers/WeissHapticSensor/BinaryLogger.cpp b/source/RobotAPI/drivers/WeissHapticSensor/BinaryLogger.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b3a494138b7b09728b93c8db2e5fdf8250bc98de --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/BinaryLogger.cpp @@ -0,0 +1,34 @@ +#include "BinaryLogger.h" +#include <boost/format.hpp> + +BinaryLogger::BinaryLogger(std::string filename) +{ + this->log.open(filename.c_str()); +} + +BinaryLogger::~BinaryLogger() +{ + log.close(); +} + +void BinaryLogger::logRead(unsigned char *buf, unsigned int len) +{ + log << "READ"; + for(unsigned int i = 0; i < len; i++) + { + log << boost::format(" %02X") % (int)buf[i]; + } + log << std::endl; + log.flush(); +} + +void BinaryLogger::logWrite(unsigned char *buf, unsigned int len) +{ + log << "WRITE"; + for(unsigned int i = 0; i < len; i++) + { + log << boost::format(" %02X") % (int)buf[i]; + } + log << std::endl; + log.flush(); +} diff --git a/source/RobotAPI/drivers/WeissHapticSensor/BinaryLogger.h b/source/RobotAPI/drivers/WeissHapticSensor/BinaryLogger.h new file mode 100644 index 0000000000000000000000000000000000000000..d16c85ca6f26e5245b3adeb834214e440131e1f1 --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/BinaryLogger.h @@ -0,0 +1,19 @@ +#ifndef BINARYLOGGER_H +#define BINARYLOGGER_H + +#include <fstream> + +class BinaryLogger +{ +public: + BinaryLogger(std::string filename); + ~BinaryLogger(); + + void logRead(unsigned char *buf, unsigned int len); + void logWrite(unsigned char *buf, unsigned int len); + +private: + std::ofstream log; +}; + +#endif // BINARYLOGGER_H diff --git a/source/RobotAPI/drivers/WeissHapticSensor/CMakeLists.txt b/source/RobotAPI/drivers/WeissHapticSensor/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..01d560fb88deeaf26fe40072368db32e01715b9d --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/CMakeLists.txt @@ -0,0 +1,41 @@ +armarx_set_target("WeissHapticSensor Library: WeissHapticSensor") + + +find_package(Eigen3 QUIET) + +armarx_build_if(Eigen3_FOUND "Eigen3 not available") + +if (Eigen3_FOUND) + include_directories( + ${Eigen3_INCLUDE_DIR}) +endif() + +set(LIB_NAME WeissHapticSensor) +set(LIB_VERSION 0.1.0) +set(LIB_SOVERSION 0) + +set(LIBS RobotAPIUnits RobotAPIInterfaces ArmarXInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreEigen3Variants) + +set(LIB_FILES + WeissHapticSensorsUnit.cpp + WeissHapticSensor.cpp + AbstractInterface.cpp + BinaryLogger.cpp + Checksum.cpp + SerialInterface.cpp + TactileSensor.cpp +) +set(LIB_HEADERS + WeissHapticSensorsUnit.h + WeissHapticSensor.h + AbstractInterface.h + BinaryLogger.h + Checksum.h + Response.h + SerialInterface.h + TactileSensor.h + TransmissionException.h + Types.h +) + +armarx_add_library("${LIB_NAME}" "${LIB_VERSION}" "${LIB_SOVERSION}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") diff --git a/source/RobotAPI/drivers/WeissHapticSensor/Checksum.cpp b/source/RobotAPI/drivers/WeissHapticSensor/Checksum.cpp new file mode 100644 index 0000000000000000000000000000000000000000..15b3cecfff3a5073d476ce5c544f6ad617696859 --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/Checksum.cpp @@ -0,0 +1,94 @@ + +#include "Checksum.h" + +/* + * CRC16 lookup table + * + * CCITT-16 compatible crc table using polynomial 0x1021, + * corresponding to x^16 + x^12 + x^5 + 1 + */ + +const unsigned short Checksum::CRC_TABLE_CCITT16[256] = { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +/** + * Calculates the CRC16 checksum of an array by using a table. + * The crc16 polynomial is 0x1021 ( x^16 + x^12 + x^5 + 1 ). + * + * Note: The checksum generated by this function is NOT according + * to CCITT standard! + * + * @param *data Points to the byte array from which checksum should + * be calculated + * @param size Size of the byte array + * @param crc Value calculated over another array and start value + * of the crc16 calculation + * + * @return CRC16 checksum + */ + +unsigned short Checksum::Update_crc16( unsigned char *data, unsigned int size, unsigned short crc ) +{ + unsigned long c; + + /* process each byte prior to checksum field */ + for ( c=0; c < size; c++ ) + { + crc = CRC_TABLE_CCITT16[ ( crc ^ *( data ++ )) & 0x00FF ] ^ ( crc >> 8 ); + } + return crc; +} + + +/** + * Calculates the CRC16 checksum of an array by using a table. + * The crc16 polynomial is 0x1021 ( x^16 + x^12 + x^5 + 1 ). + * This function takes 0xffff as initial value. + * + * Note: The checksum generated by this function is NOT according + * to CCITT standard! + * + * @param *data Points to the byte array from which checksum should + * be calculated + * @param size Size of the byte array + * + * @return CRC16 checksum + */ + +unsigned short Checksum::Crc16( unsigned char *data, unsigned int size ) +{ + return( Update_crc16( data, size, 0xffff ) ); +} + diff --git a/source/RobotAPI/drivers/WeissHapticSensor/Checksum.h b/source/RobotAPI/drivers/WeissHapticSensor/Checksum.h new file mode 100644 index 0000000000000000000000000000000000000000..7603e1b69f4a71856b801a716c2454e18024ffca --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/Checksum.h @@ -0,0 +1,14 @@ +#ifndef CHECKSUM_H +#define CHECKSUM_H + +class Checksum +{ +public: + static unsigned short Crc16( unsigned char *data, unsigned int size ); + static unsigned short Update_crc16( unsigned char *data, unsigned int size, unsigned short crc ); + +private: + static const unsigned short CRC_TABLE_CCITT16[256]; +}; + +#endif // CHECKSUM_H diff --git a/source/RobotAPI/drivers/WeissHapticSensor/Response.h b/source/RobotAPI/drivers/WeissHapticSensor/Response.h new file mode 100644 index 0000000000000000000000000000000000000000..452f8f835d97fec39ea9e69f4e2d31e74c6796bd --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/Response.h @@ -0,0 +1,102 @@ +#ifndef RESPONSE_H +#define RESPONSE_H + +#include "Types.h" +#include "TransmissionException.h" +//#include <strstream> +#include <stdexcept> +#include <boost/format.hpp> +#include <vector> + +struct Response { +public: + Response(int res, unsigned char cmdId, status_t status, const std::vector<unsigned char> &data, unsigned int len) + : res(res), cmdId(cmdId), status(status), data(data), len(len) {} + + unsigned int getUInt(int index) + { + return (unsigned int)data[index] | ( (unsigned int)data[index + 1] << 8) | ( (unsigned int)data[index + 2] << 16) | ( (unsigned int)data[index + 3] << 24); + } + + unsigned short getShort(int index) + { + return (unsigned short)data[index] | ( (unsigned short)data[index + 1] << 8); + } + unsigned char getByte(int index) + { + return data[index]; + } + + void ensureMinLength(int len) + { + if ( res < len ) { + //std::strstream strStream; + //strStream << "Response length is too short, should be = " << len << " (is " << res << ")"; + //throw std::runtime_error(strStream.str()); + throw TransmissionException(str(boost::format("Response length is too short, should be = %1% (is %2%)") % len % res)); + } + } + + void ensureSuccess() + { + if ( status != E_SUCCESS ) + { + //std::strstream strStream; + //strStream << "Command not successful: " << status_to_str( status ); + //throw std::runtime_error(strStream.str()); + cerr << " status != E_SUCCESS" << endl; + for(int i=0; i<(int)len; i++){ + cerr << boost::format("%02X ") % (int)data[i]; + } + cerr << endl; + throw TransmissionException(str(boost::format("Command not successful: %1% (0x%2$02X)") % status_to_str( status ) % status)); + } + } + + int res; + unsigned char cmdId; + status_t status; + std::vector<unsigned char> data; + unsigned int len; + + static const char* status_to_str( status_t status ) + { + switch( status ) + { + case E_SUCCESS: return( "No error" ); + case E_NOT_AVAILABLE: return( "Service or data is not available" ); + case E_NO_SENSOR: return( "No sensor connected" ); + case E_NOT_INITIALIZED: return( "The device is not initialized" ); + case E_ALREADY_RUNNING: return( "Service is already running" ); + case E_FEATURE_NOT_SUPPORTED: return( "The requested feature is not supported" ); + case E_INCONSISTENT_DATA: return( "One or more dependent parameters mismatch" ); + case E_TIMEOUT: return( "Timeout error" ); + case E_READ_ERROR: return( "Error while reading from a device" ); + case E_WRITE_ERROR: return( "Error while writing to a device" ); + case E_INSUFFICIENT_RESOURCES: return( "No memory available" ); + case E_CHECKSUM_ERROR: return( "Checksum error" ); + case E_NO_PARAM_EXPECTED: return( "No parameters expected" ); + case E_NOT_ENOUGH_PARAMS: return( "Not enough parameters" ); + case E_CMD_UNKNOWN: return( "Unknown command" ); + case E_CMD_FORMAT_ERROR: return( "Command format error" ); + case E_ACCESS_DENIED: return( "Access denied" ); + case E_ALREADY_OPEN: return( "Interface already open" ); + case E_CMD_FAILED: return( "Command failed" ); + case E_CMD_ABORTED: return( "Command aborted" ); + case E_INVALID_HANDLE: return( "Invalid handle" ); + case E_NOT_FOUND: return( "Device not found" ); + case E_NOT_OPEN: return( "Device not open" ); + case E_IO_ERROR: return( "General I/O-Error" ); + case E_INVALID_PARAMETER: return( "Invalid parameter" ); + case E_INDEX_OUT_OF_BOUNDS: return( "Index out of bounds" ); + case E_CMD_PENDING: return( "Command is pending..." ); + case E_OVERRUN: return( "Data overrun" ); + case E_RANGE_ERROR: return( "Value out of range" ); + case E_AXIS_BLOCKED: return( "Axis is blocked" ); + case E_FILE_EXISTS: return( "File already exists" ); + default: return( "Internal error. Unknown error code." ); + } + } +}; + +#endif // RESPONSE_H diff --git a/source/RobotAPI/drivers/WeissHapticSensor/SerialInterface.cpp b/source/RobotAPI/drivers/WeissHapticSensor/SerialInterface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9bdfe5f0a93e98fa114a81e129f45e39e6bc4a1 --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/SerialInterface.cpp @@ -0,0 +1,162 @@ +#include "SerialInterface.h" + +#include <iostream> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> +#include <termios.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <iostream> +#include <boost/lexical_cast.hpp> +#include <boost/format.hpp> + +static inline tcflag_t __bitrate_to_flag( unsigned int bitrate ) +{ + switch( bitrate ) + { + case 1200: return B1200; + case 2400: return B2400; + case 4800: return B4800; + case 9600: return B9600; + case 19200: return B19200; + case 38400: return B38400; + case 57600: return B57600; + case 115200: return B115200; + case 230400: return B230400; + case 460800: return B460800; + default: return 0; + } +} + + +SerialInterface::SerialInterface(const char *device, unsigned int bitrate) + : log(NULL) +{ + this->device = device; + this->bitrate = bitrate; +} + +SerialInterface::~SerialInterface() { + if(log != NULL) + { + delete log; + } +} + +int SerialInterface::open() { + // Convert bitrate to flag + tcflag_t bitrate = __bitrate_to_flag(this->bitrate); + if ( bitrate == 0 ) + { + fprintf( stderr, "Invalid bitrate '%d' for serial device\n", this->bitrate ); + return -1; + } + + + // Open serial device + fd = ::open( device, O_RDWR | O_NOCTTY ); + if ( fd < 0 ) + { + fprintf( stderr, "Failed to open serial device '%s' (errno: %s)\n", device, strerror(errno) ); + return -1; + } + if (::ioctl(fd, TIOCEXCL)) + { + fprintf( stderr, "Failed to lock serial device '%s' (errno: %s)\n", device, strerror(errno) ); + return -1; + } + + + + // Check if device is a terminal device + if ( !isatty( fd ) ) + { + fprintf( stderr, "Device '%s' is not a terminal device (errno: %s)!\n", device, strerror(errno) ); + ::close( fd ); + return -1; + } + + struct termios settings; + // Set input flags + settings.c_iflag = IGNBRK // Ignore BREAKS on Input + | IGNPAR; // No Parity + // ICRNL: map CR to NL (otherwise a CR input on the other computer will not terminate input) + + // Set output flags + settings.c_oflag = 0; // Raw output + + // Set controlflags + settings.c_cflag = bitrate + | CS8 // 8 bits per byte + | CSTOPB // Stop bit + | CREAD // characters may be read + | CLOCAL; // ignore modem state, local connection + + // Set local flags + settings.c_lflag = 0; // Other option: ICANON = enable canonical input + + // Set maximum wait time on input - cf. Linux Serial Programming HowTo, non-canonical mode + // http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html + settings.c_cc[VTIME] = 10; // 0 means timer is not uses + + // Set minimum bytes to read + settings.c_cc[VMIN] = 0; // 1 means wait until at least 1 character is received + + // Now clean the modem line and activate the settings for the port + tcflush( fd, TCIFLUSH ); + tcsetattr( fd, TCSANOW, &settings ); + + connected = true; + + return 0; +} + +void SerialInterface::close() +{ + if(connected) ::close(fd); + connected = false; +} + +int SerialInterface::read( unsigned char *buf, unsigned int len) +{ + int res; + + res = ::read( fd, buf, len ); + if ( res < 0 ) + { + std::cerr << "Failed to read from serial device" << std::endl; + } + + if(log != NULL) + { + log->logRead(buf, res); + } + + return res; + +} +int SerialInterface::write( unsigned char *buf, unsigned int len) +{ + if(log != NULL) + { + log->logWrite(buf, len); + } + + return( ::write( fd, (void *) buf, len ) ); +} + +std::string SerialInterface::toString() const +{ + return str(boost::format("SerialInterface(connected=%1%, device=%2%, bitrate=%3%, fd=%4%)") + % connected % device % bitrate % fd); +} + +void SerialInterface::startLogging(std::string file) +{ + log = new BinaryLogger(file); +} diff --git a/source/RobotAPI/drivers/WeissHapticSensor/SerialInterface.h b/source/RobotAPI/drivers/WeissHapticSensor/SerialInterface.h new file mode 100644 index 0000000000000000000000000000000000000000..e5c9b396b4774c8b4fac8532c9ec0cfeeb6017fd --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/SerialInterface.h @@ -0,0 +1,30 @@ +#ifndef SERIALINTERFACE_H +#define SERIALINTERFACE_H + +#include "AbstractInterface.h" +#include <iostream> +#include "BinaryLogger.h" + + +class SerialInterface : public AbstractInterface { +public: + SerialInterface(const char *device, const unsigned int bitrate); + virtual ~SerialInterface(); + + virtual int open(); + virtual void close(); + virtual int read( unsigned char *, unsigned int ); + virtual int write( unsigned char *, unsigned int ); + + virtual std::string toString() const; + + void startLogging(std::string file); + +private: + const char *device; + unsigned int bitrate; + int fd; + BinaryLogger* log; +}; + +#endif // SERIALINTERFACE_H diff --git a/source/RobotAPI/drivers/WeissHapticSensor/TactileSensor.cpp b/source/RobotAPI/drivers/WeissHapticSensor/TactileSensor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ce5aaf158090938d5446e5a9d22d24636bd05ed --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/TactileSensor.cpp @@ -0,0 +1,277 @@ +#include "TactileSensor.h" +#include "AbstractInterface.h" +#include "Response.h" +#include "Types.h" +#include <string> +#include <stdio.h> + +TactileSensor::TactileSensor(boost::shared_ptr<AbstractInterface> interface) +{ + this->interface = interface; +} + +TactileSensor::~TactileSensor() { + // TODO Auto-generated destructor stub +} + +tac_matrix_info_t TactileSensor::getMatrixInformation( ) +{ + unsigned char payload[0]; + + Response response = interface->submitCmd( 0x30, payload, sizeof(payload), false ); + response.ensureMinLength(12); + response.ensureSuccess(); + + tac_matrix_info_t matrix_info; + + matrix_info.res_x = response.getShort(2); + matrix_info.res_y = response.getShort(4); + matrix_info.cell_width = response.getShort(6); + matrix_info.cell_height = response.getShort(8); + matrix_info.fullscale = response.getShort(10); + + //delete response; + return matrix_info; +} + +void TactileSensor::printMatrixInfo( tac_matrix_info_t *mi ) +{ + printf("res_x = %d, res_y = %d, cell_width = %d, cell_height = %d, fullscale = %X\n", + mi->res_x, mi->res_y, mi->cell_width, mi->cell_height, mi->fullscale); +} + +void TactileSensor::printMatrix ( short *matrix, int width, int height ) +{ + int x, y; + for (y = 0; y < height; y++) + { + printf("%03X", matrix[y * width]); + for (x = 1; x < width; x++) + { + printf(", %03X", matrix[y * width + x]); + } + printf("\n"); + } +} + +FrameData TactileSensor::readSingleFrame() +{ + unsigned char payload[1]; + payload[0] = 0x00; // FLAGS = 0 + Response response = interface->submitCmd( 0x20, payload, sizeof(payload), false ); + return getFrameData(&response); +} +PeriodicFrameData TactileSensor::receicePeriodicFrame() +{ + Response response = interface->receiveWithoutChecks(); + if(response.cmdId == 0x21) + { + response = interface->receiveWithoutChecks(); + } + if(response.cmdId == 0x00) + { + return getPeriodicFrameData(&response); + } + else + { + throw TransmissionException(str(boost::format("Response ID (%02X) does not match submitted command ID (%02X)") % (int)response.cmdId % (int)0x00)); + } +} + +PeriodicFrameData TactileSensor::getPeriodicFrameData(Response *response) +{ + response->ensureMinLength(7); + + unsigned int timestamp = response->getUInt( 0 ); + int offset = 5; + + int count = (response->len - offset) / 2; + int i; + short* data = new short[ count ]; + for(i = 0; i < count; i++) + { + short value = response->getShort(i*2 + offset); + data[i] = value; + } + return PeriodicFrameData(data, count, timestamp); +} + +FrameData TactileSensor::getFrameData(Response *response) +{ + response->ensureMinLength(7); + response->ensureSuccess(); + + int offset = 5 + 2; + + int count = (response->len - offset) / 2; + int i; + short* data = new short[ sizeof(short) * count ]; + for(i = 0; i < count; i++) + { + short value = response->getShort(i*2 + offset); + data[i] = value; + } + return FrameData(data, count); +} + +void TactileSensor::startPeriodicFrameAcquisition( unsigned short delay_ms ) +{ + unsigned char payload[3]; + payload[0] = 0x00; // FLAGS = 0 + payload[1] = delay_ms & 0xFF; + payload[2] = (delay_ms >> 8) & 0xFF; + interface->fireAndForgetCmd( 0x21, payload, sizeof(payload), false ); +} +void TactileSensor::stopPeriodicFrameAcquisition( void ) +{ + while(1) + { + unsigned char payload[0]; + interface->fireAndForgetCmd( 0x22, payload, sizeof(payload), false ); + int waitCount = 10; + while (waitCount > 0) + { + Response response = interface->receiveWithoutChecks(); + if(response.cmdId == 0x22) { + return; + } + else + { + cout << boost::format("stopPeriodicFrameAcquisition :: Discarding Response with ID 0x%02X") % (int)response.cmdId << endl; + } + waitCount--; + } + } +} +void TactileSensor::tareSensorMatrix( unsigned char operation ) +{ + unsigned char payload[1]; + payload[0] = operation; // OPERATION: 0 = un-tare the sensor matrix using the currently set threshold value, 1 = tare the sensor matrix + Response response = interface->submitCmd( 0x23, payload, sizeof(payload), false ); + response.ensureMinLength(2); + response.ensureSuccess(); +} +void TactileSensor::setAquisitionWindow( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2 ) +{ + unsigned char payload[4]; + payload[0] = x1; + payload[1] = y1; + payload[2] = x2; + payload[3] = y2; + Response response = interface->submitCmd( 0x31, payload, sizeof(payload), false ); + response.ensureMinLength(2); + response.ensureSuccess(); +} +int TactileSensor::setAdvanvedAcquisitionMask( char *mask ) { return 0; } +int TactileSensor::getAcquisitionMask( char **mask, int *mask_len ) { return 0; } +void TactileSensor::setThreshold( short threshold ) +{ + unsigned char payload[2]; + payload[0] = threshold & 0xFF; + payload[1] = (threshold >> 8) & 0xFF; + Response response = interface->submitCmd( 0x34, payload, sizeof(payload), false ); + response.ensureMinLength(2); + response.ensureSuccess(); +} +unsigned short TactileSensor::getThreshold() +{ + unsigned char payload[0]; + Response response = interface->submitCmd( 0x35, payload, sizeof(payload), false ); + response.ensureMinLength(2); + response.ensureSuccess(); + return response.getShort(2); +} +void TactileSensor::setFrontEndGain( unsigned char gain ) +{ + /* + * Adjust the pressure sensitivity of a matrix by setting the gain of the Analog Front-End. The gain can + * be set using an integer value in the range of 0 to 255, where 0 is the most insensitive (lowest gain) + * and 255 is the most sensitive (highest gain) setting. + */ + unsigned char payload[1]; + payload[0] = gain; + Response response = interface->submitCmd( 0x36, payload, sizeof(payload), false ); + response.ensureMinLength(2); + response.ensureSuccess(); +} +unsigned char TactileSensor::getFrontEndGain() +{ + /* + * Get the currently set analog front-end gain value. The gain is as an integer value ranging from 0 to + * 255, where 0 is the most insensitive (lowest gain) and 255 is the most sensitive (highest gain) setting. + */ + unsigned char payload[0]; + Response response = interface->submitCmd( 0x37, payload, sizeof(payload), false ); + response.ensureMinLength(3); + response.ensureSuccess(); + unsigned char gain = response.getByte(2); + return gain; +} +std::string TactileSensor::getSensorType() +{ + /* + * Return a string containing the sensor type. + */ + unsigned char payload[0]; + Response response = interface->submitCmd( 0x38, payload, sizeof(payload), false ); + response.ensureMinLength(2); + response.ensureSuccess(); + std::string type = std::string((char*)response.data.data() + 2, response.len - 2); + return type; +} +float TactileSensor::readDeviceTemperature() +{ + unsigned char payload[0]; + Response response = interface->submitCmd( 0x46, payload, sizeof(payload), false ); + response.ensureMinLength(2); + short value = (short)response.getShort(2); + return value * 0.1f; +} +tac_system_information_t TactileSensor::getSystemInformation() +{ + unsigned char payload[0]; + Response response = interface->submitCmd( 0x50, payload, sizeof(payload), false ); + response.ensureMinLength(9); + response.ensureSuccess(); + tac_system_information_t si; + si.type = response.getByte(2); + si.hw_rev = response.getByte(3); + si.fw_version = response.getShort(4); + si.sn = response.getShort(6); + return si; +} +void TactileSensor::printSystemInformation(tac_system_information_t si) +{ + int v1 = (si.fw_version & 0xF000) >> 12; + int v2 = (si.fw_version & 0x0F00) >> 8; + int v3 = (si.fw_version & 0x00F0) >> 4; + int v4 = (si.fw_version & 0x000F) >> 0; + cout << boost::format("System Type=%1%, Hardware Revision=%2%, Firmware Version=%3%.%4%.%5%.%6% (0x%7$04X), Serial Number=%8%") + % (int)si.type % (int)si.hw_rev % v1 % v2 % v3 % v4 % si.fw_version % si.sn << endl; +} +void TactileSensor::setDeviceTag(string tag) +{ + unsigned char *payload = (unsigned char*)tag.c_str(); + Response response = interface->submitCmd( 0x51, payload, tag.length(), false ); + response.ensureMinLength(2); + response.ensureSuccess(); +} +string TactileSensor::getDeviceTag() +{ + unsigned char payload[0]; + Response response = interface->submitCmd( 0x52, payload, sizeof(payload), false ); + response.ensureMinLength(2); + response.ensureSuccess(); + std::string type = std::string((char*)response.data.data() + 2, response.len - 2); + return type; +} +int TactileSensor::loop( char *data, int data_len ) { return 0; } + +string TactileSensor::getInterfaceInfo() +{ + return interface->toString(); +} + +ostream& operator<<(ostream &strm, const TactileSensor &a) { + return strm << a.interface; +} diff --git a/source/RobotAPI/drivers/WeissHapticSensor/TactileSensor.h b/source/RobotAPI/drivers/WeissHapticSensor/TactileSensor.h new file mode 100644 index 0000000000000000000000000000000000000000..c47414449891bd1c2aa2d423e3d643dd4e964362 --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/TactileSensor.h @@ -0,0 +1,103 @@ +#ifndef TACTILESENSOR_H +#define TACTILESENSOR_H + +#include "AbstractInterface.h" +using namespace std; +#include <boost/shared_ptr.hpp> + +#define extract_short( array, index ) ( (unsigned short)array[index] | ( (unsigned short)array[index + 1] << 8 ) ) +#define TAC_CHECK_RES( res, expected, resp ) { \ + if ( res < expected ) { \ + dbgPrint( "Response length is too short, should be = %d (is %d)\n", expected, res ); \ + if ( res > 0 ) free( resp ); \ + return -1; \ + } \ + status_t status = cmd_get_response_status( resp ); \ + if ( status != E_SUCCESS ) \ + { \ + dbgPrint( "Command not successful: %s\n", status_to_str( status ) ); \ + free( resp ); \ + return -1; \ + } \ + } + +typedef struct +{ + int res_x; // Horizontal matrix resolution. For non-rectangular matrices, this is the horizontal resolution of the surrounding rectangle measured in sensor cells. + int res_y; // Vertical matrix resolution. For non-rectangular matrices, this is the vertical resolution of the surrounding rectangle measured in sensor cells. + int cell_width; // Width of one sensor cell in 1/100 millimeters. + int cell_height; // Height of one sensor cell in 1/100 millimeters. + int fullscale; // Full scale value of the output signal. +} tac_matrix_info_t; + +typedef struct +{ + unsigned char type; // System Type: 0 - unknown, 4 - WTS Tactile Sensor Module + unsigned char hw_rev; // Hardware Revision + unsigned short fw_version; // Firmware Version: D15...12: major version, D11...8: minor version 1, D7..4 minor version 2, D3..0: 0 for release version, 1..15 for release candidate versions + unsigned short sn; // Serial Number of the device +} tac_system_information_t; + +struct FrameData +{ +public: + FrameData(short *data, int count) + : data(data), count(count) + {} + short *data; + int count; +}; +struct PeriodicFrameData +{ +public: + PeriodicFrameData(short *data, int count, unsigned int timestamp) + : data(data), count(count), timestamp(timestamp) + {} + short *data; + int count; + unsigned int timestamp; +}; + +class TactileSensor { +public: + TactileSensor(boost::shared_ptr<AbstractInterface> interface); + virtual ~TactileSensor(); + + tac_matrix_info_t getMatrixInformation( ); + static void printMatrixInfo( tac_matrix_info_t *mi ); + FrameData readSingleFrame(); + static void printMatrix ( short *matrix, int width, int height ); + + void startPeriodicFrameAcquisition( unsigned short delay_ms ); + void stopPeriodicFrameAcquisition( void ); + PeriodicFrameData receicePeriodicFrame(); + void tareSensorMatrix( unsigned char operation ); + void setAquisitionWindow( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2 ); + int setAdvanvedAcquisitionMask( char *mask ); + int getAcquisitionMask( char **mask, int *mask_len ); + void setThreshold( short threshold ); + unsigned short getThreshold(); + void setFrontEndGain( unsigned char gain ); + unsigned char getFrontEndGain(); + string getSensorType(); + float readDeviceTemperature(); + tac_system_information_t getSystemInformation(); + static void printSystemInformation(tac_system_information_t si); + void setDeviceTag(string tag); + string getDeviceTag(); + int loop( char *data, int data_len ); + + string getInterfaceInfo(); + +private: + boost::shared_ptr<AbstractInterface> interface; + FrameData getFrameData(Response *response); + PeriodicFrameData getPeriodicFrameData(Response *response); + +private: + friend std::ostream& operator<<(std::ostream&, const TactileSensor&); +}; + +std::ostream& operator<<(std::ostream &strm, const TactileSensor &a); + +#endif // TACTILESENSOR_H diff --git a/source/RobotAPI/drivers/WeissHapticSensor/TransmissionException.h b/source/RobotAPI/drivers/WeissHapticSensor/TransmissionException.h new file mode 100644 index 0000000000000000000000000000000000000000..2b19c579b2f6c0a0d82742151a4f7514ead30cad --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/TransmissionException.h @@ -0,0 +1,15 @@ +#ifndef TRANSMISSIONEXCEPTION_H +#define TRANSMISSIONEXCEPTION_H + +#include <stdexcept> + +using namespace std; + +class TransmissionException : public runtime_error { +public: + TransmissionException(string message) + : runtime_error(message) + { } +}; + +#endif // TRANSMISSIONEXCEPTION_H diff --git a/source/RobotAPI/drivers/WeissHapticSensor/Types.h b/source/RobotAPI/drivers/WeissHapticSensor/Types.h new file mode 100644 index 0000000000000000000000000000000000000000..1fec7ca5f2535af8cea1197b7e87ca326d7d317e --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/Types.h @@ -0,0 +1,51 @@ +#ifndef TYPES_H +#define TYPES_H + +#include <vector> + +typedef struct +{ + unsigned char id; + unsigned int len; + std::vector<unsigned char> data; +} msg_t; + + +typedef enum { + E_SUCCESS = 0, // No error + E_NOT_AVAILABLE, // Device, service or data is not available + E_NO_SENSOR, // No sensor connected + E_NOT_INITIALIZED, // The device is not initialized + E_ALREADY_RUNNING, // Service is already running + E_FEATURE_NOT_SUPPORTED, // The asked feature is not supported + E_INCONSISTENT_DATA, // One or more dependent parameters mismatch + E_TIMEOUT, // Timeout error + E_READ_ERROR, // Error while reading from a device + E_WRITE_ERROR, // Error while writing to a device + E_INSUFFICIENT_RESOURCES, // No memory available + E_CHECKSUM_ERROR, // Checksum error + E_NO_PARAM_EXPECTED, // No parameters expected + E_NOT_ENOUGH_PARAMS, // Not enough parameters + E_CMD_UNKNOWN, // Unknown command + E_CMD_FORMAT_ERROR, // Command format error + E_ACCESS_DENIED, // Access denied + E_ALREADY_OPEN, // The interface is already open + E_CMD_FAILED, // Command failed + E_CMD_ABORTED, // Command aborted + E_INVALID_HANDLE, // invalid handle + E_NOT_FOUND, // device not found + E_NOT_OPEN, // device not open + E_IO_ERROR, // I/O error + E_INVALID_PARAMETER, // invalid parameter + E_INDEX_OUT_OF_BOUNDS, // index out of bounds + E_CMD_PENDING, // Command was received correctly, but the execution needs more time. If the command was completely processed, another status message is returned indicating the command's result + E_OVERRUN, // Data overrun + E_RANGE_ERROR, // Range error + E_AXIS_BLOCKED, // Axis is blocked + E_FILE_EXISTS // File already exists +} status_t; + + +const char* status_to_str( status_t status ); + +#endif // TYPES_H diff --git a/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensor.cpp b/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e366018681ebe62e2ebce4c61e64f6f7eb49217a --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensor.cpp @@ -0,0 +1,93 @@ +#include "WeissHapticSensor.h" +#include <Core/util/variants/eigen3/MatrixVariant.h> + + +using namespace armarx; + +WeissHapticSensor::WeissHapticSensor(std::string device) + : device(device) +{ + sensorTask = new RunningTask<WeissHapticSensor>(this, &WeissHapticSensor::readAndReportSensorValues); +} + +void WeissHapticSensor::connect() +{ + //cout << "Open Serial" << endl; + this->interface.reset(new SerialInterface(device.c_str(), 115200)); + //interface->startLogging(this->deviceFileName + ".transmission.log"); + interface->open(); + //cout << *interface << endl; + this->sensor.reset(new TactileSensor(interface)); + + //cout << "Stop Periodic Frame Acquisition" << endl; + sensor->stopPeriodicFrameAcquisition(); + + //string sensorType = sensor->getSensorType(); + //cout << boost::format("Sensor Type = %1%") % sensorType << endl; + + //tac_system_information_t si = sensor->getSystemInformation(); + //TactileSensor::printSystemInformation(si); + + //sensor->setDeviceTag("Test Tag"); + this->tag = sensor->getDeviceTag(); + //cout << boost::format("Sensor Tag = %1%") % tag << endl; + + //cout << "Tare Sensor Matrix" << endl; + //sensor->tareSensorMatrix(1); + + //cout << "Get Matrix Information" << endl; + this->mi = sensor->getMatrixInformation(); + TactileSensor::printMatrixInfo(&mi); + + sensor->setAquisitionWindow(1, 1, mi.res_x, mi.res_y); + + connected = true; + cout << this << ": Connect done, Interface=" << sensor->getInterfaceInfo() << endl; +} + +void WeissHapticSensor::disconnect() +{ + connected = false; + sensorTask->stop(true); +} + +void WeissHapticSensor::setListenerPrx(HapticUnitListenerPrx listenerPrx) +{ + this->listenerPrx = listenerPrx; +} + +void WeissHapticSensor::startSampling() +{ + cout << this << ": startSampling" << endl; + sensorTask->start(); +} + +void WeissHapticSensor::readAndReportSensorValues() +{ + cout << this << ": readAndReportSensorValues" << endl; + //bool periodic = false; + cout << sensor->getInterfaceInfo() << endl; + + cout << this << ": startPeriodicFrameAcquisition" << endl; + sensor->startPeriodicFrameAcquisition(0); + + while(!sensorTask->isStopped()) + { + ARMARX_INFO << deactivateSpam(1) << this << ": receicePeriodicFrame"; + PeriodicFrameData data = sensor->receicePeriodicFrame(); + + MatrixFloatPtr matrix = new MatrixFloat(mi.res_y, mi.res_x); + for (int y = 0; y < mi.res_y; y++) + { + for (int x = 0; x < mi.res_x; x++) + { + short val = data.data[y * mi.res_x + x]; + (*matrix)(y, x) = val; + } + } + listenerPrx->reportSensorValues(tag, matrix); + } + + cout << this << ": stopPeriodicFrameAcquisition" << endl; + sensor->stopPeriodicFrameAcquisition(); +} diff --git a/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensor.h b/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensor.h new file mode 100644 index 0000000000000000000000000000000000000000..06838dffedc84e02703b2c9a34b00357ea97f4cd --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensor.h @@ -0,0 +1,37 @@ +#ifndef WEISSHAPTICSENSOR_H +#define WEISSHAPTICSENSOR_H + +#include <Core/core/services/tasks/RunningTask.h> +#include <Core/core/system/ImportExportComponent.h> +#include "SerialInterface.h" +#include "TactileSensor.h" +#include <RobotAPI/interface/units/HapticUnit.h> +#include <Core/util/variants/eigen3/VariantObjectFactories.h> + +namespace armarx +{ + class WeissHapticSensor : public Logging + { + public: + WeissHapticSensor(std::string device); + + void connect(); + void disconnect(); + + void setListenerPrx(HapticUnitListenerPrx listenerPrx); + void startSampling(); + + private: + RunningTask<WeissHapticSensor>::pointer_type sensorTask; + void readAndReportSensorValues(); + std::string device; + boost::shared_ptr<SerialInterface> interface; + boost::shared_ptr<TactileSensor> sensor; + bool connected; + string tag; + tac_matrix_info_t mi; + HapticUnitListenerPrx listenerPrx; + }; +} + +#endif diff --git a/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensorsUnit.cpp b/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensorsUnit.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a2f4a69f37a23eb1fff055d8e7007cdd1fac5dc0 --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensorsUnit.cpp @@ -0,0 +1,157 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * ArmarX 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 + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package ArmarXCore::units + * @author Peter Kaiser + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#include "WeissHapticSensorsUnit.h" + +#include <Core/robotstate/remote/ArmarPose.h> +#include <Core/robotstate/remote/RobotStateObjectFactories.h> + +#include <boost/regex.hpp> +#include <boost/filesystem.hpp> + + +using namespace armarx; + +void WeissHapticSensorsUnit::onInitHapticUnit() +{ + // Read pipe Id property + /*int firstPipeID = getProperty<int>("FirstPipeID").getValue(); + if(firstPipeID < 0) + { + throw UserException("Value of FirstPipeID must be bigger than 0"); + }*/ + + // Read pipe base name property + // std::string pipeBaseName = getProperty<std::string>("PipeBaseName").getValue(); + + // Read logfile property + //std::string logfile = getProperty<std::string>("Logfile").getValue(); + + //std::vector<std::string> sensors; + //sensors.push_back("RightSole.HapticMatrix"); + //hapticProtocol.defineSensorCategory(250, sensors); + + // TODO: The task frequency needs to be adapted when the underlying sensor frequency changes + //sensorTask = new RunningTask<WeissHapticSensorsUnit>(this, &WeissHapticSensorsUnit::readAndReportSensorValues); + + //remoteSystemReady = false; + /* + if(!hapticProtocol.openPipes(firstPipeID, firstPipeID + 1, false, true, pipeBaseName)) + { + throw UserException("Failed to open pipes"); + } + + if(!hapticProtocol.openLogfile(logfile)) + { + throw UserException("Failed to open logfile"); + }*/ + + std::vector<std::string> devices = getDevices(); + /*boost::shared_ptr<WeissHapticSensor> sensor(new WeissHapticSensor(devices.front())); + this->sensors.push_back(sensor);*/ + + for(std::vector<std::string>::iterator it = devices.begin(); it != devices.end(); ++it) + { + boost::shared_ptr<WeissHapticSensor> sensor(new WeissHapticSensor(*it)); + this->sensors.push_back(sensor); + } + + std::cout << "Connect Interfaces" << std::endl; + + //sensors.front()->connect(); + + for(std::vector<boost::shared_ptr<WeissHapticSensor> >::iterator it = sensors.begin(); it != sensors.end(); ++it) + { + (*it)->connect(); + } + +} + +std::vector< std::string > WeissHapticSensorsUnit::getDevices() +{ + const std::string target_path( "/dev/" ); + const boost::regex my_filter( "ttyACM[0-9]+" ); + + std::vector< std::string > files; + + boost::filesystem::directory_iterator end_itr; // Default ctor yields past-the-end + for( boost::filesystem::directory_iterator i( target_path ); i != end_itr; ++i ) + { + // Skip if not a file + //if( !boost::filesystem::is_( i->status() ) ) continue; + + boost::smatch what; + + // Skip if no match + if( !boost::regex_match( i->path().filename().string(), what, my_filter ) ) continue; + + + // File matches, store it + files.push_back( "/dev/" + i->path().filename().string() ); + } + std::sort(files.begin(), files.end()); + + std::cout << "Detected ACM-Interfaces: " << std::endl; + for(std::vector<std::string>::iterator it = files.begin(); it != files.end(); ++it) + { + std::cout << *it << std::endl; + } + + return files; +} + +void WeissHapticSensorsUnit::onStartHapticUnit() +{ + + for(std::vector<boost::shared_ptr<WeissHapticSensor> >::iterator it = sensors.begin(); it != sensors.end(); ++it) + { + (*it)->setListenerPrx(listenerPrx); + (*it)->startSampling(); + } + +} + +void WeissHapticSensorsUnit::onExitHapticUnit() +{ + for(std::vector<boost::shared_ptr<WeissHapticSensor> >::iterator it = sensors.begin(); it != sensors.end(); ++it) + { + (*it)->disconnect(); + } +} + +/*void WeissHapticSensorsUnit::onConnectComponent() +{ + +}*/ + +void WeissHapticSensorsUnit::onDisconnectComponent() +{ + +} + + +PropertyDefinitionsPtr WeissHapticSensorsUnit::createPropertyDefinitions() +{ + return PropertyDefinitionsPtr(new WeissHapticSensorsUnitPropertyDefinitions(getConfigIdentifier())); +} + diff --git a/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensorsUnit.h b/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensorsUnit.h new file mode 100755 index 0000000000000000000000000000000000000000..078bfe63905991b19026b71856470acf892e7d6a --- /dev/null +++ b/source/RobotAPI/drivers/WeissHapticSensor/WeissHapticSensorsUnit.h @@ -0,0 +1,80 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * ArmarX 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 + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package Armar4::units + * @author Peter Kaiser <peter dot kaiser at kit dot edu> + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#ifndef ARMAR4_FT_UNIT_ARMAR4_H +#define ARMAR4_FT_UNIT_ARMAR4_H + +#include <RobotAPI/units/HapticUnit.h> +//#include <Core/interface/units/ +#include <Core/core/system/ImportExportComponent.h> + +#include <string> +#include "WeissHapticSensor.h" + +namespace armarx +{ + class WeissHapticSensorsUnitPropertyDefinitions : public HapticUnitPropertyDefinitions + { + public: + WeissHapticSensorsUnitPropertyDefinitions(std::string prefix): + HapticUnitPropertyDefinitions(prefix) + { + //defineOptionalProperty<int>("FirstPipeID", 1, "Id of the first Linux/Xenomai Pipe to use for data transfer"); + //defineOptionalProperty<std::string>("PipeBaseName", "rtp", "Base name of pipe devices"); + //defineOptionalProperty<std::string>("Logfile", "", "Logfile for logging pipe communication"); + } + }; + + class WeissHapticSensorsUnit : virtual public HapticUnit + { + public: + virtual std::string getDefaultName() { return "HapticUnitArmar4"; } + + virtual void onInitHapticUnit(); + virtual void onStartHapticUnit(); + virtual void onExitHapticUnit(); + + //virtual void onConnectComponent(); + virtual void onDisconnectComponent(); + + virtual PropertyDefinitionsPtr createPropertyDefinitions(); + + protected: + //void proceedSensorCategory(SensorCategoryDefinition<MatrixFloat> *category); + + //std::map<std::string, MatrixFloatPtr> currentValues; + + + + //HapticSensorProtocolMaster hapticProtocol; + + //bool remoteSystemReady; + + private: + std::vector< std::string > getDevices(); + + std::vector< boost::shared_ptr< WeissHapticSensor > > sensors; + }; +} + +#endif diff --git a/source/RobotAPI/units/CMakeLists.txt b/source/RobotAPI/units/CMakeLists.txt index 6572a5dc9db9950d7d47ba148b82ca669855db57..494f973851ce21d59ccc39d36db1be6221a9d611 100644 --- a/source/RobotAPI/units/CMakeLists.txt +++ b/source/RobotAPI/units/CMakeLists.txt @@ -17,13 +17,14 @@ set(LIB_NAME RobotAPIUnits) set(LIB_VERSION 0.1.0) set(LIB_SOVERSION 0) -set(LIBS RobotAPIInterfaces RobotAPICore ArmarXInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreRemoteRobot ${Simox_LIBRARIES}) +set(LIBS RobotAPIInterfaces RobotAPICore ArmarXInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreEigen3Variants ArmarXCoreRemoteRobot ${Simox_LIBRARIES}) set(LIB_HEADERS ForceTorqueObserver.h ForceTorqueUnit.h HeadIKUnit.h HapticUnit.h + HapticObserver.h TCPControlUnit.h TCPControlUnitObserver.h ) @@ -33,6 +34,7 @@ set(LIB_FILES ForceTorqueUnit.cpp HeadIKUnit.cpp HapticUnit.cpp + HapticObserver.cpp TCPControlUnit.cpp TCPControlUnitObserver.cpp ) diff --git a/source/RobotAPI/units/HapticObserver.cpp b/source/RobotAPI/units/HapticObserver.cpp index ca002cd83ceec4cf865dfcdf8a1e1c4d89107d77..2867e505aa29cecf074cc6ca842781c281165203 100644 --- a/source/RobotAPI/units/HapticObserver.cpp +++ b/source/RobotAPI/units/HapticObserver.cpp @@ -8,6 +8,7 @@ #include <Core/robotstate/remote/checks/ConditionCheckMagnitudeChecks.h> #include <Core/robotstate/remote/RobotStateObjectFactories.h> +#include <Eigen/Dense> using namespace armarx; @@ -32,18 +33,6 @@ void HapticObserver::onInitObserver() offerConditionCheck("larger", new ConditionCheckLarger()); offerConditionCheck("equals", new ConditionCheckEquals()); offerConditionCheck("smaller", new ConditionCheckSmaller()); -// offerConditionCheck("magnitudeinrange", new ConditionCheckInRange()); - offerConditionCheck("magnitudelarger", new ConditionCheckMagnitudeLarger()); -// offerConditionCheck("magnitudesmaller", new ConditionCheckSmaller()); - - // register all channels -// offerChannel(FORCETORQUEVECTORS,"Force and Torque vectors on specific parts of the robot."); - -// offerChannel(RAWFORCE,"Forces on specific parts of the robot."); -// offerChannel(OFFSETFORCE,"Force Torques of specific parts of the robot with an offset."); -// offerChannel(FILTEREDFORCE,"Gaussian filtered force torques of specific parts of the robot."); - -// offerChannel(RAWTORQUE,"Torques on specific parts of the robot."); } @@ -51,13 +40,31 @@ void HapticObserver::onConnectObserver() { } -void HapticObserver::reportSensorValues(const std::string &type, const MatrixFloat &values, const Ice::Current &) +void HapticObserver::reportSensorValues(const std::string &type, const MatrixFloatBasePtr &values, const Ice::Current &) { - // TODO + ScopedLock lock(dataMutex); + MatrixFloatPtr matrix = MatrixFloatPtr::dynamicCast(values); + Eigen::MatrixXf eigenMatrix = matrix->toEigen(); + float max = eigenMatrix.maxCoeff(); + float mean = eigenMatrix.mean(); + if(!existsChannel(type)) + { + offerChannel(type, "Force and Torque vectors on specific parts of the robot."); + offerDataFieldWithDefault(type, "matrix", matrix, "Raw tactile matrix data"); + offerDataFieldWithDefault(type, "max", Variant(max), "Maximum value"); + offerDataFieldWithDefault(type, "mean", Variant(mean), "Mean value"); + } + else + { + setDataField(type, "matrix", matrix); + setDataField(type, "max", Variant(max)); + setDataField(type, "mean", Variant(mean)); + } + + updateChannel(type); } PropertyDefinitionsPtr HapticObserver::createPropertyDefinitions() { - return PropertyDefinitionsPtr(new HapticObserverPropertyDefinitions( - getConfigIdentifier())); + return PropertyDefinitionsPtr(new HapticObserverPropertyDefinitions(getConfigIdentifier())); } diff --git a/source/RobotAPI/units/HapticObserver.h b/source/RobotAPI/units/HapticObserver.h index 20a43213bcde58ce5e76dd3c8dad9d8afa7c5a90..e2357b63d8d8a7bf47fbcb26fa54ad2da36842bf 100644 --- a/source/RobotAPI/units/HapticObserver.h +++ b/source/RobotAPI/units/HapticObserver.h @@ -26,7 +26,7 @@ #include <RobotAPI/interface/units/HapticUnit.h> #include <Core/observers/Observer.h> -#include <Core/observers/variant/MatrixVariant.h> +#include <Core/util/variants/eigen3/MatrixVariant.h> namespace armarx { @@ -56,7 +56,7 @@ namespace armarx void onInitObserver(); void onConnectObserver(); - void reportSensorValues(const std::string &type, const ::armarx::MatrixFloat &values, const ::Ice::Current& = ::Ice::Current()); + void reportSensorValues(const std::string &type, const ::armarx::MatrixFloatBasePtr &values, const ::Ice::Current& = ::Ice::Current()); /** * @see PropertyUser::createPropertyDefinitions()