Skip to content

Commit

Permalink
added a client service for PowerPlantManager
Browse files Browse the repository at this point in the history
currently this service supports only one battery
  • Loading branch information
atiderko committed May 21, 2018
1 parent 08ef602 commit 4feac76
Show file tree
Hide file tree
Showing 9 changed files with 544 additions and 0 deletions.
87 changes: 87 additions & 0 deletions iop_client_power_plant_fkie/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
cmake_minimum_required(VERSION 2.8.3)
project(iop_client_power_plant_fkie)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
iop_component_fkie
iop_ocu_slavelib_fkie
roscpp
std_msgs)
iop_init(COMPONENT_ID 0)
iop_export_service(urn_jaus_jss_ugv_PowerPlantManagerClient)

###################################
## catkin specific configuration ##
###################################
catkin_package(
# INCLUDE_DIRS include/public
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS
iop_component_fkie
iop_ocu_slavelib_fkie
std_msgs
)

###########
## Build ##
###########

## Specify additional locations of header files
iop_code_generator(
IDLS
urn.jaus.jss.core-v1.1/AccessControlClient.xml
urn.jaus.jss.core-v1.1/EventsClient.xml
urn.jaus.jss.core-v1.1/Transport.xml
urn.jaus.jss.ugv/power_plantClient.xml
OWN_IDLS
OVERRIDES
include/urn_jaus_jss_ugv_PowerPlantManagerClient/PowerPlantManagerClient_ReceiveFSM.h
src/urn_jaus_jss_ugv_PowerPlantManagerClient/PowerPlantManagerClient_ReceiveFSM.cpp
src/main.cpp
EXTERN_SERVICES
urn_jaus_jss_core_AccessControlClient
urn_jaus_jss_core_EventsClient
urn_jaus_jss_core_Transport
GENERATED_SOURCES cppfiles
)
include_directories(${catkin_INCLUDE_DIRS}
# include/public
)

## Declare a cpp executable
add_library(${PROJECT_NAME}
src/PowerPlantManagerClientPlugin.cpp
${cppfiles}
)

## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
)

install(
DIRECTORY ${IOP_INSTALL_INCLUDE_DIRS} DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
PATTERN "*.old" EXCLUDE
PATTERN "*.gen" EXCLUDE
)

#install(
# DIRECTORY include/public/${PROJECT_NAME} DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
# PATTERN "*.old" EXCLUDE
# PATTERN "*.gen" EXCLUDE
#)

install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

## Mark other files for installation (e.g. launch and bag files, etc.)
install(
FILES ./plugin_iop.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

30 changes: 30 additions & 0 deletions iop_client_power_plant_fkie/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
This package is part of [ROS/IOP Bridge](https://github.com/fkie/iop_core/blob/master/README.md).


## _iop_client_power_plant_fkie:_ PowerPlantManagerClient

Currently publish reports the status of one battery.


#### Parameter:

_hz (int_ Default: 0.0)

> Sets how often the reports are requested. If [use_queries](https://github.com/fkie/iop_core/blob/master/iop_ocu_slavelib_fkie/README.md#parameter) is ```True``` hz must be greather then 0. In this case each time a ```Query``` message is sent to get a report. If ```use_queries``` is ```False``` an event is created to get Reports. In this case 0 disables the rate and an event of type ```on_change``` will be created.

#### Publisher:

_powerplant\_`ID`/voltage (std_msgs::Float32)_

> Current voltage.
_powerplant\_`ID`/capacity_percent (std_msgs::Int8)_

> Percent of maximum.

#### Subscriber:

> None
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@


#ifndef POWERPLANTMANAGERCLIENT_RECEIVEFSM_H
#define POWERPLANTMANAGERCLIENT_RECEIVEFSM_H

#include "JausUtils.h"
#include "InternalEvents/InternalEventHandler.h"
#include "Transport/JausTransport.h"
#include "JTSStateMachine.h"
#include "urn_jaus_jss_ugv_PowerPlantManagerClient/Messages/MessageSet.h"
#include "urn_jaus_jss_ugv_PowerPlantManagerClient/InternalEvents/InternalEventsSet.h"

#include "InternalEvents/Receive.h"
#include "InternalEvents/Send.h"

#include "urn_jaus_jss_core_Transport/Transport_ReceiveFSM.h"
#include "urn_jaus_jss_core_EventsClient/EventsClient_ReceiveFSM.h"
#include "urn_jaus_jss_core_AccessControlClient/AccessControlClient_ReceiveFSM.h"

#include <std_msgs/Bool.h>
#include <std_msgs/Float32.h>
#include <std_msgs/Int8.h>
#include <iop_ocu_slavelib_fkie/SlaveHandlerInterface.h>
#include <iop_events_fkie/EventHandlerInterface.h>

#include "PowerPlantManagerClient_ReceiveFSM_sm.h"

namespace urn_jaus_jss_ugv_PowerPlantManagerClient
{

class DllExport PowerPlantManagerClient_ReceiveFSM : public JTS::StateMachine, public iop::ocu::SlaveHandlerInterface, public iop::EventHandlerInterface
{
public:
PowerPlantManagerClient_ReceiveFSM(urn_jaus_jss_core_Transport::Transport_ReceiveFSM* pTransport_ReceiveFSM, urn_jaus_jss_core_EventsClient::EventsClient_ReceiveFSM* pEventsClient_ReceiveFSM, urn_jaus_jss_core_AccessControlClient::AccessControlClient_ReceiveFSM* pAccessControlClient_ReceiveFSM);
virtual ~PowerPlantManagerClient_ReceiveFSM();

/// Handle notifications on parent state changes
virtual void setupNotifications();

/// Action Methods
virtual void handleReportPowerPlantCapabilitiesAction(ReportPowerPlantCapabilities msg, Receive::Body::ReceiveRec transportData);
virtual void handleReportPowerPlantConfigurationAction(ReportPowerPlantConfiguration msg, Receive::Body::ReceiveRec transportData);
virtual void handleReportPowerPlantStatusAction(ReportPowerPlantStatus msg, Receive::Body::ReceiveRec transportData);


/// EventHandlerInterface Methods
void event(JausAddress reporter, unsigned short query_msg_id, unsigned int reportlen, const unsigned char* reportdata);

/// SlaveHandlerInterface Methods
void control_allowed(std::string service_uri, JausAddress component, unsigned char authority);
void enable_monitoring_only(std::string service_uri, JausAddress component);
void access_deactivated(std::string service_uri, JausAddress component);
void create_events(std::string service_uri, JausAddress component, bool by_query=false);
void cancel_events(std::string service_uri, JausAddress component, bool by_query=false);

/// Guard Methods



PowerPlantManagerClient_ReceiveFSMContext *context;

protected:

/// References to parent FSMs
urn_jaus_jss_core_Transport::Transport_ReceiveFSM* pTransport_ReceiveFSM;
urn_jaus_jss_core_EventsClient::EventsClient_ReceiveFSM* pEventsClient_ReceiveFSM;
urn_jaus_jss_core_AccessControlClient::AccessControlClient_ReceiveFSM* pAccessControlClient_ReceiveFSM;

QueryPowerPlantStatus p_query_states;
JausAddress p_remote_addr;
bool p_has_access;
ros::NodeHandle p_nh;
ros::Timer p_query_timer;
bool p_by_query;
bool p_valid_configuration;
double p_hz;

bool p_battery_valid;
int p_battery_id;
ros::Publisher p_pub_battery_voltage;
ros::Publisher p_pub_battery_capacity_percent;
void pQueryCallback(const ros::TimerEvent& event);

};

};

#endif // PowerPlantManagerCLIENT_RECEIVEFSM_H
24 changes: 24 additions & 0 deletions iop_client_power_plant_fkie/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<package format="2">
<name>iop_client_power_plant_fkie</name>
<version>1.1.0</version>
<description>
The PowerPlantManager client request battery states from PowerPlantManager services.
</description>

<author>Alexander Tiderko</author>
<maintainer email="alexander.tiderko@fkie.fraunhofer.de">Alexander Tiderko</maintainer>
<license>GPLv2</license>
<url type="website">https://github.com/fkie/iop_jaus_ugv_clients</url>

<buildtool_depend>catkin</buildtool_depend>
<depend>iop_component_fkie</depend>
<depend>iop_ocu_slavelib_fkie</depend>
<depend>roscpp</depend>
<depend>std_msgs</depend>

<export>
<iop_component_fkie plugin="${prefix}/plugin_iop.xml" />
</export>

</package>
10 changes: 10 additions & 0 deletions iop_client_power_plant_fkie/plugin_iop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library path="libiop_client_power_plant_fkie">
<class name="PowerPlantManagerClient" type="iop::PowerPlantManagerClientPlugin" base_class_type="iop::PluginInterface">
<description>
PowerPlantManager client Service Plugin, used e.g. by OCU
</description>
<iop_service name="PowerPlantManagerClient" id="urn:jaus:jss:ugv:PowerPlantManagerClient" version="1.1">
<inherits_from id="urn:jaus:jss:core:AccessControlClient" min_version="1.1"/>
</iop_service>
</class>
</library>
54 changes: 54 additions & 0 deletions iop_client_power_plant_fkie/src/PowerPlantManagerClientPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
ROS/IOP Bridge
Copyright (c) 2017 Fraunhofer
This program is dual licensed; 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, or
enter into a proprietary license agreement with the copyright
holder.
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; or you can read the full license at
<http://www.gnu.de/documents/gpl-2.0.html>
*/

/** \author Alexander Tiderko */

#include <pluginlib/class_list_macros.h>
#include "PowerPlantManagerClientPlugin.h"

using namespace iop;
using namespace urn_jaus_jss_ugv_PowerPlantManagerClient;
using namespace urn_jaus_jss_core_AccessControlClient;
using namespace urn_jaus_jss_core_EventsClient;
using namespace urn_jaus_jss_core_Transport;


PowerPlantManagerClientPlugin::PowerPlantManagerClientPlugin()
{
p_my_service = NULL;
p_base_service = NULL;
p_events_service = NULL;
p_transport_service = NULL;
}

JTS::Service* PowerPlantManagerClientPlugin::get_service()
{
return p_my_service;
}

void PowerPlantManagerClientPlugin::create_service(JTS::JausRouter* jaus_router)
{
p_base_service = static_cast<AccessControlClientService *>(get_base_service());
p_events_service = static_cast<EventsClientService *>(get_base_service(2));
p_transport_service = static_cast<TransportService *>(get_base_service(3));
p_my_service = new PowerPlantManagerClientService(jaus_router, p_transport_service, p_events_service, p_base_service);
}

PLUGINLIB_EXPORT_CLASS(iop::PowerPlantManagerClientPlugin, iop::PluginInterface)
54 changes: 54 additions & 0 deletions iop_client_power_plant_fkie/src/PowerPlantManagerClientPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
ROS/IOP Bridge
Copyright (c) 2017 Fraunhofer
This program is dual licensed; 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, or
enter into a proprietary license agreement with the copyright
holder.
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; or you can read the full license at
<http://www.gnu.de/documents/gpl-2.0.html>
*/

/** \author Alexander Tiderko */

#ifndef POWERPLANTMANAGERCLIENTPLUGIN_H
#define POWERPLANTMANAGERCLIENTPLUGIN_H

#include "urn_jaus_jss_ugv_PowerPlantManagerClient/PowerPlantManagerClientService.h"
#include "urn_jaus_jss_core_AccessControlClient/AccessControlClientService.h"
#include "urn_jaus_jss_core_EventsClient/EventsClientService.h"
#include "urn_jaus_jss_core_Transport/TransportService.h"

#include <iop_component_fkie/iop_plugin_interface.h>

namespace iop
{

class DllExport PowerPlantManagerClientPlugin : public PluginInterface
{
public:
PowerPlantManagerClientPlugin();

JTS::Service* get_service();
void create_service(JTS::JausRouter* jaus_router);

protected:
urn_jaus_jss_ugv_PowerPlantManagerClient::PowerPlantManagerClientService *p_my_service;
urn_jaus_jss_core_AccessControlClient::AccessControlClientService *p_base_service;
urn_jaus_jss_core_EventsClient::EventsClientService *p_events_service;
urn_jaus_jss_core_Transport::TransportService *p_transport_service;

};

};

#endif
1 change: 1 addition & 0 deletions iop_client_power_plant_fkie/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// it is a library, we don't need this main
Loading

0 comments on commit 4feac76

Please sign in to comment.