31#include <VirtualRobot/Random.h>
48 const std::string Component::defaultName =
"costmap_example";
75 def->optional(properties.updateSize,
77 "If enabled, the costmap size is updated randomly in each iteration.");
78 def->optional(properties.size,
80 "If updateSize is false, this is the size used for the costmap.");
142 return Component::defaultName;
148 return Component::defaultName;
158 tab.clearAll.setLabel(
"Clear all areas");
163 spinner.setRange(0, 50000);
164 spinner.setDecimals(1);
166 setupSpinner(tab.minX);
167 setupSpinner(tab.minY);
168 setupSpinner(tab.maxX);
169 setupSpinner(tab.maxY);
171 tab.addArea.setLabel(
"Add blocked area");
178 grid.
add(
Label(
"Min X"), {row, 0}).add(tab.minX, {row, 1});
181 grid.
add(
Label(
"Min Y"), {row, 0}).add(tab.minY, {row, 1});
184 grid.
add(
Label(
"Max X"), {row, 0}).add(tab.maxX, {row, 1});
187 grid.
add(
Label(
"Max Y"), {row, 0}).add(tab.maxY, {row, 1});
190 grid.
add(tab.addArea, {row, 0});
201 if (tab.clearAll.wasClicked())
203 std::scoped_lock lock(areasMutex);
204 blockedAreas.clear();
208 if (tab.addArea.wasClicked())
210 std::scoped_lock lock(areasMutex);
211 Eigen::AlignedBox2f area(Eigen::Vector2f(tab.minX.getValue(), tab.minY.getValue()),
212 Eigen::Vector2f(tab.maxX.getValue(), tab.maxY.getValue()));
213 ARMARX_INFO <<
"Add blocked area with min: " << area.min() <<
" and max " << area.max();
214 blockedAreas.emplace_back(area);
247 const int size = properties.updateSize
248 ?
static_cast<int>(VirtualRobot::RandomFloat(500, 2000))
254 .max = Eigen::Vector2f(size, size)};
261 const float centerX = VirtualRobot::RandomFloat(0, size - 1);
262 const float centerY = VirtualRobot::RandomFloat(0, size - 1);
263 const Eigen::Vector2f center(centerX, centerY);
265 for (
int x = 0;
x < grid.rows(); ++
x)
267 for (
int y = 0; y < grid.cols(); ++y)
269 const Eigen::Vector2f cellPos(
x * params.cellSize, y * params.cellSize);
283 std::scoped_lock lock(areasMutex);
284 for (
const auto& area : blockedAreas)
289 for (
int x = minVertex.x();
x <= maxVertex.x(); ++
x)
291 for (
int y = minVertex.y(); y <= maxVertex.y(); ++y)
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
static DateTime Now()
Current time on the virtual clock.
Default component property definition container.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
std::string getName() const
Retrieve name of object.
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Duration waitForNextTick() const
Wait and block until the target period is met.
static Eigen::MatrixXf createUniformGrid(const SceneBounds &sceneBounds, const Costmap::Parameters ¶meters)
Vertex toVertex(const Position &globalPosition) const
Eigen::Matrix< bool, Eigen::Dynamic, Eigen::Dynamic > Mask
void onInitComponent() override
void onDisconnectComponent() override
void RemoteGui_update() override
After calling RemoteGui_startRunningTask, this function is called periodically in a separate thread.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
RunningTask< Component >::pointer_type costmapUpdateTask
void onConnectComponent() override
static std::string GetDefaultName()
Get the component's default name.
void onExitComponent() override
void createRemoteGuiTab()
This function should be called once in onConnect() or when you need to re-create the Remote GUI tab.
std::string getDefaultName() const override
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
double norm(const Point &a)
double distance(const Point &a, const Point &b)
void RemoteGui_startRunningTask()
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})