From e728a1041e93ef0a4c888019da06447118e339e5 Mon Sep 17 00:00:00 2001 From: Francisco Perez Date: Sat, 28 Jan 2017 07:50:00 -0800 Subject: [PATCH 1/2] Added parallelIce motorsClient for c++ --- src/libs/parallelIce/CMakeLists.txt | 4 +- src/libs/parallelIce/motorsClient.cpp | 118 ++++++++++++++++++++++++++ src/libs/parallelIce/motorsClient.h | 69 +++++++++++++++ 3 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 src/libs/parallelIce/motorsClient.cpp create mode 100644 src/libs/parallelIce/motorsClient.h diff --git a/src/libs/parallelIce/CMakeLists.txt b/src/libs/parallelIce/CMakeLists.txt index 332834757..3dccccf51 100644 --- a/src/libs/parallelIce/CMakeLists.txt +++ b/src/libs/parallelIce/CMakeLists.txt @@ -5,10 +5,10 @@ include_directories(${LIBS_DIR}) # Aquí se alojan las cabeceras de las interfac include_directories( ${LIBS_DIR}/) -add_library (parallelIce STATIC cameraClient.cpp cameraClient.h pointcloudClient.cpp pointcloudClient.h laserClient.cpp laserClient.h) +add_library (parallelIce STATIC cameraClient.cpp cameraClient.h pointcloudClient.cpp pointcloudClient.h laserClient.cpp laserClient.h motorsClient.cpp motorsClient.h) TARGET_LINK_LIBRARIES(parallelIce colorspacesmm logger ${Boost_LIBRARIES}) -add_library (parallelIceshare SHARED cameraClient.cpp cameraClient.h pointcloudClient.cpp pointcloudClient.h laserClient.cpp laserClient.h) +add_library (parallelIceshare SHARED cameraClient.cpp cameraClient.h pointcloudClient.cpp pointcloudClient.h laserClient.cpp laserClient.h motorsClient.cpp motorsClient.h) TARGET_LINK_LIBRARIES(parallelIceshare colorspacesmm logger ${Boost_LIBRARIES} ${ZLIB_LIBRARIES}) diff --git a/src/libs/parallelIce/motorsClient.cpp b/src/libs/parallelIce/motorsClient.cpp new file mode 100644 index 000000000..e9ea91518 --- /dev/null +++ b/src/libs/parallelIce/motorsClient.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (C) 1997-2013 JDE Developers TeamkinectViewer.camRGB + * + * 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 3 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, see http://www.gnu.org/licenses/. + * + * Author : Jose María Cañas + Francisco Miguel Rivas Montero + + */ +#include "motorsClient.h" + +namespace jderobot { + +motorsClient::motorsClient(Ice::CommunicatorPtr ic, std::string prefix, bool debug) { + // TODO Auto-generated constructor stub + this->prefix=prefix; + this->debug= debug; + Ice::PropertiesPtr prop; + prop = ic->getProperties(); + + try{ + + std::string maxWstr = prop->getPropertyWithDefault(prefix+".maxW","0.5"); + this->maxW = atof(maxWstr.c_str()); + + std::string maxVstr = prop->getPropertyWithDefault(prefix+".maxV","0.5"); + this->maxV = atof(maxVstr.c_str()); + + if (debug){ + std::cout << "maxV value:" << this->maxV << std::endl; + std::cout << "maxW value:" << this->maxW << std::endl; + } + + Ice::ObjectPrx baseMotors = ic->propertyToProxy(prefix+"Proxy"); + this->prx = jderobot::MotorsPrx::checkedCast(baseMotors); + if (0==this->prx) { + std::cerr << "Interface " << prefix << " not configured "<< std::endl;; + } + + }catch (const Ice::Exception& ex) { + std::cerr << ex << std::endl; + } + catch (const char* msg) { + std::cerr << msg << std::endl; + jderobot::Logger::getInstance()->error(prefix + " Not motors provided"); + } +} + +motorsClient::~motorsClient() { + // TODO Auto-generated destructor stub +} + +void motorsClient::setV(float v) { + this->controlMutex.lock(); + this->v = v; + this->controlMutex.unlock(); + +} + +void motorsClient::setW(float w) { + this->controlMutex.lock(); + this->w = w; + this->controlMutex.unlock(); + +} + +float motorsClient::getMaxV() { + return this->maxV; +} + +float motorsClient::getMaxW() { + return this->maxW; +} + +void motorsClient::sendVelocities() { + if (this->hasProxy()){ + this->controlMutex.lock(); + float v = this->v; + float w = this->w; + this->controlMutex.unlock(); + this->prx->setV(v); + this->prx->setW(w); + } +} + +void motorsClient::sendV(float v) { + if (this->hasProxy()){ + this->controlMutex.lock(); + this->prx->setV(v); + this->controlMutex.unlock(); + } + +} + +void motorsClient::sendW(float w) { + if (this->hasProxy()){ + this->controlMutex.lock(); + this->prx->setW(w); + this->controlMutex.unlock(); + } +} + +bool motorsClient::hasProxy(){ + return this->prx; +} + +} /* namespace eldercare */ diff --git a/src/libs/parallelIce/motorsClient.h b/src/libs/parallelIce/motorsClient.h new file mode 100644 index 000000000..e53282dae --- /dev/null +++ b/src/libs/parallelIce/motorsClient.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 1997-2013 JDE Developers TeamkinectViewer.camRGB + * + * 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 3 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, see http://www.gnu.org/licenses/. + * + * Author : Jose María Cañas + Francisco Miguel Rivas Montero + + */ + +#ifndef MOTORSCLIENT_H_ +#define MOTORSCLIENT_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace jderobot { + + +class motorsClient { +public: + motorsClient(Ice::CommunicatorPtr ic, std::string prefix, bool debug = false); + virtual ~motorsClient(); + + void setV(float v); + void setW(float w); + float getMaxW(); + float getMaxV(); + void sendVelocities(); + void sendV(float v); + void sendW(float w); + bool hasProxy(); + + +private: + std::string prefix; + float v; + float w; + float maxV; + float maxW; + + + jderobot::MotorsPrx prx; + IceUtil::Mutex controlMutex; + bool debug; + bool _done; + +}; + + +} /* namespace jderobot */ +#endif /* LASERCLIENT_H_ */ From 1be1eb20925aaa508bb46cecf301a8ade82093b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20P=C3=A9rez?= Date: Wed, 8 Feb 2017 12:28:51 +0100 Subject: [PATCH 2/2] Update motorsClient.h --- src/libs/parallelIce/motorsClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/parallelIce/motorsClient.h b/src/libs/parallelIce/motorsClient.h index e53282dae..3d78d5d6c 100644 --- a/src/libs/parallelIce/motorsClient.h +++ b/src/libs/parallelIce/motorsClient.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include namespace jderobot {