RobotHeadMovement.cpp
Go to the documentation of this file.
1 #include "RobotHeadMovement.h"
2 
6 
7 
9 {
10 
12  {
13  defs->optional(checkHeadVelocity, prefix + "checkHeadVelocity",
14  "If true, check whether the head is moving and discard updates in the meantime.");
15  defs->optional(maxJointVelocity, prefix + "maxJointVelocity",
16  "If a head joint's velocity is higher, the head is considered moving.");
17  defs->optional(discardIntervalAfterMoveMS, prefix + "discardIntervalAfterMoveMS",
18  "For how long new updates are ignored after moving the head.");
19  }
20 
22  {
24  {
25  for (const std::string& jointName : jointNames)
26  {
27  std::string error = "";
28  try
29  {
30  DatafieldRefBasePtr datafield = kinematicUnitObserver->getDatafieldRefByName(jointVelocitiesChannelName, jointName);
31  DatafieldRefPtr casted = DatafieldRefPtr::dynamicCast(datafield);
32  if (casted)
33  {
34  jointVelocitiesDatafields.push_back(casted);
35  }
36  }
37  catch (const InvalidDatafieldException& e)
38  {
39  error = e.what();
40  }
41  catch (const InvalidChannelException& e)
42  {
43  error = e.what();
44  }
45  if (error.size() > 0)
46  {
47  ARMARX_WARNING << "Could not get datafield for joint '" << jointName << "' in channel '" << jointVelocitiesChannelName << "': \n "
48  << error;
49  }
50  }
51  }
52  else
53  {
54  ARMARX_INFO << "Cannot fetch joint velocity datafields because there is no kinematic unit observer.";
55  }
56  }
57 
59  {
61  {
62  if (df)
63  {
64  float jointVelocity = df->getFloat();
65  // ARMARX_IMPORTANT << "Is " << df->datafieldName << " " << VAROUT(std::abs(jointVelocity)) << " > " << VAROUT(maxJointVelocity) << "?";
66  if (std::abs(jointVelocity) > maxJointVelocity)
67  {
68  return true;
69  }
70  }
71  }
72  return false;
73  }
74 
75  void RobotHeadMovement::movementStarts(long discardIntervalMs)
76  {
77  return movementStarts(Duration::MilliSeconds(discardIntervalMs));
78  }
79  void RobotHeadMovement::movementStarts(const Duration& discardInterval)
80  {
81  discardUpdatesUntil = DateTime::Now() + discardInterval;
82  }
83  void RobotHeadMovement::movementStops(long discardIntervalMs)
84  {
85  return movementStops(Duration::MilliSeconds(discardIntervalMs));
86  }
87  void RobotHeadMovement::movementStops(const Duration& discardInterval)
88  {
89  if (discardInterval.toMilliSeconds() < 0)
90  {
91  // Stop discarding.
93  }
94  else
95  {
96  // Basically the same as starting.
97  discardUpdatesUntil = DateTime::Now() + discardInterval;
98  }
99  }
100 
101  objpose::SignalHeadMovementOutput RobotHeadMovement::signalHeadMovement(const objpose::SignalHeadMovementInput& input)
102  {
103  objpose::SignalHeadMovementOutput output;
104  switch (input.action)
105  {
106  case objpose::HeadMovementAction::HeadMovementAction_Starting:
107  this->movementStarts(input.discardUpdatesIntervalMilliSeconds < 0
108  ? this->discardIntervalAfterMoveMS
109  : input.discardUpdatesIntervalMilliSeconds);
110  break;
111  case objpose::HeadMovementAction::HeadMovementAction_Stopping:
112  this->movementStops(input.discardUpdatesIntervalMilliSeconds);
113  break;
114  default:
115  ARMARX_UNEXPECTED_ENUM_VALUE(objpose::HeadMovementAction, input.action);
116  break;
117  }
118  output.discardUpdatesUntilMilliSeconds = this->discardUpdatesUntil.toMilliSecondsSinceEpoch();
119  return output;
120  }
121 
122 
124  {
125  Discard discard;
126  if (checkHeadVelocity)
127  {
128  if (isMoving())
129  {
131  // ARMARX_IMPORTANT << "Ignoring pose update because robot head is moving! until " << discardUpdatesUntil;
132  discard.all = true;
133  }
134  else if (DateTime::Now() < discardUpdatesUntil)
135  {
136  discard.all = true;
137  // ARMARX_IMPORTANT << "Ignoring pose update because robot head has moved until: " << discardUpdatesUntil;
138  }
139  else
140  {
142  }
143  }
144  return discard;
145  }
146 
147 
149  {
150  using namespace armarx::RemoteGui::Client;
151 
153  {
154  float max = 10.0;
157  maxJointVelocity.setSteps(int(100 * max)); // = 0.01 steps
159  }
160  {
161  int max = 10 * 1000;
164  }
165 
166  GridLayout grid;
167  int row = 0;
168  grid.add(Label("Check Head Motion"), {row, 0}).add(checkHeadVelocity, {row, 1});
169  row++;
170  grid.add(Label("Max Joint Velocity"), {row, 0}).add(maxJointVelocity, {row, 1});
171  row++;
172  grid.add(Label("Discard Interval after Move [ms]"), {row, 0}).add(discardIntervalAfterMoveMS, {row, 1});
173  row++;
174 
175  group.setLabel("Robot Head Movement");
176  group.addChild(grid);
177  }
178 
180  {
184  }
185 
186 }
armarx::RemoteGui::Client::IntSpinBox::setValue
void setValue(int newValue)
Definition: Widgets.cpp:58
armarx::RemoteGui::Client::FloatSpinBox::getValue
float getValue() const
Definition: Widgets.cpp:332
armarx::RemoteGui::Client::ContainerWidget::addChild
void addChild(Widget const &child)
Definition: Widgets.cpp:95
ARMARX_UNEXPECTED_ENUM_VALUE
#define ARMARX_UNEXPECTED_ENUM_VALUE(EnumType, value)
Throw an UnexpectedEnumValueException.
Definition: UnexpectedEnumValueException.h:61
armarx::armem::server::obj::instance::RobotHeadMovement::getDiscard
Discard getDiscard()
Definition: RobotHeadMovement.cpp:123
armarx::armem::server::obj::instance::RobotHeadMovement::discardUpdatesUntil
DateTime discardUpdatesUntil
Definition: RobotHeadMovement.h:62
armarx::armem::server::obj::instance::RobotHeadMovement::RemoteGui::setup
void setup(const RobotHeadMovement &rhm)
Definition: RobotHeadMovement.cpp:148
armarx::armem::server::obj::instance::RobotHeadMovement::RemoteGui::maxJointVelocity
armarx::RemoteGui::Client::FloatSpinBox maxJointVelocity
Definition: RobotHeadMovement.h:72
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::armem::server::obj::instance::RobotHeadMovement::maxJointVelocity
float maxJointVelocity
Definition: RobotHeadMovement.h:57
armarx::RemoteGui::Client::GridLayout::add
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition: Widgets.cpp:412
armarx::RemoteGui::Client::FloatSpinBox::setValue
void setValue(float newValue)
Definition: Widgets.cpp:337
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
armarx::RemoteGui::Client::FloatSpinBox::setRange
void setRange(float min, float max)
Definition: Widgets.cpp:313
armarx::armem::server::obj::instance::RobotHeadMovement::kinematicUnitObserver
KinematicUnitObserverInterfacePrx kinematicUnitObserver
Definition: RobotHeadMovement.h:60
armarx::armem::server::obj::instance::RobotHeadMovement::Discard::all
bool all
Definition: RobotHeadMovement.h:46
armarx::armem::server::obj::instance::RobotHeadMovement::movementStops
void movementStops(long discardIntervalMs)
Definition: RobotHeadMovement.cpp:83
armarx::armem::server::obj::instance::RobotHeadMovement::fetchDatafields
void fetchDatafields()
Definition: RobotHeadMovement.cpp:21
UnexpectedEnumValueException.h
armarx::armem::server::obj::instance::RobotHeadMovement::jointNames
std::vector< std::string > jointNames
Definition: RobotHeadMovement.h:56
armarx::armem::server::obj::instance::RobotHeadMovement::defineProperties
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="head.")
Definition: RobotHeadMovement.cpp:11
armarx::armem::server::obj::instance
Definition: ArticulatedObjectVisu.cpp:16
armarx::armem::server::obj::instance::RobotHeadMovement::RemoteGui::group
armarx::RemoteGui::Client::GroupBox group
Definition: RobotHeadMovement.h:69
armarx::armem::server::obj::instance::RobotHeadMovement::RemoteGui::update
void update(RobotHeadMovement &rhm)
Definition: RobotHeadMovement.cpp:179
IceInternal::Handle< DatafieldRef >
armarx::armem::server::obj::instance::RobotHeadMovement::movementStarts
void movementStarts(long discardIntervalMs)
Definition: RobotHeadMovement.cpp:75
armarx::RemoteGui::Client::CheckBox::getValue
bool getValue() const
Definition: Widgets.cpp:237
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:7
armarx::RemoteGui::Client::GridLayout
Definition: Widgets.h:186
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
armarx::armem::server::obj::instance::RobotHeadMovement::RemoteGui::discardIntervalAfterMoveMS
armarx::RemoteGui::Client::IntSpinBox discardIntervalAfterMoveMS
Definition: RobotHeadMovement.h:73
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::armem::server::obj::instance::RobotHeadMovement::Discard
Definition: RobotHeadMovement.h:43
armarx::exceptions::local::InvalidChannelException
Definition: InvalidChannelException.h:33
armarx::RemoteGui::Client::FloatSpinBox::setDecimals
void setDecimals(int decimals)
Definition: Widgets.cpp:326
armarx::RemoteGui::Client::FloatSpinBox::setSteps
void setSteps(int steps)
Definition: Widgets.cpp:320
armarx::RemoteGui::Client::GroupBox::setLabel
void setLabel(std::string const &text)
Definition: Widgets.cpp:395
armarx::armem::server::obj::instance::RobotHeadMovement::isMoving
bool isMoving() const
Definition: RobotHeadMovement.cpp:58
armarx::core::time::DateTime::toMilliSecondsSinceEpoch
std::int64_t toMilliSecondsSinceEpoch() const
Definition: DateTime.cpp:102
armarx::armem::server::obj::instance::RobotHeadMovement::Discard::updatesUntil
std::optional< DateTime > updatesUntil
Definition: RobotHeadMovement.h:45
armarx::armem::server::obj::instance::RobotHeadMovement
Definition: RobotHeadMovement.h:26
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
PropertyDefinitionContainer.h
armarx::RemoteGui::Client::CheckBox::setValue
void setValue(bool newValue)
Definition: Widgets.cpp:242
armarx::RemoteGui::Client::IntSpinBox::setRange
void setRange(int min, int max)
Definition: Widgets.cpp:51
IceUtil::Handle< class PropertyDefinitionContainer >
RobotHeadMovement.h
armarx::armem::server::obj::instance::RobotHeadMovement::discardIntervalAfterMoveMS
int discardIntervalAfterMoveMS
Definition: RobotHeadMovement.h:58
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::RemoteGui::Client::IntSpinBox::getValue
int getValue() const
Definition: Widgets.cpp:68
armarx::core::time::Duration::toMilliSeconds
std::int64_t toMilliSeconds() const
Returns the amount of milliseconds.
Definition: Duration.cpp:69
armarx::armem::server::obj::instance::RobotHeadMovement::signalHeadMovement
objpose::SignalHeadMovementOutput signalHeadMovement(const objpose::SignalHeadMovementInput &input)
Definition: RobotHeadMovement.cpp:101
armarx::armem::server::obj::instance::RobotHeadMovement::RemoteGui::checkHeadVelocity
armarx::RemoteGui::Client::CheckBox checkHeadVelocity
Definition: RobotHeadMovement.h:71
armarx::armem::server::obj::instance::RobotHeadMovement::checkHeadVelocity
bool checkHeadVelocity
Definition: RobotHeadMovement.h:53
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::armem::server::obj::instance::RobotHeadMovement::jointVelocitiesDatafields
std::vector< DatafieldRefPtr > jointVelocitiesDatafields
Definition: RobotHeadMovement.h:61
armarx::armem::server::obj::instance::RobotHeadMovement::jointVelocitiesChannelName
std::string jointVelocitiesChannelName
Definition: RobotHeadMovement.h:55
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
armarx::core::time::DateTime::Invalid
static DateTime Invalid()
Definition: DateTime.cpp:60
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55