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);
68 client::StopEvent se = helper.
getNavigator()->waitForStop();
75 if (se.isSafetyStopTriggeredEvent())
79 return ::armarx::skills::Skill::MainResult{
82 if (se.isUserAbortTriggeredEvent())
86 return ::armarx::skills::Skill::MainResult{
89 if (se.isInternalErrorEvent())
92 << se.toInternalErrorEvent().message;
94 return ::armarx::skills::Skill::MainResult{
97 if (se.isGlobalPlanningFailedEvent())
100 << se.toGlobalPlanningFailedEvent().message;
102 return ::armarx::skills::Skill::MainResult{
107 return ::armarx::skills::Skill::MainResult{
112 return ::armarx::skills::Skill::MainResult{
117 GuideHumanToRoom::onStopRequested()
119 if (helper.getNavigator().has_value())
122 helper.getNavigator()->stop();
127 GuideHumanToRoom::getTargetInFrontOfRoom(
const std::string& roomName)
const
129 const algorithms::Costmap costmap = [&]
131 const memory::client::costmap::Reader::Query costmapQuery{
132 .providerName = properties.distanceToObstacleCostmapProvider,
133 .name =
"distance_to_obstacles",
136 const auto result = srv_->costmapReader.query(costmapQuery);
139 return result.costmap.value();
142 const armarx::navigation::algorithms::Room room = [&]
144 const memory::client::rooms::Reader::Query roomQuery{.providerName =
145 properties.roomsProvider,
149 const auto result = srv_->roomsReader.query(roomQuery);
150 ARMARX_CHECK(result) <<
"Failed to query room " <<
QUOTED(roomName) <<
" from provider `"
151 << properties.roomsProvider
152 <<
"`. Reason: " << result.errorMessage;
156 return result.rooms.front();
160 srv_->virtualRobotReader.getRobotWaiting(properties.robotName);
164 const core::Pose global_T_robot(robot->getGlobalPose());
166 rooms::RoomNavigationTargetCreator::Params algoParams;
167 rooms::RoomNavigationTargetCreator algo(algoParams);
168 auto result = algo.getClosestPositionOutsideOfRoom(
169 costmap, room, global_T_robot.translation(), &srv_->arviz);
171 const core::Direction dirToRoom = result.global_P_roomEntry - result.global_P_robot;
174 const float yaw = std::atan2(dirToRoom.y(), dirToRoom.x()) - M_PI_2f32;
178 core::Pose global_T_robot_target = core::Pose::Identity();
179 global_T_robot_target.translation() = result.global_P_robot;
180 global_T_robot_target.linear() =
181 Eigen::AngleAxisf(yaw, Eigen::Vector3f::UnitZ()).toRotationMatrix();
183 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)
#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.