-
Notifications
You must be signed in to change notification settings - Fork 986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Orientation enum name #342
Changes from 8 commits
d5f736a
5f06c83
3e7f786
9b8ece4
9162a50
0462cd9
08f4e8f
b44a461
8fedc4e
73cea49
1dbaf73
3779217
ad10689
ad7a7b4
5a7478d
872fdce
b9275aa
9f92221
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,25 +114,67 @@ distance_sensor: | |
hrlv_ez4_pub: | ||
id: 0 | ||
frame_id: "hrlv_ez4_sonar" | ||
orientation: 8 # RPY:{180.0, 0.0, 0.0} | ||
orientation: "ROLL_180" # RPY:{180.0, 0.0, 0.0} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
pub:
orientation: ROLL_180 |
||
field_of_view: 0.0 # XXX TODO | ||
send_tf: true | ||
sensor_position: {x: 0.0, y: 0.0, z: -0.1} | ||
lidarlite_pub: | ||
id: 1 | ||
frame_id: "lidarlite_laser" | ||
orientation: 8 | ||
orientation: "ROLL_180" | ||
field_of_view: 0.0 # XXX TODO | ||
send_tf: true | ||
sensor_position: {x: 0.0, y: 0.0, z: -0.1} | ||
sonar_1_sub: | ||
subscriber: true | ||
id: 2 | ||
orientation: 8 | ||
orientation: "ROLL_180" | ||
laser_1_sub: | ||
subscriber: true | ||
id: 3 | ||
orientation: 8 | ||
orientation: "ROLL_180" | ||
|
||
## Currently available orientations: | ||
# "NONE" | ||
# "YAW_45" | ||
# "YAW_90" | ||
# "YAW_135" | ||
# "YAW_180" | ||
# "YAW_225" | ||
# "YAW_270" | ||
# "YAW_315" | ||
# "ROLL_180" | ||
# "ROLL_180_YAW_45" | ||
# "ROLL_180_YAW_90" | ||
# "ROLL_180_YAW_135" | ||
# "PITCH_180" | ||
# "ROLL_180_YAW_225" | ||
# "ROLL_180_YAW_270" | ||
# "ROLL_180_YAW_315" | ||
# "ROLL_90" | ||
# "ROLL_90_YAW_45" | ||
# "ROLL_90_YAW_90" | ||
# "ROLL_90_YAW_135" | ||
# "ROLL_270" | ||
# "ROLL_270_YAW_45" | ||
# "ROLL_270_YAW_90" | ||
# "ROLL_270_YAW_135" | ||
# "PITCH_90" | ||
# "PITCH_270" | ||
# "PITCH_180_YAW_90" | ||
# "PITCH_180_YAW_270" | ||
# "ROLL_90_PITCH_90" | ||
# "ROLL_180_PITCH_90" | ||
# "ROLL_270_PITCH_90" | ||
# "ROLL_90_PITCH_180" | ||
# "ROLL_270_PITCH_180" | ||
# "ROLL_90_PITCH_270" | ||
# "ROLL_180_PITCH_270" | ||
# "ROLL_270_PITCH_270" | ||
# "ROLL_90_PITCH_180_YAW_90" | ||
# "ROLL_90_YAW_270" | ||
# "ROLL_315_PITCH_315_YAW_315" | ||
## | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tooooo long. That should be in ros wiki (and link to that doc). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So add it :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why me? You also can edit. WIKI There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do I add it? There's no place for enums there right now and this is not specific for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should have a general Enumerations page like http://wiki.ros.org/mavros/Enumerations. And then we add them all there (there's also others like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
|
||
# image_pub | ||
image: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
* https://github.com/mavlink/mavros/tree/master/LICENSE.md | ||
*/ | ||
#include <array> | ||
#include <angles/angles.h> | ||
#include <mavros/mavros_uas.h> | ||
|
||
#define DEG_TO_RAD (M_PI / 180.0f) | ||
|
@@ -26,66 +25,87 @@ typedef std::pair<const std::string, const Eigen::Quaterniond> OrientationPair; | |
|
||
// internal data initializer | ||
static const OrientationPair make_orientation(const std::string &name, | ||
const double roll, | ||
const double pitch, | ||
const double yaw) | ||
const double roll, | ||
const double pitch, | ||
const double yaw) | ||
{ | ||
const Eigen::Quaterniond rot = UAS::quaternion_from_rpy(Eigen::Vector3d(roll, pitch, yaw) * DEG_TO_RAD); | ||
return std::make_pair(name, rot); | ||
} | ||
|
||
/** @todo Combine the bellow with string representation */ | ||
|
||
// Note: usage of double { makes YouCompleteMe happy | ||
static const std::array<const OrientationPair, 39> sensor_orientations = {{ | ||
/* 0 */ make_orientation("", 0.0, 0.0, 0.0), | ||
/* 1 */ make_orientation("", 0.0, 0.0, 45.0), | ||
/* 2 */ make_orientation("", 0.0, 0.0, 90.0), | ||
/* 3 */ make_orientation("", 0.0, 0.0, 135.0), | ||
/* 4 */ make_orientation("", 0.0, 0.0, 180.0), | ||
/* 5 */ make_orientation("", 0.0, 0.0, 225.0), | ||
/* 6 */ make_orientation("", 0.0, 0.0, 270.0), | ||
/* 7 */ make_orientation("", 0.0, 0.0, 315.0), | ||
/* 8 */ make_orientation("", 180.0, 0.0, 0.0), | ||
/* 9 */ make_orientation("", 180.0, 0.0, 45.0), | ||
/* 10 */ make_orientation("", 180.0, 0.0, 90.0), | ||
/* 11 */ make_orientation("", 180.0, 0.0, 135.0), | ||
/* 12 */ make_orientation("", 0.0, 180.0, 0.0), | ||
/* 13 */ make_orientation("", 180.0, 0.0, 225.0), | ||
/* 14 */ make_orientation("", 180.0, 0.0, 270.0), | ||
/* 15 */ make_orientation("", 180.0, 0.0, 315.0), | ||
/* 16 */ make_orientation("", 90.0, 0.0, 0.0), | ||
/* 17 */ make_orientation("", 90.0, 0.0, 45.0), | ||
/* 18 */ make_orientation("", 90.0, 0.0, 90.0), | ||
/* 19 */ make_orientation("", 90.0, 0.0, 135.0), | ||
/* 20 */ make_orientation("", 270.0, 0.0, 0.0), | ||
/* 21 */ make_orientation("", 270.0, 0.0, 45.0), | ||
/* 22 */ make_orientation("", 270.0, 0.0, 90.0), | ||
/* 23 */ make_orientation("", 270.0, 0.0, 135.0), | ||
/* 24 */ make_orientation("", 0.0, 90.0, 0.0), | ||
/* 25 */ make_orientation("", 0.0, 270.0, 0.0), | ||
/* 26 */ make_orientation("", 0.0, 180.0, 90.0), | ||
/* 27 */ make_orientation("", 0.0, 180.0, 270.0), | ||
/* 28 */ make_orientation("", 90.0, 90.0, 0.0), | ||
/* 29 */ make_orientation("", 180.0, 90.0, 0.0), | ||
/* 30 */ make_orientation("", 270.0, 90.0, 0.0), | ||
/* 31 */ make_orientation("", 90.0, 180.0, 0.0), | ||
/* 32 */ make_orientation("", 270.0, 180.0, 0.0), | ||
/* 33 */ make_orientation("", 90.0, 270.0, 0.0), | ||
/* 34 */ make_orientation("", 180.0, 270.0, 0.0), | ||
/* 35 */ make_orientation("", 270.0, 270.0, 0.0), | ||
/* 36 */ make_orientation("", 90.0, 180.0, 90.0), | ||
/* 37 */ make_orientation("", 90.0, 0.0, 270.0), | ||
/* 38 */ make_orientation("", 315.0, 315.0, 315.0) | ||
/* 0 */ make_orientation("NONE", 0.0, 0.0, 0.0), | ||
/* 1 */ make_orientation("YAW_45", 0.0, 0.0, 45.0), | ||
/* 2 */ make_orientation("YAW_90", 0.0, 0.0, 90.0), | ||
/* 3 */ make_orientation("YAW_135", 0.0, 0.0, 135.0), | ||
/* 4 */ make_orientation("YAW_180", 0.0, 0.0, 180.0), | ||
/* 5 */ make_orientation("YAW_225", 0.0, 0.0, 225.0), | ||
/* 6 */ make_orientation("YAW_270", 0.0, 0.0, 270.0), | ||
/* 7 */ make_orientation("YAW_315", 0.0, 0.0, 315.0), | ||
/* 8 */ make_orientation("ROLL_180", 180.0, 0.0, 0.0), | ||
/* 9 */ make_orientation("ROLL_180_YAW_45", 180.0, 0.0, 45.0), | ||
/* 10 */ make_orientation("ROLL_180_YAW_90", 180.0, 0.0, 90.0), | ||
/* 11 */ make_orientation("ROLL_180_YAW_135", 180.0, 0.0, 135.0), | ||
/* 12 */ make_orientation("PITCH_180", 0.0, 180.0, 0.0), | ||
/* 13 */ make_orientation("ROLL_180_YAW_225", 180.0, 0.0, 225.0), | ||
/* 14 */ make_orientation("ROLL_180_YAW_270", 180.0, 0.0, 270.0), | ||
/* 15 */ make_orientation("ROLL_180_YAW_315", 180.0, 0.0, 315.0), | ||
/* 16 */ make_orientation("ROLL_90", 90.0, 0.0, 0.0), | ||
/* 17 */ make_orientation("ROLL_90_YAW_45", 90.0, 0.0, 45.0), | ||
/* 18 */ make_orientation("ROLL_90_YAW_90", 90.0, 0.0, 90.0), | ||
/* 19 */ make_orientation("ROLL_90_YAW_135", 90.0, 0.0, 135.0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here better to use spaces, else formatting will depend on editor. |
||
/* 20 */ make_orientation("ROLL_270", 270.0, 0.0, 0.0), | ||
/* 21 */ make_orientation("ROLL_270_YAW_45", 270.0, 0.0, 45.0), | ||
/* 22 */ make_orientation("ROLL_270_YAW_90", 270.0, 0.0, 90.0), | ||
/* 23 */ make_orientation("ROLL_270_YAW_135", 270.0, 0.0, 135.0), | ||
/* 24 */ make_orientation("PITCH_90", 0.0, 90.0, 0.0), | ||
/* 25 */ make_orientation("PITCH_270", 0.0, 270.0, 0.0), | ||
/* 26 */ make_orientation("PITCH_180_YAW_90", 0.0, 180.0, 90.0), | ||
/* 27 */ make_orientation("PITCH_180_YAW_270", 0.0, 180.0, 270.0), | ||
/* 28 */ make_orientation("ROLL_90_PITCH_90", 90.0, 90.0, 0.0), | ||
/* 29 */ make_orientation("ROLL_180_PITCH_90", 180.0, 90.0, 0.0), | ||
/* 30 */ make_orientation("ROLL_270_PITCH_90", 270.0, 90.0, 0.0), | ||
/* 31 */ make_orientation("ROLL_90_PITCH_180", 90.0, 180.0, 0.0), | ||
/* 32 */ make_orientation("ROLL_270_PITCH_180", 270.0, 180.0, 0.0), | ||
/* 33 */ make_orientation("ROLL_90_PITCH_270", 90.0, 270.0, 0.0), | ||
/* 34 */ make_orientation("ROLL_180_PITCH_270", 180.0, 270.0, 0.0), | ||
/* 35 */ make_orientation("ROLL_270_PITCH_270", 270.0, 270.0, 0.0), | ||
/* 36 */ make_orientation("ROLL_90_PITCH_180_YAW_90", 90.0, 180.0, 90.0), | ||
/* 37 */ make_orientation("ROLL_90_YAW_270", 90.0, 0.0, 270.0), | ||
/* 38 */ make_orientation("ROLL_315_PITCH_315_YAW_315", 315.0, 315.0, 315.0) | ||
}}; | ||
|
||
std::string UAS::str_sensor_orientation(MAV_SENSOR_ORIENTATION orientation) | ||
{ | ||
size_t idx = size_t(orientation); | ||
if (idx >= sensor_orientations.size()) { | ||
ROS_WARN_NAMED("uas", "SENSOR: wrong orientation index: %zu", idx); | ||
return std::to_string(idx); | ||
} | ||
|
||
return sensor_orientations[idx].first; | ||
} | ||
|
||
Eigen::Quaterniond UAS::sensor_orientation_matching(MAV_SENSOR_ORIENTATION orientation) | ||
{ | ||
size_t idx = size_t(orientation); | ||
if (idx >= sensor_orientations.size()) { | ||
ROS_WARN_NAMED("uas", "SENSOR: wrong orintation index: %zu", idx); | ||
ROS_WARN_NAMED("uas", "SENSOR: wrong orientation index: %zu", idx); | ||
return Eigen::Quaterniond::Identity(); | ||
} | ||
|
||
return sensor_orientations[idx].second; | ||
} | ||
|
||
int UAS::orientation_from_str(std::string sensor_orientation) | ||
{ | ||
int index, idx = 0; | ||
for (const auto &orientation : sensor_orientations) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you may use regular for, not foreach. for (size_t idx = 0; idx < so.size(); idx++) {
if (so[idx].first == key)
return idx;
}
// fallback
v = strtol(key); // this should not fail, so use try {} catch
// not found at all
return -1; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for (size_t idx = 0; idx < so.size(); idx++) {
if (so[idx].first == key)
return idx;
} if return -1; So I don't see why we have to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/mavlink/mavros/blob/master/mavros/src/lib/uas_stringify.cpp#L185 only makes sense because you are using a int UAS::orientation_from_str(std::string sensor_orientation)
{
for (int idx = 0; idx < sensor_orientations.size(); idx++) {
if (sensor_orientations[idx].first == sensor_orientation)
return idx;
}
return -1;
} |
||
if (orientation.first == sensor_orientation) | ||
index = idx; | ||
else | ||
index = -1; | ||
++idx; | ||
} idx = 0; | ||
return index; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ class DistanceSensorItem { | |
send_tf(false), | ||
sensor_id(0), | ||
field_of_view(0), | ||
orientation(-1), | ||
orientation("ROLL_180"), | ||
covariance(0), | ||
data_index(0) | ||
{ } | ||
|
@@ -48,7 +48,7 @@ class DistanceSensorItem { | |
uint8_t sensor_id; //!< id of the sensor | ||
double field_of_view; //!< FOV of the sensor | ||
tf::Vector3 position; //!< sensor position | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's one field that need to change type: Eigen::Vector3d. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. But please(!), instead, go to specific lines to change so to orientation handling work ok (that's the purpose of this PR). |
||
int orientation; //!< check orientation of sensor if != -1 | ||
std::string orientation;//!< check orientation of sensor if != -1 | ||
int covariance; //!< in centimeters, current specification | ||
std::string frame_id; //!< frame id for send | ||
|
||
|
@@ -191,10 +191,12 @@ class DistanceSensorPlugin : public MavRosPlugin { | |
return; | ||
} | ||
|
||
if (sensor->orientation >= 0 && dist_sen.orientation != sensor->orientation) { | ||
if (UAS::orientation_from_str(sensor->orientation) >= 0 && dist_sen.orientation != UAS::orientation_from_str(sensor->orientation)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not again! Please don't do expensive calls where you may avoid that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well yes. But sensor->orientation is supposed to be a string, that's the purpose. What do you suggest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I know what to do. Will let you know soon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave this if as is. Wrong place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not understanding this. |
||
ROS_ERROR_NAMED("distance_sensor", | ||
"DS: %s: received sensor data has different orientation (%d) than in config (%d)!", | ||
sensor->topic_name.c_str(), dist_sen.orientation, sensor->orientation); | ||
"DS: %s: received sensor data has different orientation (%s) than in config (%s)!", | ||
sensor->topic_name.c_str(), | ||
UAS::str_sensor_orientation(static_cast<MAV_SENSOR_ORIENTATION>(dist_sen.orientation)).c_str(), | ||
sensor->orientation.c_str()); | ||
} | ||
|
||
auto range = boost::make_shared<sensor_msgs::Range>(); | ||
|
@@ -263,13 +265,14 @@ void DistanceSensorItem::range_cb(const sensor_msgs::Range::ConstPtr &msg) | |
msg->range / 1E-2, | ||
type, | ||
sensor_id, | ||
orientation, | ||
UAS::orientation_from_str(orientation), | ||
covariance_); | ||
} | ||
|
||
DistanceSensorItem::Ptr DistanceSensorItem::create_item(DistanceSensorPlugin *owner, std::string topic_name) | ||
{ | ||
auto p = boost::make_shared<DistanceSensorItem>(); | ||
auto orientation_value = UAS::orientation_from_str(p->orientation); | ||
|
||
ros::NodeHandle pnh(owner->dist_nh, topic_name); | ||
|
||
|
@@ -302,7 +305,7 @@ DistanceSensorItem::Ptr DistanceSensorItem::create_item(DistanceSensorPlugin *ow | |
} | ||
|
||
// orientation check | ||
pnh.param("orientation", p->orientation, -1); | ||
pnh.param("orientation", orientation_value, -1); | ||
|
||
// optional | ||
pnh.param("send_tf", p->send_tf, false); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change
std::string sensor_orientation
toconst std::string &sensor_orientation
.Also this function should be capable convert numeric value of enum (e.g. strtol() then check & return).
That needed for backward compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? And why not also
Eigen::Quaterniond sensor_orientation_matching
?Convert to what?
MAV_SENSOR_ORIENTATION orientation
is supposed to be a number, which is used as an index to return: orientation name in case ofUAS::str_sensor_orientation()
; and orientation values in case ofUAS::sensor_orientation_matching()
. Andorientation_from_str()
was created so we can return the orientation number/index if we give the orientation name. So I think we have all the functionalities we need.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this reduces object copying. What you want change in UAS::sensor_orientation_matching()?
Because there may be lots of configs with number representation. Why not just simply try to fall back to old behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This I undestand, but:
... I can't. Can you code an example please?