g2o
Loading...
Searching...
No Matches
simulator.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 G. Grisetti, R. Kuemmerle, W. Burgard
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright notice,
10// this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27#include "simulator.h"
28
29#include <cassert>
30#include <iostream>
31namespace g2o {
32using namespace std;
33
34// BaseWorldObject
37 if (_world) return _world->graph();
38 return 0;
39}
40
44
45// BaseRobot
47 if (_world) return _world->graph();
48 return 0;
49}
50
52 assert(graph());
53 std::pair<std::set<BaseSensor*>::iterator, bool> result =
54 _sensors.insert(sensor);
55 if (result.second) {
56 sensor->setRobot(this);
57 sensor->addParameters();
58 }
59 return result.second;
60}
61
63 for (std::set<BaseSensor*>::iterator it = _sensors.begin();
64 it != _sensors.end(); ++it) {
65 BaseSensor* s = *it;
66 s->sense();
67 }
68}
69
70// Sensor
72 if (!_robot) return 0;
73 return _robot->world();
74}
75
77 if (!_robot) return 0;
78 return _robot->graph();
79}
80
81// World
83 std::pair<std::set<BaseRobot*>::iterator, bool> result =
84 _robots.insert(robot);
85 if (result.second) {
86 robot->setWorld(this);
87 }
88 return result.second;
89}
90
92 std::pair<std::set<BaseWorldObject*>::iterator, bool> result =
93 _objects.insert(object);
94 if (result.second) {
95 object->setWorld(this);
96 }
97 if (graph() && object->vertex()) {
98 object->vertex()->setId(_runningId++);
99 graph()->addVertex(object->vertex());
100 }
101 return result.second;
102}
103
105 if (!graph()) return false;
106 param->setId(_paramId);
107 graph()->addParameter(param);
108 _paramId++;
109 return true;
110}
111
112} // namespace g2o
virtual void sense()
Definition simulator.cpp:62
void setWorld(World *world_)
Definition simulator.h:89
World * world() const
Definition simulator.h:90
World * _world
Definition simulator.h:98
bool addSensor(BaseSensor *sensor)
Definition simulator.cpp:51
OptimizableGraph * graph() const
Definition simulator.cpp:46
std::set< BaseSensor * > _sensors
Definition simulator.h:99
BaseRobot * _robot
Definition simulator.h:173
OptimizableGraph * graph() const
Definition simulator.cpp:76
virtual void sense()=0
World * world() const
Definition simulator.cpp:71
virtual void addParameters()
Definition simulator.h:168
void setRobot(BaseRobot *robot_)
Definition simulator.h:163
OptimizableGraph * graph()
Definition simulator.cpp:36
virtual void setVertex(OptimizableGraph::Vertex *vertex_)
Definition simulator.cpp:41
OptimizableGraph::Vertex * _vertex
Definition simulator.h:59
virtual ~BaseWorldObject()
Definition simulator.cpp:35
OptimizableGraph::Vertex * vertex()
Definition simulator.h:54
A general case Vertex for optimization.
void setId(int id_)
Definition parameter.cpp:33
std::set< BaseWorldObject * > _objects
Definition simulator.h:119
bool addRobot(BaseRobot *robot)
Definition simulator.cpp:82
std::set< BaseRobot * > _robots
Definition simulator.h:120
bool addParameter(Parameter *p)
int _runningId
Definition simulator.h:122
bool addWorldObject(BaseWorldObject *worldObject)
Definition simulator.cpp:91
OptimizableGraph * graph()
Definition simulator.h:110
Definition jet.h:876
bool addParameter(Parameter *p)
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)