Skip to content

Commit 9ee6cb1

Browse files
yosukegbiggs
authored andcommitted
FSM4RTC implementation (#8)
* import FSM4RTC idls from http://svn.openrtm.org/OpenRTM-aist/branches/FSM4RTC * add event handler for FSM events * fix typo * add script to compile openrtm-aist fsm4rtc branch for testing * implement setter and getter for property: dynamic * add utility method to get ExtendedFsmService * getter and setter for dynamic was there at node.py * add utility script to run fsm4rtc test component * fix idl prefix issue * increase portability * raise exception when observer service not found * dirty fix for openrtm-aist get_sdo_service bug * revert change made by accident
1 parent cb80b15 commit 9ee6cb1

File tree

8 files changed

+164
-14
lines changed

8 files changed

+164
-14
lines changed

idl/ComponentObserver.idl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "SDOPackage.idl"
2020
#include "RTC.idl"
2121

22+
#pragma prefix "omg.org"
23+
2224
/*!
2325
* @if jp
2426
* @brief コンポーネント状態オブザーバインターフェース
@@ -43,7 +45,7 @@
4345
* @since 1.1
4446
* @endif
4547
*/
46-
module OpenRTM
48+
module RTC
4749
{
4850
/*!
4951
* @if jp
@@ -277,10 +279,18 @@ module OpenRTM
277279
*
278280
* @endif
279281
*/
280-
HEARTBEAT,
282+
RTC_HEARTBEAT,
283+
EC_HEARTBEAT,
284+
285+
FSM_PROFILE,
286+
FSM_STATUS,
287+
FSM_STRUCTURE,
288+
289+
USER_DEFINED,
281290

282291
STATUS_KIND_NUM
283292
};
293+
#pragma version StatusKind 1.0
284294

285295
/*!
286296
* @if jp
@@ -492,5 +502,6 @@ module OpenRTM
492502
*/
493503
oneway void update_status(in StatusKind status_kind, in string hint);
494504
};
505+
#pragma version ComponentObserver 1.0
495506

496507
};

idl/ExtendedFsmService.idl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef _EXTENDED_FSM_SERVICE_IDL_
2+
#define _EXTENDED_FSM_SERVICE_IDL_
3+
4+
#include <RTC.idl>
5+
6+
#pragma prefix "omg.org"
7+
8+
module RTC
9+
{
10+
struct FsmEventProfile
11+
{
12+
string name;
13+
string data_type;
14+
};
15+
#pragma version FsmEventProfile 1.0
16+
typedef sequence<FsmEventProfile> FsmEventProfileList;
17+
18+
struct FsmStructure
19+
{
20+
string name;
21+
string structure;
22+
FsmEventProfileList event_profiles;
23+
NVList properties;
24+
};
25+
#pragma version FsmStructure 1.0
26+
27+
interface ExtendedFsmService : SDOPackage::SDOService
28+
{
29+
string get_current_state();
30+
ReturnCode_t set_fsm_structure(in FsmStructure fsm_structure);
31+
ReturnCode_t get_fsm_structure(out FsmStructure fsm_structure);
32+
};
33+
#pragma version ExtendedFsmService 1.0
34+
};
35+
36+
#endif // _EXTENDED_FSM_SERVICE_IDL_
37+

rtctree/component.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ class Component(TreeNode):
6767
one of Component.CFG_UPDATE_SET, Component.CFG_UPDATE_PARAM,
6868
Component.CFG_UPDATE_PARAM_IN_ACTIVE, Component.CFG_ADD_SET,
6969
Component.CFG_REMOVE_SET and Component.CFG_ACTIVATE_SET.
70-
- heartbeat(time)
71-
A heartbeat was received from the component. The time the beat was
72-
received is passed.
70+
- heartbeat(type, time)
71+
A heartbeat was received from the component or from the execution context.
72+
The time the beat was received is passed.
73+
- fsm_event(type, hint)
74+
A change in the FSM status has occurred. The type of the event and the
75+
content of the event is passed.
7376
7477
To explain the usage of Component node, we first launch example components:
7578
>>> import subprocess, shlex
@@ -245,7 +248,7 @@ def __init__(self, name=None, parent=None, obj=None, *args, **kwargs):
245248
super(Component, self).__init__(name=name, parent=parent,
246249
*args, **kwargs)
247250
self._set_events(['rtc_status', 'component_profile', 'ec_event',
248-
'port_event', 'config_event', 'heartbeat'])
251+
'port_event', 'config_event', 'heartbeat', 'fsm_event'])
249252
self._reset_data()
250253
self._parse_profile()
251254

@@ -852,6 +855,22 @@ def state_string(self):
852855
'''The state of this component as a colourised string.'''
853856
return self.get_state_string()
854857

858+
###########################################################################
859+
# FSM4RTC
860+
861+
def get_extended_fsm_service(self):
862+
'''Get a reference to the ExtendedFsmService.
863+
864+
@return A reference to the ExtendedFsmService object
865+
@raises InvalidSdoServiceError
866+
867+
'''
868+
with self._mutex:
869+
try:
870+
return self._obj.get_sdo_service(RTC.ExtendedFsmService._NP_RepositoryId)._narrow(RTC.ExtendedFsmService)
871+
except:
872+
raise exceptions.InvalidSdoServiceError('ExtendedFsmService')
873+
855874
###########################################################################
856875
# Port management
857876

@@ -1002,7 +1021,7 @@ def add_logger(self, cb, level='NORMAL', filters='ALL'):
10021021
10031022
'''
10041023
with self._mutex:
1005-
obs = rtctree.sdo.RTCLogger(self, cb)
1024+
obs = sdo.RTCLogger(self, cb)
10061025
uuid_val = uuid.uuid4()
10071026
intf_type = obs._this()._NP_RepositoryId
10081027
props = {'logger.log_level': level,
@@ -1130,11 +1149,15 @@ def _config_event(self, name, event):
11301149

11311150
def _enable_dynamic(self, enable=True):
11321151
if enable:
1133-
obs = rtctree.sdo.RTCObserver(self)
1152+
obs = sdo.RTCObserver(self)
11341153
uuid_val = uuid.uuid4().get_bytes()
11351154
intf_type = obs._this()._NP_RepositoryId
11361155
props = utils.dict_to_nvlist({'heartbeat.enable': 'YES',
11371156
'heartbeat.interval': '1.0',
1157+
'rtc_heartbeat.enable': 'YES',
1158+
'rtc_heartbeat.interval': '1.0',
1159+
'ec_heartbeat.enable': 'YES',
1160+
'ec_heartbeat.interval': '1.0',
11381161
'observed_status': 'ALL'})
11391162
sprof = SDOPackage.ServiceProfile(id=uuid_val,
11401163
interface_type=intf_type, service=obs._this(),
@@ -1147,6 +1170,8 @@ def _enable_dynamic(self, enable=True):
11471170
self._obs_id = uuid_val
11481171
# If we could set an observer, the component is alive
11491172
self._last_heartbeat = time.time()
1173+
else:
1174+
raise exceptions.InvalidSdoServiceError('Observer')
11501175
else: # Disable
11511176
conf = self.object.get_configuration()
11521177
res = conf.remove_service_profile(self._obs_id)
@@ -1214,10 +1239,14 @@ def _get_ec_state(self, ec):
12141239
else:
12151240
return self.CREATED
12161241

1217-
def _heartbeat(self):
1218-
# Received a heart beat
1242+
def _heartbeat(self, kind):
1243+
# Received a heart beat signal
12191244
self._last_heartbeat = time.time()
1220-
self._call_cb('heartbeat', self._last_heartbeat)
1245+
self._call_cb('heartbeat', (kind, self._last_heartbeat))
1246+
1247+
def _fsm_event(self, kind, hint):
1248+
# Received a fsm event
1249+
self._call_cb('fsm_event', (kind, hint))
12211250

12221251
def _parse_configuration(self):
12231252
# Parse the component's configuration sets

rtctree/exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,11 @@ def __str__(self):
287287
return 'Not a CORBA CosNaming.Name: {0}'.format(self.args[0])
288288

289289

290+
class InvalidSdoServiceError(RtcTreeError):
291+
'''Could not find specified SDO service.'''
292+
def __str__(self):
293+
return 'Invalid SDO service: {0}'.format(self.args[0])
294+
295+
296+
290297
# vim: set expandtab tabstop=8 shiftwidth=4 softtabstop=4 textwidth=79

rtctree/sdo.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020

2121
from rtctree.rtc import OpenRTM__POA
22+
from rtctree.rtc import RTC__POA
2223

2324

24-
class RTCObserver(OpenRTM__POA.ComponentObserver):
25+
class RTCObserver(RTC__POA.ComponentObserver):
2526
def __init__(self, target):
2627
self._tgt = target
2728

@@ -77,8 +78,10 @@ def update_status(self, kind, hint):
7778
elif event == 'ACTIVATE_CONFIG_SET':
7879
event = self._tgt.CFG_ACTIVATE_SET
7980
self._tgt._config_event(arg, event)
80-
elif kind == 'HEARTBEAT':
81-
self._tgt._heartbeat()
81+
elif kind == 'HEARTBEAT' or kind == 'RTC_HEARTBEAT' or kind == 'EC_HEARTBEAT':
82+
self._tgt._heartbeat(kind)
83+
elif kind == 'FSM_PROFILE' or kind == 'FSM_STATUS' or kind == 'FSM_STRUCTURE':
84+
self._tgt._fsm_event(kind, hint)
8285

8386

8487
class RTCLogger(OpenRTM__POA.Logger):

test/run-fsm4rtc.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
BASEDIR=$(dirname $(readlink -f "$0"))
4+
5+
FSM4RTC_HOME="$BASEDIR/FSM4RTC/OpenRTM-aist"
6+
7+
$FSM4RTC_HOME/examples/SimpleIO/ConsoleInComp -f $BASEDIR/rtc.conf -o "logger.log_level:DEBUG" -o "sdo.service.provider.enabled_services:ALL" -o "manager.local_service.modules:$FSM4RTC_HOME/src/ext/sdo/fsm4rtc_observer/.libs/ComponentObserverConsumer.so(ComponentObserverConsumerInit),$FSM4RTC_HOME/src/ext/sdo/extended_fsm/.libs/ExtendedFsmServiceProvider.so(ExtendedFsmServiceProviderInit)"
8+

test/setup-fsm4rtc.patch

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Index: OpenRTM-aist/src/lib/rtm/FsmActionListener.h
2+
===================================================================
3+
--- OpenRTM-aist/src/lib/rtm/FsmActionListener.h (リビジョン 2806)
4+
+++ OpenRTM-aist/src/lib/rtm/FsmActionListener.h (作業コピー)
5+
@@ -29,9 +29,7 @@
6+
7+
namespace RTC
8+
{
9+
- struct FsmStructure
10+
- {
11+
- };
12+
+ struct FsmStructure;
13+
/*!
14+
* @if jp
15+
*
16+
Index: OpenRTM-aist/src/lib/rtm/SdoServiceAdmin.cpp
17+
===================================================================
18+
--- OpenRTM-aist/src/lib/rtm/SdoServiceAdmin.cpp (リビジョン 2806)
19+
+++ OpenRTM-aist/src/lib/rtm/SdoServiceAdmin.cpp (作業コピー)
20+
@@ -82,6 +82,7 @@
21+
22+
// If types include '[Aa][Ll][Ll]', all types enabled in this RTC
23+
::coil::vstring activeProviderTypes;
24+
+/*
25+
for (size_t i(0); i < enabledProviderTypes.size(); ++i)
26+
{
27+
std::string tmp(enabledProviderTypes[i]);
28+
@@ -100,6 +101,8 @@
29+
}
30+
}
31+
}
32+
+*/
33+
+ activeProviderTypes = availableProviderTypes;
34+
35+
SdoServiceProviderFactory& factory(SdoServiceProviderFactory::instance());
36+
for (size_t i(0); i < activeProviderTypes.size(); ++i)

test/setup-fsm4rtc.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
BASEDIR=$(dirname $(readlink -f "$0"))
4+
5+
sudo apt install subversion autoconf autotools-bin libpoco-dev
6+
if [ ! -d "$BASEDIR/FSM4RTC" ]; then
7+
svn co http://svn.openrtm.org/OpenRTM-aist/branches/FSM4RTC $BASEDIR/FSM4RTC
8+
fi
9+
cd $BASEDIR/FSM4RTC
10+
svn update
11+
patch -p0 -E < $BASEDIR/setup-fsm4rtc.patch
12+
cd OpenRTM-aist
13+
./autogen.sh
14+
./configure
15+
make -j4
16+
17+
## To launch the test component:
18+
# cd src/ext/sdo/fsm4rtc_observer/test/
19+
# ./test.sh

0 commit comments

Comments
 (0)