parameters_ros.h
Go to the documentation of this file.
1 #ifndef INCLUDE_ROTORS_CONTROL_PARAMETERS_ROS_H_
2 #define INCLUDE_ROTORS_CONTROL_PARAMETERS_ROS_H_
3 
4 #include <ros/ros.h>
5 
7 
8 namespace rotors_control {
9 
10 template<typename T> inline void GetRosParameter(const ros::NodeHandle& nh,
11  const std::string& key,
12  const T& default_value,
13  T* value) {
14  ROS_ASSERT(value != nullptr);
15  bool have_parameter = nh.getParam(key, *value);
16  if (!have_parameter) {
17  ROS_WARN_STREAM("[rosparam]: could not find parameter " << nh.getNamespace()
18  << "/" << key << ", setting to default: " << default_value);
19  *value = default_value;
20  }
21 }
22 
23 inline void GetRotorConfiguration(const ros::NodeHandle& nh,
24  RotorConfiguration* rotor_configuration) {
25  std::map<std::string, double> single_rotor;
26  std::string rotor_configuration_string = "rotor_configuration/";
27  unsigned int i = 0;
28  while (nh.getParam(rotor_configuration_string + std::to_string(i), single_rotor)) {
29  if (i == 0) {
30  rotor_configuration->rotors.clear();
31  }
32  Rotor rotor;
33  nh.getParam(rotor_configuration_string + std::to_string(i) + "/angle",
34  rotor.angle);
35  nh.getParam(rotor_configuration_string + std::to_string(i) + "/arm_length",
36  rotor.arm_length);
37  nh.getParam(rotor_configuration_string + std::to_string(i) + "/rotor_force_constant",
38  rotor.rotor_force_constant);
39  nh.getParam(rotor_configuration_string + std::to_string(i) + "/rotor_moment_constant",
40  rotor.rotor_moment_constant);
41  nh.getParam(rotor_configuration_string + std::to_string(i) + "/direction",
42  rotor.direction);
43  rotor_configuration->rotors.push_back(rotor);
44  ++i;
45  }
46 }
47 
48 inline void GetVehicleParameters(const ros::NodeHandle& nh, VehicleParameters* vehicle_parameters) {
49  GetRosParameter(nh, "mass",
50  vehicle_parameters->mass_,
51  &vehicle_parameters->mass_);
52  GetRosParameter(nh, "inertia/xx",
53  vehicle_parameters->inertia_(0, 0),
54  &vehicle_parameters->inertia_(0, 0));
55  GetRosParameter(nh, "inertia/xy",
56  vehicle_parameters->inertia_(0, 1),
57  &vehicle_parameters->inertia_(0, 1));
58  vehicle_parameters->inertia_(1, 0) = vehicle_parameters->inertia_(0, 1);
59  GetRosParameter(nh, "inertia/xz",
60  vehicle_parameters->inertia_(0, 2),
61  &vehicle_parameters->inertia_(0, 2));
62  vehicle_parameters->inertia_(2, 0) = vehicle_parameters->inertia_(0, 2);
63  GetRosParameter(nh, "inertia/yy",
64  vehicle_parameters->inertia_(1, 1),
65  &vehicle_parameters->inertia_(1, 1));
66  GetRosParameter(nh, "inertia/yz",
67  vehicle_parameters->inertia_(1, 2),
68  &vehicle_parameters->inertia_(1, 2));
69  vehicle_parameters->inertia_(2, 1) = vehicle_parameters->inertia_(1, 2);
70  GetRosParameter(nh, "inertia/zz",
71  vehicle_parameters->inertia_(2, 2),
72  &vehicle_parameters->inertia_(2, 2));
73  GetRotorConfiguration(nh, &vehicle_parameters->rotor_configuration_);
74 }
75 }
76 
77 #endif /* INCLUDE_ROTORS_CONTROL_PARAMETERS_ROS_H_ */
void GetRosParameter(const ros::NodeHandle &nh, const std::string &key, const T &default_value, T *value)
RotorConfiguration rotor_configuration_
Definition: parameters.h:83
void GetVehicleParameters(const ros::NodeHandle &nh, VehicleParameters *vehicle_parameters)
double rotor_moment_constant
Definition: parameters.h:43
void GetRotorConfiguration(const ros::NodeHandle &nh, RotorConfiguration *rotor_configuration)
bool getParam(const std::string &key, std::string &s) const
#define ROS_WARN_STREAM(args)
std::vector< Rotor > rotors
Definition: parameters.h:69
const std::string & getNamespace() const
double rotor_force_constant
Definition: parameters.h:42
#define ROS_ASSERT(cond)


rotors_control
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Mon Feb 28 2022 23:38:55