00001 // File: HawkSimulator.C 00002 // Author: Josh Villbrandt <josh.villbrandt@usc.edu> 00003 // Date: April 2010 00004 00005 #include "Robots/BeoHawk/computer/HawkSimulator.H" 00006 //#include <GL/glut.h> 00007 #include <GL/gl.h> 00008 00009 HawkSimulator::HawkSimulator(std::string myName,int argc, char* argv[]) 00010 : HawkAgent(myName, argc, argv) { 00011 state = LOOP; 00012 } 00013 00014 void HawkSimulator::registerTopics() { 00015 registerPublisher("SensorDataMessage"); 00016 //registerSubscription("ExampleMessage"); 00017 } 00018 00019 bool HawkSimulator::scheduler() { 00020 if(state == LOOP) { 00021 sendSensorDataMessage(); 00022 return true; 00023 } 00024 return false; 00025 } 00026 00027 void HawkSimulator::catchMessage(const HawkMessages::MessagePtr& hawkMessage, 00028 const Ice::Current&) { 00029 /*if(hawkMessage->ice_isA("::HawkMessages::Example")) 00030 { 00031 HawkMessages::ExamplePtr msg = HawkMessages::ExamplePtr::dynamicCast(hawkMessage); 00032 std::cout << "Caught a message! " << msg->name << " says: " << msg->chatter << std::endl; 00033 00034 // Update State / Wake Up Agent 00035 if(msg->name != itsName && msg->chatter == "Hello?") { 00036 state = RECEIVED_FIRST_MESSAGE; 00037 wakeUp(); 00038 } 00039 }*/ 00040 00041 // if we've received a message to move, then move the robot. 00042 if(hawkMessage->ice_isA("::HawkMessages::ControlMoveMessage")) { 00043 HawkMessages::ControlMoveMessagePtr message = HawkMessages::ControlMoveMessagePtr::dynamicCast(hawkMessage); 00044 std::cout << "Caught a ControlMove message." << std::endl; 00045 } 00046 // if we've received a message to land, then land the robot. 00047 else if(hawkMessage->ice_isA("HawkMessages::ControlLandMessage")) { 00048 HawkMessages::ControlLandMessagePtr message = HawkMessages::ControlLandMessagePtr::dynamicCast(hawkMessage); 00049 std::cout << "Caught a ControlLand message." << std::endl; 00050 } 00051 // if we've received a message to take off, then make the robot take flight. 00052 else if(hawkMessage->ice_isA("HawkMessages::ControlTakeOffMessage")) { 00053 HawkMessages::ControlTakeOffMessagePtr message = HawkMessages::ControlTakeOffMessagePtr::dynamicCast(hawkMessage); 00054 std::cout << "Caught a ControlTakeOff message." << std::endl; 00055 } 00056 00057 } 00058 00059 void HawkSimulator::sendSensorDataMessage() { 00060 // Create Message 00061 HawkMessages::SensorDataMessagePtr msg = new HawkMessages::SensorDataMessage; 00062 //msg->name = itsName; 00063 00064 // Send Message 00065 publish("SensorDataMessage", msg); 00066 00067 // Update State 00068 state = LOOP; 00069 00070 // Wait (this should be scheduled in a separate thread later...) 00071 usleep(5000000); 00072 } 00073 00074 int main (int argc, char* argv[]) { 00075 std::cout << "HawkSimulator: starting..." << std::endl; 00076 00077 HawkSimulator agent("HawkSimulator", argc, argv); 00078 agent.start(); 00079 00080 std::cout << "HawkSimulator: all done!" << std::endl; 00081 }