[openrtm-commit:02403] r937 - trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm
openrtm @ openrtm.org
openrtm @ openrtm.org
2017年 2月 7日 (火) 16:59:08 JST
Author: win-ei
Date: 2017-02-07 16:59:08 +0900 (Tue, 07 Feb 2017)
New Revision: 937
Added:
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/Inputbutton.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/InputbuttonComp.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/InputbuttonImpl.java
Modified:
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/MicrowaveComp.java
Log:
[FSM4RTC,example] StaticFsm sample which is for new Static FSM framework has been added. refs #3775
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/Inputbutton.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/Inputbutton.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/Inputbutton.java 2017-02-07 07:59:08 UTC (rev 937)
@@ -0,0 +1,42 @@
+package RTMExamples.StaticFsm;
+
+
+import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.RTObject_impl;
+import jp.go.aist.rtm.RTC.RtcDeleteFunc;
+import jp.go.aist.rtm.RTC.RtcNewFunc;
+import jp.go.aist.rtm.RTC.RegisterModuleFunc;
+import jp.go.aist.rtm.RTC.util.Properties;
+
+public class Inputbutton implements RtcNewFunc, RtcDeleteFunc, RegisterModuleFunc {
+
+// Module specification
+// <rtc-template block="module_spec">
+ public static String component_conf[] = {
+ "implementation_id", "Inputbutton",
+ "type_name", "Inputbutton",
+ "description", "Console input component",
+ "version", "1.0",
+ "vendor", "Noriaki Ando, AIST",
+ "category", "example",
+ "activity_type", "DataFlowComponent",
+ "max_instance", "10",
+ "language", "Java",
+ "lang_type", "compile",
+ ""
+ };
+// </rtc-template>
+
+ public RTObject_impl createRtc(Manager mgr) {
+ return new InputbuttonImpl(mgr);
+ }
+
+ public void deleteRtc(RTObject_impl rtcBase) {
+ rtcBase = null;
+ }
+ public void registerModule() {
+ Properties prop = new Properties(component_conf);
+ final Manager manager = Manager.instance();
+ manager.registerFactory(prop, new Inputbutton(), new Inputbutton());
+ }
+}
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/InputbuttonComp.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/InputbuttonComp.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/InputbuttonComp.java 2017-02-07 07:59:08 UTC (rev 937)
@@ -0,0 +1,92 @@
+package RTMExamples.StaticFsm;
+
+
+import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.ModuleInitProc;
+import jp.go.aist.rtm.RTC.RTObject_impl;
+import jp.go.aist.rtm.RTC.util.NVUtil;
+import jp.go.aist.rtm.RTC.util.Properties;
+import RTC.ComponentProfile;
+import RTC.PortService;
+import RTC.PortInterfacePolarity;
+import RTC.PortInterfaceProfileListHolder;
+import RTC.PortServiceListHolder;
+import _SDOPackage.NVListHolder;
+
+public class InputbuttonComp implements ModuleInitProc {
+
+ public void myModuleInit(Manager mgr) {
+ Properties prop = new Properties(Inputbutton.component_conf);
+ mgr.registerFactory(prop, new Inputbutton(), new Inputbutton());
+
+ // Create a component
+ System.out.println("Creating a component: \"Inputbutton\"....");
+ RTObject_impl comp = mgr.createComponent("Inputbutton");
+ System.out.println("succeed.");
+
+ ComponentProfile prof = comp.get_component_profile();
+/*
+ System.out.println( "=================================================" );
+ System.out.println( " Component Profile" );
+ System.out.println( "-------------------------------------------------" );
+ System.out.println( "InstanceID: " + prof.instance_name );
+ System.out.println( "Implementation: " + prof.type_name );
+ System.out.println( "Description: " + prof.description );
+ System.out.println( "Version: " + prof.version );
+ System.out.println( "Maker: " + prof.vendor );
+ System.out.println( "Category: " + prof.category );
+ System.out.println( " Other properties " );
+ NVUtil.dump(new NVListHolder(prof.properties));
+ System.out.println( "=================================================" );
+*/
+
+ PortServiceListHolder portlist = new PortServiceListHolder(comp.get_ports());
+/*
+ for( int intIdx=0;intIdx<portlist.value.length;++intIdx ) {
+ PortService port = portlist.value[intIdx];
+ System.out.println( "=================================================" );
+ System.out.println( "Port" + intIdx + " (name): ");
+ System.out.println( port.get_port_profile().name );
+ System.out.println( "-------------------------------------------------" );
+ PortInterfaceProfileListHolder iflist = new PortInterfaceProfileListHolder(port.get_port_profile().interfaces);
+
+ for( int intIdx2=0;intIdx2<iflist.value.length;++intIdx2 ) {
+ System.out.println( "I/F name: " );
+ System.out.println( iflist.value[intIdx2].instance_name );
+ System.out.println( "I/F type: ");
+ System.out.println( iflist.value[intIdx2].type_name );
+ if( iflist.value[intIdx2].polarity==PortInterfacePolarity.PROVIDED ) {
+ System.out.println( "Polarity: PROVIDED" );
+ } else {
+ System.out.println( "Polarity: REQUIRED" );
+ }
+ }
+ System.out.println( "- properties -" );
+ NVUtil.dump(new NVListHolder(port.get_port_profile().properties));
+ System.out.println( "-------------------------------------------------" );
+ }
+*/
+
+ }
+
+ public static void main(String[] args) {
+ // Initialize manager
+ final Manager manager = Manager.init(args);
+
+ // Set module initialization proceduer
+ // This procedure will be invoked in activateManager() function.
+ InputbuttonComp init = new InputbuttonComp();
+ manager.setModuleInitProc(init);
+
+ // Activate manager and register to naming service
+ manager.activateManager();
+
+ // run the manager in blocking mode
+ // runManager(false) is the default.
+ manager.runManager();
+
+ // If you want to run the manager in non-blocking mode, do like this
+ // manager.runManager(true);
+ }
+
+}
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/InputbuttonImpl.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/InputbuttonImpl.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/InputbuttonImpl.java 2017-02-07 07:59:08 UTC (rev 937)
@@ -0,0 +1,386 @@
+package RTMExamples.StaticFsm;
+
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Observer;
+import java.util.Observable;
+
+import jp.go.aist.rtm.RTC.DataFlowComponentBase;
+import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.connectorListener.ReturnCode;
+import jp.go.aist.rtm.RTC.port.OutPort;
+import jp.go.aist.rtm.RTC.port.ConnectorBase;
+import jp.go.aist.rtm.RTC.port.ConnectorListener;
+import jp.go.aist.rtm.RTC.port.ConnectorDataListener;
+import jp.go.aist.rtm.RTC.port.ConnectorDataListenerT;
+import jp.go.aist.rtm.RTC.port.ConnectorDataListenerType;
+import jp.go.aist.rtm.RTC.port.ConnectorListenerType;
+import jp.go.aist.rtm.RTC.util.DataRef;
+import RTC.ReturnCode_t;
+import RTC.TimedLong;
+
+import org.omg.CORBA.portable.OutputStream;
+
+import jp.go.aist.rtm.RTC.util.DataRef;
+import jp.go.aist.rtm.RTC.util.ORBUtil;
+import org.omg.IOP.IOR;
+import org.omg.IOP.IORHelper;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+import java.io.ByteArrayOutputStream;
+import org.omg.CORBA.OctetSeqHelper;
+
+
+import java.util.ArrayList;
+import org.omg.IOP.TaggedProfile;
+import org.omg.IOP.TaggedProfileHelper;
+import org.omg.IOP.TAG_MULTIPLE_COMPONENTS;
+import org.omg.IOP.TAG_INTERNET_IOP;
+
+public class InputbuttonImpl extends DataFlowComponentBase {
+
+ public InputbuttonImpl(Manager manager) {
+ super(manager);
+ // <rtc-template block="initializer">
+ m_open_val = new TimedLong(new RTC.Time(0,0),0);
+ m_open = new DataRef<TimedLong>(m_open_val);
+ m_openOut = new OutPort<TimedLong>("open", m_open);
+
+ m_close_val = new TimedLong(new RTC.Time(0,0),0);
+ m_close = new DataRef<TimedLong>(m_close_val);
+ m_closeOut = new OutPort<TimedLong>("close", m_close);
+
+ m_minute_val = new TimedLong(new RTC.Time(0,0),0);
+ m_minute = new DataRef<TimedLong>(m_minute_val);
+ m_minuteOut = new OutPort<TimedLong>("minute", m_minute);
+
+ m_start_val = new TimedLong(new RTC.Time(0,0),0);
+ m_start = new DataRef<TimedLong>(m_start_val);
+ m_startOut = new OutPort<TimedLong>("start", m_start);
+
+ m_stop_val = new TimedLong(new RTC.Time(0,0),0);
+ m_stop = new DataRef<TimedLong>(m_stop_val);
+ m_stopOut = new OutPort<TimedLong>("stop", m_stop);
+
+ m_tick_val = new TimedLong(new RTC.Time(0,0),0);
+ m_tick = new DataRef<TimedLong>(m_tick_val);
+ m_tickOut = new OutPort<TimedLong>("tick", m_tick);
+ // </rtc-template>
+
+ // Registration: InPort/OutPort/Service
+ // <rtc-template block="registration">
+ // Set InPort buffers
+
+ // Set OutPort buffer
+ // Set service provider to Ports
+
+ // Set service consumers to Ports
+
+ // Set CORBA Service Ports
+
+ // </rtc-template>
+ m_mgr = manager;
+ }
+
+ // The initialize action (on CREATED->ALIVE transition)
+ // formaer rtc_init_entry()
+// @Override
+ protected ReturnCode_t onInitialize() {
+
+ try {
+ addOutPort("open", m_openOut);
+ addOutPort("close", m_closeOut);
+ addOutPort("minute", m_minuteOut);
+ addOutPort("start", m_startOut);
+ addOutPort("stop", m_stopOut);
+ addOutPort("tick", m_tickOut);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+/*
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_WRITE,
+ new DataListener("ON_BUFFER_WRITE"));
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_FULL,
+ new DataListener("ON_BUFFER_FULL"));
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT,
+ new DataListener("ON_BUFFER_WRITE_TIMEOUT"));
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_OVERWRITE,
+ new DataListener("ON_BUFFER_OVERWRITE"));
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_READ,
+ new DataListener("ON_BUFFER_READ"));
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_SEND,
+ new DataListener("ON_SEND"));
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_RECEIVED,
+ new DataListener("ON_RECEIVED"));
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_RECEIVER_FULL,
+ new DataListener("ON_RECEIVER_FULL"));
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_RECEIVER_TIMEOUT,
+ new DataListener("ON_RECEIVER_TIMEOUT"));
+ m_outOut.addConnectorDataListener(
+ ConnectorDataListenerType.ON_RECEIVER_ERROR,
+ new DataListener("ON_RECEIVER_ERROR"));
+*/
+/*
+ m_outOut.addConnectorListener(
+ ConnectorListenerType.ON_CONNECT,
+ new Listener("ON_CONNECT"));
+ m_outOut.addConnectorListener(
+ ConnectorListenerType.ON_DISCONNECT,
+ new Listener("ON_DISCONNECT"));
+*/
+
+ return super.onInitialize();
+ }
+
+
+ // The finalize action (on ALIVE->END transition)
+ // formaer rtc_exiting_entry()
+// @Override
+// protected ReturnCode_t onFinalize() {
+// return super.onFinalize();
+// }
+ //
+ // The startup action when ExecutionContext startup
+ // former rtc_starting_entry()
+// @Override
+// protected ReturnCode_t onStartup(int ec_id) {
+// return super.onStartup(ec_id);
+// }
+ //
+ // The shutdown action when ExecutionContext stop
+ // former rtc_stopping_entry()
+// @Override
+// protected ReturnCode_t onShutdown(int ec_id) {
+// return super.onShutdown(ec_id);
+// }
+ //
+ // The activated action (Active state entry action)
+ // former rtc_active_entry()
+// @Override
+// protected ReturnCode_t onActivated(int ec_id) {
+// return super.onActivated(ec_id);
+// }
+ //
+ // The deactivated action (Active state exit action)
+ // former rtc_active_exit()
+// @Override
+// protected ReturnCode_t onDeactivated(int ec_id) {
+// return super.onDeactivated(ec_id);
+// }
+ //
+ // The execution action that is invoked periodically
+ // former rtc_active_do()
+ @Override
+ protected ReturnCode_t onExecute(int ec_id) {
+ System.out.println("Please select action!!");
+ System.out.println("Commands: ");
+ System.out.println(" open : Open the microwave's door.");
+ System.out.println(" close : Close the microwave's door.");
+ System.out.println(" minute <int> : Increment timer. ");
+ System.out.println(" start : Start the microwave.");
+ System.out.println(" stop : Stop the microwave.");
+ System.out.println(" tick : Proceed time.");
+ System.out.println(" -> others are interpreted as tick commnad.");
+ System.out.println(">> ");
+
+ BufferedReader buff = new BufferedReader(new InputStreamReader( System.in ));
+ try {
+ String cmd = buff.readLine();
+ String[] cmds = cmd.split(" ");
+ cmds[0] = cmds[0].trim();
+
+ System.out.print("[command]: "+cmds[0]);
+ if(cmds.length >1){
+ System.out.print(" [args]: ");
+ for(int ic=0;ic<cmds.length;++ic){
+ System.out.print(cmds[ic]+" ");
+ }
+ }
+ System.out.print("");
+ if(cmds[0].equals("open")){
+ m_open_val.data = 0;
+ m_openOut.write();
+ }
+ else if(cmds[0].equals("close")){
+ m_close_val.data = 0;
+ m_closeOut.write();
+ }
+ else if(cmds[0].equals("minute")){
+ if(cmds.length < 2 ){
+ System.out.println("minute command needs an integer arg.");
+ }
+ else{
+ try {
+ int min = Integer.parseInt(cmds[1]);
+ m_minute_val.data = min;
+ m_minuteOut.write();
+ }
+ catch (Exception ex) {
+ System.out.println("minute command needs an integer arg.");
+ }
+ }
+ }
+ else if(cmds[0].equals("start")){
+ m_start_val.data = 0;
+ m_startOut.write();
+ }
+ else if(cmds[0].equals("stop")){
+ m_stop_val.data = 0;
+ m_stopOut.write();
+ }
+ else{
+ System.out.println("tick");
+ m_tick_val.data = 0;
+ m_tickOut.write();
+ }
+ }
+ catch (Exception ex) {
+ System.out.println("Input Error!");
+ }
+
+ return super.onExecute(ec_id);
+ }
+ //
+ // The aborting action when main logic error occurred.
+ // former rtc_aborting_entry()
+// @Override
+// public ReturnCode_t onAborting(int ec_id) {
+// return super.onAborting(ec_id);
+// }
+ //
+ // The error action in ERROR state
+ // former rtc_error_do()
+// @Override
+// public ReturnCode_t onError(int ec_id) {
+// return super.onError(ec_id);
+// }
+ //
+ // The reset action that is invoked resetting
+ // This is same but different the former rtc_init_entry()
+// @Override
+// protected ReturnCode_t onReset(int ec_id) {
+// return super.onReset(ec_id);
+// }
+//
+ // The state update action that is invoked after onExecute() action
+ // no corresponding operation exists in OpenRTm-aist-0.2.0
+// @Override
+// protected ReturnCode_t onStateUpdate(int ec_id) {
+// return super.onStateUpdate(ec_id);
+// }
+ //
+ // The action that is invoked when execution context's rate is changed
+ // no corresponding operation exists in OpenRTm-aist-0.2.0
+// @Override
+// protected ReturnCode_t onRateChanged(int ec_id) {
+// return super.onRateChanged(ec_id);
+// }
+//
+ // DataInPort declaration
+ // <rtc-template block="inport_declare">
+
+ // </rtc-template>
+
+ // DataOutPort declaration
+ // <rtc-template block="outport_declare">
+ protected TimedLong m_open_val;
+ protected DataRef<TimedLong> m_open;
+ protected OutPort<TimedLong> m_openOut;
+
+ protected TimedLong m_close_val;
+ protected DataRef<TimedLong> m_close;
+ protected OutPort<TimedLong> m_closeOut;
+
+ protected TimedLong m_minute_val;
+ protected DataRef<TimedLong> m_minute;
+ protected OutPort<TimedLong> m_minuteOut;
+
+ protected TimedLong m_start_val;
+ protected DataRef<TimedLong> m_start;
+ protected OutPort<TimedLong> m_startOut;
+
+ protected TimedLong m_stop_val;
+ protected DataRef<TimedLong> m_stop;
+ protected OutPort<TimedLong> m_stopOut;
+
+ protected TimedLong m_tick_val;
+ protected DataRef<TimedLong> m_tick;
+ protected OutPort<TimedLong> m_tickOut;
+
+ protected Manager m_mgr;
+
+ // </rtc-template>
+
+ // CORBA Port declaration
+ // <rtc-template block="corbaport_declare">
+
+ // </rtc-template>
+
+ // Service declaration
+ // <rtc-template block="service_declare">
+
+ // </rtc-template>
+
+ // Consumer declaration
+ // <rtc-template block="consumer_declare">
+
+ // </rtc-template>
+
+ class DataListener extends ConnectorDataListenerT<TimedLong>{
+ public DataListener(final String name){
+ super(TimedLong.class);
+ m_name = name;
+ }
+
+ public ReturnCode operator(ConnectorBase.ConnectorInfo arg,
+ TimedLong data) {
+ ConnectorBase.ConnectorInfo info =(ConnectorBase.ConnectorInfo)arg;
+ System.out.println("------------------------------");
+ System.out.println("Listener: "+m_name);
+ System.out.println("Profile::name: "+info.name);
+ System.out.println("Profile::id: "+info.id);
+// System.out.println("Profile::properties: ");
+// System.out.println(info.properties);
+ System.out.println("Data: "+data.data);
+ System.out.println("------------------------------");
+ return ReturnCode.NO_CHANGE;
+ }
+ public String m_name;
+ }
+ class Listener extends ConnectorListener{
+ public Listener(final String name){
+ m_name = name;
+ }
+
+ public ReturnCode operator(ConnectorBase.ConnectorInfo arg){
+ System.out.println("------------------------------");
+ System.out.println("Listener: "+m_name);
+ System.out.println("Profile::name: "+arg.name);
+ System.out.println("Profile::id: "+arg.id);
+ String str = new String();
+ //System.out.println("Profile::data_type:"+arg.properties.getProperty("data_type"));
+ System.out.println("Profile::properties:");
+ System.out.print("["+arg.properties.getProperty("interface_type"));
+ System.out.print("]["+arg.properties.getProperty("dataflow_type"));
+ System.out.print("]["+arg.properties.getProperty("subscription_type"));
+ System.out.print("]["+arg.properties.getProperty("publisher.push_policy"));
+ System.out.println("]["+arg.properties.getProperty("timestamp_policy")+"]");
+// System.out.println(arg.properties._dump(str,arg.properties,0));
+ System.out.println("------------------------------");
+ return ReturnCode.NO_CHANGE;
+ }
+ public String m_name;
+ }
+}
+
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/MicrowaveComp.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/MicrowaveComp.java 2017-02-07 06:39:01 UTC (rev 936)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/StaticFsm/MicrowaveComp.java 2017-02-07 07:59:08 UTC (rev 937)
@@ -42,6 +42,7 @@
System.out.println("succeed.");
ComponentProfile prof = comp.get_component_profile();
+/*
System.out.println( "=================================================" );
System.out.println( " Component Profile" );
System.out.println( "-------------------------------------------------" );
@@ -54,10 +55,11 @@
System.out.println( " Other properties " );
NVUtil.dump(new NVListHolder(prof.properties));
System.out.println( "=================================================" );
+*/
// Example
// The following procedure is examples how handle RT-Components.
// These should not be in this function.
-
+/*
// Get the component's object reference
Manager manager = Manager.instance();
RTObject rtobj = null;
@@ -97,6 +99,7 @@
NVUtil.dump( new NVListHolder(port.get_port_profile().properties) );
System.out.println( "----------------" );
}
+*/
}
public static void main(String[] args) {
More information about the openrtm-commit
mailing list