~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to src/srSensor/sampleSensor.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
 * sampleSensor.cpp
 
3
 *
 
4
 *  Created on: Nov 28, 2008
 
5
 *      Author: winkler
 
6
 */
 
7
 
 
8
#include <srSensor/sampleSensor.h>
 
9
 
 
10
namespace srCore {
 
11
 
 
12
SampleSensor::SampleSensor(dtCore::RefPtr<BodyBase> attachedBody,
 
13
                osg::Vec3f translation, osg::Vec3f orientation,
 
14
                std::string name,
 
15
                bool active) :
 
16
 
 
17
                SensorBase(attachedBody,  translation, orientation, name, "SampleSensor", NO_CAMERA, active),
 
18
                sensorValue (0)
 
19
 
 
20
{
 
21
        this->sensorReturnValueType = typeid(float*).name();
 
22
 
 
23
}
 
24
 
 
25
SampleSensor::~SampleSensor() {
 
26
        // TODO Auto-generated destructor stub
 
27
}
 
28
 
 
29
void SampleSensor::getParameter(const std::string &name, ParameterReturnValue  parameter) {
 
30
 
 
31
        ObjectBase::getParameter(name, parameter);
 
32
 
 
33
}
 
34
 
 
35
void SampleSensor::setParameter(const std::string &name, ParameterReturnValue  parameter) {
 
36
 
 
37
        ObjectBase::setParameter(name, parameter);
 
38
}
 
39
 
 
40
void SampleSensor::evaluate(ParameterReturnValue srv) {
 
41
        //check right type
 
42
        if (srv.type!=this->sensorReturnValueType) {
 
43
                std::ostringstream msg; msg.clear(); msg.str("");
 
44
                msg << "Parameter type needs to be " << sensorReturnValueType;
 
45
                msg << " while given type is " << srv.type;
 
46
                LOG_ERROR(msg.str());
 
47
        }
 
48
 
 
49
        float* data = reinterpret_cast<float*> (srv.pValue);
 
50
        *data = this->sensorValue;
 
51
}
 
52
 
 
53
 
 
54
void SampleSensor::requestData() {
 
55
 
 
56
        osg::Vec3f pos, rot;
 
57
 
 
58
        pos = osg::Vec3f(5,5,5); rot = osg::Vec3f(5,5,5);
 
59
        getParameter("AbsPosition", MAKE_PARAMETER_VALUE(&pos));
 
60
        //getParameter("AbsOrientation", MAKE_PARAMETER_VALUE(&rot));
 
61
 
 
62
        sensorValue = myFancySimulatedEnvironmentFunction(pos, rot);
 
63
 
 
64
}
 
65
 
 
66
void SampleSensor::getNewSensorValue() {
 
67
 
 
68
        requestData();
 
69
 
 
70
}
 
71
 
 
72
void SampleSensor::getSensorValue(std::ostream& theStream) const {
 
73
 
 
74
        theStream << sensorValue;
 
75
 
 
76
}
 
77
 
 
78
float SampleSensor::myFancySimulatedEnvironmentFunction(osg::Vec3f pos, osg::Vec3f rot) {
 
79
 
 
80
        return (pos - osg::Vec3f(20,15,0)).length();
 
81
 
 
82
}
 
83
 
 
84
void SampleSensor::update(float deltaSimTme) {
 
85
 
 
86
        if (active && isActiveSensor) requestData();
 
87
 
 
88
}
 
89
 
 
90
}