00001
00002
00003 #include <controllers/fitnessFramework/almChoreoAgent.h>
00004 #include <controllers/fitnessFramework/almPuppet.h>
00005 #include "basic/robotActorBase.h"
00006
00007 namespace srAlmende {
00008
00012 AlmChoreoAgent::AlmChoreoAgent(const std::string &name,
00013 srCore::RobotActorBase *robotActor):
00014 AlmPuppet(name, robotActor),
00015 success (0),
00016 rightVel(0),
00017 leftVel(0) {
00018 }
00019
00020 AlmChoreoAgent::~AlmChoreoAgent() {
00021
00022 }
00023
00030 void AlmChoreoAgent::ProcessMessage(const dtGame::Message& message) {
00031 AlmPuppet::ProcessMessage(message);
00032
00033
00034 }
00035
00036 void AlmChoreoAgent::ProcessSensorMessage() {
00037 unsigned long sensorLeft, sensorRight;
00038 getSensor("Front Left DistanceSensor")->evaluate(srCore::MAKE_PARAMETER_VALUE(&sensorLeft));
00039 getSensor("Front Right DistanceSensor")->evaluate(srCore::MAKE_PARAMETER_VALUE(&sensorRight));
00040 sensorLeft = sensorLeft >> 16;
00041 sensorRight = sensorRight >> 16;
00042
00043
00044 dtCore::RefPtr<srExternal::NonEmulationMessage> tcpipMsg = new srExternal::NonEmulationMessage();
00045 GetGameManager()->GetMessageFactory().CreateMessage(
00046 srExternal::NonEmulationMessageType::TCPIP, tcpipMsg);
00047 if (GetGameManager()->GetMessageFactory().IsMessageTypeSupported(
00048 tcpipMsg->GetMessageType())) {
00049 dtCore::UniqueId *id = getBusID();
00050 tcpipMsg->setBusID(id);
00051 std::ostringstream msg_stream;
00052 unsigned char msg_size = 8;
00053 unsigned char origin = 0;
00054 msg_stream << msg_size;
00055 msg_stream << origin;
00056 msg_stream << static_cast<unsigned int>(sensorLeft);
00057 msg_stream << static_cast<unsigned int>(sensorRight);
00058 tcpipMsg->setMessage(msg_stream.str());
00059 tcpipMsg->setMsgType(srExternal::NonEmulationMessageType::SENSOR);
00060
00061 GetGameManager()->SendMessage(*tcpipMsg);
00062
00063 }
00064 }
00065
00066 void AlmChoreoAgent::ProcessActuatorMessage(srExternal::NonEmulationMessage *neMsg) {
00067 std::string msg = neMsg->getMessage();
00068 const char *arr_msg = msg.c_str();
00069 rightVel = arr_msg[0];
00070 leftVel = arr_msg[1];
00071 setActuatorVelocity(getActuator(1), rightVel);
00072 setActuatorVelocity(getActuator(2), leftVel);
00073
00074
00075 ProcessSensorMessage();
00076 }
00077
00078 unsigned char AlmChoreoAgent::getChoreoSignal() {
00079 return success;
00080 }
00081
00082 }
00083
00084