![](/media/cache/profiles/a4e3073e15bd50e07f194ef7c0d28b01.50x50_q85.jpg)
RTnoV3 is a program which enables your device to communicate with RT-middleware world This is an example for using Timer1ExecutionContext To know RT-middleware, visit: http://www.openrtm.org To know more about RTno, visit: http://ysuga.net/robot_e/rtm_e/rtc_e/1065?lang=en
Dependencies: EthernetNetIf mbed RTnoV3
main.cpp
00001 #include "mbed.h" 00002 00003 00004 00005 /** 00006 * RTno_Template.pde 00007 * RTno is RT-middleware and arduino. 00008 * 00009 * Using RTno, arduino device can communicate any RT-components 00010 * through the RTno-proxy component which is launched in PC. 00011 * Connect arduino with USB, and program with RTno library. 00012 * You do not have to define any protocols to establish communication 00013 * between arduino and PC. 00014 * 00015 * Using RTno, you must not define the function "setup" and "loop". 00016 * Those functions are automatically defined in the RTno libarary. 00017 * You, developers, must define following functions: 00018 * int onInitialize(void); 00019 * int onActivated(void); 00020 * int onDeactivated(void); 00021 * int onExecute(void); 00022 * int onError(void); 00023 * int onReset(void); 00024 * These functions are spontaneously called by the RTno-proxy 00025 * RT-component which is launched in the PC. 00026 * @author Yuki Suga 00027 * This code is written/distributed for public-domain. 00028 */ 00029 00030 #include <RTno.h> 00031 00032 /** 00033 * This function is called at first. 00034 * conf._default.baudrate: baudrate of serial communication 00035 * exec_cxt.periodic.type: reserved but not used. 00036 */ 00037 void rtcconf(config_str& conf, exec_cxt_str& exec_cxt) { 00038 // If you want to use Serial Connection, configure below: 00039 conf._default.connection_type = ConnectionTypeSerialUSB; // USBTX & USBRX (In Windows, Driver must be updated.) 00040 conf._default.baudrate = 57600; // This value is required when you select ConnectionTypeSerial* 00041 00042 exec_cxt.periodic.type = Timer1ExecutionContext; // onExecute is called by Timer1. Period must be specified by 'rate' option. 00043 exec_cxt.periodic.rate = 1; // [Hz] This option is indispensable when type is Timer*ExecutionContext. 00044 } 00045 00046 00047 /** 00048 * Declaration Division: 00049 * 00050 * DataPort and Data Buffer should be placed here. 00051 * 00052 * available data types are as follows: 00053 * TimedLong 00054 * TimedDouble 00055 * TimedFloat 00056 * TimedLongSeq 00057 * TimedDoubleSeq 00058 * TimedFloatSeq 00059 * 00060 * Please refer following comments. If you need to use some ports, 00061 * uncomment the line you want to declare. 00062 **/ 00063 00064 00065 DigitalOut led1(LED1); 00066 DigitalOut led2(LED2); 00067 DigitalOut led3(LED3); 00068 DigitalOut led4(LED4); 00069 00070 ////////////////////////////////////////// 00071 // on_initialize 00072 // 00073 // This function is called in the initialization 00074 // sequence. The sequence is triggered by the 00075 // PC. When the RTnoRTC is launched in the PC, 00076 // then, this function is remotely called 00077 // through the USB cable. 00078 // In on_initialize, usually DataPorts are added. 00079 // 00080 ////////////////////////////////////////// 00081 int RTno::onInitialize() { 00082 /* Data Ports are added in this section. 00083 */ 00084 00085 addInPort(in0In); 00086 00087 // Some initialization (like port direction setting) 00088 led1 = 1; 00089 led2 = 0; 00090 led3 = 0; 00091 led4 = 0; 00092 return RTC_OK; 00093 } 00094 00095 //////////////////////////////////////////// 00096 // on_activated 00097 // This function is called when the RTnoRTC 00098 // is activated. When the activation, the RTnoRTC 00099 // sends message to call this function remotely. 00100 // If this function is failed (return value 00101 // is RTC_ERROR), RTno will enter ERROR condition. 00102 //////////////////////////////////////////// 00103 int RTno::onActivated() { 00104 // Write here initialization code. 00105 led2 = 1; 00106 led3 = 0; 00107 led4 = 0; 00108 return RTC_OK; 00109 } 00110 00111 ///////////////////////////////////////////// 00112 // on_deactivated 00113 // This function is called when the RTnoRTC 00114 // is deactivated. 00115 ///////////////////////////////////////////// 00116 int RTno::onDeactivated() 00117 { 00118 // Write here finalization code. 00119 led2 = 0; 00120 led3 = 0; 00121 led4 = 0; 00122 return RTC_OK; 00123 } 00124 00125 ////////////////////////////////////////////// 00126 // This function is repeatedly called when the 00127 // RTno is in the ACTIVE condition. 00128 // If this function is failed (return value is 00129 // RTC_ERROR), RTno immediately enter into the 00130 // ERROR condition.r 00131 ////////////////////////////////////////////// 00132 int RTno::onExecute() { 00133 static int flag; 00134 if(flag) { 00135 led3 = 1; 00136 flag = 0; 00137 } else { 00138 led3 = 0; 00139 flag++; 00140 } 00141 00142 return RTC_OK; 00143 } 00144 00145 00146 ////////////////////////////////////// 00147 // on_error 00148 // This function is repeatedly called when 00149 // the RTno is in the ERROR condition. 00150 // The ERROR condition can be recovered, 00151 // when the RTno is reset. 00152 /////////////////////////////////////// 00153 int RTno::onError() 00154 { 00155 return RTC_OK; 00156 } 00157 00158 //////////////////////////////////////// 00159 // This function is called when 00160 // the RTno is reset. If on_reset is 00161 // succeeded, the RTno will enter into 00162 // the INACTIVE condition. If failed 00163 // (return value is RTC_ERROR), RTno 00164 // will stay in ERROR condition.ec 00165 /////////////////////////////////////// 00166 int RTno::onReset() 00167 { 00168 return RTC_OK; 00169 }
Generated on Fri Jul 22 2022 08:07:36 by
![doxygen](doxygen.png)