~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to src/srCore/robotCreator.cpp

  • Committer: Anne van Rossum
  • Date: 2010-08-10 15:58:55 UTC
  • Revision ID: anne@gamix-20100810155855-kve7x2vwouagdij9
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file RobotCreator.cpp
 
3
 * @brief 
 
4
 *
 
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.
 
11
 *
 
12
 * @author  Anne C. van Rossum
 
13
 * @date    Jul 13, 2010
 
14
 * @project Replicator FP7
 
15
 * @company Almende B.V.
 
16
 * @case        
 
17
 */
 
18
 
 
19
 
 
20
// General files
 
21
#include <sstream>
 
22
 
 
23
// Delta3D files
 
24
#include <dtUtil/log.h>
 
25
 
 
26
// Robot3D files
 
27
#include <srCore/robotCreator.h>
 
28
#include <srCore/robot/robotActorBase.h>
 
29
 
 
30
namespace srCore {
 
31
 
 
32
/* **************************************************************************************
 
33
 * Implementation of RobotCreator
 
34
 * **************************************************************************************/
 
35
 
 
36
RobotCreator::RobotCreator() {
 
37
 
 
38
}
 
39
 
 
40
RobotCreator::~RobotCreator() {
 
41
 
 
42
}
 
43
 
 
44
/*
 
45
 * Function: addRobotToGM
 
46
 *
 
47
 * Adds a previously registered robot to the game manager.
 
48
 */
 
49
void RobotCreator::addRobotToGM(int id, const RobotInitData &parameters, float height) {
 
50
 
 
51
        std::ostringstream msg; msg.clear(); msg.str("");
 
52
        msg << "Add robot of type: " << parameters.type << " to the game manager";
 
53
        LOG_INFO(msg.str());
 
54
 
 
55
        dtCore::RefPtr<RobotActorBaseProxy> mRobotActorProxy;
 
56
        dtGame::GameApplication *GA = dtGame::GameApplication::GetInstance(0);
 
57
 
 
58
        // Create the robot
 
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);
 
63
        } else 
 
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);
 
69
        } else {
 
70
                LOG_ERROR("That robot type we do not know!");
 
71
                return;
 
72
        }
 
73
        assert (mRobotActorProxy != NULL);
 
74
 
 
75
        // Set identification
 
76
        mRobotActorProxy->setID(id);
 
77
        mRobotActorProxy->setConnectorStates(parameters.connectorStates);
 
78
        mRobotActorProxy->SetName(parameters.name);
 
79
 
 
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);
 
85
 
 
86
        // Initialise joint angles and sensor values
 
87
        mRobotActorProxy->setInitialJointAngles(parameters.jointAngles);
 
88
        mRobotActorProxy->setSensors(parameters.sensors);
 
89
 
 
90
        // Debug information
 
91
        msg.clear(); msg.str();
 
92
        msg << "Joint angles are: " << parameters.jointAngles[0];
 
93
        LOG_DEBUG(msg.str());
 
94
 
 
95
        // Finally add actor to the game manager
 
96
        GA->GetGameManager()->AddActor(*mRobotActorProxy, false, false);
 
97
}
 
98
 
 
99
} // end of namespace srCore