ObstacleAvoidingPlatformUnit.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::ObstacleAvoidingPlatformUnit
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 <deque>
29#include <mutex>
30#include <string>
31#include <tuple>
32#include <vector>
33
34// Eigen
35#include <Eigen/Core>
36
37// Ice
38#include <IceUtil/Time.h>
39
40// Simox
41#include <VirtualRobot/Nodes/RobotNode.h>
42
43// ArmarX
47
48// RobotAPI
50#include <RobotAPI/interface/components/ObstacleAvoidance/ObstacleAvoidanceInterface.h>
54
55namespace armarx
56{
57
59 virtual public PlatformUnit,
60 virtual public RobotStateComponentPluginUser,
61 virtual public ArVizComponentPluginUser,
63 {
64
65 public:
72
73 private:
74 struct control_loop
75 {
76 std::mutex mutex;
79 IceUtil::Time cycle_time = IceUtil::Time::milliSeconds(10);
80 };
81
82 struct control_data
83 {
84 std::mutex mutex;
85 Eigen::Vector2f target_pos;
86 float target_ori;
87 Eigen::Vector2f target_vel;
88 float target_rot_vel;
89 float target_dist;
90 float target_angular_dist;
91 Eigen::Vector2f agent_pos;
92 float agent_ori;
93 double agent_safety_margin = 0;
94 float min_vel_near_target = 50;
95 float min_vel_general = 100;
96 float max_vel = 200;
97 float max_rot_vel = 0.3;
98 float pos_near_threshold = 250;
99 float pos_reached_threshold = 8;
100 float ori_reached_threshold = 0.1;
101 float kp = 3.5;
102 std::deque<std::tuple<Eigen::Vector2f, Eigen::Vector2f>> vel_history;
103 unsigned amount_smoothing = 50;
104 unsigned amount_max_vel = 3;
105 float adaptive_max_vel_exp = 0;
106 };
107
108 struct visualization
109 {
110 Eigen::Vector3f start;
111 std::vector<Eigen::Vector3f> path;
112 bool enabled = true;
113 };
114
115 struct velocities
116 {
117 Eigen::Vector2f target_local;
118 Eigen::Vector2f modulated_local;
119 Eigen::Vector2f target_global;
120 Eigen::Vector2f modulated_global;
121 float target_rot;
122 float err_dist;
123 float err_angular_dist;
124 };
125
126 public:
128
130
131 virtual std::string getDefaultName() const override;
132
133 virtual void moveTo(float target_pos_x,
134 float target_pos_y,
135 float target_ori,
136 float pos_reached_threshold,
137 float ori_reached_threshold,
138 const Ice::Current& = Ice::Current{}) override;
139
140 virtual void move(float target_vel_x,
141 float target_vel_y,
142 float target_rot_vel,
143 const Ice::Current& = Ice::Current{}) override;
144
145 virtual void moveRelative(float target_pos_delta_x,
146 float target_pos_delta_y,
147 float target_delta_ori,
148 float pos_reached_threshold,
149 float ori_reached_threshold,
150 const Ice::Current& = Ice::Current{}) override;
151
152 virtual void setMaxVelocities(float max_pos_vel,
153 float max_rot_vel,
154 const Ice::Current& = Ice::Current{}) override;
155
156 virtual void stopPlatform(const Ice::Current& = Ice::Current{}) override;
157
158 protected:
159 virtual void onInitPlatformUnit() override;
160
161 virtual void onStartPlatformUnit() override;
162
163 virtual void onExitPlatformUnit() override;
164
166
167 private:
168 void schedule_high_level_control_loop(control_mode mode);
169
170 void high_level_control_loop();
171
172 velocities get_velocities();
173
174 void update_agent_dependent_values();
175
176 Eigen::Vector2f get_target_velocity() const;
177
178 float get_target_rotational_velocity() const;
179
180 bool target_position_reached() const;
181
182 bool target_orientation_reached() const;
183
184 bool target_reached() const;
185
186 Eigen::Vector2f post_process_vel(const Eigen::Vector2f& target_vel,
187 const Eigen::Vector2f& modulated_vel);
188
189 Eigen::Vector2f calculate_mean_modulated_vel() const;
190
191 unsigned calculate_adaptive_smoothing_buffer_size() const;
192
193 float calculate_adaptive_max_vel() const;
194
195 void visualize();
196
197 void visualize(const velocities& vels);
198
199 bool is_near_target(const Eigen::Vector2f& control_velocity) const noexcept;
200
201 public:
202 static const std::string default_name;
203
204 private:
205 PlatformUnitInterfacePrx m_platform;
206 ObstacleAvoidanceInterfacePrx m_obstacle_avoidance;
208
209 ObstacleAvoidingPlatformUnit::control_loop m_control_loop;
210 ObstacleAvoidingPlatformUnit::control_data m_control_data;
211
212 mutable PIDController m_rot_pid_controller{1.0, 0.00009, 0.0};
213
214 visualization m_viz;
215 };
216
217} // namespace armarx
virtual void moveRelative(float target_pos_delta_x, float target_pos_delta_y, float target_delta_ori, float pos_reached_threshold, float ori_reached_threshold, const Ice::Current &=Ice::Current{}) override
virtual ~ObstacleAvoidingPlatformUnit() override
virtual PropertyDefinitionsPtr createPropertyDefinitions() override
virtual void stopPlatform(const Ice::Current &=Ice::Current{}) override
virtual void move(float target_vel_x, float target_vel_y, float target_rot_vel, const Ice::Current &=Ice::Current{}) override
virtual void setMaxVelocities(float max_pos_vel, float max_rot_vel, const Ice::Current &=Ice::Current{}) override
virtual std::string getDefaultName() const override
Retrieve default name of component.
virtual void moveTo(float target_pos_x, float target_pos_y, float target_ori, float pos_reached_threshold, float ori_reached_threshold, const Ice::Current &=Ice::Current{}) override
The PlatformUnit class.
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.