RosReflexxesVelocityInterface.cpp
Go to the documentation of this file.
3 
5  if (!load_parameters(nh.getNamespace()) ) {
6  ROS_FATAL_STREAM("Unable to initialize Reflexxes as no parameters could be read. Please verify that all "
7  "parameters exist on the given namespace '" <<
8  nh.getNamespace() <<"' and try again!");
9  return false;
10  } else {
11  //initialize Reflexxes with loaded value
12  rml_.reset(new ReflexxesAPI(n_dim_, period_));
15  for (int i=0; i<n_dim_; i++) {
16  input_params_->CurrentVelocityVector->VecData[i] = 0.0;
17  input_params_->CurrentAccelerationVector->VecData[i] = 0.0;
18  input_params_->MaxAccelerationVector->VecData[i] = max_acceleration_[i];
19  input_params_->MaxJerkVector->VecData[i] = max_jerk_[i];
20  input_params_->TargetVelocityVector->VecData[i] = 0.0;
21  input_params_->SelectionVector->VecData[i] = true;
22  }
23  }
24  position_initialized_ = false;
25  return true;
26 }//RosReflexxesVelocityInterface::RosReflexxesVelocityInterface()
27 
29  std::string param_name = ns + "/dimensions";
30  if (!nh_.getParam(param_name, n_dim_)) {
31  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
32  return false;
33  }
34  param_name = ns + "/period";
35  if (!nh_.getParam(param_name, period_)) {
36  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
37  return false;
38  }
39  param_name = ns + "/max_velocities";
40  if (!nh_.getParam(param_name, max_velocities_)) {
41  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
42  return false;
43  }
44  param_name = ns + "/max_acceleration";
45  if (!nh_.getParam(param_name, max_acceleration_)) {
46  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
47  return false;
48  }
49  param_name = ns + "/max_jerk";
50  if (!nh_.getParam(param_name, max_jerk_)) {
51  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
52  return false;
53  }
54  param_name = ns + "/sync_behavior";
55  int sync_behavior_;
56  if (!nh_.getParam(param_name, sync_behavior_)) {
57  ROS_ERROR_STREAM("Failed to getParam '" << param_name << "' (namespace: " << ns << ").");
58  return false;
59  }
60  if (sync_behavior_ == 0) { //set SyncronizationBehavior flag
62  } else if (sync_behavior_ == 1) {
64  } else if (sync_behavior_ == 2) {
66  } else {
68  }
69  return true;
70 }//RosReflexxesVelocityInterface::load_parameters
71 
72 void RosReflexxesVelocityInterface::starting(const std::vector<double> &c_pos) {
73 
74  if (c_pos.size() == n_dim_) {
75  for (int i=0; i<n_dim_; i++) {
76  input_params_->CurrentPositionVector->VecData[i] = c_pos[i];
77  }
78  ROS_INFO("RosReflexxesVelocityInterface::starting successful");
79  position_initialized_ = true;
80  } else {
81  ROS_WARN("RosReflexxesVelocityInterface::starting is unable to execute the input because input dimensions (%d) don't match the reflexxes dimension (%d)", (int) c_pos.size(), n_dim_ );
82  }
83 }//RosReflexxesVelocityInterface::starting
84 
87  int result_value = rml_->RMLVelocity(*input_params_, output_params_.get(), flags_);
88  *input_params_->CurrentPositionVector = *output_params_->NewPositionVector;
89  *input_params_->CurrentVelocityVector = *output_params_->NewVelocityVector;
90  *input_params_->CurrentAccelerationVector = *output_params_->NewAccelerationVector;
91  } else {
92  ROS_WARN("RosReflexxesVelocityInterface::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!");
93  }
94 }//RosReflexxesVelocityInterface::advance_reflexxes()
95 
98  return get_current_velocity();
99 }//RosReflexxesVelocityInterface::update()
100 
103  *input_params_ = previous_state;
105 }//RosReflexxesVelocityInterface::reset_to_previous_state
106 
107 /*getter*/
109  std::vector<double> c_acc(n_dim_);
110  for (int i=0; i<n_dim_; i++) {
111  c_acc[i] = input_params_->CurrentAccelerationVector->VecData[i];
112  }
113  return c_acc;
114 }//RosReflexxesVelocityInterface::get_current_acceleration()
115 
117  std::vector<double> c_vel(n_dim_);
118  for (int i=0; i<n_dim_; i++) {
119  c_vel[i] = input_params_->CurrentVelocityVector->VecData[i];
120  }
121  return c_vel;
122 }//RosReflexxesVelocityInterface::get_current_velocity()
123 
125  std::vector<double> c_pos(n_dim_);
126  for (int i=0; i<n_dim_; i++) {
127  c_pos[i] = input_params_->CurrentPositionVector->VecData[i];
128  }
129  return c_pos;
130 }//RosReflexxesVelocityInterface::get_current_position()
131 
133  std::vector<double> t_vel(n_dim_);
134  for (int i=0; i<n_dim_; i++) {
135  t_vel[i] = input_params_->TargetVelocityVector->VecData[i];
136  }
137  return t_vel;
138 }//RosReflexxesVelocityInterface::get_target_velocity()
139 
148  return c_state;
149 }//RosReflexxesVelocityInterface::get_current_state()
150 
152  return period_;
153 }//RosReflexxesVelocityInterface::get_period()
154 
155 /*setter*/
156 void RosReflexxesVelocityInterface::set_target_velocity( const std::vector<double> &t_vel) {
157  if (t_vel.size() == n_dim_) {
158  for (int i=0; i<n_dim_; i++) {
159  input_params_->TargetVelocityVector->VecData[i] = t_vel[i];
160  }
161  } else {
162  ROS_WARN("RosReflexxesVelocityInterface::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_ );
163  }
164 }//RosReflexxesVelocityInterface::set_target_velocity
165 
166 
boost::shared_ptr< RMLVelocityOutputParameters > output_params_
std::vector< double > update() override
std::vector< double > get_current_acceleration() override
std::vector< double > get_current_position() override
void starting(const std::vector< double > &initial_command) override
void reset_to_previous_state(RMLVelocityInputParameters previous_state)
boost::shared_ptr< RMLVelocityInputParameters > input_params_
RMLVelocityInputParameters get_current_state()
#define ROS_WARN(...)
unsigned char SynchronizationBehavior
ONLY_TIME_SYNCHRONIZATION
#define ROS_FATAL_STREAM(args)
#define ROS_INFO(...)
void set_target_velocity(const std::vector< double > &t_vel) override
boost::shared_ptr< ReflexxesAPI > rml_
const std::string & getNamespace() const
ONLY_PHASE_SYNCHRONIZATION
PLUGINLIB_EXPORT_CLASS(RosReflexxesVelocityInterface, RosReflexxesInterface)
PHASE_SYNCHRONIZATION_IF_POSSIBLE
bool init(ros::NodeHandle nh) override
std::vector< double > get_current_velocity() override
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR_STREAM(args)


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