Skip to content
This repository was archived by the owner on Feb 21, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/libs/comm_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ set(HEADERS
include/jderobot/comm/ardroneextraClient.hpp
include/jderobot/comm/interfaces/ardroneextraClient.hpp
include/jderobot/comm/ice/ardroneextraIceClient.hpp
include/jderobot/comm/bumperClient.hpp
include/jderobot/comm/interfaces/bumperClient.hpp
include/jderobot/comm/ice/bumperIceClient.hpp
)

set(SOURCES
Expand All @@ -78,6 +81,8 @@ set(SOURCES
src/ice/ardroneextraIceClient.cpp
src/navdataClient.cpp
src/ice/navdataIceClient.cpp
src/bumperClient.cpp
src/ice/bumperIceClient.cpp
)


Expand All @@ -90,6 +95,7 @@ IF(JDEROBOTCOM_ROS)
include/jderobot/comm/ros/listenerCamera.hpp
include/jderobot/comm/ros/listenerPose.hpp
include/jderobot/comm/ros/publisherMotors.hpp
include/jderobot/comm/ros/listenerBumper.hpp
)

set(SOURCES
Expand All @@ -99,6 +105,7 @@ IF(JDEROBOTCOM_ROS)
src/ros/listenerCamera.cpp
src/ros/listenerPose.cpp
src/ros/publisherMotors.cpp
src/ros/listenerBumper.cpp
)

ENDIF()
Expand Down
48 changes: 48 additions & 0 deletions src/libs/comm_cpp/include/jderobot/comm/bumperClient.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 1997-2016 JDE Developers Team
*
* 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/.
* Authors :
* Aitor Martinez Fernandez <aitor.martinez.fernandez@gmail.com>
*/

#ifndef JDEROBOTCOMM_BUMPERCLIENT_H
#define JDEROBOTCOMM_BUMPERCLIENT_H

#include <jderobot/types/bumperData.h>
#include <Ice/Communicator.h>
#include <jderobot/comm/communicator.hpp>
#include <jderobot/comm/interfaces/bumperClient.hpp>




namespace Comm {

/**
* @brief make a BumperClient using propierties
*
*
* @param communicator that contains properties
* @param prefix of client Propierties (example: "kobukiViewer.Bumper")
*
*
* @return null if propierties are wrong
*/
BumperClient* getBumperClient(Comm::Communicator* jdrc, std::string prefix);


} //NS

#endif // JDEROBOTCOMM_BUMPERCLIENT_H
69 changes: 69 additions & 0 deletions src/libs/comm_cpp/include/jderobot/comm/ice/bumperIceClient.hpp
Original file line number Diff line number Diff line change
@@ -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 <jmplaza@gsyc.es>
Francisco Miguel Rivas Montero <franciscomiguel.rivas@urjc.es>

*/

#ifndef JDEROBOTCOMM_BUMPERICECLIENT_H_
#define JDEROBOTCOMM_BUMPERICECLIENT_H_

#include <IceUtil/IceUtil.h>
#include <iostream>
#include <Ice/Ice.h>
#include <jderobot/bumper.h>
#include <sstream>
#include <fstream>
#include <logger/Logger.h>
#include <jderobot/types/bumperData.h>
#include <jderobot/comm/communicator.hpp>
#include <jderobot/comm/interfaces/bumperClient.hpp>

namespace Comm {


class BumperIceClient: public IceUtil::Thread, public Comm::BumperClient {
public:
BumperIceClient(Comm::Communicator* jdrc, std::string prefix);
virtual ~BumperIceClient();
virtual void run();

virtual JdeRobotTypes::BumperData getBumperData();
int getRefreshRate(){return refreshRate;};
void pause();
void resume();
bool getPause(){return pauseStatus;};



private:
std::string prefix;
jderobot::BumperPrx prx;
long long int cycle;
IceUtil::Mutex controlMutex;
bool debug;
bool _done;
int refreshRate;
bool pauseStatus;

IceUtil::Cond sem;

};


} /* namespace jderobot */
#endif /* JDEROBOTCOMM_BUMPERICECLIENT_H_ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 1997-2016 JDE Developers Team
*
* 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/.
* Authors :
* Aitor Martinez Fernandez <aitor.martinez.fernandez@gmail.com>
*/

#ifndef JDEROBOTCOMM_BUMPERCLIENT_INTERFACE_H
#define JDEROBOTCOMM_BUMPERCLIENT_INTERFACE_H

#include <jderobot/types/bumperData.h>


namespace Comm {

/**
* @brief BumperClient class.
* This class is a Interface to seprate communications from tools.
* With this, the tools don't need know which communicator (ROS or ICE) are using because both use the same interface.
*
*/
class BumperClient {
public:
virtual JdeRobotTypes::BumperData getBumperData() = 0;
bool on = false;
protected:
JdeRobotTypes::BumperData bumperData;
};

} //NS

#endif // JDEROBOTCOMM_BUMPERCLIENT_INTERFACE_H
60 changes: 60 additions & 0 deletions src/libs/comm_cpp/include/jderobot/comm/ros/listenerBumper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 1997-2016 JDE Developers Team
*
* 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/.
* Authors :
* Aitor Martinez Fernandez <aitor.martinez.fernandez@gmail.com>
*/

#ifndef JDEROBOTCOMM_LISTENERBUMPER_H_
#define JDEROBOTCOMM_LISTENERBUMPER_H_


#include <ros/ros.h>
#include <kobuki_msgs/BumperEvent.h>
#include <boost/thread/thread.hpp>
#include <jderobot/types/bumperData.h>
#include <jderobot/comm/interfaces/bumperClient.hpp>
#include <jderobot/comm/ros/translators.hpp>

namespace Comm {
class ListenerBumper: public Comm::BumperClient {

public:
ListenerBumper(int argc, char** argv, std::string nodeName, std::string topic);
~ListenerBumper();

void start();
void stop();
virtual JdeRobotTypes::BumperData getBumperData();


private:
pthread_mutex_t mutex;
ros::Subscriber sub;
std::string topic;
std::string nodeName;

ros::AsyncSpinner* spinner;

void bumpercallback (const kobuki_msgs::BumperEventConstPtr& bumper_msg);





};//class

} //NS
#endif /* JDEROBOTCOMM_LISTENERBUMPER_H_ */
14 changes: 14 additions & 0 deletions src/libs/comm_cpp/include/jderobot/comm/ros/translators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include <jderobot/types/cmdvel.h>
#include <geometry_msgs/Twist.h>

#include <kobuki_msgs/BumperEvent.h>
#include <jderobot/types/bumperData.h>


namespace Comm {

Expand All @@ -55,6 +58,17 @@ namespace Comm {
*/
JdeRobotTypes::LaserData translate_laser_messages(const sensor_msgs::LaserScanConstPtr& scan);

/**
* @brief translate ROS BumperEvent messages to JdeRobot BumperData
*
*
* @param ROS kobuki Bumper Event Message
*
*
* @return BumperData translated from ROS Message
*/
JdeRobotTypes::BumperData translate_bumper_messages(const kobuki_msgs::BumperEventConstPtr& bump);

/**
* @brief translate ROS Image messages to JdeRobot Image
*
Expand Down
2 changes: 2 additions & 0 deletions src/libs/comm_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<build_depend>image_transport</build_depend>
<build_depend>nav_msgs</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>kobuki_msgs</build_depend>

<run_depend>message_runtime</run_depend>
<run_depend>roscpp</run_depend>
Expand All @@ -54,6 +55,7 @@
<run_depend>image_transport</run_depend>
<run_depend>nav_msgs</run_depend>
<run_depend>geometry_msgs</run_depend>
<run_depend>kobuki_msgs</run_depend>


<!-- The export tag contains other, unspecified, tags -->
Expand Down
60 changes: 60 additions & 0 deletions src/libs/comm_cpp/src/bumperClient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <jderobot/comm/interfaces/bumperClient.hpp>
#include <jderobot/comm/ice/bumperIceClient.hpp>
#ifdef JDERROS
#include <jderobot/comm/ros/listenerBumper.hpp>
#endif

namespace Comm {

BumperClient*
getBumperClient(Comm::Communicator* jdrc, std::string prefix){
BumperClient* client = 0;

int server = jdrc->getConfig().asIntWithDefault(prefix+".Server", 0);
switch (server){
case 0:
{
std::cout << "Bumper disabled" << std::endl;
break;
}
case 1:
{
std::cout << "Receiving BumperData from ICE interfaces" << std::endl;
BumperIceClient* cl;
cl = new BumperIceClient(jdrc, prefix);
cl->start();
client = (Comm::BumperClient*) cl;
break;
}
case 2:
{
#ifdef JDERROS
std::cout << "Receiving BumperData from ROS messages" << std::endl;
std::string nodeName;
nodeName = jdrc->getConfig().asStringWithDefault(prefix+".Name", "BumperNode");
std::string topic;
topic = jdrc->getConfig().asStringWithDefault(prefix+".Topic", "");
ListenerBumper* lc;
lc = new ListenerBumper(0, nullptr, nodeName, topic);
lc->start();
client = (Comm::BumperClient*) lc;
#else
throw "ERROR: ROS is not available";
#endif

break;
}
default:
{
std::cerr << "Wrong " + prefix+".Server property" << std::endl;
break;
}

}

return client;


}

}//NS
Loading