9#include <Eigen/Geometry>
11#include <VirtualRobot/VirtualRobot.h>
44 GuideHumanToRoom::init(
const Base::SpecializedInitInput& in)
48 helper.
init(in.parameters.navigatingSkillParams,
51 return ::armarx::skills::Skill::InitResult{
56 GuideHumanToRoom::main(
const Base::SpecializedMainInput& in)
58 const core::Pose globalTarget = getTargetInFrontOfRoom(in.parameters.room);
69 [] {
return false; });
76 if (se.isSafetyStopTriggeredEvent())
80 return ::armarx::skills::Skill::MainResult{
83 if (se.isUserAbortTriggeredEvent())
87 return ::armarx::skills::Skill::MainResult{
90 if (se.isInternalErrorEvent())
93 << se.toInternalErrorEvent().message;
95 return ::armarx::skills::Skill::MainResult{
98 if (se.isGlobalPlanningFailedEvent())
101 << se.toGlobalPlanningFailedEvent().message;
103 return ::armarx::skills::Skill::MainResult{
108 return ::armarx::skills::Skill::MainResult{
113 return ::armarx::skills::Skill::MainResult{
118 GuideHumanToRoom::onStopRequested()
120 if (helper.getNavigator().has_value())
123 helper.getNavigator()->stop();
128 GuideHumanToRoom::getTargetInFrontOfRoom(
const std::string& roomName)
const
130 const algorithms::Costmap costmap = [&]
132 const memory::client::costmap::Reader::Query costmapQuery{
133 .providerName = properties.distanceToObstacleCostmapProvider,
134 .name =
"distance_to_obstacles",
137 const auto result = srv_->costmapReader.query(costmapQuery);
140 return result.costmap.value();
143 const armarx::navigation::algorithms::Room room = [&]
145 const memory::client::rooms::Reader::Query roomQuery{.providerName =
146 properties.roomsProvider,
150 const auto result = srv_->roomsReader.query(roomQuery);
151 ARMARX_CHECK(result) <<
"Failed to query room " <<
QUOTED(roomName) <<
" from provider `"
152 << properties.roomsProvider
153 <<
"`. Reason: " << result.errorMessage;
157 return result.rooms.front();
161 srv_->virtualRobotReader.getRobotWaiting(properties.robotName);
165 const core::Pose global_T_robot(robot->getGlobalPose());
167 rooms::RoomNavigationTargetCreator::Params algoParams;
168 rooms::RoomNavigationTargetCreator algo(algoParams);
169 auto result = algo.getClosestPositionOutsideOfRoom(
170 costmap, room, global_T_robot.translation(), &srv_->arviz);
172 const core::Direction dirToRoom = result.global_P_roomEntry - result.global_P_robot;
175 const float yaw = std::atan2(dirToRoom.y(), dirToRoom.x()) - M_PI_2f32;
179 core::Pose global_T_robot_target = core::Pose::Identity();
180 global_T_robot_target.translation() = result.global_P_robot;
181 global_T_robot_target.linear() =
182 Eigen::AngleAxisf(yaw, Eigen::Vector3f::UnitZ()).toRotationMatrix();
184 return global_T_robot_target;
#define ARMARX_CHECK_NOT_EMPTY(c)
static DateTime Now()
Current time on the virtual clock.
::armarx::skills::SimpleSpecializedSkill< Params > Base
GuideHumanToRoom(const NavigatingSkillHelper::Properties &helperProperties, const NavigatingSkillHelper::Services &helperSrv, const Services &srv)
static armarx::skills::SkillDescription DefaultSkillDescription()
std::optional< client::Navigator > & getNavigator()
void init(const arondto::NavigatingSkillParams ¶ms, const std::string &id)
client::StopEvent moveAndWaitForStop(IssueNavigationCommandT &&issueNavigationCommand, ShouldTerminateT &&shouldTerminate)
Issues the navigation command and waits for the navigator to stop, polling shouldTerminate meanwhile.
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
std::shared_ptr< class Robot > RobotPtr
Eigen::Vector3f Direction
A result struct for skill initialization.
A result struct for th main method of a skill.