LookForObjectsWithKinematicUnit.cpp
Go to the documentation of this file.
2 
3 #include <thread>
4 #include <vector>
5 
6 #include <Eigen/Core>
7 #include <Eigen/Geometry>
8 
9 #include <VirtualRobot/Robot.h>
10 
12 
18 
20 
22 {
23 
24  std::map<std::string, float> neck_joint_angles = {{"Neck_1_Yaw", 0.0}, {"Neck_2_Pitch", 0.3}};
26 
28  Base(DefaultSkillDescription())
29  {
30  srv_.emplace(srv);
31  }
32 
34  LookForObjectsWithKinematicUnit::init(const Base::SpecializedInitInput& in)
35  {
36  return ::armarx::skills::Skill::InitResult{
37  .status = ::armarx::skills::TerminatedSkillStatus::Succeeded};
38  }
39 
40  void
42  float goal_pitch,
43  int waypoints_num)
44  {
45  float yaw_step_size = (goal_yaw - neck_joint_angles["Neck_1_Yaw"]) / waypoints_num;
46  float pitch_step_size = (goal_pitch - neck_joint_angles["Neck_2_Pitch"]) / waypoints_num;
47 
48  for (int i = 1; i < waypoints_num; i++)
49  {
50  neck_joint_angles["Neck_1_Yaw"] = neck_joint_angles["Neck_1_Yaw"] + yaw_step_size;
51  neck_joint_angles["Neck_2_Pitch"] = neck_joint_angles["Neck_2_Pitch"] + pitch_step_size;
52  srv_->kinematicUnit->setJointAngles(
53  {{"Neck_1_Yaw", neck_joint_angles["Neck_1_Yaw"]},
54  {"Neck_2_Pitch", neck_joint_angles["Neck_2_Pitch"]}});
55  std::this_thread::sleep_for(std::chrono::milliseconds(300));
56  }
57  std::this_thread::sleep_for(std::chrono::milliseconds(300));
58  }
59 
60  void
61  LookForObjectsWithKinematicUnit::speak(const std::string& text)
62  {
63  ARMARX_INFO << "Saying '" << text.substr(0, 50) << "...'";
64  srv_->textToSpeech->reportText(text);
65  }
66 
68  LookForObjectsWithKinematicUnit::main(const Base::SpecializedMainInput& in)
69  {
70 
71 
72  srv_->kinematicUnit->switchControlMode(
73  {{"Neck_1_Yaw", armarx::ControlMode::ePositionControl},
74  {"Neck_2_Pitch", armarx::ControlMode::ePositionControl},
75  {"TorsoJoint", armarx::ControlMode::ePositionControl}});
76  srv_->kinematicUnit->setJointAngles({{"TorsoJoint", -109.76679992675781}});
77  std::this_thread::sleep_for(std::chrono::milliseconds(300));
78 
79  ARMARX_INFO << "start the running";
80  // doing the neck movement routine
81  // move neck to start position
82  setNeckJointAngles(0.0, 0.2, 10);
83  ARMARX_INFO << "finished first movement'";
84  // move the neck to the max right
85  setNeckJointAngles(-0.593412, 0.66654124, 10);
86  std::this_thread::sleep_for(std::chrono::milliseconds(450));
87  // move the neck to the max left
88  setNeckJointAngles(0.0, 0.66654124, 10);
89  std::this_thread::sleep_for(std::chrono::milliseconds(450));
90  setNeckJointAngles(0.593412, 0.66654124, 10);
91  std::this_thread::sleep_for(std::chrono::milliseconds(450));
92  // move the neck back to the normal
93  setNeckJointAngles(0.0, 0.2, 10);
94  ARMARX_INFO << "no problem with the neck";
95 
96  // getting the
97  objpose::ObjectPoseSeq objectPoses = srv_->objectPoseClient.fetchObjectPoses();
98  // these objects are always in the memory so, we need to not consider them for what can u see now scenario
99  armarx::ObjectID objectId;
100  std::vector<std::string> predefined_poses = {"r003-door",
101  "r003-pillar",
102  "clean-box",
103  "dirty-box",
104  "beam",
105  "hund-table-120x80",
106  "hund-table-180x60",
107  "hund-table-180x80",
108  "hund-table-200x80",
109  "mobile-dishwasher",
110  "mobile-fridge",
111  "mobile-kitchen-counter",
112  "guard-support-full-with-light",
113  "ladder-closed",
114  "mounting-adhesive",
115  "spraybottle",
116  "workbench",
117  "box"};
118 
119  std::vector<std::string> objects_names;
120 
121  armarx::ObjectFinder objFind;
122 
123  for (auto o : objectPoses)
124  {
125 
126  const std::string className = o.objectID.className();
127 
128  if (std::find(predefined_poses.begin(), predefined_poses.end(), className) ==
129  predefined_poses.end() &&
130  std::find(objects_names.begin(), objects_names.end(), className) ==
131  objects_names.end())
132  {
133  std::string objectName;
134  std::optional<armarx::ObjectInfo> info = objFind.findObject(o.objectID);
135  if (info)
136  {
137  std::optional<std::vector<std::string>> names = info->loadSpokenNames();
138  if (names.has_value() and not names->empty())
139  {
140  objectName = names->front();
141  }
142  }
143 
144  if (objectName.empty())
145  {
146  objectName = className;
147  objectName.erase(std::remove_if(std::begin(objectName),
148  std::end(objectName),
149  [](auto ch) { return std::isdigit(ch); }),
150  objectName.end());
151  }
152 
153  objects_names.push_back(objectName);
154  }
155  }
156 
157  ARMARX_INFO << "no problem with the poses";
158  for (int i = 0; i < static_cast<int>(objects_names.size()); i++)
159  {
160  if (i == 0)
161  {
162  if (static_cast<int>(objects_names.size()) == 1)
163  {
164  speak("I can see the following object");
165  std::this_thread::sleep_for(std::chrono::milliseconds(200));
166  }
167  else
168  {
169 
170  speak("I can see the following objects");
171  std::this_thread::sleep_for(std::chrono::milliseconds(200));
172  }
173  // speak("I can see the following objects");
174  // std::this_thread::sleep_for(std::chrono::milliseconds(200));
175  }
176  else if (i == (static_cast<int>(objects_names.size()) - 1))
177  {
178  speak("and");
179  std::this_thread::sleep_for(std::chrono::milliseconds(200));
180  }
181  speak(objects_names[i]);
182  std::this_thread::sleep_for(std::chrono::milliseconds(200));
183  }
184 
185 
186  return ::armarx::skills::Skill::MainResult{
187  .status = ::armarx::skills::TerminatedSkillStatus::Succeeded};
188  }
189 
190  void
191  LookForObjectsWithKinematicUnit::onStopRequested()
192  {
193  }
194 
197  {
198  ParamType defaultParameters;
199  // TODO(): set parameter defaults
200 
203  .description = "",
204  .rootProfileDefaults = defaultParameters.toAron(),
205  .timeout = armarx::core::time::Duration(),
206  .parametersType = Params::ToAronType(),
207  };
208  }
209 
210 
211 } // namespace armarx::view_selection::skills
armarx::view_selection::skills
This file is part of ArmarX.
Definition: constants.cpp:25
RemoteRobot.h
armarx::skills::SimpleSpecializedSkill< arondto::LookForObjectsParams >::init
Skill::InitResult init() final
Definition: SimpleSpecializedSkill.h:62
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:10
armarx::view_selection::skills::LookForObjectsWithKinematicUnit::speak
void speak(const std::string &text)
Definition: LookForObjectsWithKinematicUnit.cpp:61
armarx::skills::SimpleSpecializedSkill< arondto::LookForObjectsParams >::ParamType
arondto::LookForObjectsParams ParamType
Definition: SimpleSpecializedSkill.h:14
armarx::objpose::ObjectPoseSeq
std::vector< ObjectPose > ObjectPoseSeq
Definition: forward_declarations.h:20
armarx::skills::SkillID::skillName
std::string skillName
Definition: SkillID.h:41
armarx::view_selection::skills::LookForObjectsWithKinematicUnit::LookForObjectsWithKinematicUnit
LookForObjectsWithKinematicUnit(const Services &srv)
Definition: LookForObjectsWithKinematicUnit.cpp:27
armarx::skills::SkillDescription
Definition: SkillDescription.h:17
armarx::view_selection::skills::LookForObjectsWithKinematicUnit::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition: LookForObjectsWithKinematicUnit.cpp:196
Duration.h
aron_conversions.h
armarx::view_selection::skills::constants::skill_names::LookForObjectsWithKinematicUnit
const std::string LookForObjectsWithKinematicUnit
Definition: constants.cpp:33
armarx::ObjectFinder
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
Definition: ObjectFinder.h:22
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition: SkillDescription.h:19
armarx::skills::SimpleSpecializedSkill
Definition: SimpleSpecializedSkill.h:10
LookForObjectsWithKinematicUnit.h
ObjectInfo.h
constants.h
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:39
armarx::view_selection::skills::LookForObjectsWithKinematicUnit::Services
Definition: LookForObjectsWithKinematicUnit.h:43
armarx::viz::data::ElementFlags::names
const simox::meta::IntEnumNames names
Definition: json_elements.cpp:13
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::skills::SimpleSpecializedSkill< arondto::LookForObjectsParams >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
armarx::skills::Skill::InitResult::status
TerminatedSkillStatus status
Definition: Skill.h:29
magic_enum::detail::find
constexpr std::size_t find(string_view str, char_type c) noexcept
Definition: magic_enum.hpp:309
armarx::view_selection::skills::neck_joint_angles
std::map< std::string, float > neck_joint_angles
Definition: LookForObjectsWithKinematicUnit.cpp:24
armarx::view_selection::skills::LookForObjectsWithKinematicUnit::setNeckJointAngles
void setNeckJointAngles(float goal_yaw, float goal_pitch, int waypoints_num)
Definition: LookForObjectsWithKinematicUnit.cpp:41
armarx::skills::Skill::InitResult
A result struct for skill initialization.
Definition: Skill.h:27
armarx::ObjectFinder::findObject
std::optional< ObjectInfo > findObject(const std::string &dataset, const std::string &name) const
Definition: ObjectFinder.cpp:64
armarx::view_selection::skills::localRobot
VirtualRobot::RobotPtr localRobot
Definition: LookForObjectsWithKinematicUnit.cpp:25
aron_conversions.h
armarx::armem::Duration
armarx::core::time::Duration Duration
Definition: forward_declarations.h:14
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
ObjectFinder.h