diff --git a/etc/cmake/FindOptoForceOMD.cmake b/etc/cmake/FindOptoForceOMD.cmake new file mode 100644 index 0000000000000000000000000000000000000000..44b699650be8468416e08521b40a0b41a4cf8e4f --- /dev/null +++ b/etc/cmake/FindOptoForceOMD.cmake @@ -0,0 +1,49 @@ +# - Try to find OptoForceOMD +# Once done this will define +# +# OptoForceOMD_FOUND - OptoForceOMD found +# OptoForceOMD_INCLUDE_DIR - the OptoForceOMD include directory +# OptoForceOMD_LIBRARIES - OptoForceOMD library +# + +FIND_PATH(OptoForceOMD_INCLUDE_DIR NAMES opto.h + PATHS + $ENV{OptoForceOMD_DIR}/include/ + $ENV{OptoForceOMD_DIR}/include/OptoForceOMD/ + ${OptoForceOMD_DIR}/include/ + ${OptoForceOMD_DIR}/include/OptoForceOMD/ + ENV CPATH + /usr/include/OptoForceOMD/ + /usr/local/include/OptoForceOMD/ + /opt/local/include/OptoForceOMD/ + NO_DEFAULT_PATH +) + + +FIND_LIBRARY(OptoForceOMD_LIBRARIES NAMES libOMD.so + PATHS + $ENV{OptoForceOMD_DIR}/lib + ${OptoForceOMD_DIR}/lib + ENV LD_LIBRARY_PATH + ENV LIBRARY_PATH + /usr/lib + /usr/local/lib + /opt/local/lib + NO_DEFAULT_PATH +) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set OODL_YOUBOT_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(OptoForceOMD DEFAULT_MSG + OptoForceOMD_LIBRARIES OptoForceOMD_INCLUDE_DIR) + +set(OptoForceOMD_FOUND ${OPTOFORCEOMD_FOUND}) # CMake UPPERCASE-FUNTIME! + +#message( "OptoForceOMD_FOUND:" ${OptoForceOMD_FOUND}) +#message( "OPTOFORCEOMD_FOUND:" ${OPTOFORCEOMD_FOUND}) +#message( "OptoForceOMD_LIBRARIES:" ${OptoForceOMD_LIBRARIES}) +#message( "OptoForceOMD_INCLUDE_DIR:" ${OptoForceOMD_INCLUDE_DIR}) + +# show the OptoForceOMD_INCLUDE_DIR and OptoForceOMD_LIBRARY_DIR variables only in the advanced view +MARK_AS_ADVANCED(OptoForceOMD_INCLUDE_DIR OptoForceOMD_LIBRARIES) diff --git a/scenarios/OptoForceUnit/OptoForceUnit.scx b/scenarios/OptoForceUnit/OptoForceUnit.scx new file mode 100644 index 0000000000000000000000000000000000000000..b61734dea6b15f026b6b46b0c95e46b04fd185f7 --- /dev/null +++ b/scenarios/OptoForceUnit/OptoForceUnit.scx @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<scenario name="OptoForceUnit" lastChange="2017-03-03.15:11:46" creation="2017-03-03.15:11:40" globalConfigName="./config/global.cfg" package="RobotAPI"> + <application name="OptoForceUnitApp" instance="" package="RobotAPI"/> +</scenario> + diff --git a/scenarios/OptoForceUnit/config/OptoForceUnitApp.cfg b/scenarios/OptoForceUnit/config/OptoForceUnitApp.cfg new file mode 100644 index 0000000000000000000000000000000000000000..f5d0795f711190daabfc601e025ad26da69a7add --- /dev/null +++ b/scenarios/OptoForceUnit/config/OptoForceUnitApp.cfg @@ -0,0 +1,156 @@ +# ================================================================== +# OptoForceUnitApp properties +# ================================================================== + +# ArmarX.AdditionalPackages: List of additional ArmarX packages which should be in the list of default packages. If you have custom packages, which should be found by the gui or other apps, specify them here. Comma separated List. +# Attributes: +# - Default: Default value not mapped. +# - Case sensitivity: no +# - Required: no +# ArmarX.AdditionalPackages = Default value not mapped. + + +# ArmarX.ApplicationName: Application name +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.ApplicationName = "" + + +# ArmarX.CachePath: Path for cache files +# Attributes: +# - Default: ${HOME}/.armarx/mongo/.cache +# - Case sensitivity: no +# - Required: no +# ArmarX.CachePath = ${HOME}/.armarx/mongo/.cache + + +# ArmarX.Config: Comma-separated list of configuration files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.Config = "" + + +# ArmarX.DataPath: Semicolon-separated search list for data files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.DataPath = "" + + +# ArmarX.DefaultPackages: List of ArmarX packages which are accessible by default. Comma separated List. If you want to add your own packages and use all default ArmarX packages, use the property 'AdditionalPackages'. +# Attributes: +# - Default: Default value not mapped. +# - Case sensitivity: no +# - Required: no +# ArmarX.DefaultPackages = Default value not mapped. + + +# ArmarX.DependenciesConfig: Path to the (usually generated) config file containing all data paths of all dependent projects. This property usually does not need to be edited. +# Attributes: +# - Default: ./config/dependencies.cfg +# - Case sensitivity: no +# - Required: no +# ArmarX.DependenciesConfig = ./config/dependencies.cfg + + +# ArmarX.DisableLogging: Turn logging off in whole application +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.DisableLogging = 0 + + +# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.EnableProfiling = 0 + + +# ArmarX.OptoForceUnit.EnableProfiling: enable profiler which is used for logging performance events +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.OptoForceUnit.EnableProfiling = 0 + + +# ArmarX.OptoForceUnit.MinimumLoggingLevel: Local logging level only for this component +# Attributes: +# - Default: Undefined +# - Case sensitivity: no +# - Required: no +# ArmarX.OptoForceUnit.MinimumLoggingLevel = Undefined + + +# ArmarX.OptoForceUnit.ObjectName: Name of IceGrid well-known object +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.OptoForceUnit.ObjectName = "" + + +# ArmarX.RedirectStdout: Redirect std::cout and std::cerr to ArmarXLog +# Attributes: +# - Default: 1 +# - Case sensitivity: no +# - Required: no +# ArmarX.RedirectStdout = 1 + + +# ArmarX.RemoteHandlesDeletionTimeout: The timeout (in ms) before a remote handle deletes the managed object after the use count reached 0. This time can be used by a client to increment the count again (may be required when transmitting remote handles) +# Attributes: +# - Default: 3000 +# - Case sensitivity: no +# - Required: no +# ArmarX.RemoteHandlesDeletionTimeout = 3000 + + +# ArmarX.StartDebuggerOnCrash: If this application crashes (segmentation fault) qtcreator will attach to this process and start the debugger. +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.StartDebuggerOnCrash = 0 + + +# ArmarX.TopicSuffix: Suffix appended to all topic names for outgoing topics. This is mainly used to direct all topics to another name for TopicReplaying purposes. +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.TopicSuffix = "" + + +# ArmarX.UseTimeServer: Enable using a global Timeserver (e.g. from ArmarXSimulator) +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.UseTimeServer = 0 + + +# ArmarX.Verbosity: Global logging level for whole application +# Attributes: +# - Default: Info +# - Case sensitivity: no +# - Required: no +# ArmarX.Verbosity = Info + + +# Ice.Config: Custom Property +# Attributes: +# - Default: ::NOT_DEFINED:: +# - Case sensitivity: no +# - Required: no +# Ice.Config = ::NOT_DEFINED:: + + diff --git a/scenarios/OptoForceUnit/config/global.cfg b/scenarios/OptoForceUnit/config/global.cfg new file mode 100644 index 0000000000000000000000000000000000000000..4602696c2afa4afbeb2dc4495d91705b6bfb5e46 --- /dev/null +++ b/scenarios/OptoForceUnit/config/global.cfg @@ -0,0 +1,7 @@ +# ================================================================== +# Global Config from Scenario OptoForceUnit +# ================================================================== + + + + diff --git a/source/RobotAPI/applications/CMakeLists.txt b/source/RobotAPI/applications/CMakeLists.txt index 91731e3bdc411e53d2d585349873524b6831b8b7..e61b41ad472eef26e14cbb05a80ed58e5ce41763 100644 --- a/source/RobotAPI/applications/CMakeLists.txt +++ b/source/RobotAPI/applications/CMakeLists.txt @@ -21,3 +21,5 @@ add_subdirectory(XsensIMU) add_subdirectory(InertialMeasurementUnitObserver) add_subdirectory(ViewSelection) + +add_subdirectory(OptoForceUnit) diff --git a/source/RobotAPI/applications/OptoForceUnit/CMakeLists.txt b/source/RobotAPI/applications/OptoForceUnit/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..be1955e8199bd33e62b90ef6514c12cf1f28d60f --- /dev/null +++ b/source/RobotAPI/applications/OptoForceUnit/CMakeLists.txt @@ -0,0 +1,23 @@ +armarx_component_set_name("OptoForceUnitApp") + +find_package(OptoForceOMD QUIET) +armarx_build_if(OptoForceOMD_FOUND "OptoForceOMD not available") + +if(OptoForceOMD_FOUND) + include_directories(${OptoForceOMD_INCLUDE_DIR}) +endif() + +#message("OptoForceOMD_INCLUDE_DIR: " ${OptoForceOMD_INCLUDE_DIR}) +#message("OptoForceOMD_LIBRARIES: " ${OptoForceOMD_LIBRARIES}) + +set(COMPONENT_LIBS ArmarXCoreInterfaces ArmarXCore ${OptoForceOMD_LIBRARIES}) + +set(COMPONENT_LIBS + ArmarXCoreInterfaces + ArmarXCore + OptoForceUnit +) + +set(EXE_SOURCE main.cpp) + +armarx_add_component_executable("${EXE_SOURCE}") diff --git a/source/RobotAPI/applications/OptoForceUnit/main.cpp b/source/RobotAPI/applications/OptoForceUnit/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c41d5d633660d88e8087cbf7b67320b23c7c642 --- /dev/null +++ b/source/RobotAPI/applications/OptoForceUnit/main.cpp @@ -0,0 +1,32 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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 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::OptoForceUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include <RobotAPI/drivers/OptoForceUnit/OptoForceUnit.h> + +#include <ArmarXCore/core/application/Application.h> +#include <ArmarXCore/core/Component.h> +#include <ArmarXCore/core/logging/Logging.h> + +int main(int argc, char* argv[]) +{ + return armarx::runSimpleComponentApp < armarx::OptoForceUnit > (argc, argv, "OptoForceUnit"); +} diff --git a/source/RobotAPI/drivers/CMakeLists.txt b/source/RobotAPI/drivers/CMakeLists.txt index ce2834d8731aa2a82f549313634a7d28b2277084..7488028c33169db7961c848bf109bcade934cb62 100644 --- a/source/RobotAPI/drivers/CMakeLists.txt +++ b/source/RobotAPI/drivers/CMakeLists.txt @@ -1,2 +1,4 @@ add_subdirectory(WeissHapticSensor) add_subdirectory(XsensIMU) +add_subdirectory(OptoForceUnit) + diff --git a/source/RobotAPI/drivers/OptoForce/CMakeLists.txt b/source/RobotAPI/drivers/OptoForce/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..69ebc2ee58ac092c170ded635229f10655dfe01b --- /dev/null +++ b/source/RobotAPI/drivers/OptoForce/CMakeLists.txt @@ -0,0 +1,24 @@ +armarx_component_set_name("OptoForce") + +find_package(OptoForceOMD QUIET) +armarx_build_if(OptoForceOMD_FOUND "OptoForceOMD not available 11elf!") + +if(OptoForceOMD_FOUND) + include_directories(${OptoForceOMD_INCLUDE_DIR}) +endif() + +set(COMPONENT_LIBS ArmarXCoreInterfaces ArmarXCore OMD) + +set(SOURCES +OptoForce.cpp +#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.cpp +) +set(HEADERS +OptoForce.h +#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.h +) + +armarx_add_component("${SOURCES}" "${HEADERS}") + +# add unit tests +add_subdirectory(test) diff --git a/source/RobotAPI/drivers/OptoForce/OptoForce.cpp b/source/RobotAPI/drivers/OptoForce/OptoForce.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4583843a0b503724fcf040cb225f37e2259d14e --- /dev/null +++ b/source/RobotAPI/drivers/OptoForce/OptoForce.cpp @@ -0,0 +1,57 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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 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::OptoForce + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "OptoForce.h" + + +using namespace armarx; + + +void OptoForce::onInitComponent() +{ + +} + + +void OptoForce::onConnectComponent() +{ + +} + + +void OptoForce::onDisconnectComponent() +{ + +} + + +void OptoForce::onExitComponent() +{ + +} + +armarx::PropertyDefinitionsPtr OptoForce::createPropertyDefinitions() +{ + return armarx::PropertyDefinitionsPtr(new OptoForcePropertyDefinitions( + getConfigIdentifier())); +} + diff --git a/source/RobotAPI/drivers/OptoForce/OptoForce.h b/source/RobotAPI/drivers/OptoForce/OptoForce.h new file mode 100644 index 0000000000000000000000000000000000000000..d8cffde689d631b3385b7a647384c531f2274025 --- /dev/null +++ b/source/RobotAPI/drivers/OptoForce/OptoForce.h @@ -0,0 +1,99 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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 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::OptoForce + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#ifndef _ARMARX_COMPONENT_RobotAPI_OptoForce_H +#define _ARMARX_COMPONENT_RobotAPI_OptoForce_H + + +#include <ArmarXCore/core/Component.h> +#include <opto.h> + +namespace armarx +{ + /** + * @class OptoForcePropertyDefinitions + * @brief + */ + class OptoForcePropertyDefinitions: + public armarx::ComponentPropertyDefinitions + { + public: + OptoForcePropertyDefinitions(std::string prefix): + armarx::ComponentPropertyDefinitions(prefix) + { + //defineRequiredProperty<std::string>("PropertyName", "Description"); + //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description"); + } + }; + + /** + * @defgroup Component-OptoForce OptoForce + * @ingroup RobotAPI-Components + * A description of the component OptoForce. + * + * @class OptoForce + * @ingroup Component-OptoForce + * @brief Brief description of class OptoForce. + * + * Detailed description of class OptoForce. + */ + class OptoForce : + virtual public armarx::Component + { + public: + /** + * @see armarx::ManagedIceObject::getDefaultName() + */ + virtual std::string getDefaultName() const + { + return "OptoForce"; + } + + 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 armarx::PropertyDefinitionsPtr createPropertyDefinitions(); + }; +} + +#endif diff --git a/source/RobotAPI/drivers/OptoForce/test/CMakeLists.txt b/source/RobotAPI/drivers/OptoForce/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..752baf57ed0a71efa1839d086abc830efd2fc363 --- /dev/null +++ b/source/RobotAPI/drivers/OptoForce/test/CMakeLists.txt @@ -0,0 +1,5 @@ + +# Libs required for the tests +SET(LIBS ${LIBS} ArmarXCore OptoForce) + +armarx_add_test(OptoForceTest OptoForceTest.cpp "${LIBS}") \ No newline at end of file diff --git a/source/RobotAPI/drivers/OptoForce/test/OptoForceTest.cpp b/source/RobotAPI/drivers/OptoForce/test/OptoForceTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..721c33f3de840451e4ef7ce2b6092d8ede4c0a80 --- /dev/null +++ b/source/RobotAPI/drivers/OptoForce/test/OptoForceTest.cpp @@ -0,0 +1,37 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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 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::OptoForceOMD + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::OptoForceOMD + +#define ARMARX_BOOST_TEST + +#include <RobotAPI/Test.h> +#include <RobotAPI/components/OptoForceOMD/OptoForceOMD.h> + +#include <iostream> + +BOOST_AUTO_TEST_CASE(testExample) +{ + armarx::OptoForceOMD instance; + + BOOST_CHECK_EQUAL(true, true); +} diff --git a/source/RobotAPI/drivers/OptoForceUnit/CMakeLists.txt b/source/RobotAPI/drivers/OptoForceUnit/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6bb74c019e89e71368d3694936559db19f1da014 --- /dev/null +++ b/source/RobotAPI/drivers/OptoForceUnit/CMakeLists.txt @@ -0,0 +1,27 @@ +armarx_component_set_name("OptoForceUnit") + +find_package(OptoForceOMD QUIET) +armarx_build_if(OptoForceOMD_FOUND "OptoForceOMD not available") + +if(OptoForceOMD_FOUND) + include_directories(${OptoForceOMD_INCLUDE_DIR}) +endif() + +#message("OptoForceOMD_INCLUDE_DIR: " ${OptoForceOMD_INCLUDE_DIR}) +#message("OptoForceOMD_LIBRARIES: " ${OptoForceOMD_LIBRARIES}) + +set(COMPONENT_LIBS ArmarXCoreInterfaces ArmarXCore ${OptoForceOMD_LIBRARIES}) + +set(SOURCES +./OptoForceUnit.cpp +#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.cpp +) +set(HEADERS +./OptoForceUnit.h +#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.h +) + +armarx_add_component("${SOURCES}" "${HEADERS}") + +# add unit tests +add_subdirectory(test) diff --git a/source/RobotAPI/drivers/OptoForceUnit/OptoForceUnit.cpp b/source/RobotAPI/drivers/OptoForceUnit/OptoForceUnit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da4adfece6bcd40ef282c1535793552f447830dc --- /dev/null +++ b/source/RobotAPI/drivers/OptoForceUnit/OptoForceUnit.cpp @@ -0,0 +1,168 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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 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::OptoForceUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "OptoForceUnit.h" + + +using namespace armarx; + + +void OptoForceUnit::onInitComponent() +{ + OPort* portlist = ports.listPorts(true); + ARMARX_INFO << "Found " << ports.getLastSize() << " Optoforce device(s)."; + + + int numPorts = ports.getLastSize(); + ARMARX_INFO << "number of ports: " << numPorts; + + OPort* portListNew = ports.listPorts(true); + + for (int i = 0; i < ports.getLastSize(); i++) + { + ARMARX_INFO << "Port liste new: " << portListNew[i].name; + } + + ARMARX_INFO << "number of ports: " << ports.getLastSize(); + + if (ports.getLastSize() > 0) + { + for (int i = 0; i < ports.getLastSize(); ++i) + { + ARMARX_INFO << "Opening port #" << i << "..."; + if (i == 0) + { + daq.open(portlist[i]); + ARMARX_INFO << "opened port 1"; + } + if (daq.getVersion() == _95 || daq.getVersion() == _64) + { + ARMARX_IMPORTANT << "Wrong sensor type! (not 3D)"; + daq.close(); + return; + } + } + } + + readTask = new RunningTask<OptoForceUnit>(this, &OptoForceUnit::run, "OptoForceUnit"); + readTask->start(); +} + + +void OptoForceUnit::onConnectComponent() +{ + +} + +void OptoForceUnit::run() +{ + ARMARX_IMPORTANT << "run"; + + SensorConfig config = daq.getConfig(); + + int state = config.getState(); + int speed = config.getSpeed(); + int filter = config.getFilter(); + int mode = config.getMode(); + + ARMARX_IMPORTANT << "state: " << state; + ARMARX_IMPORTANT << "speed: " << speed; + ARMARX_IMPORTANT << "filter: " << filter; + ARMARX_IMPORTANT << "mode: " << mode; + + while(readTask->isRunning()) + { + OptoPackage* pa = 0; + //OptoPackage* pa2 = 0; + + int size = daq.readAll(pa, false); + if (size <= 0) + { + usleep(1000); // 1ms + continue; + } + ARMARX_IMPORTANT << "size: " << size; + ARMARX_IMPORTANT << "daq.getSize(): " << daq.getSize(); + // necessary so that there are no lines without values + if (daq.getSize() > 0) + { + //optoForceOutputFile << "getsize: " << daq.getSize() << "\n"; + //optoForceOutputFile << "getBytesperRead: " << daq.getBytesPerRead() << "\n"; + + //optoForceOutputFile << "getsize2: " << daq2.getSize() << "\n"; + //optoForceOutputFile << "getBytesperRead2: " << daq2.getBytesPerRead() << "\n"; + + //optoForceOutputFile << IceUtil::Time::now().toDateTime() << " OptoForce: "; + // get values of first DAQ - 4 OptoForce sensors connected + for (int k = 0; k < daq.getSensorSize(); k++) + { + ARMARX_INFO << "Sensor " << k; + + for (int i = 0; i < size; i++) + { + ARMARX_INFO << "x: " << pa[k * size + i].x << " y: " << pa[k * size + i].y << " z: " << pa[k * size + i].z << " s1: " << pa[k * size + i].s1 << " s2: " << pa[k * size + i].s2 << " s3: " << pa[k * size + i].s3 << " s4: " << pa[k * size + i].s4 << " TEMP: " << pa[k * size + i].temp << flush; + //optoForceOutputFile << "x: " << pa[k * size + i].x << " y: " << pa[k * size + i].y << " z: " << pa[k * size + i].z << " "; + + } + } + + /*// get values of second DAQ - 3 OptoForce sensors connected + //needs to be (daq2.getSensorSize()-1) to read out only 3 ports + for (int k = 0; k < (daq2.getSensorSize() - 1) ; k++) + { + ARMARX_INFO << "Sensor " << k; + + + for (int i = 0; i < size2; i++) + { + ARMARX_INFO << "x: " << pa2[k * size2 + i].x << " y: " << pa2[k * size2 + i].y << " z: " << pa2[k * size2 + i].z << " s1: " << pa2[k * size2 + i].s1 << " s2: " << pa2[k * size2 + i].s2 << " s3: " << pa2[k * size2 + i].s3 << " s4: " << pa2[k * size2 + i].s4 << " TEMP: " << pa2[k * size2 + i].temp << flush; + optoForceOutputFile << "x: " << pa2[k * size2 + i].x << " y: " << pa2[k * size2 + i].y << " z: " << pa2[k * size2 + i].z << " "; + + } + }*/ + // buffer needs to be deleted + delete[] pa; + //delete[] pa2; + //optoForceOutputFile << "\n"; + //optoForceOutputFile.flush(); + } + } +} + + +void OptoForceUnit::onDisconnectComponent() +{ + +} + + +void OptoForceUnit::onExitComponent() +{ + readTask->stop(); +} + +armarx::PropertyDefinitionsPtr OptoForceUnit::createPropertyDefinitions() +{ + return armarx::PropertyDefinitionsPtr(new OptoForceUnitPropertyDefinitions( + getConfigIdentifier())); +} + diff --git a/source/RobotAPI/drivers/OptoForceUnit/OptoForceUnit.h b/source/RobotAPI/drivers/OptoForceUnit/OptoForceUnit.h new file mode 100644 index 0000000000000000000000000000000000000000..92d760307041030ae2747d8499dd43b6eee2fdf0 --- /dev/null +++ b/source/RobotAPI/drivers/OptoForceUnit/OptoForceUnit.h @@ -0,0 +1,108 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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 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::OptoForceUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#ifndef _ARMARX_COMPONENT_RobotAPI_OptoForceUnit_H +#define _ARMARX_COMPONENT_RobotAPI_OptoForceUnit_H + + +#include <ArmarXCore/core/Component.h> +#include <ArmarXCore/core/services/tasks/RunningTask.h> +#include <opto.h> + +namespace armarx +{ + /** + * @class OptoForceUnitPropertyDefinitions + * @brief + */ + class OptoForceUnitPropertyDefinitions: + public armarx::ComponentPropertyDefinitions + { + public: + OptoForceUnitPropertyDefinitions(std::string prefix): + armarx::ComponentPropertyDefinitions(prefix) + { + //defineRequiredProperty<std::string>("PropertyName", "Description"); + //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description"); + } + }; + + /** + * @defgroup Component-OptoForceUnit OptoForceUnit + * @ingroup RobotAPI-Components + * A description of the component OptoForceUnit. + * + * @class OptoForceUnit + * @ingroup Component-OptoForceUnit + * @brief Brief description of class OptoForceUnit. + * + * Detailed description of class OptoForceUnit. + */ + class OptoForceUnit : + virtual public armarx::Component + { + public: + /** + * @see armarx::ManagedIceObject::getDefaultName() + */ + virtual std::string getDefaultName() const + { + return "OptoForceUnit"; + } + + 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 armarx::PropertyDefinitionsPtr createPropertyDefinitions(); + + private: + void run(); + + OptoPorts ports; + OptoDAQ daq; + RunningTask<OptoForceUnit>::pointer_type readTask; + + }; +} + +#endif diff --git a/source/RobotAPI/drivers/OptoForceUnit/test/CMakeLists.txt b/source/RobotAPI/drivers/OptoForceUnit/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d98753d86660f78faaee7e476511d3af7e9daa29 --- /dev/null +++ b/source/RobotAPI/drivers/OptoForceUnit/test/CMakeLists.txt @@ -0,0 +1,5 @@ + +# Libs required for the tests +SET(LIBS ${LIBS} ArmarXCore OptoForceUnit) + +armarx_add_test(OptoForceUnitTest OptoForceUnitTest.cpp "${LIBS}") \ No newline at end of file diff --git a/source/RobotAPI/drivers/OptoForceUnit/test/OptoForceUnitTest.cpp b/source/RobotAPI/drivers/OptoForceUnit/test/OptoForceUnitTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f12161380ccbae533b0d649ac5dd957ad57b086 --- /dev/null +++ b/source/RobotAPI/drivers/OptoForceUnit/test/OptoForceUnitTest.cpp @@ -0,0 +1,37 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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 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::OptoForceUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::OptoForceUnit + +#define ARMARX_BOOST_TEST + +#include <RobotAPI/Test.h> +#include <RobotAPI/drivers/OptoForceUnit/OptoForceUnit.h> + +#include <iostream> + +BOOST_AUTO_TEST_CASE(testExample) +{ + armarx::OptoForceUnit instance; + + BOOST_CHECK_EQUAL(true, true); +}