00001
00009
00010
00011
00012
00013
00014
00015
00016 #include <array>
00017 #include <mavros/mavros_uas.h>
00018
00019 #define DEG_TO_RAD (M_PI / 180.0f)
00020
00021 using namespace mavros;
00022
00023
00024 typedef std::pair<const std::string, const Eigen::Quaterniond> OrientationPair;
00025
00026
00027 static const OrientationPair make_orientation(const std::string &name,
00028 const double roll,
00029 const double pitch,
00030 const double yaw)
00031 {
00032 const Eigen::Quaterniond rot = UAS::quaternion_from_rpy(Eigen::Vector3d(roll, pitch, yaw) * DEG_TO_RAD);
00033 return std::make_pair(name, rot);
00034 }
00035
00036 static const std::array<const OrientationPair, 39> sensor_orientations = {{
00037 make_orientation("NONE", 0.0, 0.0, 0.0),
00038 make_orientation("YAW_45", 0.0, 0.0, 45.0),
00039 make_orientation("YAW_90", 0.0, 0.0, 90.0),
00040 make_orientation("YAW_135", 0.0, 0.0, 135.0),
00041 make_orientation("YAW_180", 0.0, 0.0, 180.0),
00042 make_orientation("YAW_225", 0.0, 0.0, 225.0),
00043 make_orientation("YAW_270", 0.0, 0.0, 270.0),
00044 make_orientation("YAW_315", 0.0, 0.0, 315.0),
00045 make_orientation("ROLL_180", 180.0, 0.0, 0.0),
00046 make_orientation("ROLL_180_YAW_45", 180.0, 0.0, 45.0),
00047 make_orientation("ROLL_180_YAW_90", 180.0, 0.0, 90.0),
00048 make_orientation("ROLL_180_YAW_135", 180.0, 0.0, 135.0),
00049 make_orientation("PITCH_180", 0.0, 180.0, 0.0),
00050 make_orientation("ROLL_180_YAW_225", 180.0, 0.0, 225.0),
00051 make_orientation("ROLL_180_YAW_270", 180.0, 0.0, 270.0),
00052 make_orientation("ROLL_180_YAW_315", 180.0, 0.0, 315.0),
00053 make_orientation("ROLL_90", 90.0, 0.0, 0.0),
00054 make_orientation("ROLL_90_YAW_45", 90.0, 0.0, 45.0),
00055 make_orientation("ROLL_90_YAW_90", 90.0, 0.0, 90.0),
00056 make_orientation("ROLL_90_YAW_135", 90.0, 0.0, 135.0),
00057 make_orientation("ROLL_270", 270.0, 0.0, 0.0),
00058 make_orientation("ROLL_270_YAW_45", 270.0, 0.0, 45.0),
00059 make_orientation("ROLL_270_YAW_90", 270.0, 0.0, 90.0),
00060 make_orientation("ROLL_270_YAW_135", 270.0, 0.0, 135.0),
00061 make_orientation("PITCH_90", 0.0, 90.0, 0.0),
00062 make_orientation("PITCH_270", 0.0, 270.0, 0.0),
00063 make_orientation("PITCH_180_YAW_90", 0.0, 180.0, 90.0),
00064 make_orientation("PITCH_180_YAW_270", 0.0, 180.0, 270.0),
00065 make_orientation("ROLL_90_PITCH_90", 90.0, 90.0, 0.0),
00066 make_orientation("ROLL_180_PITCH_90", 180.0, 90.0, 0.0),
00067 make_orientation("ROLL_270_PITCH_90", 270.0, 90.0, 0.0),
00068 make_orientation("ROLL_90_PITCH_180", 90.0, 180.0, 0.0),
00069 make_orientation("ROLL_270_PITCH_180", 270.0, 180.0, 0.0),
00070 make_orientation("ROLL_90_PITCH_270", 90.0, 270.0, 0.0),
00071 make_orientation("ROLL_180_PITCH_270", 180.0, 270.0, 0.0),
00072 make_orientation("ROLL_270_PITCH_270", 270.0, 270.0, 0.0),
00073 make_orientation("ROLL_90_PITCH_180_YAW_90", 90.0, 180.0, 90.0),
00074 make_orientation("ROLL_90_YAW_270", 90.0, 0.0, 270.0),
00075 make_orientation("ROLL_315_PITCH_315_YAW_315", 315.0, 315.0, 315.0)
00076 }};
00077
00078 std::string UAS::str_sensor_orientation(MAV_SENSOR_ORIENTATION orientation)
00079 {
00080 const size_t idx(orientation);
00081 if (idx >= sensor_orientations.size()) {
00082 ROS_ERROR_NAMED("uas", "SENSOR: wrong orientation index: %zu", idx);
00083 return std::to_string(idx);
00084 }
00085
00086 return sensor_orientations[idx].first;
00087 }
00088
00089 Eigen::Quaterniond UAS::sensor_orientation_matching(MAV_SENSOR_ORIENTATION orientation)
00090 {
00091 const size_t idx(orientation);
00092 if (idx >= sensor_orientations.size()) {
00093 ROS_ERROR_NAMED("uas", "SENSOR: wrong orientation index: %zu", idx);
00094 return Eigen::Quaterniond::Identity();
00095 }
00096
00097 return sensor_orientations[idx].second;
00098 }
00099
00100 int UAS::orientation_from_str(const std::string &sensor_orientation)
00101 {
00102
00103 for (size_t idx = 0; idx < sensor_orientations.size(); idx++) {
00104 if (sensor_orientations[idx].first == sensor_orientation)
00105 return idx;
00106 }
00107
00108
00109
00110 try {
00111 int idx = std::stoi(sensor_orientation, 0, 0);
00112 if (0 > idx || size_t(idx) > sensor_orientations.size()) {
00113 ROS_ERROR_NAMED("uas", "SENSOR: orientation index out of bound: %d", idx);
00114 return -1;
00115 }
00116 else
00117 return idx;
00118 }
00119 catch (std::invalid_argument &ex) {
00120
00121 }
00122
00123 ROS_ERROR_STREAM_NAMED("uas", "SENSOR: wrong orientation str: " << sensor_orientation);
00124
00125 return -1;
00126 }