RosReflexxesPositionInterface.cpp
Go to the documentation of this file.
3 
4 
6 
7  if (!load_parameters(nh.getNamespace()) ) {
8  ROS_FATAL_STREAM("RosReflexxesPositionInterface: Unable to initialize Reflexxes as no parameters could "
9  "be read. Please verify that all parameters exist on the given namespace '"
10  << nh.getNamespace() <<"' and try again!");
11  } else {
12  //initialize Reflexxes with loaded values
13  rml_.reset(new ReflexxesAPI(n_dim_, period_));
16  for (int i=0; i<n_dim_; i++) {
17  input_params_->CurrentVelocityVector->VecData[i] = 0.0;
18  input_params_->CurrentAccelerationVector->VecData[i] = 0.0;
19  input_params_->MaxVelocityVector->VecData[i] = max_velocities_[i];
20  input_params_->MaxAccelerationVector->VecData[i] = max_acceleration_[i];
21  input_params_->MaxJerkVector->VecData[i] = max_jerk_.at(i);
22  input_params_->TargetVelocityVector->VecData[i] = 0.0;
23  input_params_->SelectionVector->VecData[i] = true;
24  }
25  }
26  position_initialized_ = false;
27  return true;
28 }//RosReflexxesPositionInterface::RosReflexxesPositionInterface()
29 
31  std::string param_name = ns + "/dimensions";
32  if (!nh_.getParam(param_name, n_dim_)) {
33  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
34  return false;
35  }
36  param_name = ns + "/period";
37  if (!nh_.getParam(param_name, period_)) {
38  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
39  return false;
40  }
41  param_name = ns + "/max_velocities";
42  if (!nh_.getParam(param_name, max_velocities_)) {
43  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
44  return false;
45  }
46  param_name = ns + "/max_acceleration";
47  if (!nh_.getParam(param_name, max_acceleration_)) {
48  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
49  return false;
50  }
51  param_name = ns + "/max_jerk";
52  if (!nh_.getParam(param_name, max_jerk_)) {
53  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
54  return false;
55  }
56  param_name = ns + "/sync_behavior";
57  int sync_behavior_;
58  if (!nh_.getParam(param_name, sync_behavior_)) {
59  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
60  return false;
61  }
62  if (sync_behavior_ == 0) { //set SyncronizationBehavior flag
64  } else if (sync_behavior_ == 1) {
66  } else if (sync_behavior_ == 2) {
68  } else {
70  }
71  param_name = ns + "/final_behavior";
72  int final_behavior_;
73  if (!nh_.getParam(param_name, final_behavior_)) {
74  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
75  return false;
76  }
77  if (final_behavior_ == 0) { //set BehaviorAfterFinalStateOfMotionIsReached
79  } else {
81  }
82  ROS_DEBUG("RosReflexxesPositionInterface::load_params:\nPeriod:%f\nMaxVel:[%.2f, %.2f, %.2f, %.2f, %.2f, %.2f]\nMaxAcc:[%.2f, %.2f, %.2f, %.2f, %.2f, %.2f]\nMaxJerk:[%.2f, %.2f, %.2f, %.2f, %.2f, %.2f]\nSyncBehavior: %d\nFinalBehavior: %d",
83  period_,
87  sync_behavior_,
88  final_behavior_);
89  return true;
90 }//RosReflexxesPositionInterface::load_parameters
91 
92 void RosReflexxesPositionInterface::starting(const std::vector<double> &c_pos ) {
93  if (c_pos.size() == n_dim_) {
94  for (int i=0; i<n_dim_; i++) {
95  input_params_->CurrentPositionVector->VecData[i] = c_pos[i];
96  }
97  position_initialized_ = true;
98  } else {
99  ROS_WARN("RosReflexxesPositionInterface::starting is unable to execute the input because input dimensions (%d) don't match the reflexxes dimension (%d)", (int) c_pos.size(), n_dim_ );
100  }
101 }//RosReflexxesPositionInterface::starting
102 
104  if (position_initialized_) {
105  int result_value = rml_->RMLPosition(*input_params_, output_params_.get(), flags_);
106  *input_params_->CurrentPositionVector = *output_params_->NewPositionVector;
107  *input_params_->CurrentVelocityVector = *output_params_->NewVelocityVector;
108  *input_params_->CurrentAccelerationVector = *output_params_->NewAccelerationVector;
109  ROS_DEBUG("Reflexxes::advance NEW CurrentPos:[%.2f, %.2f, %.2f, %.2f, %.2f, %.2f] \n", input_params_->CurrentPositionVector->VecData[0], input_params_->CurrentPositionVector->VecData[1], input_params_->CurrentPositionVector->VecData[2], input_params_->CurrentPositionVector->VecData[3], input_params_->CurrentPositionVector->VecData[4], input_params_->CurrentPositionVector->VecData[5] );
110  } else {
111  ROS_WARN("RosReflexxesPositionInterface::update is unable to advance as the current position is not initialized yet. Please define the current position by using 'set_current_position' setter function first!");
112  }
113 }//RosReflexxesPositionInterface::advance_reflexxes()
114 
117  return get_current_position();
118 }//RosReflexxesPositionInterface::update()
119 
122  *input_params_ = previous_state;
124 }//RosReflexxesPositionInterface::reset_to_previous_state
125 
127  std::vector<double> c_acc(n_dim_);
128  for (int i=0; i<n_dim_; i++) {
129  c_acc[i] = input_params_->CurrentAccelerationVector->VecData[i];
130  }
131  return c_acc;
132 }//RosReflexxesPositionInterface::get_current_acceleration()
133 
134 /*getter*/
136 
137  std::vector<double> c_vel(n_dim_);
138  for (int i=0; i<n_dim_; i++) {
139  c_vel[i] = input_params_->CurrentVelocityVector->VecData[i];
140  }
141  return c_vel;
142 }//RosReflexxesPositionInterface::get_current_velocity()
143 
145 
146  std::vector<double> c_pos(n_dim_);
147  for (int i=0; i<n_dim_; i++) {
148  c_pos[i] = input_params_->CurrentPositionVector->VecData[i];
149  }
150  return c_pos;
151 }//RosReflexxesPositionInterface::get_current_position()
152 
154 
155  std::vector<double> t_pos(n_dim_);
156  for (int i=0; i<n_dim_; i++) {
157  t_pos[i] = input_params_->TargetPositionVector->VecData[i];
158  }
159  return t_pos;
160 }//RosReflexxesPositionInterface::get_target_position()
161 
170  return c_state;
171 }//RosReflexxesPositionInterface::get_current_state()
172 
174  if ( output_params_->WasACompleteComputationPerformedDuringTheLastCycle() ) {
175  return ros::Duration( output_params_->GetGreatestExecutionTime() );
176  } else {
177  return ros::Duration(-1.0);
178  }
179 }
180 
181 /*setter*/
182 void RosReflexxesPositionInterface::set_target_position( const std::vector<double> &t_pos ) {
183 
184  if (t_pos.size() == n_dim_) {
185  for (int i=0; i<n_dim_; i++) {
186  input_params_->TargetPositionVector->VecData[i] = t_pos[i];
187  }
188  } else {
189  ROS_WARN("RosReflexxesPositionInterface::set_target_position is unable to execute the input because input dimensions (%d) don't match the reflexxes dimension (%d)", (int) t_pos.size(), n_dim_ );
190  }
191 }//RosReflexxesPositionInterface::set_target_position
192 
193 void RosReflexxesPositionInterface::set_target_velocity( const std::vector<double> &t_vel ) {
194 
195  if (t_vel.size() == n_dim_) {
196  for (int i=0; i<n_dim_; i++) {
197  input_params_->TargetVelocityVector->VecData[i] = t_vel[i];
198  }
199  } else {
200  ROS_WARN("RosReflexxesPositionInterface::set_target_velocity is unable to execute the input because input dimensions (%d) don't match the reflexxes dimension (%d)", (int) t_vel.size(), n_dim_ );
201  }
202 }//RosReflexxesPositionInterface::set_target_velocity
203 
204 
std::vector< double > get_current_acceleration() override
boost::shared_ptr< RMLPositionInputParameters > input_params_
std::vector< double > update() override
void reset_to_previous_state(RMLPositionInputParameters previous_state)
std::vector< double > get_current_position() override
#define ROS_WARN(...)
boost::shared_ptr< RMLPositionOutputParameters > output_params_
unsigned char SynchronizationBehavior
ONLY_TIME_SYNCHRONIZATION
int BehaviorAfterFinalStateOfMotionIsReached
#define ROS_FATAL_STREAM(args)
const std::string & getNamespace() const
ONLY_PHASE_SYNCHRONIZATION
PHASE_SYNCHRONIZATION_IF_POSSIBLE
std::vector< double > get_current_velocity() override
bool getParam(const std::string &key, std::string &s) const
bool init(ros::NodeHandle nh) override
RMLPositionInputParameters get_current_state()
PLUGINLIB_EXPORT_CLASS(RosReflexxesPositionInterface, RosReflexxesInterface)
boost::shared_ptr< ReflexxesAPI > rml_
void starting(const std::vector< double > &c_pos) override
#define ROS_ERROR_STREAM(args)
void set_target_velocity(const std::vector< double > &t_vel) override
void set_target_position(const std::vector< double > &t_pos) override
#define ROS_DEBUG(...)


ros_reflexxes
Author(s):
autogenerated on Sat Nov 21 2020 03:17:43