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 <deque>
29 #include <string>
30 #include <tuple>
31 #include <mutex>
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 #include <VirtualRobot/Safety.h>
43 
44 // ArmarX
46 #include <ArmarXCore/util/tasks.h>
47 #include <ArmarXCore/util/time.h>
48 
49 // RobotAPI
51 #include <RobotAPI/interface/components/ObstacleAvoidance/DynamicObstacleManagerInterface.h>
55 
56 
57 namespace armarx
58 {
59 
61  virtual public PlatformUnit,
62  virtual public RobotStateComponentPluginUser,
63  virtual public ArVizComponentPluginUser,
65  {
66 
67  public:
68 
69  enum class control_mode
70  {
71  position,
72  velocity,
73  none
74  };
75 
76  private:
77 
78  struct control_loop
79  {
80  std::mutex mutex;
83  IceUtil::Time cycle_time = IceUtil::Time::milliSeconds(10);
84  };
85 
86  struct control_data
87  {
88  std::mutex mutex;
89  Eigen::Vector2f target_pos;
90  float target_ori;
91  Eigen::Vector2f target_vel;
92  float target_rot_vel;
93  float target_dist;
94  float target_angular_dist;
95  Eigen::Vector2f agent_pos;
96  float agent_ori;
97  double agent_safety_margin = 0;
98  float min_vel_near_target = 50;
99  float min_vel_general = 100;
100  float max_vel = 200;
101  float max_rot_vel = 0.3;
102  float pos_near_threshold = 250;
103  float pos_reached_threshold = 8;
104  float ori_reached_threshold = 0.1;
105  float kp = 3.5;
106  };
107 
108  struct visualization
109  {
110  Eigen::Vector3f start;
111  std::vector<Eigen::Vector3f> path;
112  bool enabled = true;
113  VirtualRobot::Circle boundingCircle;
114  };
115 
116  struct velocities
117  {
118  Eigen::Vector2f target_local;
119  Eigen::Vector2f modulated_local;
120  Eigen::Vector2f target_global;
121  Eigen::Vector2f modulated_global;
122  float target_rot;
123  float err_dist;
124  float err_angular_dist;
125  };
126 
127  public:
128 
130 
132  override;
133 
134  std::string
136  const override;
137 
138  void
139  moveTo(
140  float target_pos_x,
141  float target_pos_y,
142  float target_ori,
143  float pos_reached_threshold,
144  float ori_reached_threshold,
145  const Ice::Current& = Ice::Current{})
146  override;
147 
148  void
149  move(
150  float target_vel_x,
151  float target_vel_y,
152  float target_rot_vel,
153  const Ice::Current& = Ice::Current{})
154  override;
155 
156  void
157  moveRelative(
158  float target_pos_delta_x,
159  float target_pos_delta_y,
160  float target_delta_ori,
161  float pos_reached_threshold,
162  float ori_reached_threshold,
163  const Ice::Current& = Ice::Current{})
164  override;
165 
166  void
168  float max_pos_vel,
169  float max_rot_vel,
170  const Ice::Current& = Ice::Current{})
171  override;
172 
173  void
174  stopPlatform(const Ice::Current& = Ice::Current{})
175  override;
176 
177  protected:
178 
179  void
181  override;
182 
183  void
185  override;
186 
187  void
189  override;
190 
193  override;
194 
195  private:
196 
197  void
198  schedule_high_level_control_loop(control_mode mode);
199 
200  void
201  high_level_control_loop();
202 
203  velocities
204  get_velocities();
205 
206  void
207  update_agent_dependent_values();
208 
209  Eigen::Vector2f
210  get_target_velocity()
211  const;
212 
213  float
214  get_target_rotational_velocity()
215  const;
216 
217  bool
218  target_position_reached()
219  const;
220 
221  bool
222  target_orientation_reached()
223  const;
224 
225  bool
226  target_reached()
227  const;
228 
229  void
230  visualize();
231 
232  void
233  visualize(const velocities& vels);
234 
235  bool
236  is_near_target(const Eigen::Vector2f& control_velocity)
237  const
238  noexcept;
239 
240  public:
241 
242  static const std::string default_name;
243 
244  private:
245 
246  PlatformUnitInterfacePrx m_platform;
247  VirtualRobot::RobotPtr m_robot;
248  DynamicObstacleManagerInterfacePrx m_obsman;
249 
250  ObstacleAwarePlatformUnit::control_loop m_control_loop;
251  ObstacleAwarePlatformUnit::control_data m_control_data;
252 
253  mutable PIDController m_rot_pid_controller{1.0, 0.00009, 0.0, std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), true};
254 
255  visualization m_viz;
256 
257  };
258 
259 }
ArVizComponentPlugin.h
armarx::ObstacleAwarePlatformUnit::control_mode
control_mode
Definition: ObstacleAwarePlatformUnit.h:69
time.h
armarx::ObstacleAwarePlatformUnit
Definition: ObstacleAwarePlatformUnit.h:60
RobotStateComponentPlugin.h
armarx::ObstacleAwarePlatformUnit::control_mode::none
@ none
armarx::ObstacleAwarePlatformUnit::control_mode::position
@ position
armarx::ObstacleAwarePlatformUnit::default_name
static const std::string default_name
Definition: ObstacleAwarePlatformUnit.h:242
armarx::ObstacleAwarePlatformUnit::moveRelative
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
Definition: ObstacleAwarePlatformUnit.cpp:205
armarx::navigation::components::laser_scanner_feature_extraction::Circle
memory::Circle Circle
Definition: FeatureExtractor.h:42
armarx::ObstacleAwarePlatformUnit::moveTo
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
Definition: ObstacleAwarePlatformUnit.cpp:154
armarx::ObstacleAwarePlatformUnit::ObstacleAwarePlatformUnit
ObstacleAwarePlatformUnit()
armarx::ObstacleAwarePlatformUnit::control_mode::velocity
@ velocity
armarx::ObstacleAwarePlatformUnit::onInitPlatformUnit
void onInitPlatformUnit() override
Definition: ObstacleAwarePlatformUnit.cpp:106
armarx::PlatformUnit
The PlatformUnit class.
Definition: PlatformUnit.h:70
armarx::ArVizComponentPluginUser
Provides a ready-to-use ArViz client arviz as member variable.
Definition: ArVizComponentPlugin.h:36
armarx::ObstacleAwarePlatformUnit::~ObstacleAwarePlatformUnit
~ObstacleAwarePlatformUnit() override
armarx::PIDController
Definition: PIDController.h:43
armarx::ObstacleAwarePlatformUnit::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ObstacleAwarePlatformUnit.cpp:723
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
DebugObserverComponentPlugin.h
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::ObstacleAwarePlatformUnit::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ObstacleAwarePlatformUnit.cpp:146
tasks.h
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
PIDController.h
armarx::ObstacleAwarePlatformUnit::setMaxVelocities
void setMaxVelocities(float max_pos_vel, float max_rot_vel, const Ice::Current &=Ice::Current{}) override
Definition: ObstacleAwarePlatformUnit.cpp:234
PlatformUnit.h
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::DebugObserverComponentPluginUser
Definition: DebugObserverComponentPlugin.h:82
armarx::ObstacleAwarePlatformUnit::move
void move(float target_vel_x, float target_vel_y, float target_rot_vel, const Ice::Current &=Ice::Current{}) override
Definition: ObstacleAwarePlatformUnit.cpp:181
armarx::ObstacleAwarePlatformUnit::onExitPlatformUnit
void onExitPlatformUnit() override
Definition: ObstacleAwarePlatformUnit.cpp:135
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::ObstacleAwarePlatformUnit::onStartPlatformUnit
void onStartPlatformUnit() override
Definition: ObstacleAwarePlatformUnit.cpp:115
armarx::RobotStateComponentPluginUser
Definition: RobotStateComponentPlugin.h:167
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ObstacleAwarePlatformUnit::stopPlatform
void stopPlatform(const Ice::Current &=Ice::Current{}) override
Definition: ObstacleAwarePlatformUnit.cpp:251
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18