Skip to content
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

ADSB Plugin #696

Closed
wants to merge 6 commits into from
Closed

ADSB Plugin #696

wants to merge 6 commits into from

Conversation

TSC21
Copy link
Member

@TSC21 TSC21 commented Apr 17, 2017

This adds a ADS-B (Automatic dependent surveillance-broadcast) wrapper so it can allow data reception/publish of modules.

  • Add handler for ADSB_VEHICLE and publish data to ROS msg - Ping RX
  • Add ROS subscriber to publish msg to FCU (in case the ADS-B system is connected offboard - pingUSB)

@TSC21 TSC21 modified the milestone: Version 0.19 Apr 17, 2017
@TSC21 TSC21 self-assigned this Apr 17, 2017
Copy link
Member

@vooon vooon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is gonna to use that plugin? Which FCU support that?

I don't want to merge plugin without a users.

@@ -35,6 +35,10 @@ namespace utils {

using mavconn::utils::format;

using mavlink::common::ADSB_ALTITUDE_TYPE;
using mavlink::common::ADSB_EMITTER_TYPE;
using mavlink::common::ADSB_FLAGS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where then? I put there so the below code in utils.h could work.

static const std::array<const std::string, 2> adsb_altitude_type_strings{{
/* 0 */ "ADSB_ALTITUDE_TYPE_PRESSURE_QNH", // Altitude reported from a Baro source using QNH reference
/* 1 */ "ADSB_ALTITUDE_TYPE_GEOMETRIC", // Altitude reported from a GNSS source
}};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADSB_ALTITUDE_TYPE_ prefix should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

}

ROS_ERROR_STREAM_NAMED("uas", "ADSB_ALTITUDE_TYPE: Unknown type: " << type);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No return - error! And what you will return if there is no requested type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion?

// for k, e in enum:
// value = e.name
// value = value.replace("ADSB_EMITTER_TYPE_",'')
// value.replace("{ename}",'')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wtf? Look at sensor orientation code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

/* 16 */ "VALID_CALLSIGN", //
/* 32 */ "VALID_SQUAWK", //
/* 64 */ "SIMULATED", //
}};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot decode bit field that way!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bit field?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind


uint32 ICAO_address
geographic_msgs/GeoPoint lla
std_msgs/String altitude_type # Type from ADSB_ALTITUDE_TYPE enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seriously?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char[]?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint16 heading # cog
uint16 hor_velocity
int16 ver_velocity
char[9] callsign # callsign, 8+null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is string!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k


std_msgs::Header header;
header.stamp = ros::Time::now();//TODO: request add time_boot_ms to msg definition
header.frame_id = frame_id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Did you use that header twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sure

char[9] callsign # callsign, 8+null
std_msgs/String emitter_type # Type from ADSB_EMITTER_TYPE enum
std_msgs/Time tslc
std_msgs/String data_status # Flags from ADSB_FLAGS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave binary data here. Who want to parse strings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more useful parsed than otherwise. For debugging and for usage. They are INFO fields...

uint16 hor_velocity
int16 ver_velocity
char[9] callsign # callsign, 8+null
std_msgs/String emitter_type # Type from ADSB_EMITTER_TYPE enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numeric.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not parse it?

@vooon vooon requested a review from mhkabir April 18, 2017 07:09
@TSC21
Copy link
Member Author

TSC21 commented Apr 18, 2017

Who is gonna to use that plugin? Which FCU support that?

Check the link. Both APM and PX4 compatible FCU. I'm buying one myself. Even useful for global planning and avoidance.

@TSC21 TSC21 force-pushed the adsb_plugin branch 7 times, most recently from da9ecab to bc373b8 Compare April 20, 2017 08:22
Copy link
Member

@vooon vooon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That to_stirng and back is completely unneeded.

@@ -65,6 +64,9 @@ std::string to_string(mavlink::common::MAV_AUTOPILOT e);
std::string to_string(mavlink::common::MAV_TYPE e);
std::string to_string(mavlink::common::MAV_STATE e);
std::string to_string(timesync_mode e);
std::string to_string(mavlink::common::ADSB_ALTITUDE_TYPE e);
std::string to_string(mavlink::common::ADSB_EMITTER_TYPE e);
std::string to_string(const uint16_t &bitmask);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! Unacceptable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for debugging purposes. it's not for msg parsing. if you just tell it is not acceptable but don't suggest a solution, it's the same as nothing...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is generic type. How you suppose to deal when another uin16_t bit field will be needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you may leave to_string for that enums.

Copy link
Member Author

@TSC21 TSC21 Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I change to

std::string flags_to_string(const uint16_t &adsb_bitmask);

is it ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Shouldn't be in lib.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Shouldn't be in lib.

Hmm ok

adsb.hor_velocity = req->hor_velocity * 1E2;
adsb.ver_velocity = req->ver_velocity * 1E2; // up is positive
mavlink::set_string(adsb.callsign, req->callsign);
adsb.emitter_type = utils::emitter_type_from_str(req->emitter_type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO!

adsb.lat = req->lla.latitude * 1E7;
adsb.lon = req->lla.longitude * 1E7;
adsb.altitude = req->lla.altitude; // in meters, TODO: #693
adsb.altitude_type = utils::alt_type_from_str(req->altitude_type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO!

adsb_msg->hor_velocity = adsb.hor_velocity / 1E2;
adsb_msg->ver_velocity = adsb.ver_velocity / 1E2; // up is positive
std::copy(adsb_callsign.cbegin(), adsb_callsign.cend(), adsb_msg->callsign.begin());
adsb_msg->emitter_type = utils::to_string(emitter_type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO!

adsb_msg->lla.latitude = adsb.lat / 1E7;
adsb_msg->lla.longitude = adsb.lon / 1E7;
adsb_msg->lla.altitude = adsb.altitude; // in meters, TODO: #693
adsb_msg->altitude_type = utils::to_string(altitude_type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO!

std_msgs/Header header

uint32 ICAO_address
geographic_msgs/GeoPoint lla
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with:

float64 latitude
float64 longitude
float32 altitude

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm following ROS conventions. Also: ros-geographic-info/geographic_info@b8043a9#commitcomment-21800531.
So don't see any problem on this. After conversion applied, everything is good


uint32 ICAO_address
geographic_msgs/GeoPoint lla
string altitude_type # Type from ADSB_ALTITUDE_TYPE enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No! Add constants to msg, and leave it integer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want me to add 29 constants to a msg just because you don't like a to_string parser on the cb?

uint16 hor_velocity
int16 ver_velocity
string callsign # callsign, 8+null
string emitter_type # Type from ADSB_EMITTER_TYPE enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integer!

@@ -22,6 +22,7 @@
<exec_depend>message_runtime</exec_depend>
<depend>std_msgs</depend>
<depend>geometry_msgs</depend>
<depend>geographic_msgs</depend>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adsb.heading = req->heading * 1E2 * 180.0f / M_PI + M_PI;
adsb.hor_velocity = req->hor_velocity * 1E2;
adsb.ver_velocity = req->ver_velocity * 1E2; // up is positive
mavlink::set_string(adsb.callsign, req->callsign);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be mavlink::set_string_z(), _z is important.
set_string() is for message fields like param_id, where '\0' may be omitted and only indicate shorter strings than buffer.
set_string_z() ensures that last byte is '\0', which required by adsb message desc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks

ros::Subscriber adsb_sub;

ADSB_ALTITUDE_TYPE altitude_type;
ADSB_EMITTER_TYPE emitter_type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what purpose that two enums are here?

int16 ver_velocity
string callsign # callsign, 8+null
uint16 emitter_type # Type from ADSB_EMITTER_TYPE enum
std_msgs/Time tslc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, again. tslc.data - you think i did not stumble at this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to convert to ros:time in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And more over, that is not time! It is duration.

tslc uint8_t Time since last communication in seconds

}

void adsb_cb(const mavros_msgs::ADSBVehicle::ConstPtr &req)
{
Copy link
Member

@vooon vooon Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ROS_DEBUG_NAMED_STREAM("adsb", "ADSB: at type " << utils::to_string(e)); For enums! Use C++ streams for std::string.
Use 0x%02x format for bit-filed.

adsb_msg->altitude_type = adsb.altitude_type;
adsb_msg->heading = adsb.heading / 1E2 / 180.0f * M_PI - M_PI;
adsb_msg->hor_velocity = adsb.hor_velocity / 1E2;
adsb_msg->ver_velocity = adsb.ver_velocity / 1E2; // up is positive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your heading, hor_, ver_velocity is int16! Check your message spec!

Copy link
Member Author

@TSC21 TSC21 Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use / 100? or 1e2?

adsb_msg->heading = adsb.heading / 1E2 / 180.0f * M_PI - M_PI;
adsb_msg->hor_velocity = adsb.hor_velocity / 1E2;
adsb_msg->ver_velocity = adsb.ver_velocity / 1E2; // up is positive
std::copy(adsb_callsign.cbegin(), adsb_callsign.cend(), adsb_msg->callsign.begin());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, man, look at available API first! mavlink::to_string()


uint32 ICAO_address
geographic_msgs/GeoPoint lla
uint16 altitude_type # Type from ADSB_ALTITUDE_TYPE enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In mavlink it is uint8_t.

@vooon vooon mentioned this pull request Apr 20, 2017
@vooon
Copy link
Member

vooon commented Apr 20, 2017

Replaced.

@vooon vooon closed this Apr 20, 2017
@TSC21 TSC21 deleted the adsb_plugin branch June 22, 2017 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants