00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <orte.h>
00013 #ifdef CONFIG_ORTE_RTL
00014 #include <linux/module.h>
00015 #include <posix/pthread.h>
00016 #define printf rtl_printf
00017 #elif defined CONFIG_ORTE_RTAI
00018 #include <linux/module.h>
00019 #include <rtai/compat.h>
00020 #define printf rt_printk
00021 #else
00022 #include <stdio.h>
00023 #endif
00024
00025 #include <RobotType.h>
00026 #include <RobotTypeArr.h>
00027
00028 ORTEDomain *d;
00029 ORTEPublication *publisherDO;
00030 ORTEPublication *publisherMotor;
00031 ORTEPublication *publisherServa;
00032 ORTEPublication *publisherSharpShort;
00033 ORTEPublication *publisherSharpLong;
00034
00035
00036
00037 unsigned int accelRecv[3];
00038 stateDigIn stateDI;
00039 uint16_t stateIR;
00040 unsigned char stateIR2;
00041 bool stateDO[8];
00042 short int motorSpeedCmd[2];
00043 uint16_t sharpToRecv[4];
00044
00045
00046 motionStatus ms;
00047 motionSpeed mspeed;
00048 stateInnerIR sir;
00049 sharpLongs ss1;
00050 sharpShorts ss2;
00051 stateServa serva;
00052 position pozice;
00053
00054 void recvPositionCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam);
00055 void recvSharp1CallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam);
00056 void recvSharp2CallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam);
00057 void recvDICallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam);
00058 void recvIRCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam);
00059 void recvAccelCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam);
00060 void sendCallBackServo(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam);
00061 void recvPosCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam);
00062 void recvMsCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam);
00063
00064 void *publisherCreateSensLong(void *arg) {
00065 NtpTime persistence, delay;
00066 robomon* ptr = (robomon*)arg;
00067
00068 sharpLongs_type_register(d);
00069 NTPTIME_BUILD(persistence,3);
00070 NTPTIME_BUILD(delay,1);
00071 publisherSharpLong=ORTEPublicationCreate(d, "sharpSouper", "sharpLongs", &(ptr->sharpySouper), &persistence, 2, NULL, arg, &delay);
00072 return arg;
00073 }
00074
00075 void *publisherCreateSensShort(void *arg) {
00076 NtpTime persistence, delay;
00077 robomon* ptr = (robomon*)arg;
00078
00079 sharpShorts_type_register(d);
00080 NTPTIME_BUILD(persistence,3);
00081 NTPTIME_BUILD(delay,1);
00082 publisherSharpShort=ORTEPublicationCreate(d, "sharpLahve", "sharpShorts", &(ptr->sharpyLahve), &persistence, 2, NULL, arg, &delay);
00083 return arg;
00084 }
00085
00086 void *publisherCreateServo(void *arg) {
00087 NtpTime persistence, delay;
00088
00089 stateServa_type_register(d);
00090 NTPTIME_BUILD(persistence,3);
00091 NTPTIME_BUILD(delay,1);
00092 publisherServa=ORTEPublicationCreate(d, "serva", "stateServa", &serva, &persistence, 1, NULL, arg, &delay);
00093 return arg;
00094 }
00095
00096 void *publisherDOCreate(void *arg) {
00097 NtpTime persistence, delay;
00098
00099 ORTETypeRegisterAdd(d,"DOMsg",NULL,NULL,NULL,sizeof(stateDO));
00100 NTPTIME_BUILD(persistence,3);
00101 NTPTIME_BUILD(delay,1);
00102 publisherDO=ORTEPublicationCreate(d, "DO", "DOMsg", &stateDO, &persistence, 1, NULL, NULL, &delay);
00103 return arg;
00104 }
00105
00106 void *publisherMotorCreate(void *arg) {
00107 NtpTime persistence, delay;
00108
00109 motionSpeed_type_register(d);
00110 NTPTIME_BUILD(persistence,3);
00111 NTPTIME_BUILD(delay,1);
00112 publisherMotor=ORTEPublicationCreate(d, "motor", "motionSpeed", &mspeed, &persistence, 1, NULL, NULL, &delay);
00113 return arg;
00114 }
00115
00116 void *subscriberPositionCreate(void *arg) {
00117 ORTESubscription *s;
00118 NtpTime deadline,minimumSeparation;
00119
00120 position_type_register(d);
00121 NTPTIME_BUILD(deadline,10);
00122 NTPTIME_BUILD(minimumSeparation,0);
00123 s=ORTESubscriptionCreate(d, IMMEDIATE, BEST_EFFORTS, "pos", "position", &pozice, &deadline, &minimumSeparation, recvPosCallBack, arg, IPADDRESS_INVALID);
00124 return arg;
00125 }
00126
00127
00128 void *subscriberSharp1Create(void *arg) {
00129 ORTESubscription *s;
00130 NtpTime deadline,minimumSeparation;
00131
00132 sharpLongs_type_register(d);
00133 NTPTIME_BUILD(deadline,10);
00134 NTPTIME_BUILD(minimumSeparation,0);
00135 s=ORTESubscriptionCreate(d, IMMEDIATE, BEST_EFFORTS, "sharpSouper", "sharpLongs", &ss1,
00136 &deadline, &minimumSeparation, recvSharp1CallBack, arg, IPADDRESS_INVALID);
00137 return arg;
00138 }
00139
00140 void * subscriberSharp2Create(void *arg) {
00141 ORTESubscription *s;
00142 NtpTime deadline,minimumSeparation;
00143
00144 sharpShorts_type_register(d);
00145 NTPTIME_BUILD(deadline,10);
00146 NTPTIME_BUILD(minimumSeparation,0);
00147 s=ORTESubscriptionCreate(d, IMMEDIATE, BEST_EFFORTS, "sharpLahve", "sharpShorts", &ss2, &deadline, &minimumSeparation, recvSharp2CallBack, arg, IPADDRESS_INVALID);
00148 return arg;
00149 }
00150
00151 void *subscriberCreateDI(void *arg) {
00152 ORTESubscription *s;
00153 NtpTime deadline,minimumSeparation;
00154
00155 stateDigIn_type_register(d);
00156 NTPTIME_BUILD(deadline,10);
00157 NTPTIME_BUILD(minimumSeparation,0);
00158 s=ORTESubscriptionCreate(d, IMMEDIATE, BEST_EFFORTS, "DI", "stateDigIn", &stateDI, &deadline, &minimumSeparation, recvDICallBack, arg, IPADDRESS_INVALID);
00159 return arg;
00160 }
00161
00162 void *subscriberCreateIR(void *arg) {
00163 ORTESubscription *s;
00164 NtpTime deadline,minimumSeparation;
00165
00166 stateInnerIR_type_register(d);
00167 NTPTIME_BUILD(deadline,10);
00168 NTPTIME_BUILD(minimumSeparation,0);
00169 s=ORTESubscriptionCreate(d, IMMEDIATE, BEST_EFFORTS, "IR", "stateInnerIR", &sir, &deadline, &minimumSeparation, recvIRCallBack, arg, IPADDRESS_INVALID);
00170 return arg;
00171 }
00172
00173
00174 void *subscriberCreateMotionStatus(void *arg) {
00175 ORTESubscription *s;
00176 NtpTime deadline,minimumSeparation;
00177
00178 motionStatus_type_register(d);
00179 NTPTIME_BUILD(deadline,10);
00180 NTPTIME_BUILD(minimumSeparation,0);
00181 s=ORTESubscriptionCreate(d, IMMEDIATE, BEST_EFFORTS, "motion_status", "motionStatus", &ms, &deadline, &minimumSeparation, recvMsCallBack, arg, IPADDRESS_INVALID);
00182 return arg;
00183 }
00184
00185 void *subscriberAccelCreate(void *arg) {
00186 ORTESubscription *s;
00187 NtpTime deadline,minimumSeparation;
00188
00189 ORTETypeRegisterAdd(d,"AccelMsg",NULL,NULL,NULL,sizeof(accelRecv));
00190 NTPTIME_BUILD(deadline,10);
00191 NTPTIME_BUILD(minimumSeparation,0);
00192 s=ORTESubscriptionCreate(d, IMMEDIATE, BEST_EFFORTS, "accel", "AccelMsg", &accelRecv, &deadline, &minimumSeparation, recvAccelCallBack, arg, IPADDRESS_INVALID);
00193 return arg;
00194 }
00195
00196 void recvPosCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
00197 robomon* ptr = (robomon*)recvCallBackParam;
00198 QEvent* event = new QEvent(EVENT_POS);
00199 switch (info->status) {
00200 case NEW_DATA:
00201 QCoreApplication::postEvent(ptr, event);
00202 break;
00203 case DEADLINE:
00204 printf("pos deadline occurred\n");
00205 break;
00206 }
00207 }
00208
00209 void recvSharp1CallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
00210 robomon* ptr = (robomon*)recvCallBackParam;
00211 QEvent* event = new QEvent(EVENT_SHARP);
00212 switch (info->status) {
00213 case NEW_DATA:
00214 QCoreApplication::postEvent(ptr, event);
00215 break;
00216 case DEADLINE:
00217 printf("sharp1 deadline occurred\n");
00218 break;
00219 }
00220 }
00221
00222 void recvSharp2CallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
00223 robomon* ptr = (robomon*)recvCallBackParam;
00224 QEvent* event = new QEvent(EVENT_SHARP);
00225 switch (info->status) {
00226 case NEW_DATA:
00227 QCoreApplication::postEvent(ptr, event);
00228 break;
00229 case DEADLINE:
00230 printf("sharp2 deadline occurred\n");
00231 break;
00232 }
00233 }
00234
00235 void recvDICallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
00236 robomon* ptr = (robomon*)recvCallBackParam;
00237 QEvent* event = new QEvent(EVENT_DI);
00238 switch (info->status) {
00239 case NEW_DATA:
00240 QCoreApplication::postEvent(ptr, event);
00241 break;
00242 case DEADLINE:
00243 printf("DI deadline occurred\n");
00244 break;
00245 }
00246 }
00247
00248 void recvIRCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
00249 robomon* ptr = (robomon*)recvCallBackParam;
00250 QEvent* event = new QEvent(EVENT_IR);
00251 switch (info->status) {
00252 case NEW_DATA:
00253 QCoreApplication::postEvent(ptr, event);
00254 break;
00255 case DEADLINE:
00256 printf("IR deadline occurred\n");
00257 break;
00258 }
00259 }
00260
00261 void recvMsCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
00262
00263
00264 switch (info->status) {
00265 case NEW_DATA:
00266
00267
00268 break;
00269 case DEADLINE:
00270 printf("motion status deadline occurred\n");
00271 break;
00272 }
00273 }
00274
00275 void recvAccelCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
00276 unsigned int *instance=(unsigned int*)vinstance;
00277
00278
00279 switch (info->status) {
00280 case NEW_DATA:
00281 printf("accel: %d, %d, %d\n",instance[0]>>16,instance[1]>>16,instance[2]>>16);
00282
00283
00284 break;
00285 case DEADLINE:
00286 printf("accel deadline occurred\n");
00287 break;
00288 }
00289 }
00290
00291 void recvMotionStatusCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
00292
00293
00294 switch (info->status) {
00295 case NEW_DATA:
00296 printf("motion status: %x, %x\n",ms.err_left,ms.err_right);
00297
00298
00299 break;
00300 case DEADLINE:
00301 printf("motion status deadline occurred\n");
00302 break;
00303 }
00304 }
00305
00306 void *orte_function( void *ptr )
00307 {
00308 ORTEInit();
00309 ORTEVerbositySetOptions("ALL.0");
00310 d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
00311
00312 if (!d) {
00313 printf("ORTEDomainAppCreate failed!\n");
00314 }
00315 publisherCreateServo(ptr);
00316
00317 publisherDOCreate(NULL);
00318 publisherMotorCreate(NULL);
00319 subscriberCreateDI(ptr);
00320 subscriberCreateIR(ptr);
00321 subscriberSharp1Create(ptr);
00322 subscriberSharp2Create(ptr);
00323 subscriberPositionCreate(ptr);
00324 subscriberCreateDI(ptr);
00325
00326 return NULL;
00327 }