MotionAgents.cc

Go to the documentation of this file.
00001 //
00002 // Copyright 2002,2004 Sony Corporation 
00003 //
00004 // Permission to use, copy, modify, and redistribute this software for
00005 // non-commercial use is hereby granted.
00006 //
00007 // This software is provided "as is" without warranty of any kind,
00008 // either expressed or implied, including but not limited to the
00009 // implied warranties of fitness for a particular purpose.
00010 //
00011 
00012 #include <OPENR/OPENRAPI.h>
00013 #include <OPENR/OSyslog.h>
00014 #include <OPENR/core_macro.h>
00015 #include <MoNetData.h>
00016 #include "MotionAgents.h"
00017 
00018 MotionAgents::MotionAgents() : motionAgentsState(MAS_IDLE),
00019                                moNetAgentManager(), neutralAgent(), mtnAgent()
00020 {
00021 }
00022 
00023 OStatus
00024 MotionAgents::DoInit(const OSystemEvent& event)
00025 {
00026     NEW_ALL_SUBJECT_AND_OBSERVER;
00027     REGISTER_ALL_ENTRY;
00028     SET_ALL_READY_AND_NOTIFY_ENTRY;
00029 
00030     char design[orobotdesignNAME_MAX+1];
00031     OStatus result = OPENR::GetRobotDesign(design);
00032     if (result != oSUCCESS) {
00033         OSYSLOG1((osyslogERROR, "%s : %s %d",
00034                   "MotionAgents::DoInit()",
00035                   "OPENR::GetRobotDesign() FAILED", result));
00036     }
00037 
00038     if (!strcmp(design, "ERS-210") || !strcmp(design, "ERS-220")) {
00039         moNetAgentManager.RegisterMoNetAgent(&neutralAgent);
00040         moNetAgentManager.RegisterMoNetAgent(&mtnAgent);
00041         moNetAgentManager.InitDRX900(); // DRX-900 : Code name of ERS-210/220
00042     } else if (!strcmp(design, "ERS-7")) {
00043         moNetAgentManager.RegisterMoNetAgent(&neutralAgent7);
00044         moNetAgentManager.RegisterMoNetAgent(&mtnAgent7);
00045         moNetAgentManager.RegisterMoNetAgent(&mtnwalkAgent7);
00046         moNetAgentManager.InitDRX1000(); // DRX-1000 : Code name of ERS-7
00047     } else {
00048         OSYSLOG1((osyslogERROR,
00049                   "MotionAgents::DoInit() UNKNOWN ROBOT DESIGN"));
00050     }
00051 
00052     return oSUCCESS;
00053 }
00054 
00055 OStatus
00056 MotionAgents::DoStart(const OSystemEvent& event)
00057 {
00058     moNetAgentManager.Start(subject[sbjEffector]);
00059     motionAgentsState = MAS_START;
00060 
00061     ENABLE_ALL_SUBJECT;
00062     ASSERT_READY_TO_ALL_OBSERVER;
00063 
00064     return oSUCCESS;
00065 }
00066 
00067 OStatus
00068 MotionAgents::DoStop(const OSystemEvent& event)
00069 {
00070     motionAgentsState = MAS_IDLE;
00071 
00072     DISABLE_ALL_SUBJECT;
00073     DEASSERT_READY_TO_ALL_OBSERVER;
00074 
00075     return oSUCCESS;
00076 }
00077 
00078 OStatus
00079 MotionAgents::DoDestroy(const OSystemEvent& event)
00080 {
00081     DELETE_ALL_SUBJECT_AND_OBSERVER;
00082     return oSUCCESS;
00083 }
00084 
00085 void
00086 MotionAgents::NotifyCommand(const ONotifyEvent& event)
00087 {
00088     OSYSDEBUG(("MotionAgents::NotifyCommand()\n"));
00089 
00090     if (motionAgentsState == MAS_START) {
00091 
00092         MoNetAgentResult result;
00093         moNetAgentManager.NotifyCommand(event, &result);
00094         if (result.status != monetSUCCESS) {
00095             subject[sbjResult]->SetData(&result, sizeof(result));
00096             subject[sbjResult]->NotifyObservers();
00097         }
00098 
00099         observer[event.ObsIndex()]->AssertReady();
00100     }
00101 }
00102 
00103 void
00104 MotionAgents::ReadyEffector(const OReadyEvent& event)
00105 {
00106     OSYSDEBUG(("MotionAgents::ReadyEffector()\n"));
00107 
00108     if (motionAgentsState == MAS_START) {
00109 
00110         MoNetAgentResult result;
00111         moNetAgentManager.ReadyEffector(event, &result);
00112         if (result.status != monetSUCCESS) {
00113             subject[sbjResult]->SetData(&result, sizeof(result));
00114             subject[sbjResult]->NotifyObservers();
00115         }
00116     }
00117 }

Generated on Sun Dec 2 23:04:29 2007 for openSDK by  doxygen 1.3.9.1