ObstacleAwarePlatformUnit.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::ObstacleAwarePlatformUnit
17 * @author Christian R. G. Dreher <c.dreher@kit.edu>
18 * @date 2021
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 <mutex>
29#include <string>
30#include <vector>
31
32// Eigen
33#include <Eigen/Core>
34
35// Ice
36#include <IceUtil/Time.h>
37
38// Simox
39#include <VirtualRobot/Safety.h>
40#include <VirtualRobot/VirtualRobot.h>
41
42// ArmarX
46
47// RobotAPI
49#include <RobotAPI/interface/components/ObstacleAvoidance/DynamicObstacleManagerInterface.h>
53
54namespace armarx
55{
56
58 virtual public PlatformUnit,
59 virtual public RobotStateComponentPluginUser,
60 virtual public ArVizComponentPluginUser,
62 {
63
64 public:
71
72 private:
73 struct control_loop
74 {
75 std::mutex mutex;
78 IceUtil::Time cycle_time = IceUtil::Time::milliSeconds(10);
79 };
80
81 struct control_data
82 {
83 std::mutex mutex;
84 Eigen::Vector2f target_pos;
85 float target_ori;
86 Eigen::Vector2f target_vel;
87 float target_rot_vel;
88 float target_dist;
89 float target_angular_dist;
90 Eigen::Vector2f agent_pos;
91 float agent_ori;
92 double agent_safety_margin = 0;
93 float min_vel_near_target = 50;
94 float min_vel_general = 100;
95 float max_vel = 200;
96 float max_rot_vel = 0.3;
97 float pos_near_threshold = 250;
98 float pos_reached_threshold = 8;
99 float ori_reached_threshold = 0.1;
100 float kp = 3.5;
101 };
102
103 struct visualization
104 {
105 Eigen::Vector3f start;
106 std::vector<Eigen::Vector3f> path;
107 bool enabled = true;
108 VirtualRobot::Circle boundingCircle;
109 };
110
111 struct velocities
112 {
113 Eigen::Vector2f target_local;
114 Eigen::Vector2f modulated_local;
115 Eigen::Vector2f target_global;
116 Eigen::Vector2f modulated_global;
117 float target_rot;
118 float err_dist;
119 float err_angular_dist;
120 };
121
122 public:
124
126
127 std::string getDefaultName() const override;
128
129 void moveTo(float target_pos_x,
130 float target_pos_y,
131 float target_ori,
132 float pos_reached_threshold,
133 float ori_reached_threshold,
134 const Ice::Current& = Ice::Current{}) override;
135
136 void move(float target_vel_x,
137 float target_vel_y,
138 float target_rot_vel,
139 const Ice::Current& = Ice::Current{}) override;
140
141 void moveRelative(float target_pos_delta_x,
142 float target_pos_delta_y,
143 float target_delta_ori,
144 float pos_reached_threshold,
145 float ori_reached_threshold,
146 const Ice::Current& = Ice::Current{}) override;
147
148 void setMaxVelocities(float max_pos_vel,
149 float max_rot_vel,
150 const Ice::Current& = Ice::Current{}) override;
151
152 void stopPlatform(const Ice::Current& = Ice::Current{}) override;
153
154 protected:
155 void onInitPlatformUnit() override;
156
157 void onStartPlatformUnit() override;
158
159 void onExitPlatformUnit() override;
160
162
163 private:
164 void schedule_high_level_control_loop(control_mode mode);
165
166 void high_level_control_loop();
167
168 velocities get_velocities();
169
170 void update_agent_dependent_values();
171
172 Eigen::Vector2f get_target_velocity() const;
173
174 float get_target_rotational_velocity() const;
175
176 bool target_position_reached() const;
177
178 bool target_orientation_reached() const;
179
180 bool target_reached() const;
181
182 void visualize();
183
184 void visualize(const velocities& vels);
185
186 bool is_near_target(const Eigen::Vector2f& control_velocity) const noexcept;
187
188 public:
189 static const std::string default_name;
190
191 private:
192 PlatformUnitInterfacePrx m_platform;
194 DynamicObstacleManagerInterfacePrx m_obsman;
195
196 ObstacleAwarePlatformUnit::control_loop m_control_loop;
197 ObstacleAwarePlatformUnit::control_data m_control_data;
198
199 mutable PIDController m_rot_pid_controller{1.0,
200 0.00009,
201 0.0,
202 std::numeric_limits<double>::max(),
203 std::numeric_limits<double>::max(),
204 true};
205
206 visualization m_viz;
207 };
208
209} // namespace armarx
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
PropertyDefinitionsPtr createPropertyDefinitions() override
void stopPlatform(const Ice::Current &=Ice::Current{}) override
void move(float target_vel_x, float target_vel_y, float target_rot_vel, const Ice::Current &=Ice::Current{}) override
void setMaxVelocities(float max_pos_vel, float max_rot_vel, const Ice::Current &=Ice::Current{}) override
std::string getDefaultName() const override
Retrieve default name of component.
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.