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
44 #include <ArmarXCore/util/tasks.h>
45 #include <ArmarXCore/util/time.h>
46 
47 // RobotAPI
49 #include <RobotAPI/interface/components/ObstacleAvoidance/DynamicObstacleManagerInterface.h>
53 
54 namespace armarx
55 {
56 
58  virtual public PlatformUnit,
59  virtual public RobotStateComponentPluginUser,
60  virtual public ArVizComponentPluginUser,
62  {
63 
64  public:
65  enum class control_mode
66  {
67  position,
68  velocity,
69  none
70  };
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 
125  ~ObstacleAwarePlatformUnit() override;
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;
193  VirtualRobot::RobotPtr m_robot;
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,
204  true};
205 
206  visualization m_viz;
207  };
208 
209 } // namespace armarx
ArVizComponentPlugin.h
armarx::ObstacleAwarePlatformUnit::control_mode
control_mode
Definition: ObstacleAwarePlatformUnit.h:65
time.h
armarx::ObstacleAwarePlatformUnit
Definition: ObstacleAwarePlatformUnit.h:57
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:189
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:191
armarx::navigation::components::laser_scanner_feature_extraction::Circle
memory::Circle Circle
Definition: FeatureExtractor.h:40
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:144
armarx::ObstacleAwarePlatformUnit::ObstacleAwarePlatformUnit
ObstacleAwarePlatformUnit()
armarx::ObstacleAwarePlatformUnit::control_mode::velocity
@ velocity
armarx::ObstacleAwarePlatformUnit::onInitPlatformUnit
void onInitPlatformUnit() override
Definition: ObstacleAwarePlatformUnit.cpp:101
armarx::PlatformUnit
The PlatformUnit class.
Definition: PlatformUnit.h:69
armarx::ArVizComponentPluginUser
Provides a ready-to-use ArViz client arviz as member variable.
Definition: ArVizComponentPlugin.h:35
armarx::ObstacleAwarePlatformUnit::~ObstacleAwarePlatformUnit
~ObstacleAwarePlatformUnit() override
armarx::PIDController
Definition: PIDController.h:43
armarx::ObstacleAwarePlatformUnit::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ObstacleAwarePlatformUnit.cpp:683
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
DebugObserverComponentPlugin.h
max
T max(T t1, T t2)
Definition: gdiam.h:51
armarx::ObstacleAwarePlatformUnit::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ObstacleAwarePlatformUnit.cpp:138
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:217
PlatformUnit.h
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::DebugObserverComponentPluginUser
Definition: DebugObserverComponentPlugin.h:73
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:169
armarx::ObstacleAwarePlatformUnit::onExitPlatformUnit
void onExitPlatformUnit() override
Definition: ObstacleAwarePlatformUnit.cpp:128
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::ObstacleAwarePlatformUnit::onStartPlatformUnit
void onStartPlatformUnit() override
Definition: ObstacleAwarePlatformUnit.cpp:109
armarx::RobotStateComponentPluginUser
Definition: RobotStateComponentPlugin.h:165
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::ObstacleAwarePlatformUnit::stopPlatform
void stopPlatform(const Ice::Current &=Ice::Current{}) override
Definition: ObstacleAwarePlatformUnit.cpp:232
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19