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

Add translation of rpm uORB message to Mavlink #14863

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modules/mavlink/mavlink_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,7 @@ Mavlink::configure_streams_to_default(const char *configure_single_stream)
configure_stream_local("PING", 0.1f);
configure_stream_local("POSITION_TARGET_GLOBAL_INT", 1.0f);
configure_stream_local("POSITION_TARGET_LOCAL_NED", 1.5f);
configure_stream_local("RAW_RPM", 2.0f);
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add as well to MAVLINK_MODE_ONBOARD with an higher rate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Message added to MAVLINK_MODE_ONBOARD with 5 Hz rate. It should be enough.

configure_stream_local("RC_CHANNELS", 5.0f);
configure_stream_local("SERVO_OUTPUT_RAW_0", 1.0f);
configure_stream_local("SYS_STATUS", 1.0f);
Expand Down
74 changes: 70 additions & 4 deletions src/modules/mavlink/mavlink_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include <uORB/topics/orbit_status.h>
#include <uORB/topics/position_controller_status.h>
#include <uORB/topics/position_setpoint_triplet.h>
#include <uORB/topics/rpm.h>
#include <uORB/topics/sensor_accel_integrated.h>
#include <uORB/topics/sensor_accel_status.h>
#include <uORB/topics/sensor_baro.h>
Expand Down Expand Up @@ -2549,17 +2550,17 @@ class MavlinkStreamOdometry : public MavlinkStream
if (_mavlink->odometry_loopback_enabled()) {
odom_updated = _vodom_sub.update(&odom);
// frame matches the external vision system
msg.frame_id = MAV_FRAME_VISION_NED;
msg.frame_id = MAV_FRAME_RESERVED_16;

} else {
odom_updated = _odom_sub.update(&odom);
// frame matches the PX4 local NED frame
msg.frame_id = MAV_FRAME_ESTIM_NED;
msg.frame_id = MAV_FRAME_RESERVED_18;
}

if (odom_updated) {
msg.time_usec = odom.timestamp_sample;
msg.child_frame_id = MAV_FRAME_BODY_FRD;
msg.child_frame_id = MAV_FRAME_RESERVED_12;

// Current position
msg.x = odom.x;
Expand Down Expand Up @@ -5188,6 +5189,70 @@ class MavlinkStreamObstacleDistance : public MavlinkStream
}
};



class MavlinkStreamRawRpm : public MavlinkStream
{
public:
const char *get_name() const override
{
return MavlinkStreamRawRpm::get_name_static();
}

static constexpr const char *get_name_static()
{
return "RAW_RPM";
}

static constexpr uint16_t get_id_static()
{
return MAVLINK_MSG_ID_RAW_RPM;
}

uint16_t get_id() override
{
return get_id_static();
}

static MavlinkStream *new_instance(Mavlink *mavlink)
{
return new MavlinkStreamRawRpm(mavlink);
}

unsigned get_size() override
{
return _rpm_sub.advertised() ? MAVLINK_MSG_ID_RAW_RPM + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
}

private:
uORB::Subscription _rpm_sub{ORB_ID(rpm)};

/* do not allow top copying this class */
MavlinkStreamRawRpm(MavlinkStreamRawRpm &) = delete;
MavlinkStreamRawRpm &operator = (const MavlinkStreamRawRpm &) = delete;

protected:
explicit MavlinkStreamRawRpm(Mavlink *mavlink) : MavlinkStream(mavlink)
{}

bool send(const hrt_abstime t) override
{
rpm_s rpm;

if (_rpm_sub.update(&rpm)) {
mavlink_raw_rpm_t msg{};

msg.frequency = rpm.indicated_frequency_rpm;

mavlink_msg_raw_rpm_send_struct(_mavlink->get_channel(), &msg);

return true;
}

return false;
}
};

static const StreamListItem streams_list[] = {
create_stream_list_item<MavlinkStreamHeartbeat>(),
create_stream_list_item<MavlinkStreamStatustext>(),
Expand Down Expand Up @@ -5247,7 +5312,8 @@ static const StreamListItem streams_list[] = {
create_stream_list_item<MavlinkStreamGroundTruth>(),
create_stream_list_item<MavlinkStreamPing>(),
create_stream_list_item<MavlinkStreamOrbitStatus>(),
create_stream_list_item<MavlinkStreamObstacleDistance>()
create_stream_list_item<MavlinkStreamObstacleDistance>(),
create_stream_list_item<MavlinkStreamRawRpm>()
};

const char *get_stream_name(const uint16_t msg_id)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/mavlink/mavlink_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ MavlinkReceiver::handle_message_odometry(mavlink_message_t *msg)
* local NED frame. The angular velocity needs to be expressed in the
* body (fcu_frd) frame.
*/
if (odom.child_frame_id == MAV_FRAME_BODY_FRD) {
if (odom.child_frame_id == MAV_FRAME_RESERVED_12) {
/* Linear velocity has to be rotated to the local NED frame
* Angular velocities are already in the right body frame */
const matrix::Dcmf R_body_to_local = matrix::Dcmf(q_body_to_local);
Expand Down Expand Up @@ -1377,7 +1377,7 @@ MavlinkReceiver::handle_message_odometry(mavlink_message_t *msg)
if (odom.frame_id == MAV_FRAME_LOCAL_FRD) {
_visual_odometry_pub.publish(odometry);

} else if (odom.frame_id == MAV_FRAME_MOCAP_NED) {
} else if (odom.frame_id == MAV_FRAME_RESERVED_14) {
_mocap_odometry_pub.publish(odometry);

} else {
Expand Down