LookDirection.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Niklas Arlt ( ujrwq at student dot kit dot edu )
17  * @date 2023
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
25 
27 #include <armarx/view_selection/skills/aron/LookDirection.aron.generated.h>
28 
30 {
31  namespace direction
32  {
33  const Eigen::Vector3f centerPosition{0., 1500., 1500.};
34  const Eigen::Vector3f downstraightPosition{0., 1500., 500.};
35  const Eigen::Vector3f DeltaUp{0., 0., 1000.};
36  const Eigen::Vector3f deltaDown{0., 0., -1000.};
37  const Eigen::Vector3f deltaLeft{-1000., 0., 0.};
38  const Eigen::Vector3f deltaRight{1000., 0., 0.};
39 
40  /**
41  * The namespace state contains the states of allowed directions.
42  * There are 9 states in total:
43  * Left+Up Center+Up Right + Up
44  * Left+Center Center Right+Center
45  * Left+Down Center+Down Right+Down
46  */
47  namespace state
48  {
49  using Type = std::uint8_t;
50  constexpr std::uint8_t Center = 0;
51  constexpr std::uint8_t Up = 0b1;
52  constexpr std::uint8_t Down = 0b10;
53  constexpr std::uint8_t Left = 0b1000;
54  constexpr std::uint8_t Right = 0b10000;
55  constexpr std::uint8_t Downstraight = 0b100000;
56 
58 
59  state::Type from(Eigen::Vector3f targetPosition);
60 
61  Eigen::Vector3f generateTargetPosition(state::Type state);
62 
63  state::Type center(state::Type previous);
64  state::Type up(state::Type previous);
65  state::Type down(state::Type previous);
66  state::Type left(state::Type previous);
67  state::Type right(state::Type previous);
68 
70 
71  } // namespace state
72 
73 
74  } // namespace direction
75 
76  /*
77  * The LookDirection class implements all functions except DefaultSkillDescription().
78  *
79  * For each implemented direction there is a specialized subclass below.
80  */
81 
82  class LookDirection :
83  virtual public armarx::skills::SimpleSpecializedSkill<arondto::LookDirectionParams>
84  {
85  public:
86  using Params = arondto::LookDirectionParams;
88 
89  struct Context
90  {
92  // RobotReader from RobotAPI? Would be another option to get current state.
93  };
94 
95  LookDirection(const Context& services,
96  direction::state::StateModFn* stateModFn,
97  armarx::skills::SkillDescription skillDescription);
98 
99  void connect(const Context& srv);
100 
101  private:
104 
105  void onStopRequested() override;
106 
107 
108  protected:
110  generateDefaultSkillDescription(std::string name, std::string directionText);
111 
112  private:
113  std::optional<Context> srv_;
114  direction::state::StateModFn* stateModFn;
115 
116  // will be initialized in "init()"
117  std::optional<gaze_targets::GazeTarget> gazeTarget;
118  };
119 
120  /*
121  * Specialized classes for each direction
122  */
123 
124  class LookUp : public LookDirection
125  {
126  public:
127  LookUp(const Context& services);
128 
130  };
131 
132  class LookDown : public LookDirection
133  {
134  public:
135  LookDown(const Context& services);
136 
138  };
139 
140  /**
141  * This direction forces to look down in the middle
142  */
144  {
145  public:
146  LookDownstraight(const Context& services);
147 
149  };
150 
151  class LookLeft : public LookDirection
152  {
153  public:
154  LookLeft(const Context& services);
155 
157  };
158 
159  class LookRight : public LookDirection
160  {
161  public:
162  LookRight(const Context& services);
163 
165  };
166 
167  class LookAhead : public LookDirection
168  {
169  public:
170  LookAhead(const Context& services);
171 
173  };
174 } // namespace armarx::view_selection::skills
armarx::view_selection::skills::direction::state::up
state::Type up(state::Type previous)
Definition: LookDirection.cpp:240
armarx::view_selection::skills
This file is part of ArmarX.
Definition: constants.cpp:25
armarx::view_selection::skills::direction::state::Right
constexpr std::uint8_t Right
Definition: LookDirection.h:54
armarx::view_selection::skills::direction::state::right
state::Type right(state::Type previous)
Definition: LookDirection.cpp:264
armarx::skills::SimpleSpecializedSkill< arondto::LookDirectionParams >::init
Skill::InitResult init() final
Definition: SimpleSpecializedSkill.h:62
armarx::view_selection::skills::direction::state::downstraight
state::Type downstraight(state::Type previous)
Definition: LookDirection.cpp:252
armarx::view_selection::skills::direction::centerPosition
const Eigen::Vector3f centerPosition
Definition: LookDirection.h:33
armarx::skills::SkillDescription
Definition: SkillDescription.h:17
armarx::view_selection::skills::direction::state::Left
constexpr std::uint8_t Left
Definition: LookDirection.h:53
armarx::view_selection::skills::LookRight::LookRight
LookRight(const Context &services)
Definition: LookDirection.cpp:161
armarx::view_selection::skills::LookDownstraight::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition: LookDirection.cpp:139
armarx::view_selection::skills::direction::state::Center
constexpr std::uint8_t Center
Definition: LookDirection.h:50
armarx::view_selection::skills::LookDown
Definition: LookDirection.h:132
armarx::view_selection::skills::LookUp::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition: LookDirection.cpp:107
armarx::view_selection::skills::direction::state::Down
constexpr std::uint8_t Down
Definition: LookDirection.h:52
armarx::view_selection::skills::LookDirection::Context
Definition: LookDirection.h:89
armarx::view_selection::skills::direction::state::from
state::Type from(Eigen::Vector3f targetPosition)
Definition: LookDirection.cpp:194
armarx::view_selection::skills::LookDirection::LookDirection
LookDirection(const Context &services, direction::state::StateModFn *stateModFn, armarx::skills::SkillDescription skillDescription)
Definition: LookDirection.cpp:15
armarx::view_selection::skills::direction::state::StateModFn
state::Type(state::Type) StateModFn
Definition: LookDirection.h:57
armarx::view_selection::skills::direction::DeltaUp
const Eigen::Vector3f DeltaUp
Definition: LookDirection.h:35
armarx::view_selection::skills::direction::state::generateTargetPosition
Eigen::Vector3f generateTargetPosition(state::Type state)
Definition: LookDirection.cpp:213
armarx::view_selection::skills::LookLeft
Definition: LookDirection.h:151
armarx::view_selection::client::ViewSelection
Definition: ViewSelection.h:37
armarx::view_selection::skills::LookRight::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition: LookDirection.cpp:172
SimpleSpecializedSkill.h
armarx::view_selection::skills::LookUp::LookUp
LookUp(const Context &services)
Definition: LookDirection.cpp:96
armarx::skills::SimpleSpecializedSkill::SpecializedMainInput
Definition: SimpleSpecializedSkill.h:24
armarx::view_selection::skills::LookUp
Definition: LookDirection.h:124
armarx::view_selection::skills::LookDown::LookDown
LookDown(const Context &services)
Definition: LookDirection.cpp:112
armarx::view_selection::skills::LookAhead::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition: LookDirection.cpp:188
armarx::view_selection::skills::direction::state::Downstraight
constexpr std::uint8_t Downstraight
Definition: LookDirection.h:55
ViewSelection.h
armarx::skills::SimpleSpecializedSkill
Definition: SimpleSpecializedSkill.h:10
armarx::view_selection::skills::LookDirection
Definition: LookDirection.h:82
armarx::view_selection::skills::direction::state::Up
constexpr std::uint8_t Up
Definition: LookDirection.h:51
armarx::view_selection::skills::LookLeft::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition: LookDirection.cpp:156
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:39
armarx::view_selection::skills::LookDown::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition: LookDirection.cpp:133
armarx::view_selection::skills::direction::state::Type
std::uint8_t Type
Definition: LookDirection.h:49
armarx::view_selection::skills::LookLeft::LookLeft
LookLeft(const Context &services)
Definition: LookDirection.cpp:145
armarx::view_selection::skills::direction::deltaRight
const Eigen::Vector3f deltaRight
Definition: LookDirection.h:38
armarx::view_selection::skills::direction::deltaDown
const Eigen::Vector3f deltaDown
Definition: LookDirection.h:36
armarx::view_selection::skills::LookDownstraight
This direction forces to look down in the middle.
Definition: LookDirection.h:143
armarx::skills::SimpleSpecializedSkill::SpecializedInitInput
Definition: SimpleSpecializedSkill.h:18
armarx::view_selection::skills::LookDirection::connect
void connect(const Context &srv)
Definition: LookDirection.cpp:23
armarx::view_selection::skills::LookDirection::generateDefaultSkillDescription
static armarx::skills::SkillDescription generateDefaultSkillDescription(std::string name, std::string directionText)
Definition: LookDirection.cpp:79
armarx::skills::SimpleSpecializedSkill< arondto::LookDirectionParams >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
armarx::view_selection::skills::direction::state::center
state::Type center(state::Type previous)
Definition: LookDirection.cpp:233
armarx::skills::Skill::InitResult
A result struct for skill initialization.
Definition: Skill.h:27
armarx::view_selection::skills::direction::downstraightPosition
const Eigen::Vector3f downstraightPosition
Definition: LookDirection.h:34
armarx::view_selection::skills::direction::state::down
state::Type down(state::Type previous)
Definition: LookDirection.cpp:246
armarx::view_selection::skills::LookDownstraight::LookDownstraight
LookDownstraight(const Context &services)
Definition: LookDirection.cpp:122
armarx::view_selection::skills::direction::state::left
state::Type left(state::Type previous)
Definition: LookDirection.cpp:258
armarx::view_selection::skills::LookDirection::Params
arondto::LookDirectionParams Params
Definition: LookDirection.h:86
armarx::view_selection::skills::direction::deltaLeft
const Eigen::Vector3f deltaLeft
Definition: LookDirection.h:37
armarx::view_selection::skills::LookDirection::Context::viewSelectionClient
client::ViewSelection & viewSelectionClient
Definition: LookDirection.h:91
armarx::view_selection::skills::LookAhead
Definition: LookDirection.h:167
armarx::view_selection::skills::LookAhead::LookAhead
LookAhead(const Context &services)
Definition: LookDirection.cpp:177
armarx::view_selection::skills::LookRight
Definition: LookDirection.h:159