Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sw/armarx/robot-api
  • uwkce_singer/robot-api
  • untcg_hofmann/robot-api
  • ulqba_korosakov/RobotAPI
4 results
Show changes
Showing
with 593 additions and 313 deletions
......@@ -156,6 +156,16 @@ namespace armarx
return SkillManagerComponentPluginUser::executeSkill(info, current);
}
skills::manager::dto::SkillExecutionID
SkillsMemory::executeSkillAsync(const skills::manager::dto::SkillExecutionRequest& info,
const Ice::Current& current)
{
auto e = skills::SkillExecutionRequest::FromIce(info);
skillExecutionRequestCoreSegment.addSkillExecutionRequest(e);
return SkillManagerComponentPluginUser::executeSkillAsync(info, current);
}
void
SkillsMemory::updateStatusForSkill(const skills::provider::dto::SkillStatusUpdate& update,
const skills::callback::dto::ProviderID& providerId,
......@@ -166,14 +176,27 @@ namespace armarx
skillEventCoreSegment.addSkillUpdateEvent(u);
}
IceUtil::Optional<skills::manager::dto::SkillStatusUpdate>
SkillsMemory::getSkillExecutionStatus(const skills::manager::dto::SkillExecutionID& executionId,
const Ice::Current& current)
{
auto eid = skills::SkillExecutionID::FromIce(executionId);
auto op = this->skillEventCoreSegment.getSkillStatusUpdate(eid);
if (op.has_value())
{
return op->toManagerIce();
}
return {};
}
skills::manager::dto::SkillStatusUpdateMap
SkillsMemory::getLatestSkillExecutionStatuses(int n, const Ice::Current& current)
SkillsMemory::getSkillExecutionStatuses(const Ice::Current& current)
{
auto m = skillEventCoreSegment.getLatestSkillEvents(n);
skills::manager::dto::SkillStatusUpdateMap ret;
for (const auto& [k, v] : m)
auto updates = this->skillEventCoreSegment.getSkillStatusUpdates();
for (const auto& [k, v] : updates)
{
ret[k.toManagerIce()] = v.toManagerIce();
ret.insert({k.toManagerIce(), v.toManagerIce()});
}
return ret;
}
......
......@@ -85,12 +85,21 @@ namespace armarx
executeSkill(const skills::manager::dto::SkillExecutionRequest& info,
const Ice::Current& current) override;
skills::manager::dto::SkillExecutionID
executeSkillAsync(const skills::manager::dto::SkillExecutionRequest& info,
const Ice::Current& current) override;
void updateStatusForSkill(const skills::provider::dto::SkillStatusUpdate& update,
const skills::callback::dto::ProviderID& id,
const Ice::Current& current) override;
IceUtil::Optional<skills::manager::dto::SkillStatusUpdate>
getSkillExecutionStatus(const skills::manager::dto::SkillExecutionID& executionId,
const Ice::Current& current) override;
skills::manager::dto::SkillStatusUpdateMap
getLatestSkillExecutionStatuses(int n, const Ice::Current& current) override;
getSkillExecutionStatuses(const Ice::Current& current) override;
// WritingInterface interface
armem::data::CommitResult commit(const armem::data::Commit& commit,
......
......@@ -13,10 +13,20 @@ set(COMPONENT_LIBS
set(SOURCES
SkillProviderExample.cpp
HelloWorld.cpp
Incomplete.cpp
Chaining.cpp
Callback.cpp
Timeout.cpp
)
set(HEADERS
SkillProviderExample.h
HelloWorld.h
Incomplete.h
Chaining.h
Callback.h
Timeout.h
)
armarx_add_component("${SOURCES}" "${HEADERS}")
......
#include "Callback.h"
namespace armarx::skills::provider
{
CallbackSkill::CallbackSkill() : SimpleSkill(GetSkillDescription())
{
}
SkillDescription
CallbackSkill::GetSkillDescription()
{
return SkillDescription{.skillId = skills::SkillID{.skillName = "ShowMeCallbacks"},
.description = "This skill does shows callbacks",
.timeout = armarx::core::time::Duration::MilliSeconds(1000)};
}
Skill::MainResult
CallbackSkill::main(const MainInput& in)
{
ARMARX_IMPORTANT << "Logging three updates via the callback";
auto up1 = std::make_shared<aron::data::Dict>();
up1->addElement("updateInfo", std::make_shared<aron::data::String>("Update 1"));
in.callback(skills::SkillStatus::Running, up1);
auto up2 = std::make_shared<aron::data::Dict>();
up2->addElement("updateInfo", std::make_shared<aron::data::String>("Update 2"));
in.callback(skills::SkillStatus::Running, up2);
auto up3 = std::make_shared<aron::data::Dict>();
up3->addElement("updateInfo", std::make_shared<aron::data::String>("Update 3"));
in.callback(skills::SkillStatus::Running, up3);
return {TerminatedSkillStatus::Succeeded, nullptr};
}
} // namespace armarx::skills::provider
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
// RobotAPI
#include <RobotAPI/libraries/skills/provider/SimpleSkill.h>
namespace armarx::skills::provider
{
class CallbackSkill : public SimpleSkill
{
public:
CallbackSkill();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main(const MainInput&) final;
};
} // namespace armarx::skills::provider
#include "Chaining.h"
namespace armarx::skills::provider
{
ChainingSkill::ChainingSkill() : SimpleSkill(GetSkillDescription())
{
}
SkillDescription
ChainingSkill::GetSkillDescription()
{
return SkillDescription{.skillId = armarx::skills::SkillID{.skillName = "ChainingSkill"},
.description =
"This skill calls the Timeout skill three times. The last "
"execution is aborted due to a timeout of this skill.",
.timeout = armarx::core::time::Duration::MilliSeconds(5000)};
}
Skill::MainResult
ChainingSkill::main(const MainInput& in)
{
SkillProxy prx(
manager,
skills::SkillID{.providerId = *getSkillId().providerId, .skillName = "Timeout"});
ARMARX_INFO << "CALL PROXY FIRST TIME";
callSubskill(prx);
ARMARX_INFO << "CALL PROXY SECOND TIME";
callSubskill(prx);
ARMARX_INFO << "CALL PROXY THIRD TIME";
callSubskill(prx);
this->throwIfSkillShouldTerminate();
return {TerminatedSkillStatus::Succeeded, nullptr};
}
} // namespace armarx::skills::provider
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
// RobotAPI
#include <RobotAPI/libraries/skills/provider/SimpleSkill.h>
namespace armarx::skills::provider
{
class ChainingSkill : public SimpleSkill
{
public:
ChainingSkill();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main(const MainInput&) final;
};
} // namespace armarx::skills::provider
#include "HelloWorld.h"
#include <RobotAPI/libraries/aron/converter/json/NLohmannJSONConverter.h>
#include <RobotAPI/libraries/aron/core/type/variant/container/Object.h>
#include <RobotAPI/libraries/aron/core/type/variant/primitive/String.h>
namespace armarx::skills::provider
{
HelloWorldSkill::HelloWorldSkill() :
SimpleSpecializedSkill<skills::Example::HelloWorldAcceptedType>(GetSkillDescription())
{
}
SkillDescription
HelloWorldSkill::GetSkillDescription()
{
armarx::skills::Example::HelloWorldAcceptedType root_profile_params;
root_profile_params.some_float = 5;
root_profile_params.some_int = 42;
root_profile_params.some_text = "YOLO";
root_profile_params.some_optional_text = "OPTIONAL";
root_profile_params.some_list_of_matrices.push_back(Eigen::Matrix3f::Zero());
root_profile_params.some_matrix = Eigen::Matrix3f::Zero();
return SkillDescription{.skillId = skills::SkillID{.skillName = "HelloWorld"},
.description = "This skill logs a message on ARMARX_IMPORTANT",
.rootProfileDefaults = root_profile_params.toAron(),
.timeout = armarx::core::time::Duration::MilliSeconds(1000),
.parametersType =
armarx::skills::Example::HelloWorldAcceptedType::ToAronType(),
.resultType = armarx::skills::Example::HelloWorldAcceptedType::ToAronType()};
}
Skill::MainResult
HelloWorldSkill::main(const SpecializedMainInput& in)
{
ARMARX_IMPORTANT << "Hi, from the Hello World Skill.\n"
<< "I received the following data: \n"
<< aron::data::converter::AronNlohmannJSONConverter::ConvertToNlohmannJSON(
in.parameters.toAron())
.dump(2)
<< "\n"
<< "(executed at: " << IceUtil::Time::now() << ")";
return {TerminatedSkillStatus::Succeeded, in.parameters.toAron()};
}
} // namespace armarx::skills::provider
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
// RobotAPI
#include <RobotAPI/components/skills/SkillProviderExample/aron/HelloWorldAcceptedType.aron.generated.h>
#include <RobotAPI/libraries/skills/provider/SimpleSpecializedSkill.h>
namespace armarx::skills::provider
{
// Skills:
class HelloWorldSkill : public SimpleSpecializedSkill<skills::Example::HelloWorldAcceptedType>
{
public:
HelloWorldSkill();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main(const SpecializedMainInput& in) final;
};
} // namespace armarx::skills::provider
#include "Incomplete.h"
#include <RobotAPI/components/skills/SkillProviderExample/aron/HelloWorldAcceptedType.aron.generated.h>
#include "HelloWorld.h"
namespace armarx::skills::provider
{
IncompleteSkill::IncompleteSkill() : SimpleSkill(GetSkillDescription())
{
}
SkillDescription
IncompleteSkill::GetSkillDescription()
{
auto d = HelloWorldSkill::GetSkillDescription();
return SkillDescription{.skillId = {.skillName = "IncompleteSkill"},
.description = d.description,
.timeout = d.timeout + armarx::core::time::Duration::Seconds(2),
.parametersType = d.parametersType};
}
Skill::PrepareResult
IncompleteSkill::prepare()
{
if (!first_prepared)
{
first_prepared = true;
// set parameters after two seconds...
std::thread foo(
[&]()
{
auto d = HelloWorldSkill::GetSkillDescription();
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
this->setParameters(d.rootProfileDefaults);
});
foo.detach();
}
return {.status = ActiveOrTerminatedSkillStatus::Succeeded};
}
Skill::MainResult
IncompleteSkill::main(const MainInput& in)
{
auto s = HelloWorldSkill();
return s.mainOfSkill();
}
} // namespace armarx::skills::provider
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
// RobotAPI
#include <RobotAPI/libraries/skills/provider/SimpleSkill.h>
namespace armarx::skills::provider
{
class IncompleteSkill : public SimpleSkill
{
public:
IncompleteSkill();
static SkillDescription GetSkillDescription();
private:
Skill::PrepareResult prepare() final;
Skill::MainResult main(const MainInput&) final;
std::atomic_bool first_prepared = false;
};
} // namespace armarx::skills::provider
#include "SkillProviderExample.h"
#include <RobotAPI/components/skills/SkillProviderExample/aron/HelloWorldAcceptedType.aron.generated.h>
#include <RobotAPI/libraries/aron/converter/json/NLohmannJSONConverter.h>
#include <RobotAPI/libraries/aron/core/type/variant/container/Object.h>
#include <RobotAPI/libraries/aron/core/type/variant/primitive/String.h>
namespace armarx::skills::provider
{
HelloWorldSkill::HelloWorldSkill() : Skill(GetSkillDescription())
{
}
SkillDescription
HelloWorldSkill::GetSkillDescription()
{
armarx::skills::Example::HelloWorldAcceptedType root_profile_params;
root_profile_params.some_float = 5;
root_profile_params.some_int = 42;
root_profile_params.some_text = "YOLO";
root_profile_params.some_list_of_matrices.push_back(Eigen::Matrix3f::Zero());
//default_params.some_matrix = Eigen::Matrix3f::Zero();
return SkillDescription{{"HelloWorld"},
"This skill logs a message on ARMARX_IMPORTANT",
root_profile_params.toAron(),
armarx::core::time::Duration::MilliSeconds(1000),
armarx::skills::Example::HelloWorldAcceptedType::ToAronType()};
}
Skill::MainResult
HelloWorldSkill::main()
{
ARMARX_IMPORTANT << "Hi, from the Hello World Skill.\n"
<< "I received the following data: \n"
<< aron::data::converter::AronNlohmannJSONConverter::ConvertToNlohmannJSON(
parameters)
.dump(2)
<< "\n"
<< "Type fulfilled? "
<< parameters->fullfillsType(
armarx::skills::Example::HelloWorldAcceptedType::ToAronType())
<< "\n"
<< "(executed at: " << IceUtil::Time::now() << ")";
return {TerminatedSkillStatus::Succeeded, nullptr};
}
IncompleteSkill::IncompleteSkill() : Skill(GetSkillDescription())
{
}
SkillDescription
IncompleteSkill::GetSkillDescription()
{
auto d = HelloWorldSkill::GetSkillDescription();
return SkillDescription{{"IncompleteSkill"},
d.description,
{},
d.timeout + armarx::core::time::Duration::Seconds(2),
d.acceptedType};
}
Skill::PrepareResult
IncompleteSkill::prepare()
{
if (!first_prepared)
{
first_prepared = true;
std::thread foo(
[&]()
{
auto d = HelloWorldSkill::GetSkillDescription();
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
this->setParameters(d.rootProfileParameterization);
});
foo.detach();
}
auto s = HelloWorldSkill();
s.setParameters(this->getParameters());
s.mainOfSkill();
return {.status = ActiveOrTerminatedSkillStatus::Succeeded};
}
Skill::MainResult
IncompleteSkill::main()
{
auto s = HelloWorldSkill();
s.setParameters(this->getParameters());
return s.mainOfSkill();
}
ChainingSkill::ChainingSkill() : Skill(GetSkillDescription())
{
}
SkillDescription
ChainingSkill::GetSkillDescription()
{
return SkillDescription{{"ChainingSkill"},
"This skill calls the HelloWorld skill three times.",
{},
armarx::core::time::Duration::MilliSeconds(3000),
nullptr};
}
Skill::MainResult
ChainingSkill::main()
{
armarx::skills::Example::HelloWorldAcceptedType exec1;
armarx::skills::Example::HelloWorldAcceptedType exec2;
armarx::skills::Example::HelloWorldAcceptedType exec3;
exec1.some_text = "Hello from the ChainingSkill 1";
exec2.some_text = "Hello from the ChainingSkill 2";
exec3.some_text = "Hello from the ChainingSkill 3";
SkillProxy skillExecPrx(
manager, skills::SkillID(skills::ProviderID("SkillProviderExample"), "HelloWorld"));
skillExecPrx.executeSkill(getSkillId().toString(), exec1.toAron());
skillExecPrx.executeSkill(getSkillId().toString(), exec2.toAron());
skillExecPrx.executeSkill(getSkillId().toString(), exec3.toAron());
return {TerminatedSkillStatus::Succeeded, nullptr};
}
TimeoutSkill::TimeoutSkill() :
PeriodicSkill(GetSkillDescription(), armarx::core::time::Frequency::Hertz(5))
{
}
SkillDescription
TimeoutSkill::GetSkillDescription()
{
return SkillDescription{{"Timeout"},
"This fails with timeout reached",
{},
armarx::core::time::Duration::MilliSeconds(5000),
nullptr};
}
PeriodicSkill::StepResult
TimeoutSkill::step()
{
// do heavy work
std::this_thread::sleep_for(std::chrono::milliseconds(500));
return {ActiveOrTerminatedSkillStatus::Running, nullptr};
}
CallbackSkill::CallbackSkill() : Skill(GetSkillDescription())
{
}
SkillDescription
CallbackSkill::GetSkillDescription()
{
return SkillDescription{{"ShowMeCallbacks"},
"This skill does shows callbacks",
{},
armarx::core::time::Duration::MilliSeconds(1000),
nullptr};
}
Skill::MainResult
CallbackSkill::main()
{
ARMARX_IMPORTANT << "Logging three updates via the callback";
auto up1 = std::make_shared<aron::data::Dict>();
up1->addElement("updateInfo", std::make_shared<aron::data::String>("Update 1"));
this->callback(skills::SkillStatus::Running, up1);
auto up2 = std::make_shared<aron::data::Dict>();
up2->addElement("updateInfo", std::make_shared<aron::data::String>("Update 2"));
this->callback(skills::SkillStatus::Running, up2);
auto up3 = std::make_shared<aron::data::Dict>();
up3->addElement("updateInfo", std::make_shared<aron::data::String>("Update 3"));
this->callback(skills::SkillStatus::Running, up3);
return {TerminatedSkillStatus::Succeeded, nullptr};
}
SkillProviderExample::SkillProviderExample() : SkillProviderComponentPluginUser()
{
}
......@@ -213,11 +30,10 @@ namespace armarx::skills::provider
// Add another lambda example skill
{
skills::SkillDescription fooDesc({"Foo"},
"This skill does exactly nothing.",
nullptr,
armarx::core::time::Duration::MilliSeconds(1000),
nullptr);
skills::SkillDescription fooDesc{.skillId = SkillID{.skillName = "Foo"},
.description = "This skill does exactly nothing.",
.timeout =
armarx::core::time::Duration::MilliSeconds(1000)};
addSkillFactory(fooDesc,
[]()
{
......
......@@ -28,69 +28,15 @@
// RobotAPI
#include <RobotAPI/libraries/skills/provider/SkillProviderComponentPlugin.h>
#include <RobotAPI/libraries/skills/provider/SkillProxy.h>
#include "Callback.h"
#include "Chaining.h"
#include "HelloWorld.h"
#include "Incomplete.h"
#include "Timeout.h"
namespace armarx::skills::provider
{
// Skills:
class HelloWorldSkill : public Skill
{
public:
HelloWorldSkill();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main() final;
};
class IncompleteSkill : public Skill
{
public:
IncompleteSkill();
static SkillDescription GetSkillDescription();
private:
Skill::PrepareResult prepare() final;
Skill::MainResult main() final;
std::atomic_bool first_prepared = false;
};
class ChainingSkill : public Skill
{
public:
ChainingSkill();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main() final;
};
class TimeoutSkill : public PeriodicSkill
{
public:
TimeoutSkill();
static SkillDescription GetSkillDescription();
private:
PeriodicSkill::StepResult step() final;
};
class CallbackSkill : public Skill
{
public:
CallbackSkill();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main() final;
};
/**
* @defgroup Component-ExampleClient ExampleClient
* @ingroup RobotAPI-Components
......
#include "Timeout.h"
namespace armarx::skills::provider
{
TimeoutSkill::TimeoutSkill() :
PeriodicSkill(GetSkillDescription(), armarx::core::time::Frequency::Hertz(5))
{
}
SkillDescription
TimeoutSkill::GetSkillDescription()
{
return SkillDescription{.skillId = SkillID{.skillName = "Timeout"},
.description = "This fails with timeout reached",
.timeout = armarx::core::time::Duration::MilliSeconds(2000)};
}
PeriodicSkill::StepResult
TimeoutSkill::step()
{
// do heavy work
std::this_thread::sleep_for(std::chrono::milliseconds(50));
return {ActiveOrTerminatedSkillStatus::Running, nullptr};
}
} // namespace armarx::skills::provider
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
// RobotAPI
#include <RobotAPI/libraries/skills/provider/PeriodicSkill.h>
namespace armarx::skills::provider
{
class TimeoutSkill : public PeriodicSkill
{
public:
TimeoutSkill();
static SkillDescription GetSkillDescription();
private:
PeriodicSkill::StepResult step() final;
};
} // namespace armarx::skills::provider
......@@ -22,6 +22,9 @@
<ObjectChild key='some_text'>
<String />
</ObjectChild>
<ObjectChild key='some_optional_text'>
<String optional="True" />
</ObjectChild>
<ObjectChild key='some_list_of_matrices'>
<List>
......
......@@ -24,45 +24,51 @@
#include "GraspCandidateObserver.h"
//#include <ArmarXCore/core/checks/ConditionCheckEqualsPoseWithTolerance.h>
#include <ArmarXCore/observers/checks/ConditionCheckUpdated.h>
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
#include <ArmarXCore/observers/checks/ConditionCheckEquals.h>
#include <ArmarXCore/observers/checks/ConditionCheckInRange.h>
#include <ArmarXCore/observers/checks/ConditionCheckLarger.h>
#include <ArmarXCore/observers/checks/ConditionCheckSmaller.h>
#include <ArmarXCore/observers/checks/ConditionCheckUpdated.h>
#include <RobotAPI/libraries/core/checks/ConditionCheckEqualsPoseWithTolerance.h>
#include <RobotAPI/libraries/core/checks/ConditionCheckMagnitudeChecks.h>
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
#define TCP_POSE_CHANNEL "TCPPose"
#define TCP_TRANS_VELOCITIES_CHANNEL "TCPVelocities"
using namespace armarx;
using namespace armarx::grasping;
GraspCandidateObserver::GraspCandidateObserver() : graspCandidateWriter(memoryNameSystem())
GraspCandidateObserver::GraspCandidateObserver()
{
}
void GraspCandidateObserver::onInitObserver()
void
GraspCandidateObserver::onInitObserver()
{
usingTopic(getProperty<std::string>("GraspCandidatesTopicName").getValue());
offeringTopic(getProperty<std::string>("ConfigTopicName").getValue());
}
void GraspCandidateObserver::onConnectObserver()
void
GraspCandidateObserver::onConnectObserver()
{
configTopic = getTopic<GraspCandidateProviderInterfacePrx>(getProperty<std::string>("ConfigTopicName").getValue());
graspCandidateWriter.connect();
configTopic = getTopic<GraspCandidateProviderInterfacePrx>(
getProperty<std::string>("ConfigTopicName").getValue());
graspCandidateWriter.connect(memoryNameSystem());
}
PropertyDefinitionsPtr GraspCandidateObserver::createPropertyDefinitions()
PropertyDefinitionsPtr
GraspCandidateObserver::createPropertyDefinitions()
{
return PropertyDefinitionsPtr(new GraspCandidateObserverPropertyDefinitions(
getConfigIdentifier()));
return PropertyDefinitionsPtr(
new GraspCandidateObserverPropertyDefinitions(getConfigIdentifier()));
}
bool GraspCandidateObserver::FilterMatches(const CandidateFilterConditionPtr& filter, const std::string& providerName, const GraspCandidatePtr& candidate)
bool
GraspCandidateObserver::FilterMatches(const CandidateFilterConditionPtr& filter,
const std::string& providerName,
const GraspCandidatePtr& candidate)
{
if (filter->providerName != "*" && filter->providerName != providerName)
{
......@@ -72,11 +78,13 @@ bool GraspCandidateObserver::FilterMatches(const CandidateFilterConditionPtr& fi
{
return false;
}
if (filter->approach != AnyApproach && (candidate->executionHints == 0 || filter->approach != candidate->executionHints->approach))
if (filter->approach != AnyApproach &&
(candidate->executionHints == 0 || filter->approach != candidate->executionHints->approach))
{
return false;
}
if (filter->preshape != AnyAperture && (candidate->executionHints == 0 || filter->preshape != candidate->executionHints->preshape))
if (filter->preshape != AnyAperture &&
(candidate->executionHints == 0 || filter->preshape != candidate->executionHints->preshape))
{
return false;
}
......@@ -87,7 +95,8 @@ bool GraspCandidateObserver::FilterMatches(const CandidateFilterConditionPtr& fi
return true;
}
std::string GraspCandidateObserver::ObjectTypeToString(objpose::ObjectType type)
std::string
GraspCandidateObserver::ObjectTypeToString(objpose::ObjectType type)
{
switch (type)
{
......@@ -102,7 +111,8 @@ std::string GraspCandidateObserver::ObjectTypeToString(objpose::ObjectType type)
}
}
void GraspCandidateObserver::handleProviderUpdate(const std::string& providerName, int candidateCount)
void
GraspCandidateObserver::handleProviderUpdate(const std::string& providerName, int candidateCount)
{
if (updateCounters.count(providerName) == 0)
{
......@@ -118,26 +128,40 @@ void GraspCandidateObserver::handleProviderUpdate(const std::string& providerNam
{
offerChannel(providerName, "Channel of " + providerName);
}
offerOrUpdateDataField(providerName, "updateCounter", Variant(updateCounters[providerName]), "Counter that increases for each update");
offerOrUpdateDataField(providerName, "candidateCount", Variant(candidateCount), "Number of provided candiates");
offerOrUpdateDataField(providerName,
"updateCounter",
Variant(updateCounters[providerName]),
"Counter that increases for each update");
offerOrUpdateDataField(
providerName, "candidateCount", Variant(candidateCount), "Number of provided candiates");
}
void GraspCandidateObserver::reportGraspCandidates(const std::string& providerName, const GraspCandidateSeq& candidates, const Ice::Current&)
void
GraspCandidateObserver::reportGraspCandidates(const std::string& providerName,
const GraspCandidateSeq& candidates,
const Ice::Current&)
{
std::unique_lock lock(dataMutex);
this->candidates[providerName] = candidates;
graspCandidateWriter.commitGraspCandidateSeq(candidates, armarx::armem::Time::Now(), providerName);
graspCandidateWriter.commitGraspCandidateSeq(
candidates, armarx::armem::Time::Now(), providerName);
handleProviderUpdate(providerName, candidates.size());
}
void GraspCandidateObserver::reportBimanualGraspCandidates(const std::string& providerName, const BimanualGraspCandidateSeq& candidates, const Ice::Current&)
void
GraspCandidateObserver::reportBimanualGraspCandidates(const std::string& providerName,
const BimanualGraspCandidateSeq& candidates,
const Ice::Current&)
{
std::unique_lock lock(dataMutex);
this->bimanualCandidates[providerName] = candidates;
handleProviderUpdate(providerName, candidates.size());
}
void GraspCandidateObserver::reportProviderInfo(const std::string& providerName, const ProviderInfoPtr& info, const Ice::Current&)
void
GraspCandidateObserver::reportProviderInfo(const std::string& providerName,
const ProviderInfoPtr& info,
const Ice::Current&)
{
std::unique_lock lock(dataMutex);
providers[providerName] = info;
......@@ -154,36 +178,37 @@ void GraspCandidateObserver::reportProviderInfo(const std::string& providerName,
offerOrUpdateDataField(providerName, "objectType", ObjectTypeToString(info->objectType), "");
}
InfoMap GraspCandidateObserver::getAvailableProvidersWithInfo(const Ice::Current&)
InfoMap
GraspCandidateObserver::getAvailableProvidersWithInfo(const Ice::Current&)
{
std::unique_lock lock(dataMutex);
return providers;
}
StringSeq GraspCandidateObserver::getAvailableProviderNames(const Ice::Current&)
StringSeq
GraspCandidateObserver::getAvailableProviderNames(const Ice::Current&)
{
std::unique_lock lock(dataMutex);
return getAvailableProviderNames();
}
ProviderInfoPtr GraspCandidateObserver::getProviderInfo(const std::string& providerName, const Ice::Current&)
ProviderInfoPtr
GraspCandidateObserver::getProviderInfo(const std::string& providerName, const Ice::Current&)
{
std::unique_lock lock(dataMutex);
checkHasProvider(providerName);
return providers[providerName];
}
bool GraspCandidateObserver::hasProvider(const std::string& providerName, const Ice::Current& c)
bool
GraspCandidateObserver::hasProvider(const std::string& providerName, const Ice::Current& c)
{
std::unique_lock lock(dataMutex);
return hasProvider(providerName);
}
GraspCandidateSeq GraspCandidateObserver::getAllCandidates(const Ice::Current&)
GraspCandidateSeq
GraspCandidateObserver::getAllCandidates(const Ice::Current&)
{
std::unique_lock lock(dataMutex);
GraspCandidateSeq all;
......@@ -194,11 +219,16 @@ GraspCandidateSeq GraspCandidateObserver::getAllCandidates(const Ice::Current&)
return all;
}
GraspCandidateSeq GraspCandidateObserver::getCandidatesByProvider(const std::string& providerName, const Ice::Current& c)
GraspCandidateSeq
GraspCandidateObserver::getCandidatesByProvider(const std::string& providerName,
const Ice::Current& c)
{
return getCandidatesByProviders(Ice::StringSeq{providerName});
}
GraspCandidateSeq GraspCandidateObserver::getCandidatesByProviders(const Ice::StringSeq& providerNames, const Ice::Current& c)
GraspCandidateSeq
GraspCandidateObserver::getCandidatesByProviders(const Ice::StringSeq& providerNames,
const Ice::Current& c)
{
std::unique_lock lock(dataMutex);
GraspCandidateSeq all;
......@@ -213,7 +243,9 @@ GraspCandidateSeq GraspCandidateObserver::getCandidatesByProviders(const Ice::St
return all;
}
GraspCandidateSeq GraspCandidateObserver::getCandidatesByFilter(const CandidateFilterConditionPtr& filter, const Ice::Current&)
GraspCandidateSeq
GraspCandidateObserver::getCandidatesByFilter(const CandidateFilterConditionPtr& filter,
const Ice::Current&)
{
std::unique_lock lock(dataMutex);
GraspCandidateSeq matching;
......@@ -230,20 +262,26 @@ GraspCandidateSeq GraspCandidateObserver::getCandidatesByFilter(const CandidateF
return matching;
}
Ice::Int GraspCandidateObserver::getUpdateCounterByProvider(const std::string& providerName, const Ice::Current&)
Ice::Int
GraspCandidateObserver::getUpdateCounterByProvider(const std::string& providerName,
const Ice::Current&)
{
std::unique_lock lock(dataMutex);
checkHasProvider(providerName);
return updateCounters[providerName];
}
IntMap GraspCandidateObserver::getAllUpdateCounters(const Ice::Current& providerName)
IntMap
GraspCandidateObserver::getAllUpdateCounters(const Ice::Current& providerName)
{
std::unique_lock lock(dataMutex);
return updateCounters;
}
bool GraspCandidateObserver::setProviderConfig(const std::string& providerName, const StringVariantBaseMap& config, const Ice::Current&)
bool
GraspCandidateObserver::setProviderConfig(const std::string& providerName,
const StringVariantBaseMap& config,
const Ice::Current&)
{
std::unique_lock lock(dataMutex);
if (providers.count(providerName) == 0)
......@@ -254,19 +292,23 @@ bool GraspCandidateObserver::setProviderConfig(const std::string& providerName,
return true;
}
void GraspCandidateObserver::setSelectedCandidates(const GraspCandidateSeq& candidates, const Ice::Current&)
void
GraspCandidateObserver::setSelectedCandidates(const GraspCandidateSeq& candidates,
const Ice::Current&)
{
std::unique_lock lock(selectedCandidatesMutex);
selectedCandidates = candidates;
}
GraspCandidateSeq GraspCandidateObserver::getSelectedCandidates(const Ice::Current&)
GraspCandidateSeq
GraspCandidateObserver::getSelectedCandidates(const Ice::Current&)
{
std::unique_lock lock(selectedCandidatesMutex);
return selectedCandidates;
}
BimanualGraspCandidateSeq GraspCandidateObserver::getAllBimanualCandidates(const Ice::Current&)
BimanualGraspCandidateSeq
GraspCandidateObserver::getAllBimanualCandidates(const Ice::Current&)
{
std::unique_lock lock(dataMutex);
BimanualGraspCandidateSeq all;
......@@ -277,19 +319,25 @@ BimanualGraspCandidateSeq GraspCandidateObserver::getAllBimanualCandidates(const
return all;
}
void GraspCandidateObserver::setSelectedBimanualCandidates(const grasping::BimanualGraspCandidateSeq& candidates, const Ice::Current&)
void
GraspCandidateObserver::setSelectedBimanualCandidates(
const grasping::BimanualGraspCandidateSeq& candidates,
const Ice::Current&)
{
std::unique_lock lock(selectedCandidatesMutex);
selectedBimanualCandidates = candidates;
}
BimanualGraspCandidateSeq GraspCandidateObserver::getSelectedBimanualCandidates(const Ice::Current&)
BimanualGraspCandidateSeq
GraspCandidateObserver::getSelectedBimanualCandidates(const Ice::Current&)
{
std::unique_lock lock(selectedCandidatesMutex);
return selectedBimanualCandidates;
}
void GraspCandidateObserver::clearCandidatesByProvider(const std::string& providerName, const Ice::Current&)
void
GraspCandidateObserver::clearCandidatesByProvider(const std::string& providerName,
const Ice::Current&)
{
std::unique_lock lock(dataMutex);
......@@ -299,18 +347,24 @@ void GraspCandidateObserver::clearCandidatesByProvider(const std::string& provid
}
}
bool GraspCandidateObserver::hasProvider(const std::string& providerName)
bool
GraspCandidateObserver::hasProvider(const std::string& providerName)
{
return providers.count(providerName) > 0;
}
void GraspCandidateObserver::checkHasProvider(const std::string& providerName)
void
GraspCandidateObserver::checkHasProvider(const std::string& providerName)
{
if (!hasProvider(providerName))
{
throw LocalException("Unknown provider name '") << providerName << "'. Available providers: " << getAvailableProviderNames();
throw LocalException("Unknown provider name '")
<< providerName << "'. Available providers: " << getAvailableProviderNames();
}
}
StringSeq GraspCandidateObserver::getAvailableProviderNames()
StringSeq
GraspCandidateObserver::getAvailableProviderNames()
{
StringSeq names;
for (const auto& pair : providers)
......
......@@ -78,6 +78,7 @@ set(LIB_HEADERS
util/introspection/ClassMemberInfo.h
util/RtLogging.h
util/RtTiming.h
util/NonRtTiming.h
util/CtrlUtil.h
#robot unit modules need to be added to the list below (but not here)
......
......@@ -121,10 +121,14 @@ namespace armarx
const IceUtil::Time& sensorValuesTimestamp,
const IceUtil::Time& timeSinceLastIteration)
{
if (sensorGlobalPositionCorrection == nullptr or sensorRelativePosition == nullptr)
if (sensorGlobalPositionCorrection == nullptr)
{
ARMARX_ERROR << "The global position correction sensor is not available.";
return;
}
if (sensorRelativePosition == nullptr)
{
ARMARX_ERROR << "one of the sensors is not available";
ARMARX_ERROR << "The relative position sensor is not available.";
return;
}
......
......@@ -129,8 +129,8 @@ namespace armarx
}
//visu
{
_tripFakeRobotGP.getWriteBuffer()(0, 0) = std::nanf("");
_tripFakeRobotGP.commitWrite();
_tripRt2NonRtRobotGP.getWriteBuffer().setIdentity();
_tripRt2NonRtRobotGP.commitWrite();
}
}
......@@ -281,6 +281,9 @@ namespace armarx
}
}
_tripRt2NonRt.commitWrite();
_tripRt2NonRtRobotGP.getWriteBuffer() = _rtRobot->getGlobalPose();
_tripRt2NonRtRobotGP.commitWrite();
}
void
......@@ -412,17 +415,13 @@ namespace armarx
NJointCartesianWaypointController::setVisualizationRobotGlobalPose(const Eigen::Matrix4f& p,
const Ice::Current&)
{
std::lock_guard g{_tripFakeRobotGPWriteMutex};
_tripFakeRobotGP.getWriteBuffer() = p;
_tripFakeRobotGP.commitWrite();
; // No longer used ...
}
void
NJointCartesianWaypointController::resetVisualizationRobotGlobalPose(const Ice::Current&)
{
std::lock_guard g{_tripFakeRobotGPWriteMutex};
_tripFakeRobotGP.getWriteBuffer()(0, 0) = std::nanf("");
_tripFakeRobotGP.commitWrite();
; // No longer used ...
}
void
......@@ -477,7 +476,7 @@ namespace armarx
std::lock_guard g{_tripRt2NonRtMutex};
const auto& buf = _tripRt2NonRt.getUpToDateReadBuffer();
const Eigen::Matrix4f fakeGP = _tripFakeRobotGP.getUpToDateReadBuffer();
const Eigen::Matrix4f fakeGP = _tripRt2NonRtRobotGP.getUpToDateReadBuffer();
const Eigen::Matrix4f gp = std::isfinite(fakeGP(0, 0)) ? fakeGP : buf.rootPose;
if (buf.tcp != buf.tcpTarg)
......