2
* @file RobotCreator.cpp
5
* This file RobotCreator.cpp is created at Almende B.V. It is open-source software and part
6
* of the Common Hybrid Agent Platform (CHAP). A toolbox with a lot of open-source tools.
7
* Ranging from thread pools, and TCP/IP components to control architectures and learning
8
* algorithms. This software is published under the GNU Lesser General Public license,
9
* but the software is not allowed to be used for military use, within the bio-industry
10
* or for animal experimentation.
12
* @author Anne C. van Rossum
14
* @project Replicator FP7
15
* @company Almende B.V.
24
#include <dtUtil/log.h>
27
#include <srCore/robotCreator.h>
28
#include <srCore/robot/robotActorBase.h>
32
/* **************************************************************************************
33
* Implementation of RobotCreator
34
* **************************************************************************************/
36
RobotCreator::RobotCreator() {
40
RobotCreator::~RobotCreator() {
45
* Function: addRobotToGM
47
* Adds a previously registered robot to the game manager.
49
void RobotCreator::addRobotToGM(int id, const RobotInitData ¶meters, float height) {
51
std::ostringstream msg; msg.clear(); msg.str("");
52
msg << "Add robot of type: " << parameters.type << " to the game manager";
55
dtCore::RefPtr<RobotActorBaseProxy> mRobotActorProxy;
56
dtGame::GameApplication *GA = dtGame::GameApplication::GetInstance(0);
59
if (std::string(parameters.type).find("RobotKIT2") != std::string::npos) {
60
LOG_INFO("Add robot of type RobotKIT2");
61
GA->GetGameManager()->CreateActor("RobotKIT2", "RobotKIT2", mRobotActorProxy);
62
// GA->GetGameManager()->CreateActor(*RobotKITType.get(), mRobotActorProxy);
64
// if (std::string(parameters.type).find(RobotKIT::DEFAULT_NAME) != std::string::npos) {
65
if (std::string(parameters.type).find("RobotKIT") != std::string::npos) {
66
LOG_INFO("Add robot of type RobotKIT");
67
GA->GetGameManager()->CreateActor("RobotKIT", "RobotKIT", mRobotActorProxy);
68
// GA->GetGameManager()->CreateActor(*RobotKITType.get(), mRobotActorProxy);
70
LOG_ERROR("That robot type we do not know!");
73
assert (mRobotActorProxy != NULL);
76
mRobotActorProxy->setID(id);
77
mRobotActorProxy->setConnectorStates(parameters.connectorStates);
78
mRobotActorProxy->SetName(parameters.name);
80
// Set position and rotation
81
osg::Vec3f pos = parameters.pos + osg::Vec3f(0.0, 0.0, height);
82
mRobotActorProxy->SetTranslation(pos);
83
osg::Matrix matrix = osg::Matrix(parameters.quat);
84
mRobotActorProxy->SetRotationFromMatrix(matrix);
86
// Initialise joint angles and sensor values
87
mRobotActorProxy->setInitialJointAngles(parameters.jointAngles);
88
mRobotActorProxy->setSensors(parameters.sensors);
91
msg.clear(); msg.str();
92
msg << "Joint angles are: " << parameters.jointAngles[0];
95
// Finally add actor to the game manager
96
GA->GetGameManager()->AddActor(*mRobotActorProxy, false, false);
99
} // end of namespace srCore