DSObstacleAvoidance.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::ArmarXObjects::DSObstacleAvoidance
17 * @author Christian R. G. Dreher <c.dreher@kit.edu>
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
24#pragma once
25
26
27// STD/STL
28#include <array>
29#include <deque>
30#include <map>
31#include <mutex>
32#include <shared_mutex>
33#include <string>
34#include <vector>
35
36// Eigen
37#include <Eigen/Geometry>
38
39// Ice
40#include <Ice/Current.h>
41
42// DynamicObstacleAvoidance
43#include <DynamicObstacleAvoidance/Agent.hpp>
44#include <DynamicObstacleAvoidance/Environment.hpp>
45
46// ArmarX
50
51// RobotAPI
52#include <RobotAPI/interface/components/ObstacleAvoidance/DSObstacleAvoidanceInterface.h>
54
55namespace armarx
56{
57
59 virtual public Component,
60 virtual public DSObstacleAvoidanceInterface,
61 virtual public ArVizComponentPluginUser
62 {
63
64 public:
66
67 /**
68 * @see armarx::ManagedIceObject::getDefaultName()
69 */
70 std::string getDefaultName() const override;
71
72 dsobstacleavoidance::Config getConfig(const Ice::Current& = Ice::emptyCurrent) override;
73
74 void updateObstacle(const obstacledetection::Obstacle& obstacle,
75 const Ice::Current& = Ice::emptyCurrent) override;
76
77 std::vector<obstacledetection::Obstacle>
78 getObstacles(const Ice::Current& = Ice::emptyCurrent) override;
79
80 void removeObstacle(const std::string& obstacle_name,
81 const Ice::Current& = Ice::emptyCurrent) override;
82
83 Eigen::Vector3f modulateVelocity(const obstacleavoidance::Agent& agent,
84 const Ice::Current& = Ice::emptyCurrent) override;
85
86 void updateEnvironment(const Ice::Current& = Ice::emptyCurrent) override;
87
88 void writeDebugPlots(const std::string& filename,
89 const Ice::Current& = Ice::emptyCurrent) override;
90
91 protected:
92 /**
93 * @see armarx::ManagedIceObject::onInitComponent()
94 */
95 void onInitComponent() override;
96
97 /**
98 * @see armarx::ManagedIceObject::onConnectComponent()
99 */
100 void onConnectComponent() override;
101
102 /**
103 * @see armarx::ManagedIceObject::onDisconnectComponent()
104 */
105 void onDisconnectComponent() override;
106
107 /**
108 * @see armarx::ManagedIceObject::onExitComponent()
109 */
110 void onExitComponent() override;
111
112 /**
113 * @see PropertyUser::createPropertyDefinitions()
114 */
116
117 private:
118 void sanity_check_obstacle(const obstacledetection::Obstacle& obstacle) const;
119
120 void run_watchdog();
121
122 void run_visualization();
123
124 public:
125 static const std::string default_name;
126
127 private:
128 struct visualization
129 {
130 bool enabled = true;
132 unsigned task_interval = 20;
133 mutable std::mutex mutex;
134 bool needs_update = true;
135 };
136
137 struct watchdog
138 {
139 bool enabled = true;
141 unsigned task_interval = 100;
142 IceUtil::Time threshold = IceUtil::Time::milliSeconds(500);
143 };
144
145 struct dynamic_obstacle_avoidance
146 {
147 dsobstacleavoidance::Config cfg;
148 DynamicObstacleAvoidance::Environment env;
149 mutable std::shared_mutex mutex;
150 std::string load_obstacles_from_file =
151 "RobotAPI/obstacle_avoidance/r034_2d_scene_obstacles.json";
152 };
153
154 struct buffer
155 {
156 enum class update_type
157 {
158 update,
159 removal
160 };
161
162 struct update
163 {
164 IceUtil::Time time;
165 std::string name;
166 DSObstacleAvoidance::buffer::update_type type;
167 };
168
169 mutable std::mutex mutex;
170 std::vector<DSObstacleAvoidance::buffer::update> update_log;
171 std::map<std::string, obstacledetection::Obstacle> obstacles;
172 bool needs_env_update;
173 IceUtil::Time last_env_update;
174 };
175
176 DSObstacleAvoidance::visualization m_vis;
177
178 DSObstacleAvoidance::watchdog m_watchdog;
179
180 DSObstacleAvoidance::dynamic_obstacle_avoidance m_doa;
181
182 DSObstacleAvoidance::buffer m_buf;
183 };
184
185} // namespace armarx
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Definition Component.cpp:66
dsobstacleavoidance::Config getConfig(const Ice::Current &=Ice::emptyCurrent) override
void updateObstacle(const obstacledetection::Obstacle &obstacle, const Ice::Current &=Ice::emptyCurrent) override
static const std::string default_name
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void updateEnvironment(const Ice::Current &=Ice::emptyCurrent) override
void writeDebugPlots(const std::string &filename, const Ice::Current &=Ice::emptyCurrent) override
Eigen::Vector3f modulateVelocity(const obstacleavoidance::Agent &agent, const Ice::Current &=Ice::emptyCurrent) override
void removeObstacle(const std::string &obstacle_name, const Ice::Current &=Ice::emptyCurrent) override
std::string getDefaultName() const override
std::vector< obstacledetection::Obstacle > getObstacles(const Ice::Current &=Ice::emptyCurrent) override
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
DSObstacleAvoidance::buffer::update_type type